ADocumentation Index
Fetch the complete documentation index at: https://mintlify.com/0Crazy-0/ClinicFlow/llms.txt
Use this file to discover all available pages before exploring further.
Schedule in ClinicFlow represents a single recurring availability block for a doctor on a specific day of the week. Schedules are the gating mechanism that the booking system checks before any appointment is created or rescheduled — a patient cannot book a slot that falls outside an active schedule. This page explains the Schedule entity, the two commands for creating schedules, and the deactivation flow that triggers appointment reassignment downstream.
The Schedule Entity
DoctorId) and covers one day of the week (DayOfWeek). The availability window is captured by a TimeRange value object — an immutable record with Start and End as TimeOnly values.
TimeRange Value Object
schedule.CoversTimeRange(requestedRange), which delegates to TimeRange.Covers. This verifies that the requested appointment window sits entirely within the doctor’s available window for that day.
Creating Schedules
CreateScheduleCommand — Single Slot
UseCreateScheduleCommand when adding one availability slot at a time:
Schedule.EnsureNoDuplicateDay against the doctor’s existing schedules before persisting. On success it returns the new Schedule ID.
SetupWeeklyScheduleCommand — Batch Creation
SetupWeeklyScheduleCommand lets administrators configure all working days for a doctor in one request:
WeeklyScheduleSetupService.SetupWeeklySchedule:
Schedule.EnsureNoDuplicateDay and Schedule.Create in sequence before persisting the entire batch via IScheduleRepository.CreateRangeAsync. The command returns a list of the newly created IDs, one per slot.
Duplicate-Day Protection
Schedule.EnsureNoDuplicateDay is a static guard that prevents two active schedules from existing on the same day for the same doctor:
existingSchedules for any entry where s.DayOfWeek == dayOfWeek && s.IsActive. If a match is found, ScheduleAlreadyExistsException is thrown. Inactive (deactivated) schedules are excluded from this check, meaning you can replace a deactivated Monday slot by creating a fresh one without error.
Updating a Schedule
UpdateScheduleCommand replaces the time range of an existing schedule slot for the given doctor and day:
(DoctorId, DayOfWeek) and updates the TimeRange. The schedule must be active — attempting to update a deactivated slot results in an error.
Deactivating a Schedule
DeactivateScheduleCommand marks an active schedule slot as unavailable for new bookings:
Schedule.Deactivate():
ScheduleDeactivatedEvent carries the ScheduleId, DoctorId, and the affected DayOfWeek. A downstream event handler (ScheduleDeactivatedEventHandler) listens for this event and calls appointment.MarkAsRequiresReassignment() on every future Scheduled appointment for that doctor whose ScheduledDate.DayOfWeek matches the deactivated day.
Deactivating a schedule does not cancel any existing appointments. Appointments that fall within the deactivated slot are transitioned to
RequiresReassignment status. Staff must then use ReassignAppointment to move each affected appointment to a new doctor and time slot before the scheduled date. See the Appointments page for the full reassignment flow.Availability Check During Booking
Every scheduling path — patient, doctor, and staff — calls the private helperEnsureDoctorIsAvailable inside AppointmentSchedulingService:
schedule passed in is fetched by IScheduleRepository.GetByDoctorAndDayAsync(doctorId, scheduledDate.DayOfWeek). If no active schedule exists for that day, the repository returns null and the handler throws EntityNotFoundException before the domain check is even reached.
Doctor and staff actors can bypass this check by setting IsOverbook = true in their respective scheduling args, which skips the EnsureDoctorIsAvailable call entirely.
Querying Schedules
GetSchedulesByDoctorId
ScheduleDto:
IsActive == true to display only bookable slots. The GetScheduleByDoctorAndDay query is also available for targeted lookups when the day is already known.
Command Reference
| Command | Actor | Effect |
|---|---|---|
CreateScheduleCommand | Admin / Staff | Creates one schedule slot; rejects duplicates on the same active day |
SetupWeeklyScheduleCommand | Admin / Staff | Creates multiple slots in a single batch; duplicate check applies per slot |
UpdateScheduleCommand | Admin / Staff | Replaces the time range of an existing active slot |
DeactivateScheduleCommand | Admin / Staff | Sets IsActive = false; fires ScheduleDeactivatedEvent → appointments become RequiresReassignment |
Repository API
IScheduleRepository provides the full persistence contract:
GetActiveByDoctorIdAsync when building availability calendars — it excludes deactivated slots automatically.