diff --git a/app/doctor/medicos/consultas/page.tsx b/app/doctor/medicos/consultas/page.tsx new file mode 100644 index 0000000..ca53da9 --- /dev/null +++ b/app/doctor/medicos/consultas/page.tsx @@ -0,0 +1,199 @@ +"use client"; + +import type React from "react"; +import { useState, useEffect } from "react"; +import DoctorLayout from "@/components/doctor-layout"; +import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; +import { Button } from "@/components/ui/button"; +import { Clock, Calendar, MapPin, Phone, User, X, RefreshCw } from "lucide-react"; +import { Badge } from "@/components/ui/badge"; +import { toast } from "sonner"; + +const APPOINTMENTS_STORAGE_KEY = "clinic-appointments"; + +// Tipagem da consulta (mantida) +interface LocalStorageAppointment { + id: number; + patientName: string; + doctor: string; + specialty: string; + date: string; + time: string; + status: "agendada" | "confirmada" | "cancelada" | "realizada"; + location: string; + phone: string; +} + +// SIMULAÇÃO DO MÉDICO LOGADO - Mantemos apenas para informação no cabeçalho +// O NOME AQUI NÃO ESTÁ MAIS SENDO USADO PARA FILTRAR +const LOGGED_IN_DOCTOR_NAME = "Dr. João Silva (TODAS AS CONSULTAS)"; + +// --- COMPONENTE PRINCIPAL --- + +export default function DoctorAppointmentsPage() { + const [appointments, setAppointments] = useState([]); + const [isLoading, setIsLoading] = useState(true); + + useEffect(() => { + loadAppointments(); + }, []); + + const loadAppointments = () => { + setIsLoading(true); + try { + const storedAppointmentsRaw = localStorage.getItem(APPOINTMENTS_STORAGE_KEY); + const allAppointments: LocalStorageAppointment[] = storedAppointmentsRaw ? JSON.parse(storedAppointmentsRaw) : []; + + // ***** MUDANÇA IMPLEMENTADA ***** + // Removemos a filtragem para que todas as consultas sejam exibidas + const appointmentsToShow = allAppointments; + + // 2. Ordena por Data e Hora + appointmentsToShow.sort((a, b) => { + const dateTimeA = new Date(`${a.date}T${a.time}:00`); + const dateTimeB = new Date(`${b.date}T${b.time}:00`); + return dateTimeA.getTime() - dateTimeB.getTime(); + }); + + setAppointments(appointmentsToShow); // Exibe a lista completa (e ordenada) + toast.success("Agenda atualizada com sucesso!"); + } catch (error) { + console.error("Erro ao carregar a agenda do LocalStorage:", error); + toast.error("Não foi possível carregar sua agenda."); + } finally { + setIsLoading(false); + } + }; + + // Função utilitária (mantida) + const getStatusVariant = (status: LocalStorageAppointment['status']) => { + switch (status) { + case "confirmada": + case "agendada": + return "default"; + case "realizada": + return "secondary"; + case "cancelada": + return "destructive"; + default: + return "outline"; + } + }; + + const handleCancel = (id: number) => { + const storedAppointmentsRaw = localStorage.getItem(APPOINTMENTS_STORAGE_KEY); + const allAppointments: LocalStorageAppointment[] = storedAppointmentsRaw ? JSON.parse(storedAppointmentsRaw) : []; + + const updatedAppointments = allAppointments.map(app => + app.id === id ? { ...app, status: "cancelada" as const } : app + ); + + localStorage.setItem(APPOINTMENTS_STORAGE_KEY, JSON.stringify(updatedAppointments)); + loadAppointments(); // Recarrega a lista + toast.info(`Consulta cancelada com sucesso.`); + }; + + const handleReSchedule = (id: number) => { + toast.info(`Reagendamento da Consulta ID: ${id}. Navegar para a página de agendamento.`); + }; + + return ( + +
+
+

Minhas Consultas (Agenda Completa)

+

Todas as consultas agendadas, para qualquer médico, são exibidas aqui ({LOGGED_IN_DOCTOR_NAME})

+
+ +
+ +
+ +
+ {isLoading ? ( +

Carregando a agenda...

+ ) : appointments.length === 0 ? ( +

Nenhuma consulta agendada no sistema.

+ ) : ( + appointments.map((appointment) => { + const showActions = appointment.status === "agendada" || appointment.status === "confirmada"; + + return ( + + + {/* NOME DO PACIENTE */} + + + {appointment.patientName} + + {/* STATUS DA CONSULTA */} + + {appointment.status} + + + + + {/* Coluna de Detalhes */} +
+
+ + Médico: {appointment.doctor} +
+
+ + {new Date(appointment.date).toLocaleDateString("pt-BR", { timeZone: "UTC" })} +
+
+ + {appointment.time} +
+
+ + {/* Coluna 2: Local e Contato */} +
+
+ + {appointment.location} +
+
+ + {appointment.phone || "N/A"} +
+
+ + {/* COLUNA 3: Ações (Botões) */} +
+ {showActions && ( +
+ + +
+ )} +
+
+
+ ); + }) + )} +
+
+
+ ); +} \ No newline at end of file diff --git a/app/patient/schedule/page.tsx b/app/patient/schedule/page.tsx index 46cf93d..b2bbe74 100644 --- a/app/patient/schedule/page.tsx +++ b/app/patient/schedule/page.tsx @@ -1,7 +1,6 @@ "use client" import type React from "react" - import { useState } from "react" import PatientLayout from "@/components/patient-layout" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" @@ -12,17 +11,21 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@ import { Textarea } from "@/components/ui/textarea" import { Calendar, Clock, User } from "lucide-react" +// Chave do LocalStorage +const APPOINTMENTS_STORAGE_KEY = "clinic-appointments"; + export default function ScheduleAppointment() { const [selectedDoctor, setSelectedDoctor] = useState("") const [selectedDate, setSelectedDate] = useState("") const [selectedTime, setSelectedTime] = useState("") const [notes, setNotes] = useState("") + // ALTERAÇÃO AQUI: Adicionado 'location' para a tipagem e dados baterem const doctors = [ - { id: "1", name: "Dr. João Silva", specialty: "Cardiologia" }, - { id: "2", name: "Dra. Maria Santos", specialty: "Dermatologia" }, - { id: "3", name: "Dr. Pedro Costa", specialty: "Ortopedia" }, - { id: "4", name: "Dra. Ana Lima", specialty: "Ginecologia" }, + { id: "1", name: "Dr. João Silva", specialty: "Cardiologia", location: "Unidade Central - Sala 101" }, + { id: "2", name: "Dra. Maria Santos", specialty: "Dermatologia", location: "Unidade Central - Sala 205" }, + { id: "3", name: "Dr. Pedro Costa", specialty: "Ortopedia", location: "Unidade Centro-Oeste - Sala 302" }, + { id: "4", name: "Dra. Ana Lima", specialty: "Ginecologia", location: "Unidade Centro-Oeste - Sala 108" }, ] const availableTimes = [ @@ -42,8 +45,51 @@ export default function ScheduleAppointment() { const handleSubmit = (e: React.FormEvent) => { e.preventDefault() - // Aqui você implementaria a lógica para salvar o agendamento - alert("Consulta agendada com sucesso!") + + const doctorDetails = doctors.find((d) => d.id === selectedDoctor) + + // Simulação do Paciente Logado (para fins de persistência) + const patientDetails = { + id: "P001", + full_name: "Paciente Exemplo Único", + phone: "(11) 98765-4321" + }; + + if (!patientDetails || !doctorDetails || !selectedDate || !selectedTime) { + alert("Erro: Por favor, preencha todos os campos obrigatórios."); + return; + } + + const newAppointment = { + id: new Date().getTime(), + patientName: patientDetails.full_name, + doctor: doctorDetails.name, + specialty: doctorDetails.specialty, + date: selectedDate, + time: selectedTime, + status: "agendada" as const, // As const garante a tipagem correta + // CORREÇÃO AQUI: Usando a nova propriedade 'location' + location: doctorDetails.location, + phone: patientDetails.phone, + }; + + // 1. Carrega agendamentos existentes + const storedAppointmentsRaw = localStorage.getItem(APPOINTMENTS_STORAGE_KEY); + const currentAppointments = storedAppointmentsRaw ? JSON.parse(storedAppointmentsRaw) : []; + + // 2. Adiciona o novo agendamento + const updatedAppointments = [...currentAppointments, newAppointment]; + + // 3. Salva a lista atualizada no LocalStorage + localStorage.setItem(APPOINTMENTS_STORAGE_KEY, JSON.stringify(updatedAppointments)); + + alert(`Consulta com ${doctorDetails.name} agendada com sucesso!`); + + // Limpar o formulário após o sucesso + setSelectedDoctor(""); + setSelectedDate(""); + setSelectedTime(""); + setNotes(""); } return ( @@ -139,7 +185,10 @@ export default function ScheduleAppointment() { {selectedDoctor && (
- {doctors.find((d) => d.id === selectedDoctor)?.name} + + {doctors.find((d) => d.id === selectedDoctor)?.name} + {doctors.find((d) => d.id === selectedDoctor)?.location ? ` (${doctors.find((d) => d.id === selectedDoctor)?.location})` : ''} +
)} @@ -175,4 +224,4 @@ export default function ScheduleAppointment() { ) -} +} \ No newline at end of file