About Me

A picture of a woman riding a yellow mountain bike in the woods. The woman is wearing a white full-face helmet, a red and black cycling jersey with the letters 'TLD' on, and red and yellow leopard-print shorts, along with shin and elbow protection. There are large trees in the background, tape indicating the cycling course, and roots and rocks on the ground. The woman looks like she is concentrating.

  • One of two trainers on the HSMA programme @ Exeter (PenCHORD/PenARC)
  • Programming since 2012
  • Health Data Science MSc @ Exeter
  • Former NHS Analyst/Data Scientist

linkedin.com/in/sammijaderosser Add Me On LinkedIn

github.com/Bergam0t Follow Me On GitHub

PenCHORD

PenCHORD (the Peninsula Collaboration for Health Operational Research and Data Science) is one of the teams of PenARC.

PenCHORD began in 2010, and has worked with hundreds of local and national partners to use modelling and data science approaches to improve the operational delivery of health and social care services.

Our work is

  • applied
  • collaborative
  • impactful
  • open

PenCHORD Themes


Optimising Clinical Pathways

Using simulation, machine learning and geographic modelling techniques to improve clinical pathways

The SAMueL project is using ML to predict which stroke patients should receive clot-busting treatment

Open Modelling and Data Science

Supporting modellers and data scientists to make their work more open and reproducible

The STARS project is developing guidelines for how to share models to allow them to be used and reused effectively

And…

A red logo of a computer monitor and horizontal computer tower underneath it, encased in a circle. Underneath the logo is the acronym 'HSMA' in bold white lettering. Beneath this is the phrase 'Find the Future in You'

A white and orange logo saying 'NIHR - Applied Research Collaboration South West Peninsula'

The Health Service Modelling Associates is a 15 month data science and operational research training and mentoring programme.

Supported by the NIHR PenARC and the NHS Digital Academy, the full programme is provided free of charge to people working in health, social care and policing and is accredited by AphA.

Visit Our Website hsma-programme.github.io/hsma_site

Subscribe to our YouTube Channel youtube.com/@hsma

Follow us on GitHub github.com/hsma-programme

HSMA Details

The full HSMA experience is a live, 15-month programme with two distinct phases.

PHASE 1 - 6 month training phase

Participants learn the Python programming language, before progressing through simulation modelling, mapping, machine learning, natural language processing, website development, reproducible reporting, forecasting, and more.

Participants are released from their usual role for one day a week, joining the HSMA trainers online for live lectures and group work.


PHASE 2 - 9 month project phase

Participants are supported to produce a project using the new skills they have learned, applying operational research and data science techniques to a real problem within their organisation.

Participants are expected to spend at least one day a week working on their project during this phase.

HSMA Alumni and Projects

Our HSMA Community has now grown to several hundred people across 6 cohorts.

You probably have HSMA alumni in your organisation who can do amazing things if asked the right questions!

Find out more about the HSMA Programme and our projects on the HSMA website

HSMA 6 in the South West

Today’s Workshop

In today’s workshop, we’re running an interactive taster session of HSMA training content drawn from the Discrete Event Simulation (DES) module of our training programme.

You can view the interactive version of these slides at bit.ly/rke-des-slides

Before we start, let’s find out a little bit about you…



Raise your hand if you’ve heard of discrete event simulation before

Raise your hand if you are in an analyst, data scientist or data engineer-type role

Raise your hand if you know some Python or R

Pathways

Pathway Simulation: Why?

A stylised image showing very long queues outside of a hospital building

Your emergency department is struggling.

You could try a range of different things…

  • increase the number of staff available to register, triage or treat
  • increase the number of rooms or beds
  • increase the rate at which tests can be processed
  • add a new step in the process with a different kind of practitioner
  • completely redesign the pathway

Which of these is the right answer?

Queue, Queue, Barney McGrew

Healthcare tends to be full of queueing problems like this one.

  • People attending a walk-in clinic or emergency department
  • People calling a telephone-based service like 111 or a mental health crisis line
  • People on a cancer diagnosis and treatment pathway
  • People waiting to be assessed for ADHD and Autism, or on the waiting list for a gender clinic
  • People waiting for a series of treatment with a mental health practitioner
    • might have one, several or many appointments

Pathway Parts

Healthcare systems are full of resources

  • People 👩🏻‍⚕️ 👩🏿‍⚕️ 👨🏽‍⚕️ 👨🏽‍⚕️ 👩🏾‍⚕️
  • Equipment 🔬🩺
  • Rooms & cubicles 🏥
  • Beds 🛌🏻 🛌🏽 🛌🏿 🛌🏻 🛌🏼 🛌🏽 🛌🏿
  • Treatments 💉 🩹 💊
  • Vehicles 🚑 🚁 🚗

These resources experience demand from entities.

These entities might be

  • People (in person) 🤒 🤢 🤧
  • People (on the phone) ☎️
  • Test Requests 🩻 🧪

Pathways and Queues

As these entities move through a pathway - a series of steps where these resources are used - queues can build up where there isn’t enough resource.

A pathway showing several steps, starting with 'sign in with receptionist'. One person is signing in; one receptionist is in use and the other is available. A queue of 7 people is then waiting to be triaged. One person is being triaged bby the single available triage nurse. The pathway then splits; one person is seeing a nurse for treatment while two further nurses are available. There is no queue for this step. However, 8 people are waiting to be treated by the single available doctor, who is currently treating someone. People can then either be discharged, receive additional treatment from a nurse or doctor, or may require additional tests. One person is waiting for tests; one person is dealing with the tests while the other is idle. After these tests, people may be discharged, or may need to see a doctor or nurse again.

Queue What?


And these pathways are often very complicated!

There are lots of moving parts, and lots of variation.


Variation in when, and how frequently, people arrive

Variation in how long an activity in the pathway takes

Variation in the pathways people take within a single system

The Problem with Pathways

Making changes to pathways can be

  • costly
  • slow
  • unsafe!

And even if you do fix the original problem you were trying to solve, there’s a risk of knock-on effects elsewhere in the pathway that you didn’t foresee.

The Future Problems with Pathways

And even if you avoid that….

A system that is coping now might not cope

  • all the time
  • if demand increases
  • if resource temporarily decreases

It’s All a Simulation

On HSMA, we teach a couple of different computer simulation techniques.

System Dynamics

High-level technique that’s often suited to uncovering fundamental issues with pathway or wider healthcare system design

Agent-Based Simulation (ABS)

Individual-level modelling that is particularly interested in the impact of individuals’ decisions and interactions

Discrete Event Simulation (DES)

Modelling focussing on the flow of entities through a pathway and use of resources, allowing detailed investigation of capacity, queues and waits

It’s Our DEStiny



What we generally want to tackle our pathway problems in healthcare is Discrete Event Simulation (DES)

In a DES…

The top row of this diagram says 'entities' and shows stylised 'emoji' representations of 5 ill people. The next row of the diagram says 'flow through a pathway' and shows a branching diagram of a healthcare pathway with the steps 'arrive', 'sign in with receptionist', 'triaged', 'see nurse', 'see doctor', 'additional tests', 'discharge'. Some steps are optional or may be repeated more than once - the specifics are not important as it is just an indication of what is meant by 'pathway' in this context. The final row says 'using resources along the way' and shows four doctors and three beds as an indication of what resources are in these context.

DES to the Rescue

DES is so powerful because it gives us an in-silico (computer-based) reproduction of our pathway to play around with.

We can make any change we want
(e.g. more resources, higher demand, new pathway design)
safely and for free and see what impact it has on any metric we care to measure:

  • how long people wait at each step of the pathway
  • people meeting targets (e.g. 4 hour wait)
  • how much of the time the resources are utilised for


And so on!

Variation

We’ll explore this more in the interactive part of the workshop, but for now it’s just worth mentioning that DES is also really good at dealing with variation.

Instead of just planning on averages - like the average length of stay, or the average number of people who are referred each month, we can take into account the real-world variation seen, and play out many different possible futures…

A Note About Modelling

Your DES won’t be a perfect one-to-one reproduction of the pathway you are modelling.

We have to make certain assumptions and simplifications, and we can’t capture every complexity.

However…



All models are wrong, but some are useful

• George E. P. Box

A stylised colour illustration of an older man - intended to resemble the statistician George E P Box - sitting at a desk. The man has large round glasses, a large grey pointed moustache and grey hair. He is wearing a brown suit and waistcoat with a blue patterned tie. On the wall behind him are books, and on the table is a calculator, books and a clipboard. There are also graphs and charts on the wall and on a computer monitor on the desk.

Example DES Projects

Example 1: Bladder Cancer Pathway

In this PenCHORD project, a DES model of the bladder cancer pathway at Royal Cornwall Hospitals Trust (RCHT) exposed two key system bottlenecks.

  • A delay between patients being referred and receiving their surgery
  • A delay waiting for the nurse specialist to contact the patient to discuss their diagnosis and treatment options

The model was used to support an on-the-spot rewrite of the pathway, resulting in multi-week reductions to waiting times.

Find Out More

Example 2: Vaccination Clinic

This HSMA project looked at the design of a COVID-19 vaccination clinic in North Devon, exploring

  • queue lengths
  • car park capacity
  • times for each step of the vaccination process

The model identified potential issues with the original proposed plans, and was used to refine the plans to enable a safe but efficient delivery of the vaccination programme.

Find Out More

Example 3: Emergency Department Model

This HSMA project looked at ways to improve Urgent Treatment Care (UTC) performance. The team wanted to know

  • What further staff and resources would be required for any variations in patient attendance
  • How changes in the patient pathway would reduce bottlenecks
    (e.g what would be the impact of front-loading diagnostics?)

The model identified a need for additional rooms and the ED was redesigned as a result.

Find Out More

Example 4: Children’s Neurodiversity Assessment Pathway

This HSMA project created a model of a paediatric neurodevelopmental (ADHD + autism) pathway. Waits had increased to a 2 years on average.

The team wanted to understand

  • where current bottlenecks in the process were
  • what level of staffing would be needed to clear the existing backlog and maintain a steady state

The model showed that recruiting an extra lead clinician would not address the bottleneck - but an additional second assessor would.

Find Out More

Other Projects

You can find details about all of our previous and current Discrete Event Simulation projects on the HSMA website

An animation of someone navigating through a page of projects on the HSMA website. They scroll down to a project on simulation and click on 'details' to receive more information and find a video on the project.

Discussion: Opportunities for DES in your Organisations

In your groups, we’re going to spend a few minutes discussing opportunities you can see for DES in your organisation.

  • Do you have pathways you can see this being applied to?
  • Do you know of any simulation models that have already been done or are currently being worked on in your organisation?

We’ll then ask you to share some of this with the rest of the group.

Understanding Simulation Models

For the rest of the session, we’re going to play around with an interactive tool to help you build up your understanding of simulation models.

We’re going to work with a simple clinic model, gradually adding features.

Our Goal

First, patients (our entities) arrive.

They go to a triage cubicle and are triaged into one of two pathways.


1. Trauma

  • Patients are stabilised in a trauma bay
  • All truma patients are treated in a trauma treatment cubicle

2. Non-Trauma

  • Patients are registered in a registration cubicle
  • Patients are examined in an examination room
  • Some non-trauma patients are treated in a treatment cubicle

Patients then leave the emergency department.

Our Goal: Diagram

We can think of our pathway like this.

DES Step 1: Arrivals

Where are all the people?

Our simulation first needs some people in it!

We will tell our code to start generating people to place in the simulation - but how are we going to control the rate at which they arrive?

Variation

That randomness and variation in our healthcare systems that we mentioned before? DES can cope really well with that!

Let’s imagine that people turn up to our system, on average, every 10 minutes.

However, sometimes no-one turns up for half an hour, and other times 3 people turn up simultaneously.

By using distributions we can produce random times that mimic real-world patterns.

Distributions

We sample the gap between arrivals from a distribution.

Where the bar higher, there is a greater chance that the random number picked will be somewhere around that value.

Depending on the real-world pattern we are trying to mimic, our distribution will

  • be a different shape
  • peak in a different place

Randomness

Taking it even further, we can harness that variation for making the most of our models.


We can hold the random arrival patterns consistent and change resource levels or pathway design

We can hold resources or pathway design consistent and allow randomness in arrival times


This allows us to be sure the changes we’re testing really are responsible for the differences

This allows us to test our system in multiple parallel universes, running it tens or even hundreds of times!

Random Seeds

Computers aren’t very good at being random!

So we give it a ‘seed’ to start from.



If our seed is 1, maybe the arrival times sampled from the distribution will be

5 minutes, 2 minutes, 3 minutes, 6 minutes, 5 minutes



If our seed is 101, maybe the arrival times will be

10 minutes, 2 minutes, 5 minutes, 5 minutes, 3 minutes

The DES Playground

Let’s head to the playground at bit.ly/rke-des

Warning

Note that this site will not work on mobiles or on the Firefox browser

Arrivals Exercise

  1. Try changing the slider with the title ‘How many patients should arrive per day on average?’.

    • Look at the graph below it.
      • How does the shape of the distribution change?
      • What does this mean for the time between arrivals?


  1. Change the average number of patients back to the default (80) and click on ‘Run simulation’.

    • Look at the charts that show the variation in patient arrivals per simulation run.
    • Look at the chart of cumulative arrivals. By 6am, what was the highest and lowest number of arrivals in different simulation runs?


  1. Try changing the random number the computer uses without changing anything else, then run the simulation again.
    • What happens to the number of patients?
    • Do the bar charts and histograms look different?

Answers - Q1

Try changing the slider with the title ‘How many patients should arrive per day on average?’.

How does the shape of the distribution change? What does this mean for the time between arrivals?

Answers - Q2

Change the average number of patients back to the default (80) and click on ‘Run simulation’.

Look at the charts that show the variation in patient arrivals per simulation run.

Answers - Q2

Change the average number of patients back to the default (80) and click on ‘Run simulation’.

Look at the charts that show the variation in patient arrivals per simulation run.

Answers - Q2

By 6am, roughly how many patients have arrived in different simulation runs?

Answers - Q3

Try changing the random number the computer uses without changing anything else. What happens to the number of patients? Do the bar charts and histograms look different?

DES Step 2: A Simple Pathway

Using a Simple Resource

Now we have arrivals, we don’t need much more to make our first full model!

The next thing we need is a resource. 👩🏼‍⚕️

Our entities (🤒🤧🤕🤢) will arrive and hog the resource (👩🏼‍⚕️) for a certain amount of time.

Like the inter-arrival times, we don’t just use a set time for the consultation - we sample from a distribution.

Metrics Relating to Resources

We can start measuring some more results from our system now:


The utilisation of our resource

(the % of the time that it is in use)


The average waits for a resource

(the number of minutes that pass waiting for someone to reach the front of the queue and be assigned to a resource)


The % of patients who meet a target waiting time

(how many patients wait less than the target time to get to the front of that queue)

Resource Exercise

  1. Try changing the sliders for consultation time and variation in consultation time.
    • What happens to the graph below the sliders?

  1. Put the consultation times back to the default (50 minutes length on average, 10 minutes of variation).

    • Run the model and take a look at the animated flow of patients through the system.
    • What do you notice about
      • the number of nurses in use?
      • the size of the queue for treatment at different times?

  1. What happens when you play around with the number of nurses we have available?

    • Look at the queues, but look at the resource utilisation too. The resource utilisation tells us how much of the time each nurse is busy rather than waiting for a patient to turn up.
    • Can you find a middle ground where the nurse is being used a good amount without the queues building up?

Answers - Q1

Try changing the sliders for consultation time and variation in consultation time. What happens to the graph by the sliders?

Answers - Q2

Run the model and take a look at the animated flow of patients through the system. What do you notice about the number of nurses in use and the size of the queue for treatment at different times?

Answers - Q3

What happens when you play around with the number of nurses we have available? Can you find a middle ground where the nurse is being used a good amount without the queues building up?

Answers - Q3

What happens when you play around with the number of nurses we have available? Can you find a middle ground where the nurse is being used a good amount without the queues building up?

Answers - Q3

How does this vary across runs?

DES Step 3: Branching Pathways

Adding Complexity

Now, most systems are a bit more complex. Our entities (🤒🤧🤕🤢) might not all follow the same path.

Some might be ill enough to need treatment by a more specialised nurse:

Others can just have some advice and be sent on their way by the first nurse, like before:

The Revised System

Our revised system looks a bit more like this.

Dealing with Branches

Like every other step, we use a distribution!

However, this time it’s a bit like flipping a coin.

If we have a 50% probability of a client needing treatment (🏥), it’s like flipping a fair coin.

The other 50% will go home (🏠)


🏥 🏥 🏠 🏥 🏠 🏠 🏥 🏠 🏠 🏥


If we make it a 70% probability, it’s like flipping a weighted coin…

🏥 🏥 🏠 🏠 🏠 🏠 🏥 🏠 🏠 🏠

Variation in Branches

But like flipping a coin, our outcome won’t be exactly the same every time!

🏥 🏥 🏠 🏠 🏠 🏠 🏥 🏠 🏠 🏠

🏥 🏥 🏥 🏠 🏠 🏠 🏥 🏠 🏠 🏠

🏥 🏥 🏠 🏠 🏠 🏠 🏥 🏠 🏠 🏥


Or in rare cases, maybe even

🏠 🏠 🏠 🏠 🏠 🏠 🏠 🏠 🏠 🏥

What does this mean for our simulation?

Variation in Variation

While it can vary quite a lot on a single day, over a longer model run, it will average out to be closer to the value we specified - though still not exact.

Doing your Own DES Projects

Before we go on to our final exercise, let’s discuss how you could start modelling your own pathways.

Drag & Drop

There are various paid, closed-source drag-and-drop software tools for doing DES - but they are often prohibitively expensive.

Using these tools can make it hard to share your models with others.

However, If you don’t code, there is the free and open source (FOSS) tool JaamSim.

A screenshot showing the homepage of the website for the JaamSim software. It contains a link to download the software for free, as well as a video showing the use of the software and some key information about the features of the software.

DES in Code

The most flexible and powerful way to build your simulations is using code.

The logo for the simmer R package. It is a yellow hexagon with a darker yellow border, with the word 'simmer' at the bottom and a simple black mug containing a spoon and three white dots.



R has the simmer package.

The logo for the simpy package. It is the text 'SimPy' in green and grey, with the top of the S stylised as the head of a snake and the bottom as a cog.

In Python, there are a range of packages for DES.

HSMA has used and taught simpy for several years. It’s mature, stable, reliable and flexible.

HSMA Training on DES

The DES lectures and activities from this year’s HSMA can be found on our website.

Module Link

Intro to DES

• What DES is and where it may be useful

• The key terminology associated with DES

• Simplifying a real-world pathway modelling problem into a conceptual model

SimPy for DES

• Features of the SimPy package

• Writing simple simulations with SimPy

• Multi-step pathways

• Branching pathways and optional steps

Advanced Simpy

• Warm-up Periods

• Priority-based Queuing

• Resource Unavailability

• Lognormal Distributions

• Reneging

• Balking

• Jockeying

The Little Book of DES

We have also put together a free eBook that serves as a handy reference to doing DES with SimPy.

It’s packed with code snippets you can use and modify, and it goes beyond the lecture content.

HSMA Training on Web App Interfaces for DES

While creating these models and running a range of parameters yourself can be really powerful, getting the models into the hands of stakeholders can really enhance their adoption.

Frameworks like Streamlit can help you to quickly create interactive web app front-ends for your app.

A book cover, showing a robot surfing on a wave made of numbers

Our free HSMA eBook on web app development walks you through a range of Streamlit concepts.

It then goes on to providing a walk-through of how to create a simple front-end for any DES model.

  Click here to view the eBook

We also have recorded training on Streamlit.

Module Link

Simulation Library

On HSMA, we’re trying to collate and visualising models from across healthcare systems.

At present, there is

  • A simple emergency department
  • An orthopaedic surgery unit
  • A simple community-based service with a single appointment
  • A complex community-based service with varying numbers of appointments and a per-clinician caseload

More will be added in the coming months.

  Click here to try them out

  Click here for the code repository


This is an early-stage piece of work!

DES Step 4: Optimising a Complex Pathway

Now we know how every part of the full model works - so let’s put it all together.

We’ve also added in a tweak here - arrivals now don’t occur at a consistent rate throughout the day.

It’s quieter sometimes and busier at other times, like a real centre!

The final problem

Due to building work taking place, our hospital will temporarily need to close several bays.

It will be possible to have a maximum of 20 bays/cubicles/rooms in total across the whole system.

What is the best configuration we can find to keep the average wait times as low as possible?

Note

We’ll use the default probabilities for trauma/non-trauma patients (0.3) and treatment of non-trauma patients (0.7)

End of Simulation

Summary

  • DES is an amazing option for tackling your pathway problems

  • You can create these yourself, or reach out to HSMAs within your organisation or other organisations to create them for you

  • Code gives maximum flexibility, allowing us to automate problems like our final one so that the computer would find the best solution

Access the full version of the DES playground at bit.ly/des-playground

Warning

Note that this site will not work on mobiles or on the Firefox browser