From bc5fdb8c63f839bd7e8e92610dc35f5e89fe4994 Mon Sep 17 00:00:00 2001 From: DevSoftTech Server Date: Thu, 13 Aug 2026 19:14:00 +0530 Subject: [PATCH] Fix ABHA patient matching for DD-MM-YYYY dates --- app/Controllers/Abha.php | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/app/Controllers/Abha.php b/app/Controllers/Abha.php index e59f0c3..41c9d6a 100644 --- a/app/Controllers/Abha.php +++ b/app/Controllers/Abha.php @@ -1056,6 +1056,24 @@ class Abha extends BaseController return null; } + /** + * ABHA returns DOB as DD-MM-YYYY while patient_master stores YYYY-MM-DD. + */ + private function extractBirthYear(string $dob): string + { + $dob = trim($dob); + if ($dob === '') { + return ''; + } + + $normalized = $this->normalizeDobToDb($dob); + if ($normalized !== '' && preg_match('/^(\d{4})/', $normalized, $match) === 1) { + return $match[1]; + } + + return preg_match('/(?toPatientGenderValue($genderRaw); $ageYears = $this->computeAgeYears($dob); - $birthYear = preg_match('/^(\d{4})/', trim($dob), $birthYearMatch) === 1 ? $birthYearMatch[1] : ''; + // ABHA sends DOB as DD-MM-YYYY, patient_master stores YYYY-MM-DD. + $birthYear = $this->extractBirthYear($dob); $nameUp = strtoupper(trim($name)); $nameTokens = array_values(array_filter(preg_split('/\s+/', $nameUp) ?: [], fn ($t) => strlen($t) >= 3)); $aadhaar = preg_replace('/\D/', '', $aadhaar); @@ -1174,7 +1193,7 @@ class Abha extends BaseController $rowAgeYears = (int) $row['age']; } - $rowBirthYear = preg_match('/^(\d{4})/', $rowDob, $rowBirthYearMatch) === 1 ? $rowBirthYearMatch[1] : ''; + $rowBirthYear = $this->extractBirthYear($rowDob); $birthYearMatch = $birthYear !== '' && $rowBirthYear !== '' && $rowBirthYear === $birthYear; $ageMatch = $birthYearMatch; $genderMatch = $genderDb > 0 && (int) ($row['gender'] ?? 0) === $genderDb;