diff --git a/app/Controllers/Opd_prescription.php b/app/Controllers/Opd_prescription.php index 0bf584f..317976b 100644 --- a/app/Controllers/Opd_prescription.php +++ b/app/Controllers/Opd_prescription.php @@ -4,7 +4,6 @@ namespace App\Controllers; use App\Controllers\BaseController; use App\Libraries\AbdmWorkTaskService; -use App\Libraries\BridgeSyncService; use App\Libraries\CsnotkTerminologyService; use App\Models\OpdMedicineModel; use CodeIgniter\I18n\Time; @@ -11490,25 +11489,13 @@ class Opd_prescription extends BaseController return false; } - try { - $documentId = (int) $this->db->insertID(); - $bridgeSync = new BridgeSyncService(); - $bridgeSync->enqueue( - 'opd.fhir.generated', - [ - 'opd_fhir_document_id' => $documentId, - 'opd_id' => $opdId, - 'opd_session_id' => $sessionId, - 'bundle_type' => 'OPConsultRecord', - 'generated_by' => $generatedBy, - 'generated_at' => Time::now('Asia/Kolkata')->toDateTimeString(), - 'bundle_json' => $bundle, - ], - 'opd_fhir_document', - (string) $documentId - ); - } catch (\Throwable $e) { - } + // NOTE: Do NOT also enqueue an 'opd.fhir.generated' bridge_sync_queue event here. + // That event type has no 'abdm.'/'snomed.'/'nhcx.' prefix, so BridgeSyncService + // routes it to the generic CSNOtk terminology bridge (BRIDGE_SYNC_URL), which has + // no handler for it and always returns HTTP 404 -- it has no consumer anywhere in + // this codebase. The bundle is already persisted to opd_fhir_documents above; actual + // ABDM sharing is triggered separately via DreamsoftConnector::sharePrescriptionBundle() + // (event 'abdm.fhir.share.requested'), which correctly routes to ABDM_BRIDGE_URL. return true; } diff --git a/app/Controllers/Patient.php b/app/Controllers/Patient.php index 86cfc6d..b7c98da 100644 --- a/app/Controllers/Patient.php +++ b/app/Controllers/Patient.php @@ -1817,9 +1817,22 @@ class Patient extends BaseController if ((int) ($reconcileResult['ok'] ?? 0) !== 1) { $errorText = trim((string) ($reconcileResult['error_text'] ?? 'Consent status check failed.')); $httpCode = (int) ($reconcileResult['http_code'] ?? 422); - $isNonFatalPending = $httpCode === 404 + // Bridge uses several different wordings for "this reference doesn't + // resolve to a session yet" depending on which lookup key was sent + // (request_id vs consentRequestId vs consentId) -- e.g. "Consent + // record not found", "NOT_FOUND", or "No HIU sessions found matching + // the criteria". Treat all of these as non-fatal/still-pending + // (bridge just hasn't indexed the session under that key yet) rather + // than surfacing a hard "Auto flow failed" error to the user, which + // was happening repeatedly because only the first two wordings were + // recognized. Also accept 400 alongside 404 since the bridge doesn't + // consistently use 404 for this class of response. + $isNonFatalPending = in_array($httpCode, [400, 404], true) && (stripos($errorText, 'Consent record not found') !== false - || stripos($errorText, 'NOT_FOUND') !== false); + || stripos($errorText, 'NOT_FOUND') !== false + || stripos($errorText, 'No HIU sessions found') !== false + || stripos($errorText, 'no sessions found') !== false + || stripos($errorText, 'matching the criteria') !== false); if ($isNonFatalPending) { $fallbackLookup = [