fix(abdm): preserve GRANTED status for completed consent sessions on reopen

This commit is contained in:
DevSoftTech Server 2026-10-08 20:27:47 +05:30
parent 31352156c9
commit 92acaee56f
2 changed files with 23 additions and 11 deletions

View File

@ -5572,10 +5572,10 @@ class Patient extends BaseController
} elseif ($rawConsentStatus === 'DENIED') { } elseif ($rawConsentStatus === 'DENIED') {
$phase = 'DENIED'; $phase = 'DENIED';
$priority = 300; $priority = 300;
} elseif ($state === 'DATA_RECEIVED') { } elseif (in_array($state, ['DATA_RECEIVED', 'COMPLETED'], true)) {
$phase = 'COMPLETED'; $phase = 'GRANTED';
$priority = 480; $priority = 480;
} elseif ($state === 'GRANTED') { } elseif (in_array($state, ['GRANTED', 'APPROVED', 'ACTIVE'], true)) {
$phase = 'GRANTED'; $phase = 'GRANTED';
$priority = 420; $priority = 420;
} elseif ($state === 'REVOKED') { } elseif ($state === 'REVOKED') {
@ -5797,14 +5797,24 @@ class Patient extends BaseController
} }
} }
// A status stamped directly onto this request row by a live status check // A status stamped directly onto this request row by a live status check or workflow completion
// is authoritative: it names this exact consent request, unlike separate // is authoritative: it names this exact consent request.
// reconcile rows that have to be correlated back to a session.
$anchorState = strtoupper(trim((string) (is_array($consentRequestRow) ? ($consentRequestRow['workflow_state'] ?? '') : ''))); $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; $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" // A short, human-friendly identifier for this session (the "Request ID"
// guid is too long to display in a table column) -- use the underlying // 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 // abdm_hiu_workflows row id of this session's own CONSENT_REQUEST row

View File

@ -421,10 +421,10 @@ class ConsentSessionListService
} elseif ($rawConsentStatus === 'DENIED') { } elseif ($rawConsentStatus === 'DENIED') {
$phase = 'DENIED'; $phase = 'DENIED';
$priority = 300; $priority = 300;
} elseif ($state === 'DATA_RECEIVED') { } elseif (in_array($state, ['DATA_RECEIVED', 'COMPLETED'], true)) {
$phase = 'COMPLETED'; $phase = 'GRANTED';
$priority = 480; $priority = 480;
} elseif ($state === 'GRANTED') { } elseif (in_array($state, ['GRANTED', 'APPROVED', 'ACTIVE'], true)) {
$phase = 'GRANTED'; $phase = 'GRANTED';
$priority = 420; $priority = 420;
} elseif ($state === 'REVOKED') { } elseif ($state === 'REVOKED') {
@ -564,7 +564,9 @@ class ConsentSessionListService
} }
$anchorState = strtoupper(trim((string) (is_array($consentRequestRow) ? ($consentRequestRow['workflow_state'] ?? '') : ''))); $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; $phase = $anchorState;
} }