diff --git a/app/Controllers/Opd_prescription.php b/app/Controllers/Opd_prescription.php index afc1d4d..36482df 100644 --- a/app/Controllers/Opd_prescription.php +++ b/app/Controllers/Opd_prescription.php @@ -5234,13 +5234,6 @@ 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 = ''; @@ -5303,20 +5296,19 @@ class Opd_prescription extends BaseController $visitLabel = $visitDate !== '' ? date('d M Y', strtotime($visitDate)) : date('d M Y'); $displayLabel = 'OPD Visit ' . $visitLabel . ($doctorName !== '' ? ' - Dr. ' . $doctorName : ''); - // 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 . '-' . $recordRefId; + // Keep a stable OPD visit reference keyed by visit date for ABDM care-context linkage. + $ccRef = 'OPD-' . $opdId . '-' . $visitDate; $pushData = [ 'patient_id' => (string) $patientId, 'patient_name' => $patientName, - 'record_type' => 'PrescriptionRecord', - 'hi_type' => 'PrescriptionRecord', + 'record_type' => 'OPConsultRecord', + 'hi_type' => 'OPConsultRecord', 'visit_date' => $visitDate, 'care_context_reference' => $ccRef, 'care_context_display' => $displayLabel, 'notes' => $displayLabel, - 'queue_id' => 'OPD-' . $opdId . '-' . $recordRefId, + 'queue_id' => $ccRef, 'abha_address' => $abhaId, 'record_data' => $bundle, ]; diff --git a/app/Libraries/Abdm/EAtriaBridgeConnector.php b/app/Libraries/Abdm/EAtriaBridgeConnector.php index 868f3c0..49fef36 100644 --- a/app/Libraries/Abdm/EAtriaBridgeConnector.php +++ b/app/Libraries/Abdm/EAtriaBridgeConnector.php @@ -422,6 +422,12 @@ class EAtriaBridgeConnector implements AbdmConnectorInterface 'queue_id' => $queueId, ]; + // Also send ABDM-style careContexts wrapper so consent linkage remains explicit. + $body['careContexts'] = [[ + 'careContextReference' => $careContextReference, + 'description' => $careContextDisplay, + ]]; + // hfr_id is required in every push request alongside the Bearer token. if ($this->hfrId !== '') { $body['hfr_id'] = $this->hfrId;