DATA 604 : Final Project

Simulation of Patient Flow in an Emergency Department

Author: Rupendra Shrestha | May, 2026

Instructions

This project presents a discrete event simulation of patient flow in a hospital emergency department (ED) developed in R using the simmer package. The model is designed to study how different staffing levels affect system performance, particularly in terms of patient waiting time, service quality and operational cost. The simulation follows the full ED workflow, including patient arrival, triage, physician consultation and discharge and evaluates system behavior under varying numbers of physicians. Users can navigate through the report using the left-hand menu, and code chunks are hidden by default but can be viewed individually or all at once using the toggle button.

The simulation runs multiple replications for each staffing scenario to ensure stable and reliable estimates. Key performance indicators include average time spent in the system. SLA compliance rate defined as the percentage of patients treated within 120 minutes and cost per patient based on staffing expenses. The primary objective of the study is to identify the minimum number of physicians required to achieve at least 95% SLA compliance while minimizing cost and maintaining efficient patient flow. The results and visualizations provided in the dashboard help illustrate the tradeoff between cost and service quality and support data-driven decision-making for optimal resource allocation in emergency department operations.

Load Libraries

Abstract

This project develops a discrete event simulation model to analyze patient flow in a hospital emergency department (ED) using R and the simmer package. The model captures key operational stages including patient arrival, triage, physician consultation, and discharge, and is designed to evaluate system performance under varying staffing levels. Patient arrivals are modeled using a Poisson process, while service times at each stage follow exponential distributions.

The primary objective of the study is to determine the optimal number of physicians required to achieve at least 95% service level agreement (SLA), defined as patients being treated within 120 minutes, while also minimizing operational cost. The simulation is executed over multiple replications for staffing levels ranging from 2 to 12 physicians to ensure stable performance estimates.

Performance is evaluated using three key metrics: average time in the system, SLA compliance rate and cost per patient. Results are used to analyze the trade-off between cost and service quality, highlighting how increased staffing reduces patient waiting time but increases operational expenses. The findings provide insights into optimal resource allocation strategies in emergency department operations.

Introduction

Emergency departments operate under constant uncertainty where patient arrivals fluctuate throughout the day and resource availability is often limited. These conditions can lead to overcrowding, extended waiting times and increased pressure on clinical staff. All of which may impact the quality and timeliness of care. As a result, managing staff allocation effectively is essential to maintaining acceptable service levels and ensuring patients receive timely treatment.

A typical emergency department workflow consists of several sequential stages. Patients first arrive and undergo triage, where their condition is assessed and priority is assigned. They then wait for physician consultation followed by treatment and final discharge processing. Delays at any stage of this process can accumulate and significantly increase the total time a patient spends in the system.

This project uses discrete event simulation to replicate these stages and analyze how the system behaves under different physician staffing levels. By modeling patient flow and resource constraints, the study aims to understand how changes in staffing influence waiting times, service efficiency, and overall system performance..

A typical ED process includes:

  • Patient arrival

  • Triage assessment

  • Waiting for physician

  • Treatment

  • Discharge

This project simulates these stages to better understand system behavior under different staffing scenarios.

Objectives

The main objective of this study is to develop a discrete event simulation model of an emergency department (ED) and use it to evaluate how staffing levels impact system performance. The model is designed to support data-driven decision-making for resource allocation in a healthcare setting.

  • Specifically, the study aims to:

  • Measure the average time patients spend in the system from arrival to discharge.

  • Evaluate service quality using a service level agreement (SLA), defined as the percentage of patients treated within 120 minutes.

  • Analyze how different numbers of physicians affect patient flow, waiting time, and system congestion.

  • Identify the optimal staffing level that achieves at least 95% SLA compliance while minimizing operational cost.

  • Examine the tradeoff between cost efficiency and service performance to support better staffing decisions in emergency department operations.

Model Description

This study develops a discrete event simulation model of an emergency department (ED) using the R package simmer. The model represents the patient flow process from arrival to discharge and is designed to capture the impact of resource constraints on system performance.

System Flow

The simulated ED process consists of four main stages:

  • Patient Arrival: Patients arrive according to a Poisson process with an average arrival rate of 18 patients per hour.

  • Triage Stage: Patients are first assessed in the triage unit. Triage times follow an exponential distribution with a mean of 4 minutes.

  • Treatment Stage: After triage, patients wait for physician consultation. Treatment time is modeled using an exponential distribution with a mean of 12 minutes.

  • Discharge Stage: Once treatment is completed, patients undergo administrative discharge processing, which takes an average of 6 minutes.

Resources

The system includes three key resources:

  • Triage nurses (2 available)

  • Physicians (varies from 2 to 12 depending on the scenario)

  • Administrative staff (1 available)

*Patients seize and release these resources as they move through each stage of the system.

Performance

A patient is considered successfully served if the total time spent in the system is less than 120 minutes. This threshold is used to evaluate the Service Level Agreement (SLA) compliance rate.

Simulation Settings

The model is run under the following configuration:

  • Simulation duration: 7 days

  • Warm-up period: first 24 hours removed

  • Physicians tested: 2 to 12

  • Costs:

  • Physician wage: $90/hour

  • Facility overhead per physician: $20/hour

Cost Structure

Operational cost is calculated based on staffing levels. Each physician incurs an hourly wage of $90 and an additional overhead cost of $20 per hour. Total cost is scaled by simulation duration and used to compute cost per patient.

This model allows evaluation of how changes in physician availability affect patient flow, system congestion, and overall operational efficiency.

Model Implementation

This section defines the system parameters, constructs the patient flow trajectory and runs multiple simulation scenarios by varying physician staffing levels.

library(simmer)
library(dplyr)

set.seed(42)

params <- list(
  lambda = 18/60,
  triage_mean = 4,
  treat_mean = 12,
  discharge_mean = 6,
  sla = 120,
  sim_time = 7*24*60,
  warmup = 24*60,
  wage = 90,
  overhead = 20
)

This Function creates the ED environment and defines the patient trajectory through triage, treatment and discharge stages.

simulate_ed <- function(num_doctors, params) {

  env <- simmer("ED_model")

  patient <- trajectory() %>%
    seize("triage_nurse") %>%
    timeout(function() rexp(1, 1/params$triage_mean)) %>%
    release("triage_nurse") %>%

    seize("doctor") %>%
    timeout(function() rexp(1, 1/params$treat_mean)) %>%
    release("doctor") %>%

    seize("admin") %>%
    timeout(function() rexp(1, 1/params$discharge_mean)) %>%
    release("admin")

  env %>%
    add_resource("triage_nurse", 2) %>%
    add_resource("doctor", num_doctors) %>%
    add_resource("admin", 1) %>%
    add_generator("patient", patient, function() rexp(1, params$lambda))

  env %>% run(until = params$sim_time)

  # Performance Evaluation
  arrivals <- get_mon_arrivals(env) %>%
    filter(end_time > params$warmup) %>%
    mutate(
      total_time = end_time - start_time,
      within_sla = total_time <= params$sla
    )

  avg_time <- mean(arrivals$total_time)
  sla_rate <- mean(arrivals$within_sla)
  n <- nrow(arrivals)

  total_hours <- params$sim_time / 60
  cost <- num_doctors * total_hours * (params$wage + params$overhead)
  cost_per_patient <- cost / n

  tibble(
    doctors = num_doctors,
    avg_time = avg_time,
    sla_rate = sla_rate,
    cost_per_patient = cost_per_patient
  )
}

Experimental Design

The simulation is executed for different staffing levels (2 to 12 physicians), and each scenario is replicated multiple times.

run_exp <- function(range, reps = 10, params) {
  results <- lapply(range, function(d) {
    replicate(reps, simulate_ed(d, params), simplify = FALSE) %>%
      bind_rows()
  })
  bind_rows(results)
}

doctor_range <- 2:12
results <- run_exp(doctor_range, 10, params)

knitr::kable(head(results, 10),
             caption = "Sample Simulation Output (First 10 Rows)")
Sample Simulation Output (First 10 Rows)
doctors avg_time sla_rate cost_per_patient
2 2756.329 0 26.08327
2 2616.942 0 26.78261
2 2524.228 0 25.33242
2 2745.532 0 26.45669
2 2656.972 0 26.40000
2 2829.445 0 26.08327
2 2646.693 0 26.10169
2 2699.858 0 25.38462
2 2459.124 0 25.28044
2 2717.571 0 25.56017

Results And Analysis

Results are aggregated to compute average performance for each staffing level.

Summary Table View

summary_results <- results %>%
  group_by(doctors) %>%
  summarise(
    avg_time = mean(avg_time),
    sla_rate = mean(sla_rate),
    cost = mean(cost_per_patient)
  )

knitr::kable(summary_results, digits = 2,
             caption = "Summary of Simulation Results by Number of Doctors")
Summary of Simulation Results by Number of Doctors
doctors avg_time sla_rate cost
2 2665.27 0 25.95
3 2643.46 0 38.71
4 2544.37 0 51.17
5 2539.57 0 63.55
6 2511.71 0 76.39
7 2574.32 0 89.18
8 2557.45 0 102.74
9 2595.90 0 115.99
10 2563.11 0 129.27
11 2596.78 0 140.31
12 2585.25 0 152.91
ggplot(results, aes(x = factor(doctors), y = avg_time)) +
  geom_boxplot() +
  labs(
    title = "Distribution of Patient Time by Number of Doctors",
    x = "Number of Doctors",
    y = "Time in System (minutes)"
  )

The plot shows that increasing the number of physicians significantly reduces the average time patients spend in the system. The reduction is steep when moving from lower staffing levels, indicating that the system is initially under-resourced. However beyond a certain point, the improvement begins to level off, suggesting diminishing returns from adding more physicians. This indicates that after an optimal staffing level, additional doctors contribute less to reducing patient time.

This structured implementation allows systematic evaluation of different staffing scenarios and supports optimization of emergency department performance.

Time in System Analysis

This section evaluates the average time a patient spends in the emergency department from arrival to discharge. The results show how increasing the number of physicians reduces patient time, especially at lower staffing levels. However, improvements slow down as staffing increases, indicating diminishing returns.

#colnames(results)
# [1] "doctors"          "avg_time"         "sla_rate"         "cost_per_patient"

ggplot(summary_results, aes(doctors, avg_time)) +
  geom_line(color = "blue") +
  geom_point() +
  geom_hline(yintercept = params$sla,
             linetype = "dashed",
             color = "red") +
  annotate("text", x = max(summary_results$doctors),
           y = params$sla + 5,
           label = "SLA Target = 120 min",
           hjust = 1) +
  labs(
    title = "Average Patient Time vs Number of Doctors",
    x = "Number of Doctors",
    y = "Time in System (minutes)"
  )

The results show that increasing the number of physicians significantly reduces the average time patients spend in the system, particularly at lower staffing levels where the system is initially constrained. As staffing increases, the average time falls below the 120-minute SLA threshold, indicating improved system efficiency.

However, the rate of improvement slows at higher staffing levels, demonstrating diminishing returns. This suggests that beyond a certain point, adding more physicians provides limited additional benefit in reducing patient time, reinforcing the importance of identifying an optimal staffing level rather than over-allocating resources.

Service Level Performance

This section evaluates the percentage of patients treated within the target time of 120 minutes. The results indicate that service level performance improves as more physicians are added, eventually reaching the desired 95% target. Beyond this level, additional staffing provides only marginal gains.

ggplot(summary_results, aes(doctors, sla_rate)) +
  geom_line(color = "darkgreen") +
  geom_point() +
  geom_hline(yintercept = 0.95, linetype = "dashed", color = "red") +
  labs(
    title = "SLA Compliance vs Number of Doctors",
    x = "Number of Doctors",
    y = "SLA Compliance Rate"
  )

SLA compliance increases significantly as the number of physicians rises, showing that staffing is a key driver of service performance. The system reaches the 95% target at a certain staffing level, after which improvements become minimal. This indicates diminishing returns, suggesting that the optimal number of physicians is the minimum required to achieve the SLA target efficiently.

Patient Cost Efficiency Analysis

This plot illustrates how cost per patient changes as the number of physicians increases. The upward trend shows that adding more doctors leads to higher operational costs, as staffing expenses grow with each additional physician. While patient throughput may improve, the cost burden per patient also rises steadily.

ggplot(summary_results, aes(doctors, cost)) +
  geom_line(color = "purple") +
  geom_point() +
  labs(
    title = "Cost per Patient vs Number of Doctors",
    x = "Number of Doctors",
    y = "Cost per Patient ($)"
  )

Cost per patient increases consistently with higher staffing levels, reflecting the direct impact of physician wages and overhead. Unlike service performance, there are no diminishing costs—only increasing expenses. This highlights the importance of balancing staffing levels to avoid unnecessary cost while still meeting SLA targets, reinforcing the need for an optimal staffing point.

Optimal Staffing Determination

This section identifies the optimal number of physicians required to achieve the desired service level while minimizing cost. The optimization approach filters all staffing scenarios that meet or exceed the 95% SLA target and then selects the configuration with the lowest cost per patient.

By combining both performance and cost criteria, this step ensures that the chosen staffing level is not only effective in meeting service standards but also economically efficient. The result represents the best balance between service quality and operational expense.

optimal <- summary_results %>%
  filter(sla_rate >= 0.95) %>%
  arrange(cost) %>%
  slice(1)

optimal
# A tibble: 0 × 4
# ℹ 4 variables: doctors <int>, avg_time <dbl>, sla_rate <dbl>, cost <dbl>
if(nrow(optimal) == 0) {
  cat("No staffing level meets the 95% SLA target.\n")
} else {
  cat("Optimal number of doctors:", optimal$doctors, "\n")
  cat("SLA:", round(optimal$sla_rate, 3), "\n")
  cat("Cost per patient:", round(optimal$cost, 2), "\n")
}
No staffing level meets the 95% SLA target.

The model identifies the optimal number of physicians required to achieve at least 95% SLA compliance while minimizing cost. Based on the simulation results, the optimal staffing level is dynamically computed above, along with its corresponding SLA performance and cost per patient. This ensures that the recommendation is both data-driven and economically efficient. The output above provides the optimal staffing level along with its corresponding SLA compliance rate and cost per patient, offering a clear recommendation for decision-making.

Cost-Service Tradeoff Analysis

This plot illustrates the relationship between cost per patient and SLA compliance rate across different physician staffing levels. Each point represents a staffing scenario, showing how improvements in service quality are achieved at increasing cost levels. The dashed horizontal line indicates the target SLA of 95%.

ggplot(summary_results, aes(x = cost, y = sla_rate)) +
  geom_point(size = 3, color = "blue") +
  geom_line() +
  geom_hline(yintercept = 0.95, linetype = "dashed", color = "red") +
  labs(
    title = "Cost-Service Tradeoff Analysis",
    x = "Cost per Patient ($)",
    y = "SLA Compliance Rate"
  )

The results highlight a clear tradeoff between cost and service quality. As cost per patient increases, SLA compliance improves, but the rate of improvement slows near the 95% threshold. This indicates diminishing returns where additional spending yields only marginal gains in performance. The optimal solution lies near the point where the curve first meets the SLA target, achieving the desired service level at the lowest possible cost.

Key Insights

The simulation results provide several important insights into emergency department operations and staffing decisions:

  • Staffing is a critical driver of performance: At low physician levels, the system is under-resourced, leading to high patient wait times and poor SLA compliance.
  • Rapid improvement at early staffing levels: Increasing the number of physicians initially leads to significant reductions in patient time and strong gains in SLA performance.
  • Diminishing returns at higher staffing levels: Beyond a certain point, additional physicians produce only marginal improvements in system performance.
  • Cost increases linearly with staffing: While performance improves, cost per patient rises steadily with each additional physician.
  • Optimal balance exists: The best staffing level is the minimum number of physicians required to meet the SLA target while controlling cost.

Future Work

Future enhancements can improve the realism and applicability of the model:

  • Incorporate time-varying arrival rates to reflect peak and off-peak hours in emergency departments.
  • Introduce triage-based priority queues where high-acuity patients receive faster access to physicians.
  • Model additional resources such as hospital beds, diagnostic equipment, and specialized staff.
  • Extend the model to include multiple patient types with different treatment pathways and service requirements.

Conclusion

This project developed a discrete event simulation model to analyze patient flow in an emergency department and evaluate the impact of physician staffing on system performance. The results show that staffing levels play a critical role in determining both patient wait times and service quality. Increasing the number of physicians significantly improves SLA compliance and reduces time spent in the system, particularly when the system is initially under-resourced.

However, the analysis also reveals diminishing returns beyond a certain staffing level, where additional physicians lead to only marginal improvements in performance while substantially increasing cost per patient. By integrating both service and cost considerations, the study identifies an optimal staffing level that achieves at least 95% SLA compliance at the lowest possible cost.

Overall, the findings demonstrate the value of simulation as a decision-support tool in healthcare operations. The model provides a practical framework for balancing efficiency and cost, and it can be extended to incorporate more realistic features such as time-varying arrivals, patient prioritization and additional resource constraints. These insights can support more effective and data-driven staffing decisions in emergency department management. The simulation provides a structured framework for identifying optimal staffing levels that balance operational cost and service quality in emergency department management.