diff --git a/app/Controllers/Patient.php b/app/Controllers/Patient.php index 550522a..76eee82 100644 --- a/app/Controllers/Patient.php +++ b/app/Controllers/Patient.php @@ -1594,6 +1594,7 @@ class Patient extends BaseController 'phase' => 'REQUESTED', // Avoid repeated not-found polling loops against bridge. 'poll_again' => 0, + 'reset_request_id' => 1, 'request_id' => $flowRefId, 'message' => 'Consent status not found on bridge for this request yet. Please retry sync after 1-2 minutes.', 'data' => [ @@ -2950,6 +2951,7 @@ class Patient extends BaseController 'updated_at' => '', 'operation' => '', 'status' => '', + 'restart_required' => false, ]; $abhaAddress = trim($abhaAddress); @@ -3102,6 +3104,11 @@ class Patient extends BaseController $snapshot['updated_at'] = (string) ($best['updated_at'] ?? ''); $snapshot['operation'] = (string) ($best['operation'] ?? ''); $snapshot['status'] = (string) ($best['status'] ?? ''); + $snapshot['restart_required'] = (bool) ( + ($snapshot['phase'] === 'REQUESTED') + && ($snapshot['status'] === 'failed') + && stripos((string) ($snapshot['message'] ?? ''), 'not found on bridge') !== false + ); return $snapshot; } diff --git a/app/Views/billing/Patient_Profile_Opd_V.php b/app/Views/billing/Patient_Profile_Opd_V.php index 1960b1b..7dbf779 100644 --- a/app/Views/billing/Patient_Profile_Opd_V.php +++ b/app/Views/billing/Patient_Profile_Opd_V.php @@ -408,6 +408,7 @@ $(function() { var autoFlowRequestId = ''; var autoFlowAttempts = 0; var autoFlowMaxAttempts = 15; + var autoFlowNeedsFreshRequest = false; var zoom = 1; var minZoom = 0.5; @@ -609,7 +610,8 @@ $(function() { var lastSync = data.last_sync || null; if (lastSync && (lastSync.request_id || '').toString().trim() !== '') { - autoFlowRequestId = (lastSync.request_id || '').toString().trim(); + autoFlowRequestId = lastSync.restart_required ? '' : (lastSync.request_id || '').toString().trim(); + autoFlowNeedsFreshRequest = !!lastSync.restart_required; } var lastPhase = lastSync ? (lastSync.phase || '').toString().toUpperCase() : ''; @@ -694,6 +696,7 @@ $(function() { autoFlowRequestId = (data.request_id || autoFlowRequestId || '').toString(); var phase = (data.phase || '').toString(); var msg = (data.message || '').toString(); + var resetRequestId = Number(data.reset_request_id || 0) === 1; var info = msg !== '' ? msg : ('Phase: ' + (phase || 'UNKNOWN')); if (phase === 'COMPLETED') { @@ -706,6 +709,16 @@ $(function() { $('#abdmStatusBox').removeClass('text-danger').addClass('text-muted').text(info + (autoFlowRequestId ? (' | Request ID: ' + autoFlowRequestId) : '')); + if (resetRequestId) { + autoFlowNeedsFreshRequest = true; + autoFlowRequestId = ''; + if (autoFlowAttempts < autoFlowMaxAttempts) { + autoFlowAttempts += 1; + autoFlowTimer = setTimeout(runAutoFlowStep, 1200); + return; + } + } + var shouldPoll = Number(data.poll_again || 0) === 1; if (shouldPoll && autoFlowAttempts < autoFlowMaxAttempts) { autoFlowAttempts += 1; @@ -771,6 +784,10 @@ $(function() { } stopAutoFlowLoop(); autoFlowAttempts = 0; + if (autoFlowNeedsFreshRequest) { + autoFlowRequestId = ''; + autoFlowNeedsFreshRequest = false; + } setFlowProgress(1); $btn.prop('disabled', true).text('Sync Running...'); $('#abdmStatusBox').removeClass('text-danger').addClass('text-muted').text('Starting one-click sync flow...');