From 204b5f22c60e06dab1c0099a6e0d0d5e3dd14c07 Mon Sep 17 00:00:00 2001 From: DevSoftTech Server Date: Thu, 8 Oct 2026 09:56:48 +0530 Subject: [PATCH] feat(abdm): make recordsFetch body and reference parsing fully resilient --- app/Controllers/AbdmGateway.php | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/app/Controllers/AbdmGateway.php b/app/Controllers/AbdmGateway.php index 8311835..a7bf2f5 100644 --- a/app/Controllers/AbdmGateway.php +++ b/app/Controllers/AbdmGateway.php @@ -5053,19 +5053,37 @@ class AbdmGateway extends BaseController ]); } + $body = []; try { $body = $this->request->getJSON(true) ?: []; } catch (\Throwable) { - $rawBody = (string) $this->request->getBody(); - $body = json_decode($rawBody, true) ?: []; } - $careContextRefs = $body['careContextReferences'] ?? []; - if (empty($careContextRefs) && !empty($body['careContextReference'])) { + if (empty($body)) { + $rawBody = (string) $this->request->getBody(); + if ($rawBody !== '') { + $body = json_decode($rawBody, true) ?: []; + } + } + if (empty($body) && method_exists($this->request, 'getPost')) { + $body = $this->request->getPost() ?: []; + } + + $careContextRefs = $body['careContextReferences'] ?? $body['care_context_references'] ?? $body['care_contexts'] ?? []; + if (! is_array($careContextRefs) && is_string($careContextRefs)) { + $careContextRefs = [$careContextRefs]; + } + if (empty($careContextRefs) && ! empty($body['careContextReference'])) { $careContextRefs = [$body['careContextReference']]; } - if (empty($careContextRefs) && !empty($body['careContextId'])) { + if (empty($careContextRefs) && ! empty($body['care_context_reference'])) { + $careContextRefs = [$body['care_context_reference']]; + } + if (empty($careContextRefs) && ! empty($body['careContextId'])) { $careContextRefs = [$body['careContextId']]; } + if (empty($careContextRefs) && ! empty($body['care_context_id'])) { + $careContextRefs = [$body['care_context_id']]; + } if (empty($careContextRefs) && $careContextId !== null && trim($careContextId) !== '') { $careContextRefs = [trim($careContextId)]; }