resolucao de erros consulta
This commit is contained in:
parent
6f3a49575c
commit
eff11fc075
@ -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 { useNavigate } from "react-router-dom";
|
||||||
import API_KEY from "../components/utils/apiKeys.js";
|
import API_KEY from "../components/utils/apiKeys.js";
|
||||||
import AgendamentoCadastroManager from "../pages/AgendamentoCadastroManager.jsx";
|
import AgendamentoCadastroManager from "../pages/AgendamentoCadastroManager.jsx";
|
||||||
@ -15,6 +15,7 @@ import {
|
|||||||
Edit,
|
Edit,
|
||||||
Trash2,
|
Trash2,
|
||||||
CheckCircle,
|
CheckCircle,
|
||||||
|
FileText,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import "../pages/style/Agendamento.css";
|
import "../pages/style/Agendamento.css";
|
||||||
import "../pages/style/FilaEspera.css";
|
import "../pages/style/FilaEspera.css";
|
||||||
@ -295,6 +296,18 @@ const Agendamento = () => {
|
|||||||
setPageConsulta(true);
|
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) => {
|
const handleSearchMedicos = (term) => {
|
||||||
setSearchTermDoctor(term);
|
setSearchTermDoctor(term);
|
||||||
if (term.trim()) {
|
if (term.trim()) {
|
||||||
@ -609,6 +622,16 @@ const filtrarPorPaciente = (appointments) => {
|
|||||||
<Edit size={16} />
|
<Edit size={16} />
|
||||||
</button>
|
</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" && (
|
{app.status !== "cancelled" && (
|
||||||
<button
|
<button
|
||||||
className="btn-action btn-delete"
|
className="btn-action btn-delete"
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
|
// src/PagesMedico/FormNovoRelatorio.jsx
|
||||||
import React, { useEffect, useState, useRef } from 'react';
|
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 API_KEY from '../components/utils/apiKeys';
|
||||||
import { useAuth } from '../components/utils/AuthProvider';
|
import { useAuth } from '../components/utils/AuthProvider';
|
||||||
import TiptapEditor from './TiptapEditor';
|
import TiptapEditor from './TiptapEditor';
|
||||||
@ -12,6 +13,7 @@ const FormNovoRelatorio = () => {
|
|||||||
const { getAuthorizationHeader } = useAuth();
|
const { getAuthorizationHeader } = useAuth();
|
||||||
const authHeader = getAuthorizationHeader();
|
const authHeader = getAuthorizationHeader();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const location = useLocation();
|
||||||
|
|
||||||
const [patients, setPatients] = useState([]);
|
const [patients, setPatients] = useState([]);
|
||||||
const [doctors, setDoctors] = useState([]);
|
const [doctors, setDoctors] = useState([]);
|
||||||
@ -33,6 +35,7 @@ const FormNovoRelatorio = () => {
|
|||||||
const [showDoctorDropdown, setShowDoctorDropdown] = useState(false);
|
const [showDoctorDropdown, setShowDoctorDropdown] = useState(false);
|
||||||
const patientRef = useRef();
|
const patientRef = useRef();
|
||||||
const doctorRef = useRef();
|
const doctorRef = useRef();
|
||||||
|
const [lockedFromAppointment, setLockedFromAppointment] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let mounted = true;
|
let mounted = true;
|
||||||
@ -129,7 +132,24 @@ const FormNovoRelatorio = () => {
|
|||||||
|
|
||||||
const handleEditorChange = (html) => setForm(prev => ({ ...prev, contentHtml: html }));
|
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) => {
|
const handleSubmit = async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (!form.patient_id) return alert('Selecione o paciente (clicando no item) antes de salvar.');
|
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 || ''
|
requested_by: form.doctor_name || ''
|
||||||
};
|
};
|
||||||
|
|
||||||
// Busca o id do usuário logado (via token)
|
|
||||||
let userId = null;
|
let userId = null;
|
||||||
try {
|
try {
|
||||||
const token = authHeader?.replace(/^Bearer\s+/i, '') || '';
|
const token = authHeader?.replace(/^Bearer\s+/i, '') || '';
|
||||||
@ -189,8 +208,6 @@ const FormNovoRelatorio = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const created = await res.json();
|
const created = await res.json();
|
||||||
console.log('Relatório criado:', created);
|
|
||||||
|
|
||||||
window.dispatchEvent(new Event('reports:refresh'));
|
window.dispatchEvent(new Event('reports:refresh'));
|
||||||
alert('Relatório criado com sucesso!');
|
alert('Relatório criado com sucesso!');
|
||||||
navigate('/medico/relatorios');
|
navigate('/medico/relatorios');
|
||||||
@ -211,11 +228,12 @@ const FormNovoRelatorio = () => {
|
|||||||
<input
|
<input
|
||||||
className="form-control"
|
className="form-control"
|
||||||
placeholder="Comece a digitar (ex.: m para pacientes que começam com m)"
|
placeholder="Comece a digitar (ex.: m para pacientes que começam com m)"
|
||||||
value={patientQuery}
|
value={lockedFromAppointment ? form.patient_name : patientQuery}
|
||||||
onChange={(e) => { setPatientQuery(e.target.value); setShowPatientDropdown(true); }}
|
onChange={(e) => { if (!lockedFromAppointment) { setPatientQuery(e.target.value); setShowPatientDropdown(true); } }}
|
||||||
onFocus={() => 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%' }}>
|
<ul className="list-group position-absolute" style={{ zIndex: 50, maxHeight: 220, overflowY: 'auto', width: '100%' }}>
|
||||||
{filteredPatients.length > 0 ? filteredPatients.map(p => (
|
{filteredPatients.length > 0 ? filteredPatients.map(p => (
|
||||||
<li key={p.id} className="list-group-item list-group-item-action" onClick={() => choosePatient(p)}>
|
<li key={p.id} className="list-group-item list-group-item-action" onClick={() => choosePatient(p)}>
|
||||||
@ -232,11 +250,12 @@ const FormNovoRelatorio = () => {
|
|||||||
<input
|
<input
|
||||||
className="form-control"
|
className="form-control"
|
||||||
placeholder="Comece a digitar o nome do médico"
|
placeholder="Comece a digitar o nome do médico"
|
||||||
value={doctorQuery}
|
value={lockedFromAppointment ? form.doctor_name : doctorQuery}
|
||||||
onChange={(e) => { setDoctorQuery(e.target.value); setShowDoctorDropdown(true); }}
|
onChange={(e) => { if (!lockedFromAppointment) { setDoctorQuery(e.target.value); setShowDoctorDropdown(true); } }}
|
||||||
onFocus={() => 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%' }}>
|
<ul className="list-group position-absolute" style={{ zIndex: 50, maxHeight: 220, overflowY: 'auto', width: '100%' }}>
|
||||||
{filteredDoctors.length > 0 ? filteredDoctors.map(d => (
|
{filteredDoctors.length > 0 ? filteredDoctors.map(d => (
|
||||||
<li key={d.id} className="list-group-item list-group-item-action" onClick={() => chooseDoctor(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;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user