Fix auto-flow false failures and remove dead opd.fhir.generated bridge event

- Patient.php: broaden non-fatal-pending detection in abdm_content_auto_flow() to recognize more bridge error wordings (No HIU sessions found / matching the criteria) and HTTP 400, stopping spurious 'Auto flow failed' toasts.
- Opd_prescription.php: remove dead opd.fhir.generated bridge_sync_queue enqueue in storePrescriptionFhirBundle(). This unprefixed event type routed to the CSNOtk terminology bridge which has no consumer for it, always 404ing. Real ABDM sharing already works via DreamsoftConnector::sharePrescriptionBundle() (abdm.fhir.share.requested).
This commit is contained in:
DevSoftTech Server 2026-07-30 06:25:45 +05:30
parent 55bcaa7d09
commit b7f789b1c3
2 changed files with 22 additions and 22 deletions

View File

@ -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;
}

View File

@ -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 = [