From c6f415cfdcf56573107b5a17752ea1a2e700afc7 Mon Sep 17 00:00:00 2001 From: DevSoftTech Server Date: Tue, 18 Aug 2026 03:03:59 +0530 Subject: [PATCH] fix(abdm): file consent status under the right request consent_request anchor rows only registered their HMS request_id, so reconcile rows (which carry the ABDM consent_request_id) matched nothing and fell back to the newest open session. A DENIED result therefore landed on the granted session, where GRANTED outranks it, and the denied request kept showing REQUESTED. Anchors now publish their ABDM ids, and the open-session fallback applies only when the row names no consent request or that session has not resolved its ABDM id yet. --- app/Controllers/Patient.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/app/Controllers/Patient.php b/app/Controllers/Patient.php index 72c92de..2acd04f 100644 --- a/app/Controllers/Patient.php +++ b/app/Controllers/Patient.php @@ -4530,6 +4530,7 @@ class Patient extends BaseController $order = []; $abdmIdToAnchor = []; $requestIdToAnchor = []; + $anchorHasAbdmId = []; $openAnchor = null; foreach ($chronological as $row) { @@ -4545,6 +4546,17 @@ class Patient extends BaseController if ($rowRequestId !== '') { $requestIdToAnchor[$rowRequestId] = $anchorKey; } + // Reconcile/status rows usually carry only the ABDM ids, so the + // anchor must publish its own ids too or those rows cannot match. + if ($rowAbdmConsentRequestId !== '') { + $abdmIdToAnchor[$rowAbdmConsentRequestId] = $anchorKey; + $requestIdToAnchor[$rowAbdmConsentRequestId] = $anchorKey; + $anchorHasAbdmId[$anchorKey] = true; + } + if ($rowConsentId !== '') { + $abdmIdToAnchor[$rowConsentId] = $anchorKey; + $requestIdToAnchor[$rowConsentId] = $anchorKey; + } $openAnchor = $anchorKey; continue; } @@ -4556,7 +4568,10 @@ class Patient extends BaseController $anchorKey = $requestIdToAnchor[$rowRequestId]; } elseif ($rowConsentId !== '' && isset($requestIdToAnchor[$rowConsentId])) { $anchorKey = $requestIdToAnchor[$rowConsentId]; - } elseif ($openAnchor !== null) { + } elseif ($openAnchor !== null && ($rowAbdmConsentRequestId === '' || empty($anchorHasAbdmId[$openAnchor]))) { + // Covers the first reconcile that discovers the ABDM id. A row + // naming a consent request that belongs elsewhere must not be + // guessed onto this session — that hid DENIED/EXPIRED results. $anchorKey = $openAnchor; } @@ -4575,6 +4590,7 @@ class Patient extends BaseController } if ($rowAbdmConsentRequestId !== '') { $abdmIdToAnchor[$rowAbdmConsentRequestId] = $anchorKey; + $anchorHasAbdmId[$anchorKey] = true; } if ($rowRequestId !== '') { $requestIdToAnchor[$rowRequestId] = $anchorKey;