Scheduling in ClinicFlow is handled by theDocumentation 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.
AppointmentSchedulingService domain service. The service exposes three static entry points — ScheduleByPatient, ScheduleByDoctor, and ScheduleByStaff — each enforcing a distinct set of invariants before delegating to the Appointment.Schedule(...) internal factory. Every entry point requires a valid SchedulingClearance token obtained from IRegionalSchedulingService, proving that regional regulations have been evaluated.
Actor-Specific Rules
- Patient
- Doctor
- Staff (Receptionist / Admin)
When a user with the
Patient role initiates scheduling, the following checks run in order:- Relationship access check —
PatientAccessService.EnsureCanActOnBehalfOf(initiatorPatient, targetPatient)verifies the initiator and target share the sameUserId. A patient may only schedule on behalf of their own family members. - Phone must be verified —
args.IsInitiatorPhoneVerifiedmust betrue. ThrowsPHONE_NOT_VERIFIEDif not. - Complete patient profile —
targetPatient.EnsureCompleteProfile()checks thatBloodTypeandEmergencyContactare populated. ThrowsPATIENT_PROFILE_INCOMPLETEif not. - Active penalty check —
new PenaltyHistory(penalties).EnsureNotBlocked(scheduledDate)throwsPatientBlockedExceptionif the patient has an unexpired, non-removedTemporaryBlock. - Age eligibility —
appointmentType.ValidatePatientEligibility(patientAge, isGuardianScheduling)checksAgeEligibilityPolicy. Guardian consent is inferred automatically: when the initiator isSelfand the target is notSelf(i.e., a family member),isGuardianSchedulingis set totrue. - Doctor availability —
schedule.CoversTimeRange(timeRange)must returntrue. Patients cannot overbook.
SchedulingClearance
SchedulingClearance is a token value object with no data properties. It can only be instantiated by calling SchedulingClearance.Granted(), which is the exclusive output of IRegionalSchedulingService.EnforceSchedulingRegulations(...).
ScheduleByPatient, ScheduleByDoctor, ScheduleByStaff) has a required SchedulingClearance clearance parameter and throws immediately if it is null. This design makes it structurally impossible to call the scheduling service without first having evaluated regional regulations.
IRegionalSchedulingService
SchedulingClearance.Granted().
Doctor Availability: Schedule.CoversTimeRange
TimeRange.Covers returns true only when the schedule’s window fully encloses the requested window:
09:00–12:00 covers a requested 10:00–10:30 window but does not cover 11:45–12:15. An inactive schedule always fails the check regardless of the time.
Age Eligibility: AgeEligibilityPolicy
AppointmentTypeDefinition stores an AgeEligibilityPolicy with three optional constraints:
| Field | Description |
|---|---|
MinimumAge | Patient must be at least this age. null = no lower bound. |
MaximumAge | Patient must not exceed this age. null = no upper bound. |
RequiresLegalGuardian | If true, a patient under 18 requires guardian consent. |
AgeEligibilityPolicy.NoRestriction is a static shortcut that sets all three fields to their permissive defaults and is used when a new AppointmentTypeDefinition is created without an explicit policy.
Family Member Scheduling
Patients can schedule appointments on behalf of their dependents (children, spouses, parents, siblings). The gate for this isPatientAccessService.EnsureCanActOnBehalfOf:
Self) patient profile is allowed to schedule for other family members on the same account. A Child profile cannot schedule for its Sibling.
Appointment Status Lifecycle
The diagram below shows every valid state transition in the appointment lifecycle.Scheduled → CheckedIn → InProgress → Completed
Cancellation paths:
Scheduled → Cancelled— cancelled within the specialty’sCancellationLimitnotice windowScheduled → LateCancellation— cancelled after the notice deadline, triggers a penaltyScheduled → NoShow— patient did not arrive; marked by staff or the owning doctor
Scheduled → RequiresReassignment— the doctor was suspendedRequiresReassignment → Scheduled— a new doctor and timeslot have been assigned (Reassign)RequiresReassignment → Cancelled— the system timeout expired without reassignment (CancelDueToSystemTimeout), no patient penalty applied
Rescheduling Rules
Rescheduling follows the same actor-specific rule structure as scheduling:| Rule | Patient | Doctor | Staff |
|---|---|---|---|
| Phone must be verified | ✅ | ❌ | ❌ |
| Penalty block check | ✅ | ❌ | ❌ |
| Doctor must own the appointment | — | ✅ | ❌ |
| Can overbook | ❌ | ✅ | ✅ |
Requires SchedulingClearance | ✅ | ✅ | ✅ |
| Max 1 reschedule per appointment | ✅ | ✅ | ✅ |
Cancellation Rules
Cancellation is handled byAppointmentCancellationService:
- Patient — must be the owner of the patient profile (
targetPatient.UserId == initiatorUserId). Cannot cancelProcedureappointments. Emergency appointments can only be cancelled if the patient isSelfor is aChildunder 18 years old. The service checksMedicalSpecialty.IsCancellationAllowed(...)to decide whether to callCancel(no penalty) orCancelLate(penalty). - Doctor — must be the assigned doctor (
initiatorDoctorId == appointment.DoctorId). Always results in a regularCancelledstatus. - Staff — can cancel any appointment but must provide a non-empty cancellation reason. Always results in a regular
Cancelledstatus.