Skip to content

Esteem waiting time in emergency room based on real time patients volume

License

Notifications You must be signed in to change notification settings

thegoldgoat/stima-pronto-soccorso

Repository files navigation

Stima Pronto Soccorso

Introduction

The Problem

Emergency rooms are usually very crowded and many hospitals do not have the facilities and the personnel to quickly admit patients, especially those with a lower emergency code. In addition patients are in most cases unaware of the time they have to wait to be admitted to the hospital. This could cause inconvenience not only to the patients themselves, but also to their family and friends, to whom they rely upon. It would be better for the patient to know the time they have to wait in order to be visited by a doctor.

Our solution

Our solution aims to provide an estimate of the waiting times of the patients in the waiting room of the emergency department given the state of the waiting queue and the state of the therapy. The estimates are generated by a simulator that runs several statistical simulations in parallel. The simulator takes into account possible arrivals of new patients at the emergency department and therapy times of the patients in therapy. Both inter-arrival times and therapy times are determined using empirical data.

Details on the simulation can be found in the Simulator chapter. More about empirical data can be found in the Data Processing chapter.

Simulator

The calculation of the waiting time for each patient in the waiting queue is performed by a simulator. The simulator executes a fixed amount of simulations and the results of the simulations are then processed and stored in the Database so that they can be accessed by the Web Application. A simulation ends when all the patients waiting for a place in the therapy queue leave the waiting queue. A single simulation consists of several iterations.

Iteration

Each iteration is composed of four steps, which are described in the following subsections.

Find the minimum value

In the first step, the minimum value among therapy times and inter-arrival times is found. Times are modelled as the minutes between the current time and the time when the event happens, thus a therapy time is the number of minutes between now and the time the patient leaves the therapy, while an inter-arrival time is the time between now and the time a new patient arrives at the emergency department of the hospital. At the beginning of each iteration the simulator chooses the smallest value among all the therapy times (one for each patient in therapy) and the inter-arrival times (one for each ESI code).

Update the time of the simulation

The second step consists of the update of the current time of the simulation. The simulator increases the simulation time by the value found in the previous step.

Update the waiting queue and the therapy

The third step consists of the update of the waiting queue and the therapy. If the time selected in the first step is a therapy time, the patient in the therapy is removed; if the time selected is an inter-arrival time, a new patient is added to the waiting queue. Note that the simulation ends when all the patients that were originally in the waiting queue exit the queue, i.e. the simulator does not wait for newly created patients to exit the waiting queue. If a patient is removed from the therapy queue, a patient in the waiting queue accesses the therapy queue. The current time of the simulation is stored in a data structure that records the number of occurrences of each waiting time associated to the patient.

Update and generate new times

New values of therapy times and inter-arrival times are generated in this step. Therapy times and inter-arrival times which have not been selected in the first step are updated using the following formula:

If the time selected in the first step is an inter-arrival time, a new value is sampled using the exponential generator of the corresponding ESI code. The analysis of empirical data shows that by modifying the values in the tuple (month, day of the week, hour bin) the number of arrivals at the emergency department changes significantly. Therefore, the rate of the generator is modified based on the current time to model those changes. If a patient is moved from the waiting queue to the therapy room, their therapy time is sampled using the generator associated to their ESI code.

Database

Database Management System

The database management system used in our project is MongoDB, since it is better suited for the data produced by our application. Its document-oriented structure allows for efficient storage and retrieval of data on estimates, which is mainly accessed by the Simulator and the Web Application.

Data Models

Patient model

Each patient in the database has a unique identifier, which not only identifies the patient during the simulation process, but also makes it possible for the patient to see their estimated waiting time on the monitor of the emergency department or on the web application. The identifier is the only attribute needed by the simulator. It is worth noting that a new patient is added to the database during the triage process.

Waiting patient model

Each patient in the waiting room has three fields:

  • A unique identifier, which is equal to the identifier of the patient model;
  • An ESI code;
  • The arrival time, which is the time when the patient arrives at the emergency department.

The data on the patient waiting in the waiting room is registered when their ESI code is determined.

Therapy patient model

Each patient in therapy has three fields:

  • A unique identifier, which is equal to the identifier of the patient model;
  • An ESI code;
  • The entry time, which is the time when the patient leaves the waiting queue and enters the therapy room. This is also the time when a new record is added to the database.

Simulation model

This model defines the structure of a collection that contains documents with one field, which is the time when a simulation is executed. Each document in the collection links together all the documents of the estimate model which are produced by the same simulation. The simulation model not only allows to easily get the most up-to-date estimates, but also facilitates the retrieval of past data which could be used for estimates evaluation.

Arrivals compared to average model

This model is composed of the following fields:

  • An ESI code;
  • A year;
  • A day of the week;
  • An hour bin, which is an interval of four hours;
  • The number of arrivals divided by ESI code, day of the week and hour bin minus the average number of arrivals per hour bin for the ESI code. The average is calculated using the first formula of Analysis of inter-arrival times.

Monthly arrivals model

This model is composed of the following fields:

  • An ESI code;
  • A month;
  • A year;
  • The average number of arrivals at the ED divided by month and ESI code. See the description of the first data structure for more on this field.

Therapy times occurrences model

This model is composed of the following fields:

  • An ESI code;
  • A therapy time in minutes;
  • The number of occurrences of therapy time.

Estimate model

This model is composed of the following fields:

  • A unique identifier, which is equal to the identifier of the patient model;
  • A list of tuples (estimate of waiting time, frequency of the estimate);
  • An identifier of the simulation, which is equal to the field of the simulation model.

Data Processing

Data source

The data used in the analysis of inter-arrival times is taken from Admission Prediction. See Predicting hospital admission at emergency department triage using machine learning for more on the topic.

Data can be downloaded and converted to csv using the following R script:

setwd("workingDirectory")
url <- "https://github.com/yaleemmlc/admissionprediction/raw/master/Results/5v_cleandf.RData"
download.file(url, destfile="filename.rdata", mode='wb')
load("filename.rdata")
write.csv(df, "input.csv", row.names=FALSE, quote=FALSE)

The data used for the analysis of therapy times is taken from NCHS public dataset.

Description of datasets

The dataset containing data on arrivals at the emergency department has 560486 entries and almost a thousand attributes, but for the purpose of the analysis of inter-arrival times only a few of those are needed. In particular, we select the esi code of the patient, the month, the day of the week and the hour bin. These are the only attributes concerning the time when the patient arrived at the ED. An hour bin has a duration of 4 hours. The period covered by the data starts in March 2014 and ends in July 2017.

The dataset on therapy times has 949 attributes and almost 17000 entries. We select only two attributes, which are the ESI code of the patient and the length of the visit.

Data transformation for analysis

Analysis of inter-arrival times

The absence of data on the precise time of arrival of a patient at the ED has led us to the following analysis. Given the assumption that the number of arrivals at the emergency department can be modeled by a Poisson process, the problem is to find the intensity λ of the Poisson process. More precisely, the problem is to determine the rate of the underlying exponential distribution, which gives the time between consecutive arrivals. The rate of the exponential distribution can be easily calculated as $\frac{1}{λ}$. Our experience suggests that the intensity of arrivals at an emergency department changes depending on the ESI code, month, day of the week and hour bin, so we calculate a different rate for each tuple (ESI code, month, day of the week, hour bin). This is done by combining the content of two data structures:

  • The first data structure contains the average number of arrivals at the ED divided by months and ESI code. The average is calculated by dividing the total number of arrivals in a certain month by the number of occurrences of that month in the period covered by the dataset;
  • The second data structure contains the number of arrivals divided by ESI code, day of the week and hour bin minus the average number of arrivals per hour bin for the ESI code. The average is calculated using the following formula:

Let structure1 be the first data structure and structure2 be the second data structure. First we define the following values referred to the tuple (ESI, month, day of the week, hour bin):

where average1 is the average number of occurrences of day of the week in month over the period covered by the dataset. The intensity of arrivals at the emergency department for the tuple (ESI, month, day of the week, hour bin) is determined using the following formula:

Analysis of therapy times

The data on therapy times is collected in a data structure that contains the number of occurrences of each therapy time divided by ESI code. Therapy times do not follow any known distribution, thus the generation of the samples is performed by a generator that takes the relative frequency of each observation. The most likely outcome is a value close to the therapy time with the highest number of occurrences.

Web Application

We opted for a web application for the front-end of our software, since it is portable and easy to use for end users.

Back End

The back end module is built using ExpressJS, a minimalist web framework for NodeJS. The back end provides to a basic REST API the functionalities to gather data from the Database using MongooseJS. The REST API consists of the following endpoints:

  • GET /patient/:patientId, that given a patient identifier returns the most up-to-date estimate of their waiting time;
  • GET /monitor/all, that returns the most up-to-date estimates for all the patients currently in the waiting queue.

Front End

The web application is composed of two pages that display the data made available by the REST API. The pages are described in the following subsections.

Monitor

This page contains the data on the most up-to-date estimate of the waiting time of each patient. The fields displayed for each patient are the following:

  • The arrival time;
  • The ESI code;
  • The average expected waiting time;
  • Given the distribution of the estimates of the waiting time and the cumulative distribution function F, the values at which F equals 0.5, 0.75 and 0.9;

This page is designed for the patients that simply want to see their estimate on a monitor located in the waiting room of the emergency department.

Individual Patient

This page contains the same data as the page described in Monitor, but it only shows the data on the waiting time of a particular patient. It is designed for a patient that wants to access only personal data. The following image shows what the user sees when they access the page with personal data:

Conclusion

The software simulates the evolution of the state of an emergency department by considering not only the current state of the waiting queue, but also arrivals of new patients and therapy times. Empirical data on arrivals and therapy times is used to determine the parameters of the distributions from which the simulator samples. The result is a set of estimates of the waiting times of the patients in the waiting room. The most up-to-date estimates are made available to the patients through a web application and can be shown on the screen of the emergency room.

As stated in the introduction, we believe that a patient would greatly benefit from knowing their waiting time. Moreover, the emergency department would create a better environment for the patients by showing the waiting times, so it would benefit from our simulation as well.