From 6dcfb27ca86b55f35006b88b501881c6caf623a6 Mon Sep 17 00:00:00 2001 From: VPS 4 Builder Date: Thu, 14 May 2026 22:46:44 +0200 Subject: [PATCH] =?UTF-8?q?fix(lancar-gto):=20auto-sele=C3=A7=C3=A3o=20rob?= =?UTF-8?q?usta=20de=20paciente=20vindo=20da=20agenda?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Adiciona normalize() para remover acentos antes de comparar nomes, resolvendo falhas quando o agendamento usa "Joao" e o cadastro "João" - Troca correspondência exata por filtro com includes() em ambas as direções - Seleciona diretamente se há exatamente 1 match (sem abrir modal) - Se múltiplos matches: abre modal com busca pré-preenchida - Se nenhum match: abre modal vazio para busca manual - Aplica normalize() também no filteredPatients para consistência Co-Authored-By: Claude Sonnet 4.6 --- frontend/views/LancarGTO.tsx | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/frontend/views/LancarGTO.tsx b/frontend/views/LancarGTO.tsx index bad0f2e..8c26007 100644 --- a/frontend/views/LancarGTO.tsx +++ b/frontend/views/LancarGTO.tsx @@ -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