Overview
Time blocks represent available appointment slots created by doctors. They define specific time periods when a doctor is available to see patients. Patients can reserve these time blocks to create appointments.Time Block Model
The time block data structure is defined in the Prisma schema:Field Descriptions
Auto-incrementing unique identifier for the time block.
Reference to the doctor who created this time block. Only users with the
DOCTOR role can create time blocks.The beginning of the available time slot. This defines when the appointment can start.
The end of the available time slot. This defines when the appointment must conclude.
The date when this time block is valid. Defaults to the current date when created.
Timestamp when the time block was created.
Timestamp of the last update to the time block.
How Time Blocks Work
Time blocks serve as the foundation for the appointment scheduling system:Doctor Creates Availability
A doctor creates a time block by specifying a start time and end time. This represents a period when they’re available to see patients.
Time Block is Available
The time block appears in the system as an available slot. Patients can browse available time blocks to find suitable appointment times.
Patient Reserves Time Block
When a patient books an appointment, they select an available time block. This creates an
Appointment record linked to the time block.Relationships
Doctor Relationship
Each time block belongs to exactly one doctor:onDelete: Restrict constraint prevents deletion of a doctor who has created time blocks.
Appointment Relationship
Each time block can have zero or one appointment:? indicates this is an optional relationship. A time block without an appointment is available for booking.
To check if a time block is available, query for time blocks where
appointment is null.Creating Time Blocks
Doctors create time blocks through the time block controller. The system validates ownership and prevents conflicts. Example from/home/daytona/workspace/source/src/controllers/timeBlockController.js:6:
Ownership Enforcement
Doctors can only manage their own time blocks. The system validates ownership before allowing updates or deletions at
/home/daytona/workspace/source/src/controllers/timeBlockController.js:28.Constraints and Validation
Unique Constraint
The schema enforces uniqueness on the combination of doctor, start time, and end time:Business Rules
- No Overlapping Slots: While not enforced at the database level, the application should validate that time blocks don’t overlap for the same doctor.
- Future Dates: Time blocks should typically be created for future dates to allow patients to book appointments in advance.
-
Reasonable Duration: The
endTimeshould be afterstartTimeto create a valid time slot.
Managing Time Blocks
Updating Time Blocks
Doctors can update their time blocks if they haven’t been reserved:Deleting Time Blocks
Doctors can delete their unreserved time blocks:/home/daytona/workspace/source/src/controllers/timeBlockController.js:59, the system validates:
- The time block exists
- The requesting doctor owns the time block
- No appointment is linked to the time block (enforced by
onDelete: Restrict)
Querying Available Time Blocks
To find available time blocks for booking:Best Practices
- Create Blocks in Advance: Doctors should create time blocks well in advance to give patients adequate booking time.
- Standard Durations: Use consistent time block durations (e.g., 30 minutes, 1 hour) for predictable scheduling.
- Buffer Time: Consider adding buffer time between appointments by creating time blocks with gaps.
- Regular Updates: Doctors should regularly review and update their availability to reflect their actual schedule.