agendamentos
This commit is contained in:
parent
17e295d4df
commit
ff6536b606
199
app/doctor/medicos/consultas/page.tsx
Normal file
199
app/doctor/medicos/consultas/page.tsx
Normal file
@ -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<LocalStorageAppointment[]>([]);
|
||||||
|
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 (
|
||||||
|
<DoctorLayout>
|
||||||
|
<div className="space-y-6">
|
||||||
|
<div>
|
||||||
|
<h1 className="text-3xl font-bold text-gray-900">Minhas Consultas (Agenda Completa)</h1>
|
||||||
|
<p className="text-gray-600">Todas as consultas agendadas, para qualquer médico, são exibidas aqui ({LOGGED_IN_DOCTOR_NAME})</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex justify-end">
|
||||||
|
<Button onClick={loadAppointments} disabled={isLoading} variant="outline" size="sm">
|
||||||
|
<RefreshCw className={`mr-2 h-4 w-4 ${isLoading ? 'animate-spin' : ''}`} />
|
||||||
|
Atualizar Agenda
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-4">
|
||||||
|
{isLoading ? (
|
||||||
|
<p className="text-center text-lg text-gray-500">Carregando a agenda...</p>
|
||||||
|
) : appointments.length === 0 ? (
|
||||||
|
<p className="text-center text-lg text-gray-500">Nenhuma consulta agendada no sistema.</p>
|
||||||
|
) : (
|
||||||
|
appointments.map((appointment) => {
|
||||||
|
const showActions = appointment.status === "agendada" || appointment.status === "confirmada";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card key={appointment.id} className="shadow-lg">
|
||||||
|
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||||
|
{/* NOME DO PACIENTE */}
|
||||||
|
<CardTitle className="text-xl font-semibold flex items-center">
|
||||||
|
<User className="mr-2 h-5 w-5 text-blue-600" />
|
||||||
|
{appointment.patientName}
|
||||||
|
</CardTitle>
|
||||||
|
{/* STATUS DA CONSULTA */}
|
||||||
|
<Badge variant={getStatusVariant(appointment.status)} className="uppercase">
|
||||||
|
{appointment.status}
|
||||||
|
</Badge>
|
||||||
|
</CardHeader>
|
||||||
|
|
||||||
|
<CardContent className="grid md:grid-cols-3 gap-4 pt-4">
|
||||||
|
{/* Coluna de Detalhes */}
|
||||||
|
<div className="space-y-3">
|
||||||
|
<div className="flex items-center text-sm text-gray-700">
|
||||||
|
<User className="mr-2 h-4 w-4 text-gray-500" />
|
||||||
|
<span className="font-semibold">Médico:</span> {appointment.doctor}
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center text-sm text-gray-700">
|
||||||
|
<Calendar className="mr-2 h-4 w-4 text-gray-500" />
|
||||||
|
{new Date(appointment.date).toLocaleDateString("pt-BR", { timeZone: "UTC" })}
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center text-sm text-gray-700">
|
||||||
|
<Clock className="mr-2 h-4 w-4 text-gray-500" />
|
||||||
|
{appointment.time}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Coluna 2: Local e Contato */}
|
||||||
|
<div className="space-y-3">
|
||||||
|
<div className="flex items-center text-sm text-gray-700">
|
||||||
|
<MapPin className="mr-2 h-4 w-4 text-gray-500" />
|
||||||
|
{appointment.location}
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center text-sm text-gray-700">
|
||||||
|
<Phone className="mr-2 h-4 w-4 text-gray-500" />
|
||||||
|
{appointment.phone || "N/A"}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* COLUNA 3: Ações (Botões) */}
|
||||||
|
<div className="flex flex-col justify-center items-end">
|
||||||
|
{showActions && (
|
||||||
|
<div className="flex space-x-2">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => handleReSchedule(appointment.id)}
|
||||||
|
>
|
||||||
|
<RefreshCw className="mr-2 h-4 w-4" />
|
||||||
|
Reagendar
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="destructive"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => handleCancel(appointment.id)}
|
||||||
|
>
|
||||||
|
<X className="mr-2 h-4 w-4" />
|
||||||
|
Cancelar
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
})
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</DoctorLayout>
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -1,7 +1,6 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import type React from "react"
|
import type React from "react"
|
||||||
|
|
||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
import PatientLayout from "@/components/patient-layout"
|
import PatientLayout from "@/components/patient-layout"
|
||||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
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 { Textarea } from "@/components/ui/textarea"
|
||||||
import { Calendar, Clock, User } from "lucide-react"
|
import { Calendar, Clock, User } from "lucide-react"
|
||||||
|
|
||||||
|
// Chave do LocalStorage
|
||||||
|
const APPOINTMENTS_STORAGE_KEY = "clinic-appointments";
|
||||||
|
|
||||||
export default function ScheduleAppointment() {
|
export default function ScheduleAppointment() {
|
||||||
const [selectedDoctor, setSelectedDoctor] = useState("")
|
const [selectedDoctor, setSelectedDoctor] = useState("")
|
||||||
const [selectedDate, setSelectedDate] = useState("")
|
const [selectedDate, setSelectedDate] = useState("")
|
||||||
const [selectedTime, setSelectedTime] = useState("")
|
const [selectedTime, setSelectedTime] = useState("")
|
||||||
const [notes, setNotes] = useState("")
|
const [notes, setNotes] = useState("")
|
||||||
|
|
||||||
|
// ALTERAÇÃO AQUI: Adicionado 'location' para a tipagem e dados baterem
|
||||||
const doctors = [
|
const doctors = [
|
||||||
{ id: "1", name: "Dr. João Silva", specialty: "Cardiologia" },
|
{ id: "1", name: "Dr. João Silva", specialty: "Cardiologia", location: "Unidade Central - Sala 101" },
|
||||||
{ id: "2", name: "Dra. Maria Santos", specialty: "Dermatologia" },
|
{ id: "2", name: "Dra. Maria Santos", specialty: "Dermatologia", location: "Unidade Central - Sala 205" },
|
||||||
{ id: "3", name: "Dr. Pedro Costa", specialty: "Ortopedia" },
|
{ id: "3", name: "Dr. Pedro Costa", specialty: "Ortopedia", location: "Unidade Centro-Oeste - Sala 302" },
|
||||||
{ id: "4", name: "Dra. Ana Lima", specialty: "Ginecologia" },
|
{ id: "4", name: "Dra. Ana Lima", specialty: "Ginecologia", location: "Unidade Centro-Oeste - Sala 108" },
|
||||||
]
|
]
|
||||||
|
|
||||||
const availableTimes = [
|
const availableTimes = [
|
||||||
@ -42,8 +45,51 @@ export default function ScheduleAppointment() {
|
|||||||
|
|
||||||
const handleSubmit = (e: React.FormEvent) => {
|
const handleSubmit = (e: React.FormEvent) => {
|
||||||
e.preventDefault()
|
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 (
|
return (
|
||||||
@ -139,7 +185,10 @@ export default function ScheduleAppointment() {
|
|||||||
{selectedDoctor && (
|
{selectedDoctor && (
|
||||||
<div className="flex items-center space-x-2">
|
<div className="flex items-center space-x-2">
|
||||||
<User className="h-4 w-4 text-gray-500" />
|
<User className="h-4 w-4 text-gray-500" />
|
||||||
<span className="text-sm">{doctors.find((d) => d.id === selectedDoctor)?.name}</span>
|
<span className="text-sm">
|
||||||
|
{doctors.find((d) => d.id === selectedDoctor)?.name}
|
||||||
|
{doctors.find((d) => d.id === selectedDoctor)?.location ? ` (${doctors.find((d) => d.id === selectedDoctor)?.location})` : ''}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@ -175,4 +224,4 @@ export default function ScheduleAppointment() {
|
|||||||
</div>
|
</div>
|
||||||
</PatientLayout>
|
</PatientLayout>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user