diff --git a/src/components/AgendarConsulta/CardConsulta.jsx b/src/components/AgendarConsulta/CardConsulta.jsx
index 250a534..acd627c 100644
--- a/src/components/AgendarConsulta/CardConsulta.jsx
+++ b/src/components/AgendarConsulta/CardConsulta.jsx
@@ -1,23 +1,86 @@
-import React from 'react'
+import React, { useState, useEffect } from 'react';import { GetDoctorByID } from '../utils/Functions-Endpoints/Doctor';
+import { GetPatientByID } from '../utils/Functions-Endpoints/Patient';
+import { useAuth } from '../utils/AuthProvider';
+import { useNavigate } from 'react-router-dom';
+import { useMemo } from 'react';
-const CardConsulta = ( {DadosConsulta, TabelaAgendamento} ) => {
+const CardConsulta = ( {DadosConsulta, TabelaAgendamento, setShowDeleteModal} ) => {
+ const navigate = useNavigate();
+ const {getAuthorizationHeader} = useAuth()
+ const authHeader = getAuthorizationHeader()
+ const [Paciente, setPaciente] = useState()
+ const [Medico, setMedico] = useState()
- // Status (agendado, confirmado, realizado, cancelado)
+ const ids = useMemo(() => {
+ return {
+ doctor_id: DadosConsulta?.doctor_id,
+ patient_id: DadosConsulta?.patient_id,
+ status: DadosConsulta?.status
+ };
+ }, [DadosConsulta]);
+
+
+ useEffect(() => {
+ const BuscarMedicoEPaciente = async () => {
+ if (!ids.doctor_id || !ids.patient_id || ids.status === 'nada') return;
+
+ try {
+ const [Doctor, Patient] = await Promise.all([
+ GetDoctorByID(ids.doctor_id, authHeader),
+ GetPatientByID(ids.patient_id, authHeader)
+ ]);
+
+ setMedico(Doctor?.[0] || null);
+ setPaciente(Patient?.[0] || null);
+ } catch (error) {
+ console.error('Erro ao buscar médico/paciente:', error);
+ }
+ };
+
+ BuscarMedicoEPaciente();
+ }, [ids, authHeader]);
return (
- {DadosConsulta.status !== 'vazio'?
+ {DadosConsulta.id?
+
-
- {DadosConsulta.horario}|GEAP| {DadosConsulta.medico}
-
-
- {DadosConsulta.paciente} - {DadosConsulta.motivo} - 23 anos
-
+
+
+ {DadosConsulta.horario} {Medico?.full_name}
+
+
+
+ {Paciente?.full_name} - {DadosConsulta.exam}
+
+
+
+
+
+
+
+
+
+
+
:
null
diff --git a/src/components/AgendarConsulta/FormNovaConsulta.jsx b/src/components/AgendarConsulta/FormNovaConsulta.jsx
index 435bc8e..bdae91d 100644
--- a/src/components/AgendarConsulta/FormNovaConsulta.jsx
+++ b/src/components/AgendarConsulta/FormNovaConsulta.jsx
@@ -1,57 +1,21 @@
import InputMask from "react-input-mask";
import "./style/formagendamentos.css";
import { useState, useEffect } from "react";
+import { GetPatientByCPF } from "../utils/Functions-Endpoints/Patient";
+import { GetDoctorByName } from "../utils/Functions-Endpoints/Doctor";
+import { useAuth } from "../utils/AuthProvider";
+const FormNovaConsulta = ({ onCancel, onSave, setAgendamento, agendamento }) => {
+ const {getAuthorizationHeader} = useAuth()
-const FormNovaConsulta = ({ onCancel, patientID }) => {
-
const [selectedFile, setSelectedFile] = useState(null);
const [anexos, setAnexos] = useState([]);
const [loadingAnexos, setLoadingAnexos] = useState(false);
- const [paciente, setPaciente] = useState({})
+
+
const [acessibilidade, setAcessibilidade] = useState({cadeirante:false,idoso:false,gravida:false,bebe:false, autista:false })
- useEffect(() => {
- if (!patientID) return;
-
- const fetchAnexos = async () => {
- setLoadingAnexos(true);
- try {
- const res = await fetch(`https://mock.apidog.com/m1/1053378-0-default/pacientes/${patientID}/anexos`);
- const data = await res.json();
- setAnexos(data.data || []);
- } catch (err) {
- console.error("Erro ao buscar anexos:", err);
- } finally {
- setLoadingAnexos(false);
- }
- };
-
- fetchAnexos();
- }, [patientID]);
-
- const handleUpload = async () => {
- if (!selectedFile) return;
-
- const formData = new FormData();
- formData.append("file", selectedFile);
-
- try {
- const res = await fetch(`https://mock.apidog.com/m1/1053378-0-default/pacientes/${patientID}/anexos`, {
- method: "POST",
- body: formData
- });
- if (res.ok) {
- const novoAnexo = await res.json();
- setAnexos(prev => [...prev, novoAnexo]);
- setSelectedFile(null);
- } else {
- console.error("Erro ao enviar anexo");
- }
- } catch (err) {
- console.error("Erro ao enviar anexo:", err);
- }
- };
+ let authHeader = getAuthorizationHeader()
const handleclickAcessibilidade = (id) => {
@@ -62,112 +26,65 @@ const FormNovaConsulta = ({ onCancel, patientID }) => {
else if(resultado === true){ setAcessibilidade({...acessibilidade, [id]:false})}
console.log(id)
}
-
- const FormatCPF = (valor) => {
- console.log(valor)
+ const FormatCPF = (valor) => {
const digits = String(valor).replace(/\D/g, '').slice(0, 11);
- BuscarPacienteExistentePeloCPF(valor)
-
return digits
.replace(/(\d{3})(\d)/, '$1.$2')
.replace(/(\d{3})(\d)/, '$1.$2')
.replace(/(\d{3})(\d{1,2})$/, '$1-$2');
}
-
- const FormatTelefones = (valor) => {
- const digits = String(valor).replace(/\D/g, '').slice(0, 11);
- return digits
- .replace(/(\d)/, '($1')
- .replace(/(\d{2})(\d)/, '$1) $2' )
- .replace(/(\d)(\d{4})/, '$1 $2')
- .replace(/(\d{4})(\d{4})/, '$1-$2')
- }
-
-
- const BuscarCPFnoBancodeDados = async (cpf) => {
-
- var myHeaders = new Headers();
- myHeaders.append("Authorization", "Bearer
");
- myHeaders.append("Content-Type", "application/json");
-
- var raw = JSON.stringify({
- "cpf": cpf
- });
-
- var requestOptions = {
- method: 'POST',
- headers: myHeaders,
- body: raw,
- redirect: 'follow'
- };
-
- const response = await fetch("https://mock.apidog.com/m1/1053378-0-default/pacientes/validar-cpf", requestOptions);
- const result = await response.json();
- return result
-
-
- }
-
- const BuscarPacienteExistentePeloCPF = async (value) => {
-
- if(isNaN(value[13]) === false && value.length === 14)try {
- const result = await BuscarCPFnoBancodeDados(value);
- console.log("Resultado:", result);
-
- if (result.data.existe === true){
-
- var myHeaders = new Headers();
- myHeaders.append("Authorization", "Bearer ");
-
- var requestOptions = {
- method: 'GET',
- headers: myHeaders,
- redirect: 'follow'
- };
-
- fetch("https://mock.apidog.com/m1/1053378-0-default/pacientes/", requestOptions)
- .then(response => response.json())
- .then(result => setPaciente(result.data))
- .catch(error => console.log('error', error));
- }
-
-
-
- } catch (error) {
- console.log("error", error);
- }
- //BuscarCPFnoBancodeDados(value)
- }
+
const handleChange = (e) => {
const {value, name} = e.target;
-
- console.log(value, name)
-
if(name === 'email'){
- setPaciente({...paciente, contato:{
- ...paciente.contato,
+ setAgendamento({...agendamento, contato:{
+ ...agendamento.contato,
email:value
}})
- } else if(name === 'telefone'){
- setPaciente({...paciente, contato:{
- ...paciente.contato,
- telefone1:FormatTelefones(value)
- }})
+ }else if(name === 'cpf'){
+
+ let cpfFormatted = FormatCPF(value)
+ const fetchPatient = async () => {
+ let patientData = await GetPatientByCPF(cpfFormatted, authHeader);
+ if (patientData) {
+ setAgendamento((prev) => ({
+ ...prev,
+ nome: patientData.full_name,
+ patient_id: patientData.id
+ }));
+ }}
+ setAgendamento(prev => ({ ...prev, cpf: cpfFormatted }))
+ fetchPatient()
+ }else if(name==='convenio'){
+ setAgendamento({...agendamento,insurance_provider:value})
+ }else if(name ==='profissional'){
+
+
+ const fetchDoctor = async () => {
+ let DoctorData = await GetDoctorByName(value, authHeader)
+ if(DoctorData){
+ setAgendamento((prev) => ({
+ ...prev,
+ doctor_id:DoctorData.id
+ }))
+ }}
+ fetchDoctor()
}
else{
- setPaciente({...paciente,[name]:value})
+ setAgendamento({...agendamento,[name]:value})
}
}
const handleSubmit = (e) => {
e.preventDefault();
alert("Agendamento salvo!");
+ onSave(agendamento)
};
return (
@@ -180,57 +97,33 @@ const FormNovaConsulta = ({ onCancel, patientID }) => {
-
+
Informações adicionais
@@ -243,7 +136,7 @@ const FormNovaConsulta = ({ onCancel, patientID }) => {
onChange={(e) => setSelectedFile(e.target.files[0])}
/>
{selectedFile && (
-