AppointmentScheduler#
class medscheduler.AppointmentScheduler
Generates a fully synthetic yet statistically realistic dataset of outpatient appointments — including calendar slots, patient demographics, and visit outcomes. Designed for educational, analytical, and research use without privacy risks.
Purpose#
The AppointmentScheduler simulates the entire outpatient appointment process:
Builds configurable daily calendars of bookable slots.
Generates patient cohorts with realistic age–sex distributions.
Allocates appointments with probabilistic attendance, cancellation, and rebooking.
Simulates punctuality and in-clinic timing dynamics.
Outputs three relational tables:
appointments,slots, andpatients.
All parameters are configurable for reproducibility or scenario testing.
Parameters#
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
list of (date, date) |
|
Simulation window for available slots. See Date ranges and reference date. |
|
date |
|
Reference date separating past and future appointments. |
|
list[int] |
|
Active weekdays (0=Mon, …, 6=Sun). See Calendar structure. |
|
int |
|
Defines slot granularity (15 min). Must divide 60 evenly. |
|
list[tuple[int,int]] |
|
Start–end working blocks (e.g. 8 → 18 h). |
|
float |
|
Target proportion of booked slots. See Booking dynamics. |
|
int |
|
Maximum days ahead that can be booked. |
|
int |
|
Median days between scheduling and appointment. |
|
dict |
NHS-derived |
Probabilities for outcomes (attended / cancelled / DNA / unknown). See Attendance behavior. |
|
{ |
|
Intensity of rebooking behavior. |
|
float |
|
Average early arrival (minutes). See Appointment timing. |
|
float |
|
Mean visit frequency per patient per year. See Patient flow. |
|
float |
|
Ratio of first attendances among visits. |
|
dict[int,float] or list[float] |
NHS-derived |
Monthly scaling factors (Apr 2023–Mar 2024). See Seasonality and weights. |
|
dict[int,float] or list[float] |
NHS-derived |
Weekday scaling factors (Mon–Sun). |
|
int |
|
Age group width for cohort generation. See Patient demographics. |
|
int |
|
Minimum patient age. |
|
int |
|
Maximum patient age. |
|
bool |
|
Truncate ages outside cutoffs. |
|
int or None |
|
Random seed for reproducibility. See Randomness and variability. |
|
float |
|
Global stochastic variability factor. |
|
DataFrame or list[dict] |
NHS-derived |
Age–sex distribution reference. |
Attributes#
Attribute |
Type |
Description |
|---|---|---|
|
|
Appointment slot capacity table. See Slots table. |
|
|
Central table with all appointment outcomes. See Appointments table. |
|
|
Registry of simulated patients. See Patients table. |
|
|
Internal random generator instance. |
|
|
Faker instance used to generate synthetic names. |
|
int |
Running counter for unique patient IDs. |
Methods#
Method |
Description |
|---|---|
|
Runs the full pipeline: slots → appointments → patients. |
|
Builds the appointment calendar. See Slots table. |
|
Simulates bookings, cancellations, rebookings. See Appointments table. |
|
Assigns realistic check-in/start/end times. See Appointment timing. |
|
Creates synthetic patients by age and sex. See Patients table. |
|
Links patients to appointments and computes per-visit age. |
|
Adds new categorical variables to |
|
Exports all three tables to CSV files. |
|
Iterative rescheduling of cancelled visits. |
|
Finalizes appointment outcomes. |
|
Simulates upcoming bookings within the horizon. |
Usage example#
from medscheduler import AppointmentScheduler
# Initialize and run full simulation
sched = AppointmentScheduler(seed=42, fill_rate=0.9, booking_horizon=30)
slots, appointments, patients = sched.generate()
print(appointments.head())
Notes#
All date-like inputs are parsed to naive
datetime(timezone removed).The default configuration reflects NHS 2023–24 outpatient statistics.
Outputs are fully deterministic when
seedis fixed.Recommended workflow: instantiate →
generate()→ access.appointments_df.
Next steps#
Learn how temporal boundaries are defined in Date ranges and reference date.
Review Calendar structure to understand how working days, hours, and slot density are configured.
For dataset customization, see also Booking dynamics and Seasonality and weights.