From 92acaee56f481065bfe5958a3b4290704678a701 Mon Sep 17 00:00:00 2001 From: DevSoftTech Server Date: Thu, 8 Oct 2026 20:27:47 +0530 Subject: [PATCH] fix(abdm): preserve GRANTED status for completed consent sessions on reopen --- app/Controllers/Patient.php | 24 +++++++++++++------ .../Abdm/ConsentSessionListService.php | 10 ++++---- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/app/Controllers/Patient.php b/app/Controllers/Patient.php index 014f111..8405e22 100644 --- a/app/Controllers/Patient.php +++ b/app/Controllers/Patient.php @@ -5572,10 +5572,10 @@ class Patient extends BaseController } elseif ($rawConsentStatus === 'DENIED') { $phase = 'DENIED'; $priority = 300; - } elseif ($state === 'DATA_RECEIVED') { - $phase = 'COMPLETED'; + } elseif (in_array($state, ['DATA_RECEIVED', 'COMPLETED'], true)) { + $phase = 'GRANTED'; $priority = 480; - } elseif ($state === 'GRANTED') { + } elseif (in_array($state, ['GRANTED', 'APPROVED', 'ACTIVE'], true)) { $phase = 'GRANTED'; $priority = 420; } elseif ($state === 'REVOKED') { @@ -5797,14 +5797,24 @@ class Patient extends BaseController } } - // A status stamped directly onto this request row by a live status check - // is authoritative: it names this exact consent request, unlike separate - // reconcile rows that have to be correlated back to a session. + // A status stamped directly onto this request row by a live status check or workflow completion + // is authoritative: it names this exact consent request. $anchorState = strtoupper(trim((string) (is_array($consentRequestRow) ? ($consentRequestRow['workflow_state'] ?? '') : ''))); - if (in_array($anchorState, ['EXPIRED', 'DENIED', 'REVOKED'], true)) { + if (in_array($anchorState, ['GRANTED', 'APPROVED', 'ACTIVE', 'COMPLETED'], true)) { + $phase = 'GRANTED'; + } elseif (in_array($anchorState, ['EXPIRED', 'DENIED', 'REVOKED'], true)) { $phase = $anchorState; } + // If documents have already been fetched and saved in abdm_hiu_documents for this session, + // the consent is definitively granted and active. + if (! in_array($phase, ['GRANTED', 'COMPLETED', 'EXPIRED', 'DENIED', 'REVOKED'], true)) { + $lookupRef = $consentRequestId !== '' ? $consentRequestId : $consentId; + if ($lookupRef !== '' && $this->countAbdmDocumentsForPatient((int) ($patientRow['id'] ?? 0), $lookupRef) > 0) { + $phase = 'GRANTED'; + } + } + // A short, human-friendly identifier for this session (the "Request ID" // guid is too long to display in a table column) -- use the underlying // abdm_hiu_workflows row id of this session's own CONSENT_REQUEST row diff --git a/app/Libraries/Abdm/ConsentSessionListService.php b/app/Libraries/Abdm/ConsentSessionListService.php index 376e502..3a4d51b 100644 --- a/app/Libraries/Abdm/ConsentSessionListService.php +++ b/app/Libraries/Abdm/ConsentSessionListService.php @@ -421,10 +421,10 @@ class ConsentSessionListService } elseif ($rawConsentStatus === 'DENIED') { $phase = 'DENIED'; $priority = 300; - } elseif ($state === 'DATA_RECEIVED') { - $phase = 'COMPLETED'; + } elseif (in_array($state, ['DATA_RECEIVED', 'COMPLETED'], true)) { + $phase = 'GRANTED'; $priority = 480; - } elseif ($state === 'GRANTED') { + } elseif (in_array($state, ['GRANTED', 'APPROVED', 'ACTIVE'], true)) { $phase = 'GRANTED'; $priority = 420; } elseif ($state === 'REVOKED') { @@ -564,7 +564,9 @@ class ConsentSessionListService } $anchorState = strtoupper(trim((string) (is_array($consentRequestRow) ? ($consentRequestRow['workflow_state'] ?? '') : ''))); - if (in_array($anchorState, ['EXPIRED', 'DENIED', 'REVOKED'], true)) { + if (in_array($anchorState, ['GRANTED', 'APPROVED', 'ACTIVE', 'COMPLETED'], true)) { + $phase = 'GRANTED'; + } elseif (in_array($anchorState, ['EXPIRED', 'DENIED', 'REVOKED'], true)) { $phase = $anchorState; }