Overview
Med Agenda’s appointment scheduling system handles the complete lifecycle of medical consultations, including conflict detection, urgent consultation flagging, and automated email notifications. The system is built using Spring Boot and integrates with payment processing and diagnosis tracking.Appointment Data Model
Every consultation in Med Agenda contains the following information:Patient.java:11-36
consultationId: Unique UUID identifierdateTime: Scheduled date and time for the consultationduracaoMinutos: Duration in minutes (default: 60 minutes)patient: Patient reference (linked by CPF)doctor: Doctor reference (linked by CRM)isUrgent: Flag for urgent consultationsobservation: Additional notes or comments
Creating Appointments
The appointment creation process validates both patient and doctor, creates the consultation, generates a payment record, and sends email confirmation.ConsultationService.java:42-76
API Endpoint
ConsultationController.java:25-36
POST /consultations/create
Urgent Consultation Flagging
Med Agenda uses the Decorator pattern to mark consultations as urgent, allowing special handling and prioritization.UrgentConsultationDecorator.java:10-24
isUrgent = true and can receive special treatment in scheduling and notifications.
Updating Appointments
Appointments can be rescheduled by updating the date/time and observations.ConsultationService.java:78-84
PUT /consultations/update
Canceling Appointments
Cancellation removes the appointment and all associated records (diagnosis, payment).ConsultationService.java:86-102
DELETE /consultations/{id}
Querying Appointments
Get Single Appointment
ConsultationService.java:104-106
GET /consultations/{id}
Get All Appointments
ConsultationService.java:108-110
GET /consultations/all
Get Patient History
ConsultationService.java:112-114
GET /consultations/patient-history/{cpf}
Conflict Detection
The repository provides methods to query consultations by date range, enabling conflict detection:ConsultationRepository.java:20-34
Appointment Lifecycle
Integration with Other Systems
The appointment system integrates with:- Payment System: Automatic payment record creation with
PENDINGstatus - Email System: Confirmation emails via Resend API
- Diagnosis System: Linked medical records and diagnoses
- Patient Records: Complete consultation history tracking
Best Practices
- Always validate patient and doctor existence before creating consultations
- Use UUID for consultation identifiers to ensure uniqueness
- Set default duration to 60 minutes unless specified otherwise
- Handle urgent consultations with the decorator pattern for flexibility
- Clean up all related records (payments, diagnoses) when canceling appointments
- Query by date range to detect scheduling conflicts before confirming