resolucao de erros consulta

This commit is contained in:
Jessica_Faro 2025-12-02 18:14:25 -03:00
parent 6f3a49575c
commit eff11fc075
2 changed files with 57 additions and 15 deletions

View File

@ -1,4 +1,4 @@
import React, { useState, useMemo, useEffect, useCallback } from "react";
import React, { useState, useMemo, useEffect, useCallback } from "react";
import { useNavigate } from "react-router-dom";
import API_KEY from "../components/utils/apiKeys.js";
import AgendamentoCadastroManager from "../pages/AgendamentoCadastroManager.jsx";
@ -15,6 +15,7 @@ import {
Edit,
Trash2,
CheckCircle,
FileText,
} from "lucide-react";
import "../pages/style/Agendamento.css";
import "../pages/style/FilaEspera.css";
@ -295,6 +296,18 @@ const Agendamento = () => {
setPageConsulta(true);
};
const handleCreateReport = (appointment) => {
navigate("/medico/novo-relatorio", {
state: {
appointment,
patient_id: appointment.patient_id,
doctor_id: appointment.doctor_id,
paciente_nome: appointment.paciente_nome,
medico_nome: appointment.medico_nome,
},
});
};
const handleSearchMedicos = (term) => {
setSearchTermDoctor(term);
if (term.trim()) {
@ -609,6 +622,16 @@ const filtrarPorPaciente = (appointments) => {
<Edit size={16} />
</button>
)}
{app.status !== "cancelled" && (
<button
className="btn-action btn-report-blue"
onClick={() => handleCreateReport(app)}
title="Criar Relatório / Laudo"
aria-label={`Criar relatório para ${app.paciente_nome}`}
>
<FileText size={16} />
</button>
)}
{app.status !== "cancelled" && (
<button
className="btn-action btn-delete"

View File

@ -1,5 +1,6 @@
// src/PagesMedico/FormNovoRelatorio.jsx
import React, { useEffect, useState, useRef } from 'react';
import { useNavigate } from 'react-router-dom';
import { useNavigate, useLocation } from 'react-router-dom';
import API_KEY from '../components/utils/apiKeys';
import { useAuth } from '../components/utils/AuthProvider';
import TiptapEditor from './TiptapEditor';
@ -12,6 +13,7 @@ const FormNovoRelatorio = () => {
const { getAuthorizationHeader } = useAuth();
const authHeader = getAuthorizationHeader();
const navigate = useNavigate();
const location = useLocation();
const [patients, setPatients] = useState([]);
const [doctors, setDoctors] = useState([]);
@ -33,6 +35,7 @@ const FormNovoRelatorio = () => {
const [showDoctorDropdown, setShowDoctorDropdown] = useState(false);
const patientRef = useRef();
const doctorRef = useRef();
const [lockedFromAppointment, setLockedFromAppointment] = useState(false);
useEffect(() => {
let mounted = true;
@ -129,7 +132,24 @@ const FormNovoRelatorio = () => {
const handleEditorChange = (html) => setForm(prev => ({ ...prev, contentHtml: html }));
// 🔹 Agora com created_by sendo o ID do usuário logado
useEffect(() => {
if (location && location.state && location.state.appointment) {
const appt = location.state.appointment;
const paciente_nome = location.state.paciente_nome || appt.paciente_nome || '';
const medico_nome = location.state.medico_nome || appt.medico_nome || '';
setForm(prev => ({
...prev,
patient_id: appt.patient_id || prev.patient_id,
patient_name: paciente_nome || prev.patient_name,
patient_birth: prev.patient_birth || '',
doctor_id: appt.doctor_id || prev.doctor_id,
doctor_name: medico_nome || prev.doctor_name,
contentHtml: generateTemplate(paciente_nome, prev.patient_birth || '', medico_nome)
}));
setLockedFromAppointment(true);
}
}, [location]);
const handleSubmit = async (e) => {
e.preventDefault();
if (!form.patient_id) return alert('Selecione o paciente (clicando no item) antes de salvar.');
@ -149,7 +169,6 @@ const FormNovoRelatorio = () => {
requested_by: form.doctor_name || ''
};
// Busca o id do usuário logado (via token)
let userId = null;
try {
const token = authHeader?.replace(/^Bearer\s+/i, '') || '';
@ -189,8 +208,6 @@ const FormNovoRelatorio = () => {
}
const created = await res.json();
console.log('Relatório criado:', created);
window.dispatchEvent(new Event('reports:refresh'));
alert('Relatório criado com sucesso!');
navigate('/medico/relatorios');
@ -211,11 +228,12 @@ const FormNovoRelatorio = () => {
<input
className="form-control"
placeholder="Comece a digitar (ex.: m para pacientes que começam com m)"
value={patientQuery}
onChange={(e) => { setPatientQuery(e.target.value); setShowPatientDropdown(true); }}
onFocus={() => setShowPatientDropdown(true)}
value={lockedFromAppointment ? form.patient_name : patientQuery}
onChange={(e) => { if (!lockedFromAppointment) { setPatientQuery(e.target.value); setShowPatientDropdown(true); } }}
onFocus={() => { if (!lockedFromAppointment) setShowPatientDropdown(true); }}
disabled={lockedFromAppointment}
/>
{showPatientDropdown && patientQuery && (
{!lockedFromAppointment && showPatientDropdown && patientQuery && (
<ul className="list-group position-absolute" style={{ zIndex: 50, maxHeight: 220, overflowY: 'auto', width: '100%' }}>
{filteredPatients.length > 0 ? filteredPatients.map(p => (
<li key={p.id} className="list-group-item list-group-item-action" onClick={() => choosePatient(p)}>
@ -232,11 +250,12 @@ const FormNovoRelatorio = () => {
<input
className="form-control"
placeholder="Comece a digitar o nome do médico"
value={doctorQuery}
onChange={(e) => { setDoctorQuery(e.target.value); setShowDoctorDropdown(true); }}
onFocus={() => setShowDoctorDropdown(true)}
value={lockedFromAppointment ? form.doctor_name : doctorQuery}
onChange={(e) => { if (!lockedFromAppointment) { setDoctorQuery(e.target.value); setShowDoctorDropdown(true); } }}
onFocus={() => { if (!lockedFromAppointment) setShowDoctorDropdown(true); }}
disabled={lockedFromAppointment}
/>
{showDoctorDropdown && doctorQuery && (
{!lockedFromAppointment && showDoctorDropdown && doctorQuery && (
<ul className="list-group position-absolute" style={{ zIndex: 50, maxHeight: 220, overflowY: 'auto', width: '100%' }}>
{filteredDoctors.length > 0 ? filteredDoctors.map(d => (
<li key={d.id} className="list-group-item list-group-item-action" onClick={() => chooseDoctor(d)}>
@ -261,4 +280,4 @@ const FormNovoRelatorio = () => {
);
};
export default FormNovoRelatorio;
export default FormNovoRelatorio;