Computer simulation of patient flow through an operating suite David E. Clark, MD FACS Department of Surgery, Maine Medical Center, Portland ME Stata Conference 2014 The problem • Operating Rooms (ORs) may generate up to 40% of hospital revenue – efficiency is financially important • Delays and rescheduling are frustrating and demoralizing for patients and staff • In extreme cases, patient safety may suffer if vital resources are unavailable due to suboptimal management Model of an operating suite P1 OR1 P2 Preop RR P3 OR2 P4 Simulation Software • Special-purpose simulation programs (e.g., Arena, Flexsim, Simulink) take care of “housekeeping” and displays, but may be expensive, restrict flexibility, and be more difficult to learn and debug • General-purpose programming languages (including Stata) easily available, familiar, and flexible, but require the user to construct “housekeeping” and displays Tools available in Stata • Basic structure a matrix with rows (observations) and columns (up to 32,767 variables) • Loops (“forvalues”, “foreach”) • Replication (“expand”, “expandcl”) • Reshaping (“wide”, “long”) • Summarization (“egen”) • Subroutines (“program”, “.do” files) • Time-to-event modeling (“streg”, etc.) • Reporting (“list”, “save”, “append”, “replace”) Available hospital data • Patients: Day, procedure, surgeon, scheduled OR/times (in/out etc.), actual OR/times, destination from OR (RR vs ICU), RR times, etc. • Rooms: Availability for different types of procedures, at different times of day • Policies: Staffing, scheduling, priority rules, “bumping” Data Structure • Must allow for transfer of information between patients and rooms • Must allow for change in status over time • Must allow for replication with different random variables • Must allow for visualization of status, reporting of summary statistics, and modification of structural assumptions .008 .006 .004 0 .002 Probability density • Time to event, bounded on (0,∞) • Fit a parametric distribution (many possibilities) • Model covariates using regression • Derive transition probabilities (hazards) .01 Input distributions 0 60 120 180 240 300 360 420 480 Duration of operative procedure (minutes) 540 600 Methods: Derive distributions • Patient data in normal (“long”) format • Estimate two-parameter log-logistic distributions for procedure duration, recovery room duration, turnaround time • Parametric time-to-event regression (“streg”) using predicted procedure duration, procedure type, surgeon, following self, first case, add-on case Methods: Initialize patients/rooms • For a given day, convert patient data to “wide” format – that is, all variables are in the same row • Add room data on same row For example, at 0600… Rep Rsch _P1 Tin _P1 Tout _P1 Stat _P1 Rsch _P2 Tin _P2 Tout _P2 1 1 0730 0930 Pre 1 1000 1300 Stat _P2 Stat _R1 N/A Trem _R1 Methods: Use replicants to create output distributions • After initialization, “expand” 30 to 3000 • Run program and periodically “egen mvar = mean(var)” “egen sdvar = sd(var)” etc. to accumulate statistics of interest • Display one realization of simulation Methods: Step through entire day at 5-minute intervals • Loop using “forvalues” • Determine patient status at new time t, and whether status should change either deterministically (scheduled or actual) or probabilistically (simulated with random variables). • Update room status depending on which patient is now in room and/or scheduled to be in room Methods: Sequence of procedures at each time step • Identify patients arriving in preop status • Move next priority patient to OR when patient ready and room available • Move OR patient to RR if procedure finished (random number exceeds hazard function at time t); restrict room for “turnaround time” • Move RR patient out of RR if required time complete Example: Patient/room data At 0745, 0845, 0945 Rep Rsch _P1 Tin _P1 Tout _P1 Stat _P1 Rsch _P2 Tin _P2 Tout _P2 1 1 0730 0930 R1 1 1000 1300 Rep Rsch _P1 Tin _P1 Tout _P1 Stat _P1 Rsch _P2 Tin _P2 Tout _P2 1 1 0730 0930 R1 1 1000 Rep Rsch _P1 Tin _P1 Tout _P1 Stat _P1 Rsch _P2 1 1 0730 0930 RR 1 Stat _P2 Stat _R1 Trem _R1 P1 105 Stat _P2 Stat _R1 Trem _R1 1300 Pre P1 Tin _P2 Tout _P2 Stat _P2 Stat _R1 1000 1300 Pre Turn 45 Trem _R1 Methods: Periodic adjustments • Determine time remaining for current case in each room, total time remaining to complete all cases, free time remaining • Reprioritize patients scheduled in each room, including new emergency cases • Identify next case scheduled in room with greatest anticipated overtime, and reassign that case to room with greatest anticipated free time Results: Output for a typical day R1 R2 R3 R4 R5 R6 R7 R8 0700 0715 0730 P1 P11 0745 P1 P3 P5 0800 P1 P3 P5 0815 P1 P3 0830 P1 0845 P11 P18 P8 P11 P18 P23 P5 P8 TURN P15 TURN P23 P3 P5 P8 TURN P15 TURN P23 P1 P3 TURN P8 P12 P15 P19 P23 0900 P1 P3 TURN P8 P12 TURN P19 TURN 0915 P1 TURN TURN TURN TURN TURN TURN TURN 0930 TURN TURN TURN TURN TURN TURN 0945 TURN P4 P9 P13 P20 P24 P6 P16 Results • Runtime about 10 minutes to simulate a 24-hour day with 300 replications – not affected much by number of replications • Most time-consuming for computer (and most difficult to code) is reassignment of cases from overbooked rooms • Limited by incomplete data on patient destination after Recovery Room Validation: Cumulative statistics 25 Friday OR Census 15 20 Dashed: Mean scheduled Solid: Mean actual Shaded: Simulated 90% CI 10 25 Friday RR Census 15 5 20 Solid: Mean actual Shaded: Simulated 90% CI 15:00 18:00 21:00 10 12:00 5 09:00 09:00 12:00 15:00 18:00 21:00 Expand and modify • Started small, now allow for 50-100 patients in 24 rooms • Summarize multiple days with same structure (day of week, block schedule) • Add information about RR destinations • Verify assumptions about OR staffing RR staffing, scheduling policies, etc. • Predict effects of changing staffing/policies Conclusions • Stata has some useful features for simulation and enables a working model • Stata would be even better if commands could reference variable names, e.g., replace st_R7=3 if st_P3=7 • Plan to post improved version of this program on ideas.repec.org • StataCorp and/or developers should take note of “SAS Simulation Studio”