From 94839cca87c746549d4188b5b56048d6d0dc6205 Mon Sep 17 00:00:00 2001 From: Arthur Date: Thu, 11 Sep 2025 00:03:33 -0300 Subject: [PATCH] Adicionando calendario interativo do medico --- susconecta/app/profissional/page.tsx | 369 +++++++++++++++++++++++++-- 1 file changed, 345 insertions(+), 24 deletions(-) diff --git a/susconecta/app/profissional/page.tsx b/susconecta/app/profissional/page.tsx index c952f19..7d24d9f 100644 --- a/susconecta/app/profissional/page.tsx +++ b/susconecta/app/profissional/page.tsx @@ -22,7 +22,7 @@ import { SelectValue, } from "@/components/ui/select"; import { Avatar, AvatarImage, AvatarFallback } from "@/components/ui/avatar" -import { User, FolderOpen, X, Users, MessageSquare, ClipboardList } from "lucide-react" +import { User, FolderOpen, X, Users, MessageSquare, ClipboardList, Plus, Edit, Trash2 } from "lucide-react" import { Calendar as CalendarIcon, FileText, Settings } from "lucide-react"; import { Tooltip, @@ -31,6 +31,13 @@ import { TooltipTrigger, } from "@/components/ui/tooltip"; +// Importações do FullCalendar +import FullCalendar from "@fullcalendar/react"; +import dayGridPlugin from "@fullcalendar/daygrid"; +import timeGridPlugin from "@fullcalendar/timegrid"; +import interactionPlugin from "@fullcalendar/interaction"; +import ptBrLocale from "@fullcalendar/core/locales/pt-br"; + const pacientes = [ { nome: "Ana Souza", cpf: "123.456.789-00", idade: 42, statusLaudo: "Finalizado" }, { nome: "Bruno Lima", cpf: "987.654.321-00", idade: 33, statusLaudo: "Pendente" }, @@ -43,8 +50,31 @@ const medico = { fotoUrl: "", } +// Tipos de consulta com cores +const colorsByType = { + Rotina: "#4dabf7", + Cardiologia: "#f76c6c", + Otorrino: "#f7b84d", + Pediatria: "#6cf78b", + Dermatologia: "#9b59b6", + Oftalmologia: "#2ecc71" +}; + const ProfissionalPage = () => { const [pacienteSelecionado, setPacienteSelecionado] = useState(null); + const [events, setEvents] = useState([]); + const [editingEvent, setEditingEvent] = useState(null); + const [showPopup, setShowPopup] = useState(false); + const [showActionModal, setShowActionModal] = useState(false); + const [step, setStep] = useState(1); + const [newEvent, setNewEvent] = useState({ + title: "", + type: "", + time: "", + pacienteId: "" + }); + const [selectedDate, setSelectedDate] = useState(null); + const [selectedEvent, setSelectedEvent] = useState(null); const handleSave = (event: React.MouseEvent) => { event.preventDefault(); @@ -66,17 +96,12 @@ const ProfissionalPage = () => { const handleAbrirProntuario = (paciente: any) => { setPacienteSelecionado(paciente); - // Preencher campos da seção Gestão de Laudos const pacienteLaudo = document.getElementById('pacienteLaudo') as HTMLInputElement; - if (pacienteLaudo) pacienteLaudo.value = paciente.nome; - // Preencher campos da seção Comunicação com o Paciente const destinatario = document.getElementById('destinatario') as HTMLInputElement; - if (destinatario) destinatario.value = `${paciente.nome} - ${paciente.cpf}`; - // Rolar para a seção do prontuário const prontuarioSection = document.getElementById('prontuario-paciente'); if (prontuarioSection) { prontuarioSection.scrollIntoView({ behavior: 'smooth' }); @@ -87,22 +112,130 @@ const ProfissionalPage = () => { setPacienteSelecionado(null); }; + // Clicar em um dia -> abrir popup 3 etapas + const handleDateClick = (arg: any) => { + setSelectedDate(arg.dateStr); + setNewEvent({ title: "", type: "", time: "", pacienteId: "" }); + setStep(1); + setEditingEvent(null); + setShowPopup(true); + }; + + // Adicionar nova consulta + const handleAddEvent = () => { + const paciente = pacientes.find(p => p.nome === newEvent.title); + const eventToAdd = { + id: Date.now(), + title: newEvent.title, + type: newEvent.type, + time: newEvent.time, + date: selectedDate, + pacienteId: paciente ? paciente.cpf : "", + color: colorsByType[newEvent.type as keyof typeof colorsByType] || "#4dabf7" + }; + setEvents((prev) => [...prev, eventToAdd]); + setShowPopup(false); + }; + + // Editar consulta existente + const handleEditEvent = () => { + setEvents((prevEvents) => + prevEvents.map((ev) => + ev.id.toString() === editingEvent.id.toString() + ? { + ...ev, + title: newEvent.title, + type: newEvent.type, + time: newEvent.time, + color: colorsByType[newEvent.type as keyof typeof colorsByType] || "#4dabf7" + } + : ev + ) + ); + setEditingEvent(null); + setShowPopup(false); + setShowActionModal(false); + }; + + // Próxima etapa no popup + const handleNextStep = () => { + if (step < 3) setStep(step + 1); + else editingEvent ? handleEditEvent() : handleAddEvent(); + }; + + // Clicar em uma consulta -> abre modal de ação (Editar/Apagar) + const handleEventClick = (clickInfo: any) => { + setSelectedEvent(clickInfo.event); + setShowActionModal(true); + }; + + // Apagar consulta + const handleDeleteEvent = () => { + if (!selectedEvent) return; + setEvents((prevEvents) => + prevEvents.filter((ev: any) => ev.id.toString() !== selectedEvent.id.toString()) + ); + setShowActionModal(false); + }; + + // Começar a editar + const handleStartEdit = () => { + if (!selectedEvent) return; + setEditingEvent(selectedEvent); + setNewEvent({ + title: selectedEvent.title, + type: selectedEvent.extendedProps.type, + time: selectedEvent.extendedProps.time, + pacienteId: selectedEvent.extendedProps.pacienteId || "" + }); + setStep(1); + setShowActionModal(false); + setShowPopup(true); + }; + + // Aparência da consulta dentro do calendário + const renderEventContent = (eventInfo: any) => { + const bg = eventInfo.event.backgroundColor || eventInfo.event.extendedProps?.color || "#4dabf7"; + + return ( +
+ {eventInfo.event.title} + + {eventInfo.event.extendedProps.type} + + {eventInfo.event.extendedProps.time} +
+ ); + }; + return (
- - - - - - -
-

Conta do profissional

-

{medico.nome}

-

{medico.identificacao}

-
-
+ + + + + + +
+

Conta do profissional

+

{medico.nome}

+

{medico.identificacao}

+
+ +
{/* Sidebar */} -

Área do Profissional de Saúde

@@ -175,10 +307,48 @@ const ProfissionalPage = () => {

Bem-vindo à sua área exclusiva.

-

Calendário

-

- Seção do calendário (integração pode ser adicionada depois). -

+
+

Calendário de Consultas

+ +
+ +
+ ({ + id: ev.id.toString(), + title: ev.title, + date: ev.date, + color: ev.color, + extendedProps: { + type: ev.type, + time: ev.time, + pacienteId: ev.pacienteId, + color: ev.color + } + }))} + eventContent={renderEventContent} + eventClick={handleEventClick} + headerToolbar={{ + left: 'prev,next today', + center: 'title', + right: 'dayGridMonth,timeGridWeek,timeGridDay' + }} + buttonText={{ + today: 'Hoje', + month: 'Mês', + week: 'Semana', + day: 'Dia' + }} + /> +
@@ -427,9 +597,160 @@ const ProfissionalPage = () => {
+ + {/* POPUP 3 etapas (Adicionar/Editar) */} + {showPopup && ( +
+ +
+ + {step === 1 && ( + <> +

Selecionar Paciente

+ +
+ + +
+ + )} + + {step === 2 && ( + <> +

Tipo da Consulta

+ +
+ + +
+ + )} + + {step === 3 && ( + <> +

Horário da Consulta

+ setNewEvent({ ...newEvent, time: e.target.value })} + className="mb-4" + /> +
+ + +
+ + )} +
+
+ )} + + {/* MODAL de ação ao clicar em consulta */} + {showActionModal && selectedEvent && ( +
+
+

+ Consulta de {selectedEvent.title} +

+

+ {selectedEvent.extendedProps.type} às {selectedEvent.extendedProps.time} +

+ +
+ + +
+ + +
+
+ )}
); }; -export default ProfissionalPage; +export default ProfissionalPage; \ No newline at end of file