· 2026
Junior doctor on-call scheduler
Single-file web tool that generates monthly on-call schedules for the emergency department's junior doctors, accounting for leave dates and personal preferences.
The problem
At the end of every month the next month’s on-call schedule has to be put together for the department’s junior doctors. Because the cohort rotates, this process never stops: the headcount fluctuates, some doctors have fixed days they don’t want to work, weekend and holiday shifts have to be distributed fairly, no one can be on two consecutive nights. Doing this in Excel is both exhausting and error-prone — you forget a doctor, you miss a request, and at the end of the month you don’t actually know who worked more hours than whom.
Before this, building the schedule was a manual exercise. It took two or three hours, and the result was never fair.
What I built
A single-file HTML tool. Opens in a browser, no install, state persists in localStorage — every computer keeps its own records, no server involved.
The doctor list, leave days, “doesn’t want to work this day” and “wants to work this day” requests are entered through the UI. Turkish national holidays (the moveable Islamic holidays included) are detected automatically; additional holidays for the month can be added. Press one button, get a schedule.
Underneath the generated schedule, each doctor’s total hours, weekend shifts, and holiday shifts are shown — at a glance, who worked what. The whole schedule can be exported as an Excel file. Past months are archived.
What was technically interesting
The actual interesting part is in the optimization. A naive “for each day, assign the most appropriate doctor” approach doesn’t produce balanced schedules — weekend shifts in particular tend to accumulate on specific doctors, because the greedy algorithm makes locally optimal choices that aren’t globally fair.
Instead, I generate the schedule multiple times with different random seeds (six restarts) and pick the best result by score. The score is a weighted sum of total-hours variance, weekend-shift distribution variance, holiday-shift distribution variance, and the count of unfulfilled or violated doctor preferences. On top of that I run a simple hill-climbing pass that swaps random pairs of assignments and keeps the swap only if the score improves — about four hundred iterations.
The result comes out more balanced than the schedules built by hand, especially on weekend distribution. The algorithm isn’t perfect — sometimes there’s a 12- to 24-hour gap between two doctors at the end. But compared to the manual schedules it replaces, it wins on both time (from three hours to thirty seconds) and fairness, by a wide margin.
Outcome
The department’s schedule has been built with this tool for several months now. At the start of each month, the colleague responsible for the rota sits down, spends about half an hour entering the doctor list and the requests, and generates the schedule — work that used to take two or three hours, now down to about half a minute of actual computation. More important than the time savings, the post-publication arguments about “why did I get so many weekend shifts” have largely disappeared, because the distribution actually is balanced, and any doctor who wants to can see their own totals and distribution in the tool.