diff --git a/app/secretary/pacientes/page.tsx b/app/secretary/pacientes/page.tsx index c72bb85..29f4fef 100644 --- a/app/secretary/pacientes/page.tsx +++ b/app/secretary/pacientes/page.tsx @@ -8,6 +8,7 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@ import { Plus, Edit, Trash2, Eye, Calendar, Filter } from "lucide-react"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from "@/components/ui/alert-dialog"; import SecretaryLayout from "@/components/secretary-layout"; +import { patientsService } from "@/services/patientsApi.mjs" export default function PacientesPage() { const [searchTerm, setSearchTerm] = useState(""); @@ -28,40 +29,43 @@ export default function PacientesPage() { setDetailsDialogOpen(true); setPatientDetails(null); try { - const res = await fetch(`https://mock.apidog.com/m1/1053378-0-default/pacientes/${patientId}`); - if (!res.ok) throw new Error(`HTTP ${res.status}`); - const json = await res.json(); - setPatientDetails(json?.data ?? null); + const res = await patientsService.getById(patientId); + console.log(res) + setPatientDetails(res[0]); } catch (e: any) { setPatientDetails({ error: e?.message || "Erro ao buscar detalhes" }); } }; - + const fetchPacientes = useCallback( async (pageToFetch: number) => { if (isFetching || !hasNext) return; setIsFetching(true); setError(null); try { - const res = await fetch(`https://mock.apidog.com/m1/1053378-0-default/pacientes?page=${pageToFetch}&limit=20`); - if (!res.ok) throw new Error(`HTTP ${res.status}`); - const json = await res.json(); - const items = Array.isArray(json?.data) ? json.data : []; - const mapped = items.map((p: any) => ({ - id: String(p.id ?? ""), - nome: p.nome ?? "", - telefone: p?.contato?.celular ?? p?.contato?.telefone1 ?? p?.telefone ?? "", - cidade: p?.endereco?.cidade ?? p?.cidade ?? "", - estado: p?.endereco?.estado ?? p?.estado ?? "", - ultimoAtendimento: p.ultimo_atendimento ?? p.ultimoAtendimento ?? undefined, - proximoAtendimento: p.proximo_atendimento ?? p.proximoAtendimento ?? undefined, - convenio: p.convenio ?? "", - vip: Boolean(p.vip ?? false), - status: p.status ?? undefined, - })); - setPatients((prev) => [...prev, ...mapped]); - setHasNext(Boolean(json?.pagination?.has_next)); - setPage(pageToFetch + 1); + const res = await patientsService.list(); + console.log(res) + const mapped = res.map((p: any) => ({ + id: String(p.id ?? ""), + nome: p.full_name ?? "", + telefone: p.phone_mobile ?? p.phone1 ?? "", + cidade: p.city ?? "", + estado: p.state ?? "", + ultimoAtendimento: p.last_visit_at ?? "", + proximoAtendimento: p.next_appointment_at ?? "", + vip: Boolean(p.vip ?? false), + convenio: p.convenio ?? "", // se não existir, fica vazio + status: p.status ?? undefined, + })); + + setPatients((prev) => { + const all = [...prev, ...mapped]; + const unique = Array.from(new Map(all.map(p => [p.id, p])).values()); + return unique; + }); + + if (mapped.length === 0) setHasNext(false); // parar carregamento + else setPage(prev => prev + 1); } catch (e: any) { setError(e?.message || "Erro ao buscar pacientes"); } finally { @@ -311,33 +315,23 @@ export default function PacientesPage() {
Nome: {patientDetails.full_name}
+CPF: {patientDetails.cpf}
+Email: {patientDetails.email}
+Telefone: {patientDetails.phone_mobile ?? patientDetails.phone1 ?? patientDetails.phone2 ?? "-"}
+Nome social: {patientDetails.social_name ?? "-"}
+Sexo: {patientDetails.sex ?? "-"}
+Tipo sanguíneo: {patientDetails.blood_type ?? "-"}
+Peso: {patientDetails.weight_kg ?? "-"}{patientDetails.weight_kg ? "kg": ""}
+Altura: {patientDetails.height_m ?? "-"}{patientDetails.height_m ? "m": ""}
+IMC: {patientDetails.bmi ?? "-"}
+Endereço: {patientDetails.street ?? "-"}
+Bairro: {patientDetails.neighborhood ?? "-"}
+Cidade: {patientDetails.city ?? "-"}
+Estado: {patientDetails.state ?? "-"}
+CEP: {patientDetails.cep ?? "-"}
+Criado em: {patientDetails.created_at ?? "-"}
+Atualizado em: {patientDetails.updated_at ?? "-"}