# Case Study: Simple Health Clinic Model

## Problem Description

In a simple model of a health clinic, patients arrive, wait to receive treatment, receive treatment, and leave.

Common questions asked by clinic management are: "How long do our patients wait before being seen? How long are they at the clinic? How big does my waiting room need to be? ".

In this case study we are going to consider a simple health clinic model in which patients arrive every 20 mins on average. Once the doctor is ready to see them they take 2 minutes getting to the doctor’s office and treatment takes between 5 and 30 minutes, with the usual treatment time of 10 minutes and the average treatment time of 15 minutes.

The goal of this simulation study is to analyse the effects of different arrival and service distributions on the average time patients spend:

1. waiting for treatment; and
2. in the clinic; and the average length of the patient queue (which informs waiting room size).

## Problem Formulation

In order to formulate a simulation model we specify the following components:

1. Background – problem description
2. Objectives of the study
3. Expected benefits
4. The CM: inputs, outputs, content, assumptions, simplifications
5. Experiments to run

Components 1 (Background – problem description) and 2 (Objectives of the study) are given in the Problem Description section (see paragraph describing the goal of the simulation study to identify study objectives).

The Expected benefits (component 3) are a virtual environment for evaluating patient waiting times, total time patients spend in the clinic, and the number of patients waiting for treatment. This environment can be used to experiment with changes to the clinic, including the effect of variability in arrivals and treatment times.

The CM content is specified using the following components:

1. Component List
2. Process flow diagram
3. Logic flow diagram
4. Activity cycle diagram

Component List

The components of the Simple Health Clinic model are:

• Patients with their (inter)arrival times
• Doctor with their treatment times
• Waiting room with its capacity

Process flow diagram

 Logic Flow Diagram Activity Cycle Diagram

Once the content has been established (note this is usually an iterative process) we can identify the inputs and outputs: interarrival times, treatment times, waiting times (Patient arrives to Doctor sees patient), total clinic time (Patient arrives to Outside), number in waiting room.

Assumptions are used to define stochasticity (e.g., Exponential interarrivals, Triangular treatment times) and the simplifications keep the system simple (e.g., one doctor on all day, no registration, no prioritisation).

## Computational Model

We use JaamSim version 2017-06 to implement our conceptual model. First, run the JaamSim executable (JaamSim2017-06.exe).

Next, we create the components: Patients; Doctor; and Waiting room. We expand the Process Flow model palette (in the Model Builder) window and drag the SimEntity object onto the view (View1 window).

Then, select SimEntity1 from the Process Flow > SimEntity object list in the Object Selector window and wait briefly until you can change the name of the object to PatientEntity.

Now, we want an image to use for a patient. Download patient.png (icon made by Freepik from www.flaticon.com). Then, right click on PatientEntity and select Change Graphics. Click on Import and navigate to your downloaded patient.png, import it and accept the change. You will see patient.png looking a little “flattened” as it is essentially a “tile” in 3D.

Save your simulation (it will create a .cfg file that can be loaded into JaamSim).

Next, we add the Doctor. Go back to the Process Flow model palette (in the Model Builder window) and drag a Server object onto the View1 window.

Now change the name of the Server to be Doctor, download the doctor.png, and change the Doctor graphics to be doctor.png.

Save your simulation.

Finally, add the Waiting Room by adding a Queue from the Process Flow model palette and renaming it WaitingRoom.

Save your simulation.

Now that the components are present, we will add the process and logic to the model. First, we want to observe the PatientEntity in 4 states: Arrive, Wait, Treat, and Leave. We click on the PatientEntity object (in Object Selector > Process Flow > SimEntity), go to the Input Editor and enter the set of patient states { Arrive Wait Treat Leave }.

We have finished our definition of the model components, so we turn to the Simple Health Clinic process flow.

From the Process Flow palette we add an EntityGenerator, EntitySink, and 2 × EntityConveyors. We name these objects PatientGenerator, PatientSink, ArriveToTreat, and TreatToLeave respectively.

Once you have added objects, the easiest way to get them positioned properly is to edit the Graphics > Position in the Input Editor window. Edit the positions or points’ positions (for the EntityConveyors) as follows:

Object Graphics
ArriveToTreat Points = { 1 1.5 0.000 m } { 3 1.5 0.000 m }, DisplayModel = ArrowModelDefault
TreatToLeave Points = { 4 1.5 0.000 m } { 5 1.5 0.000 m }, DisplayModel = ArrowModelDefault
PatientEntity Position = -1 1 0 m, Alignment = 0 0 0
PatientGenerator Position = 1 1.5 0 m
Doctor Position = 3 1.5 0 m
WaitingRoom Position = 3.5 0.5 0 m
PatientSink Position = 5.5 1.5 0 m

The layout of the model should look like

Save your simulation.

Now the process flow has been completed, we need to define the logic flow.

This is achieved by setting the entity type generated by PatientGenerator, NextComponent on the objects and also defining how the WaitingRoom queue is used. We also track the state of entities using StateAssignment of various objects.

Edit the Key Inputs of the objects (in the Input Editor window) as follows:

Object Key Inputs
PatientGenerator PrototypeEntity = PatientEntity, NextComponent = ArriveToTreat
Doctor NextComponent = TreatToLeave, WaitQueue = WaitingRoom, StateAssignment = Treat
WaitingRoom StateAssignment = Wait
ArriveToTreat NextComponent = Doctor, StateAssignment = Arrive
TreatToLeave NextComponent = PatientSink, StateAssignment = Leave

Save your simulation.

Now that the process and logic flows are complete, we need to put data into our model. We set the first arrival time, interarrival time, service time and travel times of the objects.

Object Key Inputs
PatientGenerator FirstArrivalTime = 20 min, InterArrivalTime = 20 min
Doctor ServiceTime = 15 min
ArriveToTreat TravelTime = 2 min
TreatToLeave TravelTime = 2 s

Save your simulation.

Finally, you can run your model and see patients arriving and being treated by the doctor. Click on the run icon and set the speed up to be 256.

Save your simulation.

Now that your simulation is running, we need to collect statistics (our outputs) and also set the simulation up to run multiple replications.

Drag 2 × Statistics component from the Process Flow model palette to the View1 window and name them TimeInSystem and WaitingTime. Insert them between the TreatToLeave and PatientSink objects by making the following changes:

Object Graphics Key Inputs
TreatToLeave   NextComponent = TimeInSystem
TimeInSystem Position = 5.5 1.5 0 m NextComponent = WaitingTime
WaitingTime Position = 6.5 1.5 0 m NextComponent = PatientSink
PatientSink Position = 7.5 1.5 0 m

Set the UnitType for both Statistics objects to be TimeUnit and the SampleValue to be

```'this.obj.StateTimes([[Arrive]]) + this.obj.StateTimes([[Wait]]) + this.obj.StateTimes([[Treat]]) + this.obj.StateTimes([[Leave]])'
```
(that is the total time for patients in the clinic) for TimeInSystem and
```'this.obj.StateTimes([[Wait]])'
```
(that is waiting time) for WaitingTime.

Now, to set up the simulation model to do multiple replications, we edit the Simulation object (at the top of the Object Selector window). We set Key Inputs as follows:

Object Key Inputs Value
Simulation GlobalSubstreamSeed [Simulation].RunIndex(2)
UnitTypeList DimensionlessUnit TimeUnit TimeUnit DimensionlessUnit
RunOutputList { [Simulation].RunIndex(1) } { [WaitingTime].SampleAverage } { [TimeInSystem].SampleAverage } { [WaitingRoom].QueueLengthAverage }

This uses the second element of the simulation RunIndex (the replication number) as the random seed for the replication, sets the output units as dimensionless, time, time and dimensionless respectively, and sets the outputs as the first element of the RunIndex (the run number), the average patient waiting time, the average patient time in the clinic, and the average number of patients in the waiting room.

Set up the replications as follows:

Object Multiple Runs Value
Simulation RunIndexDefinitionList 1 10
StartingRunNumber 1-1
EndingRunNumber 1-10

Save your simulation.

Now when you run your simulation, click on the Real Time button to disable it and your simulation will run without animation, but it will create a data file with the same name as your .cfg file but with a .dat extension. Open this file in Notepad++, does it make sense? Explain why/why not to one of your lab tutors.

Save your simulation.

Now our simulation is running with deterministic values we are going to add stochasticity to both arrivals and service and run 4 different models with all combinations:

1. Deterministic arrivals and deterministic service (just completed);
2. Stochastic arrivals and deterministic service;
3. Deterministic arrivals and stochastic service;
4. Stochastic arrivals and stochastic service.

First, add an ExponentialDistribution and a TriangularDistribution from the Probability Distributions model palette. Name them ArrivalDist and TreatmentDist respectively. Set their parameters as follows:

Object Key Inputs
ArrivalDist UnitType = TimeUnit, Mean = 20 min
TreatmentDist UnitType = TimeUnit, MinValue = 5 min, MaxValue = 30 min, Mode = 10 min

Now, set 4 runs of 10 replications each in the Simulation’s Multiple Runs:

Object Multiple Runs Value
Simulation RunIndexDefinitionList 4 10
StartingRunNumber 1-1
EndingRunNumber 4-10

Lastly, set the arrival and service times to be conditional on the run number - RunIndex(1). To do this we use the conditional expression

```<conditional expression> ? <true expression> : <false expression>
```

Object Multiple Runs Value
PatientGenerator FirstArrivalTime
`'([Simulation].RunIndex(1) == 1) || ([Simulation].RunIndex(1) == 3) ? 20[min] : [ArrivalDist].Value'`
InterArrivalTime
`'([Simulation].RunIndex(1) == 1) || ([Simulation].RunIndex(1) == 3) ? 20[min] : [ArrivalDist].Value'`
Doctor ServiceTime
`'([Simulation].RunIndex(1) == 1) || ([Simulation].RunIndex(1) == 2) ? 15[min] : [TreatmentDist].Value'`

Save your simulation.

Now run the simulation with Real Time turned off again and look at your .dat file. Does it make sense now?

## Results

Now your model is complete, you can use R to analyse your results.

1. Download the R analysis file - Lab1Analysis.R;
2. In the analysis file, set the directory to be the directory where your .dat file sits;
3. Run the R file.

It will give you confidence intervals for average patient waiting time for treatment, average total patient time in the clinic, and the average number of patients in the waiting room.

Is variability in patient arrivals or treatment time the most important in your model? Justify your answer to a lab tutor.

## Conclusions

In this case study, you developed simulation model of a Simple Health Clinic. You defined a conceptual model and used it to implement your simulation model in JaamSim. You added variability and tested the effect of that variability on the system. The key inputs were the arrival times and corresponding distribution and the treatment times and their distribution. The key outputs were the average patient waiting time for treatment, the average total time a patient spends in the clinic, and the average number of patients in the waiting room. The effect of variability on the key outputs was observed across multiple replications and confidence intervals were constructed to enable comparison across different combinations of variability.

Are the key outputs appropriate? Justify your answer to a lab tutor.

Note that the Queue object in JaamSim has a property [QueueName].QueueLengthMaximum. Given your previous answer, how could this be used?

Topic attachments
I Attachment History Action Size Date Who Comment
r Lab1Analysis.R r1 manage 0.6 K 2017-08-14 - 23:38 MichaelOSullivan
png doctor.png r1 manage 4.5 K 2017-08-14 - 03:28 MichaelOSullivan
png patient.png r1 manage 5.2 K 2017-08-14 - 01:29 MichaelOSullivan

This topic: OpsRes > SubmitCaseStudy > SimpleHealthClinic
Topic revision: r6 - 2017-08-14 - MichaelOSullivan

Copyright © 2008-2022 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback