DEV Community

Axis Puls
Axis Puls

Posted on

Modeling Hospital Nurse Shift Scheduling & 12-Hour Rest Constraints in Python and TypeScript

Building a real-world hospital nurse shift scheduler is fundamentally different from generic employee timetabling. In 24/7 clinical wards (ICU, Emergency, Internal Medicine), breaking a single rest constraint can trigger dangerous Quick Returns (e.g., finishing an overnight shift at 08:00 and returning the same day) and accelerate nurse burnout.

While developing Axis Puls — a web/PWA/Android shift scheduling platform for hospitals and shift-based teams — we recently open-sourced our zero-dependency Python & TypeScript reference library for calculating statutory nursing working hours under Iran's Clinical Staff Productivity Promotion Law (Articles 2 & 5):

The 4 Hard Constraints Every Clinical Scheduler Must Enforce

  1. Minimum 12-Hour Inter-Shift Rest & Zero Quick Return: Any transition from Night (20:00–08:00) to Morning (08:00–14:00) or same-day Evening must be strictly blocked by the solver rather than silently accepted to fill coverage gaps.
  2. Dynamic Weekly Required Hours (36h–44h/week): Starting from a 44h base (6-day week), seniority (1–5h), ward hardship (0.5–2h), and non-standard rotating shifts (0–1h) reduce weekly required duty by up to 8h/week.
  3. Shift Multipliers & Dual Overtime Caps: Overnight and official holiday shifts carry a 1.5× effective multiplier. Overtime must be checked simultaneously against half of monthly required hours and the 80h/month executive bylaw ceiling, with a hard 12h consecutive duty cap.
  4. Transparent Unfilled Slots Over Silent Rule Violations: When a ward lacks enough eligible nurses on a given date, a trustworthy scheduler flags the unfilled slot for the head nurse instead of breaking safety rules behind the scenes.

Quick Example in Python (moh_calc.py)

from moh_calc import PRESETS, calculate_nursing_hours

res = calculate_nursing_hours(PRESETS["icu"])
print(res.weekly_required_hours)   # 38.0
print(res.monthly_required_hours)  # 158.33
print(res.effective_hours)         # 210.0
print(res.difference_hours)        # 51.67
print(res.status)                  # "ok"
Enter fullscreen mode Exit fullscreen mode

If you work on workforce optimization, healthcare IT, or constraint-satisfaction scheduling, feel free to inspect the MIT code on GitHub or test our live RAM-isolated shift arranger at axispuls.ir/demo/?lang=en — no login required.

Top comments (0)