Overview
The Appointment Scheduling feature is the core of Clínica Vitalis, enabling efficient management of patient appointments with healthcare professionals. The system includes intelligent conflict detection, automatic status updates, and comprehensive filtering capabilities.Data Model
Appointments are structured with the following schema:Appointment States
Appointments can have four states:- Pendiente (Pending): Appointment is scheduled and waiting
- Atendido (Completed): Patient was seen by the professional
- Cancelado (Cancelled): Appointment was cancelled
- Ausente (No-show): Patient did not attend (automatically set)
Key Features
Create Appointment
The system performs extensive validation when creating appointments:Conflict Detection
System validates:
- Patient doesn’t have another appointment at the same time
- Professional is available at the requested time
- Time falls within professional’s work schedule
Advanced Validation Rules
The appointment system includes sophisticated validation frombackend/routes/appointments.ts:29-46:
Conflict Prevention
The database enforces uniqueness constraints to prevent double-booking:The system prevents:
- A patient from having multiple appointments at the same date/time
- A professional from being double-booked at the same date/time
Automatic No-Show Detection
The system automatically marks appointments as “No-show” when:- Appointment date has passed
- Appointment time has passed for today’s date
- Appointment state is still “Pending”
Search and Filter Appointments
Comprehensive filtering options are available: Search by:- Patient DNI (partial match)
- Professional ID
- Appointment state
- All appointments (ordered by date DESC)
- Today’s appointments (ordered by time ASC)
- Daily statistics (count and cancellations)
View Appointment Details
Appointment listings include complete relational data:- Patient information
- Professional information
- Professional’s specialty
- Appointment date, time, and state
Update Appointment
Appointments can be updated with full re-validation:When updating appointments, all validation rules are re-applied including conflict detection and work schedule verification.
API Endpoints
GET /api/appointments
Retrieve appointments with optional filters.
Query Parameters:
search- Patient DNI searchprofessionalID- Filter by professionalstate- Filter by appointment state
GET /api/appointments/:id
Retrieve a specific appointment by ID.
POST /api/appointments
Create a new appointment (Admin only).
Required Fields:
- patientID, professionalID, date, time, description
PATCH /api/appointments/:id
Update an appointment (Admin only).
Required Fields:
- All fields from POST plus
state
Daily Statistics
The system automatically provides daily metrics:- Total appointments for today
- Cancelled appointments for today
- Appointment list sorted by time
- Reception desk displays
- Daily workload planning
- Professional schedules
Security
All appointment operations require JWT authentication. Create and update operations require administrator privileges.
Database Relationships
Appointments connect:- Patients (Many-to-One): Each appointment belongs to one patient
- Professionals (Many-to-One): Each appointment is with one professional
- Specialties (Through Professional): Specialty information is accessible through the professional relationship
Workflow Example
Typical appointment booking workflow:Check Professional Availability
Staff checks which professionals are available for the requested specialty.
Best Practices
- Always check professional work schedules before booking appointments
- Validate patient and professional exist and are active before creating appointments
- Use state transitions properly: Pending → Completed/Cancelled (manual) or Pending → No-show (automatic)
- Monitor daily statistics to track clinic operation efficiency
- Filter by professional to see individual workload distribution
- Update states promptly after appointments to maintain accurate records
- Never delete appointments - use state changes for record keeping
