Merge branch 'claude/admiring-chaplygin-7fde72'

This commit is contained in:
VPS 4 Builder
2026-05-14 22:46:47 +02:00
+17 -9
View File
@@ -87,6 +87,9 @@ const DENTES_CRIANCA = {
q3: [71, 72, 73, null, 74, 75, null, null]
};
const normalize = (s: string) =>
s.normalize('NFD').replace(/[̀-ͯ]/g, '').toLowerCase().trim();
// --- COMPONENT ---
export const LancarGTO: React.FC = () => {
const store = useGTOStore();
@@ -128,24 +131,29 @@ export const LancarGTO: React.FC = () => {
const filteredPatients = useMemo(() => {
if (!patientSearchTerm) return pacientes.slice(0, 30);
const term = patientSearchTerm.toLowerCase();
const term = normalize(patientSearchTerm);
return pacientes.filter(p =>
p.nome.toLowerCase().includes(term) ||
(p.cpf && p.cpf.includes(term))
normalize(p.nome).includes(term) ||
(p.cpf && p.cpf.includes(patientSearchTerm.replace(/\D/g, '')))
).slice(0, 30);
}, [pacientes, patientSearchTerm]);
}, [pacientes, patientSearchTerm]); // eslint-disable-line react-hooks/exhaustive-deps
// Auto-seleciona paciente quando vem da agenda (pendingSearch)
useEffect(() => {
const { pendingSearch } = store;
if (!pendingSearch || pacientes.length === 0) return;
const term = pendingSearch.toLowerCase();
const match = pacientes.find(p => p.nome.toLowerCase() === term);
if (match) {
store.setPaciente(match);
} else {
const term = normalize(pendingSearch);
const matches = pacientes.filter(p => {
const n = normalize(p.nome);
return n === term || n.includes(term) || term.includes(n);
});
if (matches.length === 1) {
store.setPaciente(matches[0]);
} else if (matches.length > 1) {
setPatientSearchTerm(pendingSearch);
setPatientSearchOpen(true);
} else {
setPatientSearchOpen(true);
}
store.setPendingSearch('');
}, [pacientes, store.pendingSearch]); // eslint-disable-line react-hooks/exhaustive-deps