fix(abdm): route health record push with FHIR bundle to /v3/records/push and unify care context reference format
This commit is contained in:
parent
0b048881e1
commit
092e5cd193
|
|
@ -1541,9 +1541,26 @@ class AbdmGateway extends BaseController
|
||||||
$visitDate = $visitDateRaw !== '' ? date('Y-m-d', strtotime($visitDateRaw)) : date('Y-m-d');
|
$visitDate = $visitDateRaw !== '' ? date('Y-m-d', strtotime($visitDateRaw)) : date('Y-m-d');
|
||||||
$careContextRef = trim((string) ($this->request->getPost('careContextId') ?? $this->request->getPost('care_context_reference') ?? ''));
|
$careContextRef = trim((string) ($this->request->getPost('careContextId') ?? $this->request->getPost('care_context_reference') ?? ''));
|
||||||
if ($careContextRef === '') {
|
if ($careContextRef === '') {
|
||||||
$careContextRef = $hiType === 'PrescriptionRecord'
|
$existingCcRef = '';
|
||||||
? 'PRESCRIPTION-' . $opdId . '-S' . ($sessionForRef > 0 ? $sessionForRef : 0) . '-' . $visitDate
|
if ($this->db->tableExists('health_records')) {
|
||||||
: 'OPD-' . $opdId . '-S' . ($sessionForRef > 0 ? $sessionForRef : 0) . '-' . $visitDate;
|
$existingHrRow = $this->db->table('health_records')
|
||||||
|
->select('care_context_reference')
|
||||||
|
->where('entity_type', 'opd')
|
||||||
|
->where('entity_id', (string) $opdId)
|
||||||
|
->where('care_context_reference !=', '')
|
||||||
|
->orderBy('id', 'DESC')
|
||||||
|
->get(1)
|
||||||
|
->getRowArray();
|
||||||
|
if (! empty($existingHrRow['care_context_reference'])) {
|
||||||
|
$existingCcRef = trim((string) $existingHrRow['care_context_reference']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($existingCcRef !== '') {
|
||||||
|
$careContextRef = $existingCcRef;
|
||||||
|
} else {
|
||||||
|
$dateClean = str_replace('-', '', $visitDate);
|
||||||
|
$careContextRef = 'OPD-' . $patientId . '-S' . ($sessionForRef > 0 ? $sessionForRef : 0) . '-' . $dateClean;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$careContextDisplay = $hiType === 'PrescriptionRecord'
|
$careContextDisplay = $hiType === 'PrescriptionRecord'
|
||||||
? 'Prescription - ' . $visitDate
|
? 'Prescription - ' . $visitDate
|
||||||
|
|
|
||||||
|
|
@ -1393,10 +1393,34 @@ class EAtriaBridgeConnector implements AbdmConnectorInterface
|
||||||
$effectiveAbha = $abhaAddress !== '' ? $abhaAddress : $abhaId;
|
$effectiveAbha = $abhaAddress !== '' ? $abhaAddress : $abhaId;
|
||||||
$visitDate = (string) ($data['visit_date'] ?? date('Y-m-d'));
|
$visitDate = (string) ($data['visit_date'] ?? date('Y-m-d'));
|
||||||
|
|
||||||
// Under M3 On-Demand Fetch architecture, full FHIR records are NOT sent to the Bridge.
|
$bundle = $data['record_data'] ?? $data['fhir_bundle'] ?? null;
|
||||||
// Instead, only Care Context metadata is registered with the ABDM Bridge (/v3/hip/link/notify).
|
if (! empty($bundle) && is_array($bundle)) {
|
||||||
// The complete FHIR Document Bundle stays securely inside HMS (health_records table)
|
// When a FHIR bundle is attached, push to /api/v3/records/push so the bridge
|
||||||
// and is served on-demand when the Bridge calls POST /records/fetch upon patient consent.
|
// validates the FHIR resources and holds the bundle for on-demand patient fetch.
|
||||||
|
$recordPushPayload = [
|
||||||
|
'hfr_id' => $this->hfrId,
|
||||||
|
'patient_id' => (string) ($data['patient_id'] ?? ''),
|
||||||
|
'patient_name' => $patientName,
|
||||||
|
'abha_address' => $effectiveAbha,
|
||||||
|
'care_context_reference' => $careContextReference,
|
||||||
|
'care_context_display' => $careContextDisplay,
|
||||||
|
'hi_type' => $hiType,
|
||||||
|
'visit_date' => $visitDate,
|
||||||
|
'fhir_bundle' => $bundle,
|
||||||
|
'record_data' => $bundle,
|
||||||
|
];
|
||||||
|
if ($this->bridgeHospitalId !== '') {
|
||||||
|
$recordPushPayload['hospital_id'] = $this->bridgeHospitalId;
|
||||||
|
}
|
||||||
|
if ($abhaId !== '') {
|
||||||
|
$recordPushPayload['abha_id'] = $abhaId;
|
||||||
|
}
|
||||||
|
|
||||||
|
$res = $this->post('/v3/records/push', $recordPushPayload);
|
||||||
|
return self::normalizePushRecordResponse($res);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Care-context only metadata registration
|
||||||
$notifyPayload = [
|
$notifyPayload = [
|
||||||
'hfr_id' => $this->hfrId,
|
'hfr_id' => $this->hfrId,
|
||||||
'hospital_id' => $this->bridgeHospitalId,
|
'hospital_id' => $this->bridgeHospitalId,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user