Strengthen OPD autocomplete normalization for spacing and punctuation variants
This commit is contained in:
parent
47423a7d38
commit
ec872c984c
|
|
@ -199,6 +199,26 @@ class NormalizeOpdAutocompleteText extends BaseCommand
|
|||
if ($part === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$part = preg_replace('/\s+/', ' ', $part) ?? $part;
|
||||
$part = preg_replace_callback('/\b([A-Za-z])\s*\/\s*([A-Za-z])\b/u', static function (array $m): string {
|
||||
return mb_strtoupper($m[1]) . '/' . mb_strtoupper($m[2]);
|
||||
}, $part) ?? $part;
|
||||
|
||||
if (preg_match('/^[+-]{1,3}$/', $part) && $clean !== []) {
|
||||
$lastIndex = count($clean) - 1;
|
||||
$clean[$lastIndex] = rtrim($clean[$lastIndex]) . ' ' . $part;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (preg_match('/^(.+?)([+-]{1,3})$/u', $part, $m) === 1) {
|
||||
$base = trim((string) $m[1]);
|
||||
$sign = trim((string) $m[2]);
|
||||
if ($base !== '') {
|
||||
$part = $base . ' ' . $sign;
|
||||
}
|
||||
}
|
||||
|
||||
$clean[] = $part;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4163,6 +4163,27 @@ class Opd_prescription extends BaseController
|
|||
if ($part === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$part = preg_replace('/\s+/', ' ', $part) ?? $part;
|
||||
$part = preg_replace_callback('/\b([A-Za-z])\s*\/\s*([A-Za-z])\b/u', static function (array $m): string {
|
||||
return mb_strtoupper($m[1]) . '/' . mb_strtoupper($m[2]);
|
||||
}, $part) ?? $part;
|
||||
|
||||
// If commas split out punctuation-only fragments like "+", attach to previous token.
|
||||
if (preg_match('/^[+-]{1,3}$/', $part) && $cleanParts !== []) {
|
||||
$lastIndex = count($cleanParts) - 1;
|
||||
$cleanParts[$lastIndex] = rtrim($cleanParts[$lastIndex]) . ' ' . $part;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (preg_match('/^(.+?)([+-]{1,3})$/u', $part, $m) === 1) {
|
||||
$base = trim((string) $m[1]);
|
||||
$sign = trim((string) $m[2]);
|
||||
if ($base !== '') {
|
||||
$part = $base . ' ' . $sign;
|
||||
}
|
||||
}
|
||||
|
||||
$cleanParts[] = $part;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user