Reusable by Default


Reflections on Building Sustainable Open Tools
and Knowledge for Healthcare


Sammi Rosser


HSMA        PenARC        University of Exeter

Picture a Scene

A pixellated cartoon representation of the speaker sitting at a computer and looking stressed. In the background, a robot is saying 'we need this tomorrow'.

A mockup of a Slack chat. The speaker is asking 'Hey, has anyone done something previously on forecasting ED arrivals for operational planning?'

A mockup of a Slack chat. A man named Alan Lyst has replied 'Yes!'

A mockup of a Slack chat. A man named Alan Lyst has replied 'Yes!'. He has then added 'But it was at my last job and I don't have the code'.

A mockup of a Slack chat. A woman named Dee Cision has replied with a repository link.

A screenshot of a github repository. There are a large number of folders.

A screnshot of a readme for a repository. It simply says 'this repository predicts ED attendances'

Who am I to come here and talk about this?

An image of the speaker's GitHub contributions from 2017. There are 53.

An image of the speaker in graduation attire, wearing two layers of mask.

A meme of Buzz Lightyear and Woody from toy story. Woody looks worried. Buzz - with his head replaced by the NHS logo - is saying 'Excel. Excel everywhere.'

A photo of a previous NHS R conference. There is a heatmap of the number of patients in a department shown on a large screen.

A logo comprising of a chunky red computer and the letters HSMA. It says 'find the future in you'.

An image of Dr Daniel Chalk represented as a puppet, a la the muppets

An image of the spaker represented as a puppet, a la the muppets

An image of the speaker in a HSMA t-shirt, talking to a room full of people about a simulation model of a hospital ward

An image of the speaker's github contributions in 2017. There are 53.

An image of the speaker's github contributions in 2024. Ther are 2008.

The Problem

An image of the HSMA website, showing three previous projects: Developing a service planning decision support tool to tackl inequalitis and minimise carbon output; using discrete event simulation to model the bottlenecks in the acute medical unit pathway; discrete event simulation to model elective surgery pathways

https://hsma.co.uk/previous_projects/projects_with_code


I keep seeing the
same few simple(ish) things
holding otherwise great repositories back


The utopia we want to reach

A screenshot of Rhian Davies' talk from the 2024 RPySOC conference, titled 'from reproducible to reusable'

https://statsrhian.github.io/nhsrpysoc-reusable/

Reproducible PLUS Reusable

A screenshot of the NHS England RAP community of practice playbook website

The logo of the Sharing Tools and Artefacts for Reproducible Simulations in Healthcare' project (STARS)

The Tapestry of ‘Reusable by Default’

10 colourful tesselated hexagons, each containing a question mark

My Proposals

  • Some take almost no time
  • Those that take time often save time in the long run
  • They don’t all need to happen at once (or all of them always)
  • But how much longer can we afford to NOT do them?

This is the ‘why’ - find the ‘how’ on my website

sammirosser.com

Ready?

(or any online repository hosting)

  • On GitHub > emailed/Slacked/available on request
  • Not ready to use it in full? Drag and Drop.
  • Borrow repo templates from other people!
  • Heightens impact of some of the other elements…

  • If you don’t add a licence, I can’t use your code!
  • Yes, even if you emailed it to me (unless you were clear)
  • It’s one ‘special’ file (LICENCE or LICENCE.md) GitHub recognises
  • Once you settle on one, it’s a 1 minute job

If you don’t have a readme, you could be taking hours of each persons’ time

  • Tell me how to use it
    • installing environment
    • what to run and how
    • data format required
  • Tell me why I should bother
  • Tell me how it’s doing what it’s doing

README.md is a special file GitHub will display

# vidigi (Visual Interactive Dynamics and Integrated Graphical Insights)

Welcome to vidigi - a package for visualising real or simulated pathways.

https://github.com/hsma-programme/vidigi/vidigi_video.mp4

## Getting started

Head to the [documentation](https://hsma-tools.github.io/vidigi/vidigi_docs/)
to find out how to create an animated version of your model.

You can install vidigi from PyPi with the command `pip install vidigi`.

  • Docstrings are super-comments

And you write them like this (in )

Allowed to use AI? Rope it in!

Those docstrings you just wrote?

Combine them with pdoc, sphinx, quartodoc, or mkdocs (for )

Or pkgdown (for )

Voila - website with all your code documented

You can host your documentation for free with just a few clicks

They generate a dictionary

A screenshot of a documentation webpage, listing 5 hyperlinked functions in tables, separated by headers

(this is Quartodoc)

And display your docstrings

A screenshot of a documentation webpage, breaking down a single function. All function parameters are listed with heir defaults, along with a detailed table of parameter details and type, and a brief description of what the function does.

(this is Quartodoc)

A plea…

I will not be reading your code if it’s written like this…

df=pd.read_csv("sales.csv").dropna(subset=["price","quantity"]).assign(total=lambda d:d["price"]*d["quantity"]).query("total>1000").groupby(["region","category"],as_index=False).agg({"total":"sum","quantity":"mean"}).sort_values("total",ascending=False).rename(columns={"total":"total_sales","quantity":"avg_quantity"}).reset_index(drop=True).head(10)


But I will if it looks like this

df = (
    pd.read_csv("sales.csv")
    .dropna(subset=["price", "quantity"])
    .assign(total=lambda d: d["price"] * d["quantity"])
    .query("total>1000")
    .groupby(["region", "category"], as_index=False)
    .agg({"total": "sum", "quantity": "mean"})
    .sort_values("total", ascending=False)
    .rename(columns={"total": "total_sales", "quantity": "avg_quantity"})
    .reset_index(drop=True)
    .head(10)
)

  • Install a linter like ruff for python
  • Set it to format on save = never faff with formatting again!

  • Choosing a future-proof folder structure from the start saves effort down the line (for Python in particular)
  • Avoid putting your script files in the repository root
  • It costs very little once you get used to it
  • Other things (like auto-documentation) will just work

myproject/
├── analysis.ipynb
├── main.py
├── utils.py
├── README.md
├── requirements.txt

myproject/
├── analysis.ipynb
├── pyproject.toml
├── README.md
├── requirements.txt
└── src/
    └── myproject/
        ├── __init__.py
        ├── main.py
        └── utils.py

  • Automated tests are small scripts that check your code (still) works as expected
  • They give you and others confidence in your code
  • You (or they) instantly know if changes have caused problems
  • Overall, they save you heaps of time

def add(a, b):
    return a + b
def test_add():
    assert add(2, 3) == 5


  • Or a certain thing never happens in a simulation
  • Or you have the same number of rows after a join
  • etc.

  • GitHub has fantastic free project tracking tools built in
  • Helps you to keep track of what you haven’t done yet
  • Helps others understand what’s left to happen (and maybe pitch in)

Issues

An image of a github issue. Text explains a limitation of the code. Colourful tags categorise it as relating to the anmation functions, ease of use, and prep functions. It is assigned to the milestone 1.2.0.

Projects

An image of a github project. Issues are sorted into the headers backlog, monitoring or investigating, up next, in progress, and awaiting release.

A mindset shift

Where are we now?

Ten colourful tesselated hexagons with the following text: GitHub; Readme.md; LICENCE; docstrings; documentation, folder structure, auto-linter, issues and projects, tests. The final hexagon is shinier and more special looking than the rest, and contains a question mark.

Last chance…

Remember our plea from the start?

What do you do every time you start a new script?



import pandas as pd
library(ggplot2)

Or maybe…



library(NHSRPlotTheDots)

  • We need to start identifying the bits of the work we do that we can turn into reusable elements
  • Look for patterns and repetition
  • Write more functions
  • Think how to accept elements as arguments instead of hard coding them

An animation of a model for a workshop…


Became vidigi

Summary

You don’t always know what will be worth sharing and reusing when you start


But these steps

  • Unlock possibilities
  • Make your life easier
  • Make your teams’ life easier
  • Accelerate your learning

These pieces set the stage

Ten colourful tesselated hexagons with the following text: GitHub; Readme.md; LICENCE; docstrings; documentation, folder structure, auto-linter, issues and projects, tests, package mindset.

The Final Hurdle

The challenge

The NHS-R logo

The HACA logo

The SW.AIH logo

An image of the speaker's LinkedIn network, showing 193 people being followed out of network

An image of the speaker's starred repositories on github, numbering 1.3k

An image of the speaker's github profile, showing 82 followers and 314 people being followed by the speaker

A screenshot of the Health and Care Operational Research Network - HaCORN - webpage. It says 'creating a network to cllaborate and share operational research expertise to improve health and social care'

A screenshot of the NHS-R youtube channel, showing 4 coffee and coding videos.

A screenshot of the HSMA 6 showcase playlist

The AphA logo

A screenshot of the header of the 80th issue of the AphA analysts magazine

A screenshot of the NHS-R Slack, showing the finds channel

A screenshot of the monthly data science professinal development newsletter from the NHS England Data Science Team

An image of four people holding pint glasses. The image is from the movie Shaun of the Dead.

A meme image with two large red buttons. One says 'remember this cool project'. The other says 'remember how to tie your shoelaces'. Below this is an mage of a man perspiring and wiping his brow with a white cloth.

The Healthcare Services Analytics & Decision Science Atlas

atlas.hsma.co.uk

What next?

A poster of the speaker represented as a puppet character like the muppets. She is pointing at the viewer with the words 'I need you' below it.

Contribute

Submit a project code-free via the form or read advanced instructions in the README

Get in touch

A representation of the speaker as a puppet character

Add Me On LinkedIn - Sammi Rosser


Follow Me On GitHub - Bergam0t


Watch other talks @ sammirosser.com


Email me - hi@sammirosser.com


Check out HSMA - hsma.co.uk

Acknowledgements

Slack chat mockups generated from chatmockup.com

Images generated with DALL-E3 or ChatGPT-5

Cheers icons created by Konkapp - Flaticon

Hex stickers built on Canva (all images used via Canva Pro subscription)

The STARS project team for their work on reusability

Pub image from Shaun of the Dead (Universal Pictures).

Huge thanks to Dr Dan Chalk and all of our HSMAs

And many thanks to the NIHR/PenARC for funding us!