From b949971a28e2578a3144c844e01f8dbb0793caef Mon Sep 17 00:00:00 2001 From: jp-lima Date: Fri, 10 Oct 2025 15:48:08 -0300 Subject: [PATCH] =?UTF-8?q?Come=C3=A7o=20da=20cria=C3=A7=C3=A3o=20de=20mos?= =?UTF-8?q?trar=20as=20consultas=20separadas=20por=20dias?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/Agendamento.jsx | 137 +++++++++++++++++++++++++++++++++++++- 1 file changed, 135 insertions(+), 2 deletions(-) diff --git a/src/pages/Agendamento.jsx b/src/pages/Agendamento.jsx index c99ef27..2c85001 100644 --- a/src/pages/Agendamento.jsx +++ b/src/pages/Agendamento.jsx @@ -16,15 +16,148 @@ import './style/FilaEspera.css'; const Agendamento = () => { + // Dados mocados para simular consultas com a API de Hugo + const Agendamentos = [ + { + id: "9d5c7233-0437-4283-84cd-668714b1c6af", + order_number: "APT-2025-0001", + patient_id: "47902ada-7d04-480a-a759-bae8a211973a", + appointment_type: "presencial", + cancellation_reason: null, + cancelled_at: null, + checked_in_at: null, + chief_complaint: "Dor de cabeça há 3", + completed_at: null, + created_at: "2025-10-10T15:56:59.112231+00:00", + created_by: "87f2662c-9da7-45c0-9e05-521d9d92d105", + doctor_id: "16e93000-7239-4865-85f6-7f89af3ce5cd", + duration_minutes: 30, + insurance_provider: "Unimed", + notes: null, + patient_notes: "Prefiro horário pela manhã", + scheduled_at: "2025-10-10T15:56:58.937+00:00", + status: "requested", + updated_at: "2025-10-10T15:56:59.112231+00:00", + updated_by: null + }, + // mesma data + { + id: "c8d87a3a-f221-4e88-a71e-947c03f3a9c2", + order_number: "APT-2025-0002", + patient_id: "4b102ada-7d04-480a-a759-bae8a211973b", + appointment_type: "presencial", + chief_complaint: "Retorno de consulta", + created_at: "2025-10-10T09:30:00.000+00:00", + scheduled_at: "2025-10-10T09:30:00.000+00:00", + doctor_id: "16e93000-7239-4865-85f6-7f89af3ce5cd", + duration_minutes: 45, + insurance_provider: "Amil", + status: "requested" + }, + // dia anterior 1 + { + id: "a3b77a12-1f11-45f8-912b-99372cd6a711", + order_number: "APT-2025-0003", + patient_id: "57902ada-7d04-480a-a759-bae8a211973a", + appointment_type: "teleconsulta", + chief_complaint: "Tosse persistente", + created_at: "2025-10-09T10:15:00.000+00:00", + scheduled_at: "2025-10-09T10:15:00.000+00:00", + doctor_id: "16e93000-7239-4865-85f6-7f89af3ce5cd", + duration_minutes: 20, + insurance_provider: "Bradesco Saúde", + status: "confirmed" + }, + // dia anterior 2 + { + id: "f77a42e1-b1a3-41af-8b4f-b92e8372bb20", + order_number: "APT-2025-0004", + patient_id: "5a902ada-7d04-480a-a759-bae8a211973a", + appointment_type: "presencial", + chief_complaint: "Check-up anual", + created_at: "2025-10-09T14:00:00.000+00:00", + scheduled_at: "2025-10-09T14:00:00.000+00:00", + doctor_id: "16e93000-7239-4865-85f6-7f89af3ce5cd", + duration_minutes: 60, + insurance_provider: "Unimed", + status: "requested" + }, + // dia seguinte + { + id: "b832a7e3-7319-4c22-b17b-922a6d4a9287", + order_number: "APT-2025-0005", + patient_id: "6c902ada-7d04-480a-a759-bae8a211973a", + appointment_type: "presencial", + chief_complaint: "Dor lombar", + created_at: "2025-10-11T11:45:00.000+00:00", + scheduled_at: "2025-10-11T11:45:00.000+00:00", + doctor_id: "16e93000-7239-4865-85f6-7f89af3ce5cd", + duration_minutes: 30, + insurance_provider: "SulAmérica", + status: "requested" + }, + // outro qualquer (para variedade) + { + id: "d112f76a-24a1-41de-8d03-9e8a20a73b54", + order_number: "APT-2025-0006", + patient_id: "78902ada-7d04-480a-a759-bae8a211973a", + appointment_type: "teleconsulta", + chief_complaint: "Acompanhamento pós-cirurgia", + created_at: "2025-10-10T18:00:00.000+00:00", + scheduled_at: "2025-10-10T18:00:00.000+00:00", + doctor_id: "16e93000-7239-4865-85f6-7f89af3ce5cd", + duration_minutes: 25, + insurance_provider: "Unimed", + status: "requested" + } +]; + + + const [FiladeEspera, setFiladeEspera] = useState(false); const [tabela, setTabela] = useState('diario'); const [PageNovaConsulta, setPageConsulta] = useState(false); const [searchTerm, setSearchTerm] = useState(''); const [agendamentos, setAgendamentos] = useState() const {getAuthorizationHeader} = useAuth() + const [DictAgendamentosOrganizados, setAgendamentosOrganizados ] = useState({}) + + const [AgendamentoFiltrado, setAgendamentoFiltrado] = useState() + let authHeader = getAuthorizationHeader() + + // id do doutor + // dias + + const FiltrarAgendamentos = (listaTodosAgendamentos) => { + + + // cria um dicionário temporário + let DictAgendamentosOrganizados = {}; + + for (let i = 0; i < listaTodosAgendamentos.length; i++) { + const agendamento = listaTodosAgendamentos[i]; + const DiaAgendamento = agendamento.scheduled_at.split("T")[0]; + + console.log(DictAgendamentosOrganizados) + + if (DiaAgendamento in DictAgendamentosOrganizados) { + // já existe a data → adiciona na lista + DictAgendamentosOrganizados[DiaAgendamento].push(agendamento); + } else { + // não existe → cria nova key com uma lista + DictAgendamentosOrganizados[DiaAgendamento] = [agendamento]; + } + } + + // faz o set de uma vez só ✅ + setAgendamentosOrganizados(DictAgendamentosOrganizados); + + + } + const handleSave = (Dict) => { let DataAtual = dayjs() var myHeaders = new Headers(); @@ -58,7 +191,7 @@ fetch("https://yuanqfswhberkoevtmfr.supabase.co/rest/v1/appointments", requestOp } - // Requisição inicial para mnostrar os agendamentos do banco de dados + // Requisição inicial para mostrar os agendamentos do banco de dados useEffect(() => { var myHeaders = new Headers(); myHeaders.append("Authorization", authHeader); @@ -72,7 +205,7 @@ fetch("https://yuanqfswhberkoevtmfr.supabase.co/rest/v1/appointments", requestOp fetch("https://yuanqfswhberkoevtmfr.supabase.co/rest/v1/appointments?select&doctor_id&patient_id&status&scheduled_at&order&limit&offset", requestOptions) .then(response => response.json()) - .then(result => setAgendamentos(result)) + .then(result => {FiltrarAgendamentos(Agendamentos); console.log(Agendamentos)}) .catch(error => console.log('error', error)); }, [])