Support Method 3 (fetch by abha_address) as fallback to surface historical ABDM records

Per bridge gateway team guidance, GET /v1/hiu/data/fetch?abha_address=... returns ALL historical decrypted records across every past consent for a patient, unlike the consent/request-scoped Methods 1/2 previously used exclusively. Added M3HiuWorkflowService support for a fetch_by_abha_address flag on the data_fetch operation, and wired abdm_content_fetch_only() to automatically fall back to this broader lookup when the consent-scoped fetch finds nothing new -- this surfaced 14 previously-invisible historical documents (consultation reports, pathology/cytology) for the test patient that were never being fetched before.
This commit is contained in:
DevSoftTech Server 2026-07-29 02:19:56 +05:30
parent 690dbf9572
commit c87928c2bc
2 changed files with 56 additions and 0 deletions

View File

@ -2070,6 +2070,40 @@ class Patient extends BaseController
$documentsPersisted = (int) ($fetchResult['documents_persisted'] ?? 0);
$documentsUpdated = (int) ($fetchResult['documents_updated'] ?? 0);
// The consent-artifact-scoped fetch above (bridge "Method 1/2") only
// returns data for the ONE consent/request we targeted. Per the bridge
// gateway team, GET /v1/hiu/data/fetch?abha_address=... ("Method 3")
// separately returns ALL historical decrypted records already available
// at the bridge across every past consent for this patient. If the
// consent-scoped call above found nothing new, fall back to this
// broader by-ABHA-address lookup before telling the user there is
// truly nothing to fetch yet.
if ($documentsPersisted + $documentsUpdated === 0) {
try {
$abhaFetchResult = $service->runOperation('data_fetch', [
'abha_address' => $abhaContext['abha_address'],
'fetch_by_abha_address' => 1,
]);
} catch (\Throwable $e) {
$abhaFetchResult = null;
}
if (is_array($abhaFetchResult) && (int) ($abhaFetchResult['ok'] ?? 0) === 1) {
$abhaDocumentsPersisted = (int) ($abhaFetchResult['documents_persisted'] ?? 0);
$abhaDocumentsUpdated = (int) ($abhaFetchResult['documents_updated'] ?? 0);
if ($abhaDocumentsPersisted + $abhaDocumentsUpdated > 0) {
return $this->response->setJSON([
'ok' => 1,
'phase' => 'COMPLETED',
'message' => 'Records fetched successfully from historical ABDM records for this ABHA address.',
'documents_persisted' => $abhaDocumentsPersisted,
'documents_updated' => $abhaDocumentsUpdated,
'data' => ['data_fetch' => $fetchResult, 'data_fetch_by_abha_address' => $abhaFetchResult],
]);
}
}
}
if ($documentsPersisted + $documentsUpdated === 0) {
return $this->response->setJSON([
'ok' => 1,

View File

@ -976,6 +976,28 @@ class M3HiuWorkflowService
}
if ($operation === 'data_fetch') {
// Method 3 (per bridge gateway team, 2026-07-29): GET /v1/hiu/data/fetch
// ?abha_address=... returns ALL historical decrypted records across every
// past consent for the patient, instead of only the single consent/request
// targeted by Methods 1/2. Callers opt into this broader lookup explicitly
// (fetch_by_abha_address=1) since it is not scoped to one consent artifact.
$fetchByAbha = (int) ($clean['fetch_by_abha_address'] ?? 0) === 1;
if ($fetchByAbha) {
$abhaAddress = trim((string) ($clean['abha_address'] ?? ''));
if ($abhaAddress === '') {
return [
'ok' => 0,
'http_code' => 422,
'error_text' => 'abha_address is required to fetch all historical records by ABHA address.',
];
}
return [
'ok' => 1,
'payload' => ['abha_address' => $abhaAddress],
];
}
$requestFallback = '';
if (! $requestIdGenerated) {
$requestFallback = trim((string) (