Match ABHA patients by exact identifier or demographics
This commit is contained in:
parent
bc5fdb8c63
commit
7cb57b5b28
|
|
@ -1127,7 +1127,6 @@ class Abha extends BaseController
|
||||||
string $abhaNumClean
|
string $abhaNumClean
|
||||||
): array {
|
): array {
|
||||||
$genderDb = $this->toPatientGenderValue($genderRaw);
|
$genderDb = $this->toPatientGenderValue($genderRaw);
|
||||||
$ageYears = $this->computeAgeYears($dob);
|
|
||||||
// ABHA sends DOB as DD-MM-YYYY, patient_master stores YYYY-MM-DD.
|
// ABHA sends DOB as DD-MM-YYYY, patient_master stores YYYY-MM-DD.
|
||||||
$birthYear = $this->extractBirthYear($dob);
|
$birthYear = $this->extractBirthYear($dob);
|
||||||
$nameUp = strtoupper(trim($name));
|
$nameUp = strtoupper(trim($name));
|
||||||
|
|
@ -1147,33 +1146,54 @@ class Abha extends BaseController
|
||||||
$select .= ',' . $abhaField;
|
$select .= ',' . $abhaField;
|
||||||
}
|
}
|
||||||
|
|
||||||
$builder = $db->table('patient_master')->select($select);
|
// Two targeted passes: exact identifiers can never be crowded out by a
|
||||||
$builder->groupStart();
|
// common name, and gender alone is a filter (see scoring) not a selector.
|
||||||
$any = false;
|
$rows = [];
|
||||||
foreach ($nameTokens as $tok) {
|
$collect = static function (callable $applyConditions) use ($db, $select, &$rows): void {
|
||||||
$builder->orLike('p_fname', $tok);
|
$builder = $db->table('patient_master')->select($select);
|
||||||
$any = true;
|
$builder->groupStart();
|
||||||
}
|
$applyConditions($builder);
|
||||||
if ($mobile !== '') {
|
$builder->groupEnd();
|
||||||
$builder->orWhere('mphone1', $mobile);
|
foreach ($builder->orderBy('insert_date', 'DESC')->limit(200)->get()->getResultArray() as $row) {
|
||||||
$any = true;
|
$rows[(int) ($row['id'] ?? 0)] = $row;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
$exactMatches = [];
|
||||||
|
if ($abhaField !== null && $abhaNumClean !== '') {
|
||||||
|
$exactMatches[$abhaField] = $abhaNumClean;
|
||||||
}
|
}
|
||||||
if ($aadhaar !== '') {
|
if ($aadhaar !== '') {
|
||||||
$builder->orWhere('udai', $aadhaar);
|
$exactMatches['udai'] = $aadhaar;
|
||||||
$any = true;
|
|
||||||
}
|
}
|
||||||
if ($ageYears !== null && $genderDb > 0) {
|
if ($mobile !== '') {
|
||||||
$builder->orWhere('gender', $genderDb);
|
$exactMatches['mphone1'] = $mobile;
|
||||||
$any = true;
|
|
||||||
}
|
}
|
||||||
$builder->groupEnd();
|
|
||||||
|
|
||||||
if (! $any) {
|
if ($exactMatches !== []) {
|
||||||
|
$collect(static function ($builder) use ($exactMatches): void {
|
||||||
|
foreach ($exactMatches as $column => $value) {
|
||||||
|
$builder->orWhere($column, $value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($nameTokens !== []) {
|
||||||
|
$hasLastName = in_array('p_lname', $fields, true);
|
||||||
|
$collect(static function ($builder) use ($nameTokens, $hasLastName): void {
|
||||||
|
foreach ($nameTokens as $token) {
|
||||||
|
$builder->orLike('p_fname', $token);
|
||||||
|
if ($hasLastName) {
|
||||||
|
$builder->orLike('p_lname', $token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($rows === []) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$rows = $builder->orderBy('insert_date', 'DESC')->limit(40)->get()->getResultArray();
|
|
||||||
|
|
||||||
$candidates = [];
|
$candidates = [];
|
||||||
foreach ($rows as $row) {
|
foreach ($rows as $row) {
|
||||||
$rowName = strtoupper(trim((string) ($row['p_fname'] ?? '') . ' ' . (string) ($row['p_lname'] ?? '')));
|
$rowName = strtoupper(trim((string) ($row['p_fname'] ?? '') . ' ' . (string) ($row['p_lname'] ?? '')));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user