Doctor-e-Paciente #11
@ -8,6 +8,7 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@
|
|||||||
import { Plus, Edit, Trash2, Eye, Calendar, Filter } from "lucide-react";
|
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 { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from "@/components/ui/alert-dialog";
|
||||||
import SecretaryLayout from "@/components/secretary-layout";
|
import SecretaryLayout from "@/components/secretary-layout";
|
||||||
|
import { patientsService } from "@/services/patientsApi.mjs"
|
||||||
|
|
||||||
export default function PacientesPage() {
|
export default function PacientesPage() {
|
||||||
const [searchTerm, setSearchTerm] = useState("");
|
const [searchTerm, setSearchTerm] = useState("");
|
||||||
@ -28,10 +29,9 @@ export default function PacientesPage() {
|
|||||||
setDetailsDialogOpen(true);
|
setDetailsDialogOpen(true);
|
||||||
setPatientDetails(null);
|
setPatientDetails(null);
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`https://mock.apidog.com/m1/1053378-0-default/pacientes/${patientId}`);
|
const res = await patientsService.getById(patientId);
|
||||||
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
console.log(res)
|
||||||
const json = await res.json();
|
setPatientDetails(res[0]);
|
||||||
setPatientDetails(json?.data ?? null);
|
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
setPatientDetails({ error: e?.message || "Erro ao buscar detalhes" });
|
setPatientDetails({ error: e?.message || "Erro ao buscar detalhes" });
|
||||||
}
|
}
|
||||||
@ -43,25 +43,29 @@ export default function PacientesPage() {
|
|||||||
setIsFetching(true);
|
setIsFetching(true);
|
||||||
setError(null);
|
setError(null);
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`https://mock.apidog.com/m1/1053378-0-default/pacientes?page=${pageToFetch}&limit=20`);
|
const res = await patientsService.list();
|
||||||
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
console.log(res)
|
||||||
const json = await res.json();
|
const mapped = res.map((p: any) => ({
|
||||||
const items = Array.isArray(json?.data) ? json.data : [];
|
id: String(p.id ?? ""),
|
||||||
const mapped = items.map((p: any) => ({
|
nome: p.full_name ?? "",
|
||||||
id: String(p.id ?? ""),
|
telefone: p.phone_mobile ?? p.phone1 ?? "",
|
||||||
nome: p.nome ?? "",
|
cidade: p.city ?? "",
|
||||||
telefone: p?.contato?.celular ?? p?.contato?.telefone1 ?? p?.telefone ?? "",
|
estado: p.state ?? "",
|
||||||
cidade: p?.endereco?.cidade ?? p?.cidade ?? "",
|
ultimoAtendimento: p.last_visit_at ?? "",
|
||||||
estado: p?.endereco?.estado ?? p?.estado ?? "",
|
proximoAtendimento: p.next_appointment_at ?? "",
|
||||||
ultimoAtendimento: p.ultimo_atendimento ?? p.ultimoAtendimento ?? undefined,
|
vip: Boolean(p.vip ?? false),
|
||||||
proximoAtendimento: p.proximo_atendimento ?? p.proximoAtendimento ?? undefined,
|
convenio: p.convenio ?? "", // se não existir, fica vazio
|
||||||
convenio: p.convenio ?? "",
|
status: p.status ?? undefined,
|
||||||
vip: Boolean(p.vip ?? false),
|
}));
|
||||||
status: p.status ?? undefined,
|
|
||||||
}));
|
setPatients((prev) => {
|
||||||
setPatients((prev) => [...prev, ...mapped]);
|
const all = [...prev, ...mapped];
|
||||||
setHasNext(Boolean(json?.pagination?.has_next));
|
const unique = Array.from(new Map(all.map(p => [p.id, p])).values());
|
||||||
setPage(pageToFetch + 1);
|
return unique;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (mapped.length === 0) setHasNext(false); // parar carregamento
|
||||||
|
else setPage(prev => prev + 1);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
setError(e?.message || "Erro ao buscar pacientes");
|
setError(e?.message || "Erro ao buscar pacientes");
|
||||||
} finally {
|
} finally {
|
||||||
@ -311,33 +315,23 @@ export default function PacientesPage() {
|
|||||||
<div className="text-red-600">{patientDetails.error}</div>
|
<div className="text-red-600">{patientDetails.error}</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="space-y-2 text-left">
|
<div className="space-y-2 text-left">
|
||||||
<div>
|
<p><strong>Nome:</strong> {patientDetails.full_name}</p>
|
||||||
<strong>Nome:</strong> {patientDetails.nome}
|
<p><strong>CPF:</strong> {patientDetails.cpf}</p>
|
||||||
</div>
|
<p><strong>Email:</strong> {patientDetails.email}</p>
|
||||||
<div>
|
<p><strong>Telefone:</strong> {patientDetails.phone_mobile ?? patientDetails.phone1 ?? patientDetails.phone2 ?? "-"}</p>
|
||||||
<strong>Telefone:</strong> {patientDetails?.contato?.celular ?? patientDetails?.contato?.telefone1 ?? patientDetails?.telefone ?? ""}
|
<p><strong>Nome social:</strong> {patientDetails.social_name ?? "-"}</p>
|
||||||
</div>
|
<p><strong>Sexo:</strong> {patientDetails.sex ?? "-"}</p>
|
||||||
<div>
|
<p><strong>Tipo sanguíneo:</strong> {patientDetails.blood_type ?? "-"}</p>
|
||||||
<strong>Cidade:</strong> {patientDetails?.endereco?.cidade ?? patientDetails?.cidade ?? ""}
|
<p><strong>Peso:</strong> {patientDetails.weight_kg ?? "-"}{patientDetails.weight_kg ? "kg": ""}</p>
|
||||||
</div>
|
<p><strong>Altura:</strong> {patientDetails.height_m ?? "-"}{patientDetails.height_m ? "m": ""}</p>
|
||||||
<div>
|
<p><strong>IMC:</strong> {patientDetails.bmi ?? "-"}</p>
|
||||||
<strong>Estado:</strong> {patientDetails?.endereco?.estado ?? patientDetails?.estado ?? ""}
|
<p><strong>Endereço:</strong> {patientDetails.street ?? "-"}</p>
|
||||||
</div>
|
<p><strong>Bairro:</strong> {patientDetails.neighborhood ?? "-"}</p>
|
||||||
<div>
|
<p><strong>Cidade:</strong> {patientDetails.city ?? "-"}</p>
|
||||||
<strong>Convênio:</strong> {patientDetails.convenio ?? ""}
|
<p><strong>Estado:</strong> {patientDetails.state ?? "-"}</p>
|
||||||
</div>
|
<p><strong>CEP:</strong> {patientDetails.cep ?? "-"}</p>
|
||||||
<div>
|
<p><strong>Criado em:</strong> {patientDetails.created_at ?? "-"}</p>
|
||||||
<strong>VIP:</strong> {patientDetails.vip ? "Sim" : "Não"}
|
<p><strong>Atualizado em:</strong> {patientDetails.updated_at ?? "-"}</p>
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<strong>Status:</strong> {patientDetails.status ?? ""}
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<strong>Último atendimento:</strong> {patientDetails.ultimo_atendimento ?? patientDetails.ultimoAtendimento ?? ""}
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<strong>Próximo atendimento:</strong> {patientDetails.proximo_atendimento ?? patientDetails.proximoAtendimento ?? ""}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</AlertDialogDescription>
|
</AlertDialogDescription>
|
||||||
|
|||||||
@ -66,13 +66,13 @@ export default function SecretaryLayout({ children }: PatientLayoutProps) {
|
|||||||
|
|
||||||
const menuItems = [
|
const menuItems = [
|
||||||
{
|
{
|
||||||
href: "#",
|
href: "##",
|
||||||
icon: Home,
|
icon: Home,
|
||||||
label: "Dashboard",
|
label: "Dashboard",
|
||||||
// Botão para o dashboard da secretária
|
// Botão para o dashboard da secretária
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
href: "#",
|
href: "###",
|
||||||
icon: Calendar,
|
icon: Calendar,
|
||||||
label: "Consultas",
|
label: "Consultas",
|
||||||
// Botão para página de consultas marcadas
|
// Botão para página de consultas marcadas
|
||||||
|
|||||||
@ -11,13 +11,11 @@ async function login() {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"apikey": API_KEY, // valor fixo
|
"apikey": API_KEY, // valor fixo
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ email: "hugo@popcode.com.br", password: "hdoria" }),
|
body: JSON.stringify({ email: "riseup@popcode.com.br", password: "riseup" }),
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
console.log(data.access_token)
|
||||||
console.log("Resposta da API:", data);
|
|
||||||
console.log("Token:", data.access_token);
|
|
||||||
// salvar o token do usuário
|
// salvar o token do usuário
|
||||||
//localStorage.setItem("token", data.access_token);
|
//localStorage.setItem("token", data.access_token);
|
||||||
tempToken = data.access_token
|
tempToken = data.access_token
|
||||||
@ -30,10 +28,12 @@ async function request(endpoint, options = {}) {
|
|||||||
//const token = localStorage.getItem("token"); // token do usuário, salvo no login
|
//const token = localStorage.getItem("token"); // token do usuário, salvo no login
|
||||||
const token = tempToken;
|
const token = tempToken;
|
||||||
|
|
||||||
|
console.log(`endpoint: ${endpoint}`)
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"apikey": API_KEY, // obrigatório sempre
|
"apikey": API_KEY, // obrigatório sempre
|
||||||
...(token ? { Authorization: `Bearer ${token}` } : {}), // obrigatório em todas EXCETO login
|
...(token ? { "Authorization": `Bearer ${token}` } : {}), // obrigatório em todas EXCETO login
|
||||||
...options.headers,
|
...options.headers,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import { api } from "./api.mjs";
|
|||||||
|
|
||||||
export const patientsService = {
|
export const patientsService = {
|
||||||
list: () => api.get("/rest/v1/patients"),
|
list: () => api.get("/rest/v1/patients"),
|
||||||
getById: (id) => api.get(`/rest/v1/patients/${id}`),
|
getById: (id) => api.get(`/rest/v1/patients?id=eq.${id}`),
|
||||||
create: (data) => api.post("/rest/v1/patients", data),
|
create: (data) => api.post("/rest/v1/patients", data),
|
||||||
update: (id, data) => api.patch(`/rest/v1/patients/${id}`, data),
|
update: (id, data) => api.patch(`/rest/v1/patients/${id}`, data),
|
||||||
delete: (id) => api.delete(`/rest/v1/patients/${id}`),
|
delete: (id) => api.delete(`/rest/v1/patients/${id}`),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user