From 33fc87ac8804177e86a94b45ab5390a8a8114ae1 Mon Sep 17 00:00:00 2001 From: DevSoftTech Server Date: Mon, 1 Jun 2026 13:29:10 +0530 Subject: [PATCH] Fix OPD FHIR submit record reference --- app/Controllers/Opd_prescription.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/Controllers/Opd_prescription.php b/app/Controllers/Opd_prescription.php index 8fa36c3..752c753 100644 --- a/app/Controllers/Opd_prescription.php +++ b/app/Controllers/Opd_prescription.php @@ -5234,6 +5234,13 @@ class Opd_prescription extends BaseController ]); } + $recordRefId = $sessionId > 0 + ? $sessionId + : (int) ($bundleRow['opd_session_id'] ?? ($bundleRow['id'] ?? 0)); + if ($recordRefId <= 0) { + $recordRefId = (int) ($bundleRow['id'] ?? $opdId); + } + // Gather patient / OPD context for the push payload $patientId = 0; $patientName = ''; @@ -5298,7 +5305,7 @@ class Opd_prescription extends BaseController // care_context_reference must be unique per visit in ABDM spec. // Use OPD-{id}-{session} so the reference stays stable for a specific saved record. - $ccRef = 'OPD-' . $opdId . '-' . $recordId; + $ccRef = 'OPD-' . $opdId . '-' . $recordRefId; $pushData = [ 'patient_id' => (string) $patientId, @@ -5309,7 +5316,7 @@ class Opd_prescription extends BaseController 'care_context_reference' => $ccRef, 'care_context_display' => $displayLabel, 'notes' => $displayLabel, - 'queue_id' => 'OPD-' . $opdId . '-' . $recordId, + 'queue_id' => 'OPD-' . $opdId . '-' . $recordRefId, 'abha_address' => $abhaId, 'record_data' => $bundle, ];