Overview
Appointments are the core entity of the Medical Appointments API. They represent scheduled meetings between patients and doctors at specific time slots. Each appointment is linked to a time block, which defines the date and time of the meeting.Appointment Model
The appointment data structure is defined in the Prisma schema:Field Descriptions
Auto-incrementing unique identifier for the appointment.
The scheduled date and time for the appointment. This is automatically set to match the time block’s
startTime.Reference to the time block being reserved. This field is unique, ensuring each time block can only have one appointment.
Reference to the patient user booking the appointment.
Reference to the doctor user who will conduct the appointment.
Current status of the appointment. See Appointment Lifecycle for possible values.
Optional notes about the appointment, typically added by the patient or doctor.
Optional field describing the reason for the appointment.
Appointment Lifecycle
Appointments progress through different statuses defined by theAppointmentStatus enum:
Status Definitions
PENDING
Initial state when an appointment is created. The appointment is awaiting confirmation from the doctor or admin.
CONFIRMED
The doctor or admin has confirmed the appointment. Both parties are expected to attend at the scheduled time.
CANCELLED
The appointment has been cancelled by either the patient, doctor, or admin. The time block may become available again.
Relationships
Appointments connect three key entities:Patient Relationship
Each appointment belongs to one patient. ThepatientId field references a User with the PATIENT role:
Doctor Relationship
Each appointment is assigned to one doctor. ThedoctorId field references a User with the DOCTOR role:
Time Block Relationship
Each appointment occupies exactly one time block. The relationship is one-to-one:The
timeBlockId field has a @unique constraint, ensuring that each time block can only be reserved for one appointment.Creating Appointments
Appointments are created through the reservation service. The process validates:- Patient exists and has
PATIENTrole - Doctor exists and has
DOCTORrole - Time block exists and is available
- No conflicting appointment exists for the time block
/home/daytona/workspace/source/src/services/reservationService.js:21:
The
date field is automatically populated from the associated time block’s startTime to ensure consistency.Constraints
Unique Constraint
The schema enforces a unique constraint on[timeBlockId, patientId]:
Referential Integrity
All foreign key relationships useonDelete: Restrict, preventing deletion of:
- Users who have appointments
- Time blocks that are reserved