import React, { useEffect, useState } from "react"; import avatarPlaceholder from '../assets/images/avatar_placeholder.png'; import { useParams } from "react-router-dom"; import API_KEY from "../components/utils/apiKeys"; import {GetByID} from "../components/utils/Functions-Endpoints/Patient" import { Link } from "react-router-dom"; import { useAuth } from "../components/utils/AuthProvider"; const Details = () => { const parametros = useParams(); const {getAuthorizationHeader, isAuthenticated} = useAuth(); const [paciente, setPaciente] = useState({}); const [anexos, setAnexos] = useState([]); const [selectedFile, setSelectedFile] = useState(null); const patientID = parametros.id useEffect(() => { if (!patientID) return; console.log(patientID, 'teu id') const authHeader = getAuthorizationHeader() GetByID(patientID, authHeader) .then((data) => { console.log(data, "paciente vindo da API"); setPaciente(data[0]); // supabase retorna array }) .catch((err) => console.error("Erro ao buscar paciente:", err)); /*fetch(`https://mock.apidog.com/m1/1053378-0-default/pacientes/${patientID}/anexos`) .then(res => res.json()) .then(data => setAnexos(data.data || [])) .catch(err => console.error("Erro ao buscar anexos:", err)); */ }, [patientID]); const handleUpload = async () => { if (!selectedFile) return; const formData = new FormData(); formData.append('file', selectedFile); try { const response = await fetch(`https://mock.apidog.com/m1/1053378-0-default/pacientes/${patientID}/anexos`, { method: 'POST', body: formData, }); if (response.ok) { const newAnexo = await response.json(); setAnexos(prev => [...prev, newAnexo]); setSelectedFile(null); } else { console.error('Erro ao enviar anexo'); } } catch (err) { console.error('Erro ao enviar anexo:', err); } }; const handleDelete = async (anexoId) => { try { const response = await fetch( `https://mock.apidog.com/m1/1053378-0-default/pacientes/${patientID}/anexos/${anexoId}`, { method: "DELETE", } ); if (response.ok) { setAnexos((prev) => prev.filter((a) => a.id !== anexoId)); } else { console.error("Erro ao deletar anexo"); } } catch (err) { console.error("Erro ao deletar anexo:", err); } }; return ( <>

MediConnect


{paciente.full_name || "Nome Completo"}

{paciente.cpf || "CPF"}

{/* ------------------ DADOS PESSOAIS ------------------ */}
Dados Pessoais

{paciente.full_name || "-"}

{paciente.social_name || "-"}

{paciente.birth_date || "-"}

{paciente.sex || "-"}

{paciente.cpf || "-"}

{paciente.rg || "-"}

{paciente.document_type || "-"}

{paciente.document_number || "-"}

{paciente.ethnicity || "-"}

{paciente.race || "-"}

{paciente.naturality || "-"}

{paciente.profession || "-"}

{paciente.mother_name || "-"}

{paciente.mother_profession || "-"}

{paciente.father_name || "-"}

{paciente.father_profession || "-"}

{paciente.guardian_name || "-"}

{paciente.guardian_cpf || "-"}

{paciente.marital_status || "-"}

{paciente.nome_conjuge || "-"}

{paciente.legacy_code || "-"}

{paciente.notes || "-"}

{anexos.length > 0 ?(
    {anexos.map((anexo) => (
  • {anexo.nome}
  • ))}
) : (

-

)}
{/* ------------------ INFORMAÇÕES MÉDICAS ------------------ */}
Informações Médicas

{paciente.blood_type || "-"}

{paciente.weight_kg || "-"}

{paciente.height_m || "-"}

{paciente.bmi || "-"}

{/* ------------------ INFORMAÇÕES DE CONVÊNIO ------------------ */}
Informações de Convênio

{paciente.convenio || "-"}

{paciente.plano || "-"}

{paciente.numeroMatricula || "-"}

{paciente.validadeCarteira || "-"}

{/* ------------------ ENDEREÇO ------------------ */}
Endereço

{paciente.cep || "-"}

{paciente.street || "-"}

{paciente.neighborhood || "-"}

{paciente.city || "-"}

{paciente.state || "-"}

{paciente.number || "-"}

{paciente.complement || "-"}

{/* ------------------ CONTATO ------------------ */}
Contato

{paciente.email || "-"}

{paciente.phone_mobile || "-"}

{paciente.phone1 || "-"}

{paciente.phone2 || "-"}

); }; export default Details;