NHP Demand and Capacity (D&C) Model

A Technical Deep Dive for Data Scientists

7 May 2025

The New Hospital Programme (NHP) Demand Model

Diagram showing the processes of the model

Diagram of model process

Diagram showing the model infrastructure layout

A diagram showing the architecture of the model and apps. Data is processed from the database by the targets package and stored in an Azure storage account. the model and inputs and outputs apps collected data from there. Selections in the inputs app feed into the model.

Principles

  • Deploy alongside develop
  • Reproducible analytical pipelines
  • Transparent
  • Open (FOSS where possible)
  • Team skills and work management

Tools and platforms

  • Data pipelines: , parquet, CSV
  • Model: Python , Docker
  • Apps: {shiny} and {golem} , Posit Connect
  • Infrastructure and storage: Azure
  • Documentation: Quarto
  • Version control and collaboration: Git , GitHub

Data for NHP

  • HES data stored on Azure
  • Databricks and PySpark
  • CSVs and TSVs for reference data
  • parameters derived and stored in JSON

Generating inputs data

Model running

Parameters JSON passed to model via API

  • Docker image stored on Azure Container Registry
  • Runs in Azure Container Instance
  • Built-in paralellisation features of Python language

Interfaces

Coded in R - Shiny Open repos: nhp_inputs and nhp_outputs

Modular design

  • Each function is in its own .R
  • Each module is separate
  • UIs and servers are separate
  • Packaged using {golem} to use R CMD check(), devtools::document() etc

Hosting

Posit Connect

  • Manage user access
  • RStudio, VSCode integration ( and )
  • Can handle secrets
  • No limits on views
  • We deploy a separate app per model version
    • Unambiguous
    • Backwards compatability

Outputs

Many formats:

We use a _brand.yml to help easily maintain style format of outputs (Quarto and Shiny).

Reproducible Analytical Pipeline (RAP) principles

Data versioning

Data and model follow the same semantic versioning1.

Data Log

The Strategy Unit GitHub

RAP

  • Modularised code
  • Styling and Linting
  • OPEN source code
  • Version control
  • Environment management:
  • Docker
  • {renv}
  • conda

RAP continued

  • Documentation
  • JSON schema {✔❌} for validating the parameters passed to the model

Deployment (CI/CD)

How do we maintain clean, safe, working code, centrally, when we have open repositories and up to 10 people collaborating on maintaining that code alongside its active deployment?

Continuous Integration

Automated checks, tests when merging code into main

  • On pull request submission
  • On merge to main

Continuous Deployment

Automated checks and tests when deploying (to dev or to prod)

  • On merge to main
  • On release

GitHub Actions

Actions like:

  • Formatting ({Air}) to pick up stylistic inconsistencies
  • Linting - for logical, syntactic and stylistic issues
  • Rendering the README.Rmd
  • Package checks (benefits of creating a Shiny app as a package)
  • Deploys to a ‘preview’ site
  • Assess code coverage ({codecov})

Break time!

Chris Beeley

Claire Welsh

Natasha Stephenson

Tom Jemmett

Matt Dray

YiWen Hon

Ozayr Mohammed

Rhian Davies

How we work

We are AGILE, and use Scrum (light)

  • 3 week sprints with 1 week fallow
  • Weekly sprint catch-up meetings
  • Kickoff and retro
  • Promote T-shape expertise while reducing ‘bus-factor’
  • Transparent prioritisation processes
  • Distinct team roles

  • Scrum master : keeping the sprint on track
  • Product owner : steer work towards the goals
  • Project director : overall responsibility for delivery
  • Development board : define the goals and priorities
  • QA : oversee quality

Tip

Roles have enough specificity to provide clarity, but are also shared. Flat management structure.

Agile and Scrum in GitHub

Leverage a LOT of GitHub’s excellent tooling

  • Projects
  • Issues with bespoke labelling
  • Branch protection rules
  • CODEOWNERS
  • Clear and consistent collaboration guidance
  • Checklists

CODEOWNERS

A simple but powerful idea!

Product Team

‘The model’ is a product - it has current and potential use cases and user groups.

We need a team responsible for understanding the software business as well as the software product 🚀.

“What should we build next and why?”

Product Team Members

  • Product Owner
  • Product Manager
  • Customer Engagement
  • Project Director

Information management

🗣 Info IN

Inbox, user feedback forms, button on apps, videoed interviews, roundtable, ad hoc.

📣 Info OUT

Project information site, GitHub, how-to videos, conference and meeting presentations, blogs.

To ensure that:

  • User needs guide what we build
  • We help (current and future) users know what we have built and are building

Thank you

NHP Demand and Capacity (D&C) Model: A Technical Deep Dive for Data Scientists