# the-strategy-unit/nhp_model architecture

> Architecture diagram of the GitHub repository the-strategy-unit/nhp_model, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/the-strategy-unit/nhp_model
- Repository: https://github.com/the-strategy-unit/nhp_model

## Overview

The New Hospital Programme Demand Model runs a configured forecast of inpatient, outpatient and A&E activity. Its main workflow loads parameters and prepared activity data, runs baseline and Monte Carlo iterations with demographic, birth and health-status adjustments, applies model-specific activity strategies, then aggregates and saves results. The repository also includes a Docker-oriented runner with local and Azure storage options. Edges reflect the README and SOURCE INDEX references; unsampled implementation details are not inferred.

Main entry points: [`src/nhp/docker/run.py`](https://github.com/the-strategy-unit/nhp_model/blob/main/src/nhp/docker/run.py) (Container runner), [`src/nhp/model/model.py`](https://github.com/the-strategy-unit/nhp_model/blob/main/src/nhp/model/model.py) (Generic model), [`src/nhp/model/run.py`](https://github.com/the-strategy-unit/nhp_model/blob/main/src/nhp/model/run.py) (Model orchestration), [`src/nhp/model/model_iteration.py`](https://github.com/the-strategy-unit/nhp_model/blob/main/src/nhp/model/model_iteration.py) (Model iteration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inputs["Inputs and adjustments"]
  node_params["Parameter validation<br/>[__init__.py]"]
  node_data["Data loaders<br/>[data.py]"]
  node_localdata["Local data source<br/>[local.py]"]
  node_hsa["Health adjustment"]
end

subgraph group_forecast["Activity forecasting"]
  node_runner["Model orchestration<br/>[run.py]"]
  node_generic["Generic model<br/>[model.py]"]
  node_iteration["Model iteration<br/>[model_iteration.py]"]
  node_resampling["Activity resampling"]
  node_inpatient["Inpatient model<br/>[inpatients.py]"]
  node_outpatient["Outpatient model<br/>[outpatients.py]"]
  node_aae["A&amp;E model<br/>[aae.py]"]
end

subgraph group_outputs["Results and delivery"]
  node_results["Result aggregation<br/>[results.py]"]
end

subgraph group_runtime["Container runtime"]
  node_dockercli["Container entrypoint<br/>[__main__.py]"]
  node_dockerconfig["Container configuration<br/>[config.py]"]
  node_dockerrun["Container runner<br/>[run.py]"]
end

node_user(("Model user"))
node_azureblob[("Azure blob storage")]
node_azuretable[("Azure table storage")]

node_user -->|"runs forecast"| node_runner
node_user -->|"provides JSON"| node_params
node_user -->|"provides data"| node_localdata
node_runner -->|"runs model"| node_inpatient
node_runner -->|"runs model"| node_outpatient
node_runner -->|"runs model"| node_aae
node_runner -->|"combines results"| node_results
node_generic -->|"loads activity"| node_data
node_generic -->|"creates adjustment"| node_hsa
node_generic -->|"loads parameters"| node_params
node_inpatient -->|"inherits model"| node_generic
node_outpatient -->|"inherits model"| node_generic
node_aae -->|"inherits model"| node_generic
node_iteration -->|"applies adjustments"| node_resampling
node_iteration -->|"uses model"| node_generic
node_iteration -->|"provides run results"| node_results
node_dockercli -->|"loads configuration"| node_dockerconfig
node_dockercli -->|"starts runner"| node_dockerrun
node_dockerrun -->|"uses configuration"| node_dockerconfig
node_dockerrun -->|"runs model"| node_runner
node_dockerrun -->|"loads parameters"| node_params
node_dockerrun -->|"saves results"| node_results
node_dockerrun -->|"downloads and uploads"| node_azureblob
node_dockerrun -->|"updates run status"| node_azuretable
node_data -->|"loads local data"| node_localdata

click node_params "https://github.com/the-strategy-unit/nhp_model/blob/main/src/nhp/model/params/__init__.py"
click node_data "https://github.com/the-strategy-unit/nhp_model/blob/main/src/nhp/model/data/data.py"
click node_localdata "https://github.com/the-strategy-unit/nhp_model/blob/main/src/nhp/model/data/local.py"
click node_hsa "https://github.com/the-strategy-unit/nhp_model/blob/main/src/nhp/model/health_status_adjustment.py"
click node_runner "https://github.com/the-strategy-unit/nhp_model/blob/main/src/nhp/model/run.py"
click node_generic "https://github.com/the-strategy-unit/nhp_model/blob/main/src/nhp/model/model.py"
click node_iteration "https://github.com/the-strategy-unit/nhp_model/blob/main/src/nhp/model/model_iteration.py"
click node_resampling "https://github.com/the-strategy-unit/nhp_model/blob/main/src/nhp/model/activity_resampling.py"
click node_inpatient "https://github.com/the-strategy-unit/nhp_model/blob/main/src/nhp/model/inpatients.py"
click node_outpatient "https://github.com/the-strategy-unit/nhp_model/blob/main/src/nhp/model/outpatients.py"
click node_aae "https://github.com/the-strategy-unit/nhp_model/blob/main/src/nhp/model/aae.py"
click node_results "https://github.com/the-strategy-unit/nhp_model/blob/main/src/nhp/model/results.py"
click node_dockercli "https://github.com/the-strategy-unit/nhp_model/blob/main/src/nhp/docker/__main__.py"
click node_dockerconfig "https://github.com/the-strategy-unit/nhp_model/blob/main/src/nhp/docker/config.py"
click node_dockerrun "https://github.com/the-strategy-unit/nhp_model/blob/main/src/nhp/docker/run.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_params,node_data,node_localdata,node_hsa,node_user toneBlue
class node_runner,node_generic,node_iteration,node_resampling,node_inpatient,node_outpatient,node_aae,node_azureblob,node_azuretable toneAmber
class node_results toneMint
class node_dockercli,node_dockerconfig,node_dockerrun toneRose
```

## Components

### Inputs and adjustments

- [Parameter validation](https://github.com/the-strategy-unit/nhp_model/blob/main/src/nhp/model/params/__init__.py): `src/nhp/model/params/__init__.py`
- [Data loaders](https://github.com/the-strategy-unit/nhp_model/blob/main/src/nhp/model/data/data.py): `src/nhp/model/data/data.py`
- [Local data source](https://github.com/the-strategy-unit/nhp_model/blob/main/src/nhp/model/data/local.py): `src/nhp/model/data/local.py`
- [Health adjustment](https://github.com/the-strategy-unit/nhp_model/blob/main/src/nhp/model/health_status_adjustment.py): `src/nhp/model/health_status_adjustment.py`

### Activity forecasting

- [Model orchestration](https://github.com/the-strategy-unit/nhp_model/blob/main/src/nhp/model/run.py): `src/nhp/model/run.py`
- [Generic model](https://github.com/the-strategy-unit/nhp_model/blob/main/src/nhp/model/model.py): `src/nhp/model/model.py`
- [Model iteration](https://github.com/the-strategy-unit/nhp_model/blob/main/src/nhp/model/model_iteration.py): `src/nhp/model/model_iteration.py`
- [Activity resampling](https://github.com/the-strategy-unit/nhp_model/blob/main/src/nhp/model/activity_resampling.py): `src/nhp/model/activity_resampling.py`
- [Inpatient model](https://github.com/the-strategy-unit/nhp_model/blob/main/src/nhp/model/inpatients.py): `src/nhp/model/inpatients.py`
- [Outpatient model](https://github.com/the-strategy-unit/nhp_model/blob/main/src/nhp/model/outpatients.py): `src/nhp/model/outpatients.py`
- [A&E model](https://github.com/the-strategy-unit/nhp_model/blob/main/src/nhp/model/aae.py): `src/nhp/model/aae.py`

### Results and delivery

- [Result aggregation](https://github.com/the-strategy-unit/nhp_model/blob/main/src/nhp/model/results.py): `src/nhp/model/results.py`

### Container runtime

- [Container entrypoint](https://github.com/the-strategy-unit/nhp_model/blob/main/src/nhp/docker/__main__.py): `src/nhp/docker/__main__.py`
- [Container configuration](https://github.com/the-strategy-unit/nhp_model/blob/main/src/nhp/docker/config.py): `src/nhp/docker/config.py`
- [Container runner](https://github.com/the-strategy-unit/nhp_model/blob/main/src/nhp/docker/run.py): `src/nhp/docker/run.py`

### Other components

- **Model user**
- **Azure blob storage**
- **Azure table storage**

## Connections

- Model user → Model orchestration: runs forecast (evidence: `readme.md`)
- Model user → Parameter validation: provides JSON (evidence: `readme.md`)
- Model user → Local data source: provides data (evidence: `readme.md`)
- Model orchestration → Inpatient model: runs model (evidence: `src/nhp/model/run.py`)
- Model orchestration → Outpatient model: runs model (evidence: `src/nhp/model/run.py`)
- Model orchestration → A&E model: runs model (evidence: `src/nhp/model/run.py`)
- Model orchestration → Result aggregation: combines results (evidence: `src/nhp/model/run.py`)
- Generic model → Data loaders: loads activity (evidence: `src/nhp/model/model.py`)
- Generic model → Health adjustment: creates adjustment (evidence: `src/nhp/model/model.py`)
- Generic model → Parameter validation: loads parameters (evidence: `src/nhp/model/__init__.py`)
- Inpatient model → Generic model: inherits model (evidence: `src/nhp/model/inpatients.py`)
- Outpatient model → Generic model: inherits model (evidence: `src/nhp/model/outpatients.py`)
- A&E model → Generic model: inherits model (evidence: `src/nhp/model/aae.py`)
- Model iteration → Activity resampling: applies adjustments (evidence: `src/nhp/model/model_iteration.py`)
- Model iteration → Generic model: uses model (evidence: `src/nhp/model/model_iteration.py`)
- Model iteration → Result aggregation: provides run results (evidence: `src/nhp/model/results.py`)
- Container entrypoint → Container configuration: loads configuration (evidence: `src/nhp/docker/__main__.py`)
- Container entrypoint → Container runner: starts runner (evidence: `src/nhp/docker/__main__.py`)
- Container runner → Container configuration: uses configuration (evidence: `src/nhp/docker/run.py`)
- Container runner → Model orchestration: runs model (evidence: `src/nhp/docker/run.py`)
- Container runner → Parameter validation: loads parameters (evidence: `src/nhp/docker/run.py`)
- Container runner → Result aggregation: saves results (evidence: `src/nhp/docker/run.py`)
- Container runner → Azure blob storage: downloads and uploads (evidence: `src/nhp/docker/run.py`)
- Container runner → Azure table storage: updates run status (evidence: `src/nhp/docker/run.py`)
- Data loaders → Local data source: loads local data (evidence: `src/nhp/model/data/__init__.py`)
