diff --git a/app/Controllers/Abha.php b/app/Controllers/Abha.php index 5f958d7..f7f9d35 100644 --- a/app/Controllers/Abha.php +++ b/app/Controllers/Abha.php @@ -25,6 +25,7 @@ class Abha extends BaseController $aadhaar = preg_replace('/\D/', '', trim((string) ($this->request->getPost('aadhaar') ?? ''))); $authType = trim((string) ($this->request->getPost('auth_type') ?? 'aadhaar_otp')); $consent = $this->request->getPost('consent'); + $beneficiaryName = trim((string) ($this->request->getPost('beneficiary_name') ?? '')); if (strlen($aadhaar) !== 12 || ! $this->validateVerhoeff($aadhaar)) { return $this->response->setJSON(['ok' => 0, 'error_text' => 'Aadhaar Number is not valid. Valid 12-digit Aadhaar number is required.']); @@ -47,6 +48,9 @@ class Abha extends BaseController // later for local-patient name/age/gender/aadhaar matching (never sent to browser). if ($txnId) { session()->set('abha_aadhaar_txn_' . $txnId, $aadhaar); + if ($beneficiaryName !== '') { + session()->set('abha_beneficiary_' . $txnId, $beneficiaryName); + } } return $this->response->setJSON([ 'ok' => 1, @@ -102,10 +106,7 @@ class Abha extends BaseController if (empty($result['ok']) || $result['ok'] != 1) { $requestId = trim((string) ($result['request_id'] ?? '')); - $errorText = $this->extractBridgeErrorText($result, 'Please enter a valid OTP. Entered OTP is either expired or incorrect.'); - if ($requestId !== '') { - $errorText .= ' (Bridge Request ID: ' . $requestId . ')'; - } + $errorText = $this->extractBridgeErrorText($result, 'Incorrect OTP'); return $this->response->setJSON([ 'ok' => 0, 'error_text' => $errorText, @@ -1669,7 +1670,22 @@ class Abha extends BaseController if (stripos($trimmed, 'loginId') !== false && stripos($trimmed, 'invalid') !== false) { return 'Aadhaar Number is not valid. Valid 12-digit Aadhaar number is required.'; } - return $trimmed; + // Normalize ABDM/UIDAI OTP errors: replace technical error codes with clear user-friendly messages (ABDM M1) + if (preg_match('/(?:UIDAI Error code\s*:\s*403|attempts for OTP match is exceeded|max(?:imum)? number of attempts.*exceeded)/i', $trimmed)) { + return 'Incorrect OTP. Maximum number of attempts exceeded. Please generate a fresh OTP and try again.'; + } + if (preg_match('/(?:UIDAI Error code\s*:\s*400|Invalid (?:Aadhaar )?OTP value|Invalid OTP|Incorrect OTP|OTP mismatch|OTP.*not valid|OTP.*either expired or incorrect)/i', $trimmed)) { + return 'Incorrect OTP'; + } + // Strip raw technical error code prefixes (e.g. ABDM-1204 : or UIDAI Error code : 400 :) + $cleaned = preg_replace('/^(?:ABDM-\d+\s*:\s*)?(?:UIDAI Error code\s*:\s*\d+\s*:\s*)?/i', '', $trimmed); + if (preg_match('/(?:invalid.*otp|incorrect.*otp|otp.*invalid|otp.*incorrect|otp.*match)/i', $cleaned)) { + if (preg_match('/(?:attempts|exceeded|403)/i', $cleaned)) { + return 'Incorrect OTP. Maximum number of attempts exceeded. Please generate a fresh OTP and try again.'; + } + return 'Incorrect OTP'; + } + return $cleaned; } } @@ -1691,6 +1707,10 @@ class Abha extends BaseController $fieldMsg = trim($message); if (strcasecmp($field, 'loginId') === 0 && stripos($fieldMsg, 'invalid') !== false) { $fieldErrors[] = 'Aadhaar Number is not valid. Valid 12-digit Aadhaar number is required.'; + } elseif (preg_match('/(?:attempts.*exceeded|403)/i', $fieldMsg)) { + $fieldErrors[] = 'Incorrect OTP. Maximum number of attempts exceeded. Please generate a fresh OTP and try again.'; + } elseif (preg_match('/(?:invalid.*otp|incorrect.*otp|otp.*match)/i', $fieldMsg)) { + $fieldErrors[] = 'Incorrect OTP'; } else { $fieldErrors[] = $field . ': ' . $fieldMsg; } @@ -1700,6 +1720,10 @@ class Abha extends BaseController return implode('; ', $fieldErrors); } + if (preg_match('/(?:invalid.*otp|incorrect.*otp|otp.*expired)/i', $fallback)) { + return 'Incorrect OTP'; + } + return $fallback; } diff --git a/app/Views/billing/Patient_V.php b/app/Views/billing/Patient_V.php index c9a13c4..03362b8 100644 --- a/app/Views/billing/Patient_V.php +++ b/app/Views/billing/Patient_V.php @@ -844,10 +844,22 @@ for (var i = 0; i < candidates.length; i++) { if (typeof candidates[i] === 'string' && candidates[i].trim() !== '') { - return candidates[i].trim(); + var val = candidates[i].trim(); + if (/UIDAI Error code/i.test(val) || /ABDM-1204/i.test(val) || /attempts.*exceeded/i.test(val) || /invalid.*otp/i.test(val) || /incorrect.*otp/i.test(val) || /otp.*match/i.test(val) || /otp.*expired/i.test(val)) { + if (/attempts.*exceeded/i.test(val) || /403/.test(val)) { + return 'Incorrect OTP. Maximum number of attempts exceeded. Please generate a fresh OTP and try again.'; + } + return 'Incorrect OTP'; + } + val = val.replace(/\s*\(Bridge Request ID:[^)]*\)/gi, '').replace(/^ABDM-\d+\s*:\s*/i, ''); + return val; } } + if (/invalid.*otp|incorrect.*otp/i.test(fallbackText)) { + return 'Incorrect OTP'; + } + return fallbackText; } @@ -1439,7 +1451,7 @@ window.AbhaPatientMatchModal.open(profile, profile.candidates || [], function(finalResponse) { if (typeof showRegResult === 'function') showRegResult(finalResponse); }); - }, $('#input_mphone1').val()); + }, $('#input_mphone1').val(), $('#input_name').val()); }).on('click.abhaLauncher', '#abha_open_verify_modal_btn', function() { openAbhaAccountVerification('', null); }); diff --git a/app/Views/billing/Person_profile_V.php b/app/Views/billing/Person_profile_V.php index 4a3b897..a428861 100644 --- a/app/Views/billing/Person_profile_V.php +++ b/app/Views/billing/Person_profile_V.php @@ -563,7 +563,7 @@ $(document).ready(function() { }); } window.AbhaPatientMatchModal.open(profile, candidates, refreshProfile, currentPatientId); - }, mphone1 ?? '')) ?>); + }, mphone1 ?? '')) ?>, p_fname ?? ''))) ?>); }); function getPatientIdOrWarn() { diff --git a/app/Views/partials/abha_create_modal.php b/app/Views/partials/abha_create_modal.php index 3d3e481..21fc2c8 100644 --- a/app/Views/partials/abha_create_modal.php +++ b/app/Views/partials/abha_create_modal.php @@ -10,8 +10,33 @@ * Step 5: ABHA Profile, Official Card & HIMS linking (CRT_ABHA_113, 114, 115 / TAGGING_UNIQUEPATIENTID_UNIQUEABHANUMBER) * * Include once per page: - * Then call: window.AbhaCreateModal.open(function (profile) { ... }, prefillMobile); + * Then call: window.AbhaCreateModal.open(function (profile) { ... }, prefillMobile, prefillName); */ +$healthcareWorkerName = 'Healthcare Worker'; +if (function_exists('auth') && auth()->loggedIn()) { + $u = auth()->user(); + $healthcareWorkerName = $u->username ?? 'Healthcare Worker'; + if ($u && !empty($u->id)) { + try { + $db = \Config\Database::connect(); + $tables = config('Auth')->tables ?? []; + $identitiesTable = $tables['identities'] ?? 'auth_identities'; + if ($db && $db->tableExists($identitiesTable)) { + $row = $db->table($identitiesTable) + ->where('user_id', $u->id) + ->where('type', 'email_password') + ->get() + ->getRowArray(); + if (!empty($row['extra'])) { + $extra = json_decode($row['extra'], true); + if (!empty($extra['full_name'])) { + $healthcareWorkerName = trim($extra['full_name']); + } + } + } + } catch (\Throwable $e) {} + } +} ?>