Overview
The Medical Center API manages appointments through a multi-stage workflow that transitions from public requests to confirmed appointments with assigned doctors.Appointment Lifecycle
Status States
1. Pendiente (Pending)
Initial state when a public client submits an appointment request.Public clients can request appointments without authentication. The system creates both a
Clientes_publicos record and a Citas record in a single transaction.2. Confirmada (Confirmed)
Assigned state after an admin or assistant assigns a doctor and confirms the date/time.The confirmed date/time can differ from the requested date/time if the assistant needs to reschedule based on doctor availability.
3. Atendida (Attended)
Completed state after the appointment has been attended.4. Cancelada (Cancelled)
Cancelled state - can be set from eitherpendiente or confirmada.
Workflow Stages
Stage 1: Public Appointment Request
Endpoint:POST /api/citas (No authentication required)
A public client submits basic information and desired date/time:
-
System creates a
Clientes_publicosrecord: -
System creates a
Citasrecord inpendientestate:
Why separate date and time fields?
Why separate date and time fields?
The schema uses PostgreSQL’s
@db.Date and @db.Time types:fecha_solicitada/fecha_confirmada: Date only (no time component)hora_solicitada/hora_confirmada: Time only (stored as time-of-day)
Stage 2: Assistant Reviews Pending Appointments
Endpoint:GET /api/citas (Requires auth: admin or asistente)
Staff members view all appointments with full details:
- Client information (
cliente) - Assigned doctor details if confirmed (
medico.persona,medico.especialidad) - All date/time fields
- Current status
Stage 3: Confirming and Assigning
Endpoint:PUT /api/citas/:id/confirmar (Requires auth: admin or asistente)
Assistant assigns a doctor and confirms the appointment:
The
fecha_confirmada and hora_confirmada are set to the current date/time when confirming. In practice, these should be set to the actual scheduled date/time (which may match fecha_solicitada or be different).Stage 4: Marking as Attended
Endpoint:PUT /api/citas/:id/atender (Requires auth: admin or asistente)
After the appointment is completed:
Stage 5: Cancellation
Endpoint:PUT /api/citas/:id/cancelar (Requires auth: admin or asistente)
Cancelling an appointment (from any state):
Cancelling an appointment removes the doctor assignment (
medico_id set to null), freeing up the doctor’s schedule.Date/Time Field Comparison
| Field | Set By | When | Purpose |
|---|---|---|---|
fecha_solicitada | Public client | Appointment request | Patient’s preferred date |
hora_solicitada | Public client | Appointment request | Patient’s preferred time |
fecha_confirmada | Assistant | Confirmation | Actual scheduled date |
hora_confirmada | Assistant | Confirmation | Actual scheduled time |
Why have both requested and confirmed dates?
Why have both requested and confirmed dates?
Flexibility in scheduling:
- Patient requests a date/time that may not be available
- Assistant can reschedule to an available slot
- System maintains both for record-keeping and transparency
- Patient can be notified of the actual confirmed date/time
Complete Workflow Example
Day 1: Patient Requests Appointment
Day 2: Assistant Reviews and Confirms
Day 15: Patient Attends Appointment
Alternative: Cancellation
Admin-Only Operations
Deleting Appointments
Endpoint:DELETE /api/citas/:id (Requires auth: admin only)
Medical History Notes
After an appointment is attended, staff can add notes to theHistorial table:
Multiple history records can be associated with a single appointment, allowing for follow-up notes or amendments.
Best Practices
Workflow Guidelines
Workflow Guidelines
For Assistants:
- Review pending appointments daily
- Confirm appointments only when doctor availability is verified
- Update
fecha_confirmadato the actual scheduled date if different from request - Mark appointments as attended promptly after completion
- Cancel with appropriate notice if rescheduling is needed
- Use deletion sparingly - prefer cancellation for tracking
- Monitor appointment metrics via dashboard
- Ensure doctors have appropriate schedules
- Always validate status transitions
- Include full relations when fetching appointments for display
- Handle date/time formatting carefully (PostgreSQL Date/Time types)
- Implement notifications for status changes (future enhancement)