Skip to content

Repository files navigation

🏥 NHS A&E Wait Time Analysis — England 2018–2024

Maintained Data Quality

End-to-end analysis of NHS England A&E performance across 15 major trusts. Identifies seasonal pressure patterns, trust-level performance gaps, COVID impact, and predictive signals for 4-hour breach rates.


🔴 Live Dashboard

View Live Dashboard


📌 Project Summary

This project answers four core analytical questions:

1. How far has NHS A&E performance fallen since 2018 — and is recovery underway?

2. Which trusts are consistently failing — and which are holding up?

3. How much worse is winter, and when does the seasonal pressure peak?

4. What signals best predict a 4-hour breach rate spike?

It covers 15 major Type 1 A&E departments, 84 months of data (2018–2024), and 1,260 trust-month observations.


🗂️ Repository Structure

NHS-AE-Wait-Time-Analysis/
│
├── scripts/
│   ├── 01_generate_data.py             # Data generation (NHS-aligned synthetic + live API stub)
│   ├── 02_analysis_queries.sql         # 10 SQL queries (SQLite / DuckDB / PostgreSQL)
│   └── 03_eda_analysis.py              # EDA + matplotlib chart generation (7 charts)
│
├── data/
│   └── processed/
│       ├── monthly_ae.csv              # 1,260 rows — trust × month × year
│       ├── trust_summary.csv           # 105 rows — annual trust aggregates
│       ├── seasonal_summary.csv        # 12 rows — avg metrics by calendar month
│       ├── national_trend.csv          # 84 rows — monthly national aggregates
│       ├── breach_predictor_features.csv   # Feature table for ML/predictive modelling
│       └── dashboard_data.json         # All datasets combined for dashboard
│
├── dashboard/
│   └── index.html                      # Fully self-contained interactive dashboard
│
├── outputs/
│   ├── 01_national_performance_decline.png
│   ├── 02_seasonal_heatmap.png
│   ├── 03_trust_league_table_2024.png
│   ├── 04_winter_summer_gap.png
│   ├── 05_covid_impact.png
│   ├── 06_trust_divergence.png
│   └── 07_handover_breach_correlation.png
│
├── requirements.txt
├── .gitignore
└── README.md

📊 Dashboard Features

Open dashboard/index.html in any browser — no installation, no server required.

Tab What You See
Overview National performance decline · Trust league table · Monthly attendance volume
Trends Month-by-month timeline · Breach rate trend · Median wait trend · Handover delays
Seasonal Performance by month · Attendance pattern · Wait time by month · Winter vs Summer
Trusts Best 5 vs worst 5 divergence · Breach rate by trust · Median wait by trust
Data Table Full 15-trust dataset with all metrics, filterable by year

Year selector updates all Overview charts simultaneously across 2018–2024.


📐 Key Metrics Defined

4-Hour Performance Target

4-hr Performance (%) = Patients admitted, transferred or discharged within 4 hours
                       ─────────────────────────────────────────────────────────── × 100
                                    Total A&E Attendances

NHS Constitutional Standard: 95% The 95% target was set in the NHS Plan 2000. No trust in England has consistently met it since 2015.


Breach Rate

Breach Rate (%) = 100 − 4-hr Performance (%)

A breach occurs when a patient waits more than 4 hours in A&E before a decision is made about admission, transfer, or discharge.


Performance Gap

Performance Gap = 95% − Actual 4-hr Performance (%)

How many percentage points a trust is away from the NHS constitutional standard. Higher = worse.


🔑 Key Findings

Finding Data Point
National 4-hr performance 2024 68.5% — 26.5pp below the 95% target
Performance in 2018 86.0% — already below target, but 17.5pp better than 2024
Worst year on record 2023: 65.9% — post-COVID backlog plus winter pressures
Total breaches 2024 ~839,000 episodes — up 148% vs 2018
Median wait time 2024 169 minutes — up from 91 minutes in 2018
Best performing trust 2024 Liverpool University Hospitals: 72.8% — still 22.2pp below target
Worst performing trust 2024 Oxford University Hospitals: 65.9% — 29.1pp below target
Worst winter month January — avg 4-hr performance 70.7%, median wait 159 min
Best summer month May — avg 4-hr performance 79.6%, median wait 117 min
Seasonal performance swing 8.9 percentage points between January and May
COVID lockdown attendance drop Apr–Jun 2020: −53% vs same period 2019
Handover–breach correlation r = 0.73 — strong positive correlation

⚠️ Project Limitations

This analysis provides a high-level operational view, but the following limitations should be noted:

  • Clinical Acuity (Triage): The dataset does not capture the "severity" of cases (e.g., Resuscitation vs. Minor injuries), which heavily dictates wait times regardless of department volume.
  • Staffing Levels: Performance is analyzed against attendance volume, but does not account for nursing or medical staffing vacancies which are primary drivers of 4-hour breaches.
  • Indirect Breaches: The analysis focuses on "Time to Disposition" but cannot account for "Left Before Being Seen" (LBBS) rates, which can mask the true scale of A&E pressure.

🛠️ Quick Start

1. Clone the repository

git clone https://github.com/RidhimaGupta4/NHS-AE-Wait-Time-Analysis.git
cd NHS-AE-Wait-Time-Analysis

2. Install dependencies

pip install -r requirements.txt

3. Generate all datasets

python scripts/01_generate_data.py

This creates all CSV and JSON files in data/processed/.

4. Generate all 7 charts

python scripts/03_eda_analysis.py

This outputs 7 PNG charts to outputs/.

5. Open the interactive dashboard

# macOS
open dashboard/index.html

# Windows
start dashboard/index.html

# Linux
xdg-open dashboard/index.html

Or simply double-click dashboard/index.html in your file explorer.


Optional — Run SQL queries with DuckDB

pip install duckdb
import duckdb

con = duckdb.connect()
con.execute("CREATE TABLE monthly_ae    AS SELECT * FROM read_csv_auto('data/processed/monthly_ae.csv')")
con.execute("CREATE TABLE trust_summary AS SELECT * FROM read_csv_auto('data/processed/trust_summary.csv')")
con.execute("CREATE TABLE seasonal      AS SELECT * FROM read_csv_auto('data/processed/seasonal_summary.csv')")
con.execute("CREATE TABLE national      AS SELECT * FROM read_csv_auto('data/processed/national_trend.csv')")

# Trust league table 2024
print(con.execute("""
    SELECT trust,
           ROUND(avg_4hr_performance, 1)    AS perf_pct,
           ROUND(annual_breach_rate_pct, 1) AS breach_pct,
           ROUND(avg_median_wait, 0)        AS wait_mins,
           ROUND(performance_gap, 1)        AS gap_to_target
    FROM trust_summary
    WHERE year = 2024
    ORDER BY avg_4hr_performance DESC
""").df())

All 10 analytical queries are in scripts/02_analysis_queries.sql.


🗃️ Dataset Schema

monthly_ae.csv — 1,260 rows (15 trusts × 12 months × 7 years)

Column Type Description
trust string NHS trust name
region string NHS England region
year int 2018 to 2024
month int 1 to 12
month_name string Jan to Dec
period string YYYY-MM format
attendances int Monthly Type 1 A&E attendances
admissions int Monthly emergency admissions from A&E
breaches int Monthly 4-hour breaches
perf_4hr_pct float % patients seen within 4 hours
breach_rate_pct float % attendances resulting in breach
admission_rate_pct float % attendances resulting in admission
median_wait_mins float Median wait time in minutes
ambulance_handover_delay_pct float % of handovers taking more than 30 minutes

trust_summary.csv — 105 rows (15 trusts × 7 years)

Annual aggregates per trust including total attendances, total breaches, average 4-hr performance, average median wait, best and worst month performance, and performance gap to the 95% target.


breach_predictor_features.csv — Feature-engineered ML-ready table

Includes: prior month performance, prior month breach rate, 3-month rolling attendance average, attendance growth %, winter flag (1/0), COVID period flag (1/0). Ready for use in scikit-learn or any regression model.


⚖️ Data Ethics & Clinical Governance

  • Synthetic Alignment: While the dataset is synthetic, it is meticulously calibrated to NHS England's Monthly A&E Statistics and Ambulance Quality Indicators (AQIs) to ensure the trends reflect real-world clinical pressures.
  • Patient Confidentiality: The project follows General Data Protection Regulation (GDPR) and the NHS National Data Opt-Out standards by ensuring all data is aggregated at the Trust level. No Patient Identifiable Information (PII) or individual record-level data is used or stored.
  • Operational Integrity: The metrics used (4-hour breach rates, handover delays) align with the NHS Constitutional Standards and the Clinical Review of Standards (CRS) framework.

📈 SQL Queries Included

Query Purpose
01 — Trust League Table Performance ranking with band classification (Meeting / Near / Underperforming / Critical)
02 — National Decline Year-by-year performance against 95% target with breach rate
03 — Seasonal Pattern Monthly performance with season band classification
04 — Winter vs Summer Quantified seasonal gap — peak winter vs best summer
05 — Worst 5 Trust Trend Year-by-year tracking of the five worst-performing trusts
06 — COVID Impact 2019 / 2020 / 2021 monthly comparison — lockdown attendance and performance
07 — Regional Comparison London vs Northern and Midlands trusts by region
08 — Breach Predictors Prior month performance banded as predictor of current breach rate
09 — Handover Correlation Ambulance handover delay bands vs breach rate
10 — Volume vs Performance Does higher attendance volume directly cause worse performance?

🔗 Real Data Sources

Dataset Publisher URL
A&E Waiting Times and Activity NHS England https://www.england.nhs.uk/statistics/statistical-work-areas/ae-waiting-times-and-activity/
A&E Attendances and Emergency Admissions NHS England https://www.england.nhs.uk/statistics/statistical-work-areas/ae-waiting-times-and-activity/
Ambulance Quality Indicators NHS England https://www.england.nhs.uk/statistics/statistical-work-areas/ambulance-quality-indicators/
NHS Trust Reference Data NHS Digital https://digital.nhs.uk/services/organisation-data-service

To switch from synthetic to live data, use the fetch_nhs_ae_data() stub at the bottom of scripts/01_generate_data.py and point it at the NHS England monthly CSV download URLs.


🧰 Tech Stack

Tool Badge Role
Python Python Core data pipeline and automated analysis
SQL SQL 10 complex queries (Ranking, COVID impact, Seasonal analysis)
Pandas / NumPy Data Data manipulation and numerical computation
DuckDB DuckDB High-performance SQL engine for local data processing
Frontend Web Dashboard architecture and responsive layout design
JavaScript JS Interactive logic and real-time data filtering
Chart.js Chart.js Interactive dashboard charts (12 custom visualizations)
Matplotlib Matplotlib Static EDA chart generation for reporting

💼 Skills Demonstrated

  • Healthcare domain knowledge — NHS structure, constitutional targets, trust-level reporting
  • Time series analysis — seasonal decomposition, trend identification, structural break detection
  • Real-world messy data handling — COVID disruption periods, outliers, structural breaks in 2020–2021
  • Predictive feature engineering — lag variables, rolling averages, binary flags, ready for ML models
  • SQL analytical thinking — 10 queries covering ranking, cohort, correlation, pivot, and predictive banding
  • Stakeholder communication — every finding framed as an operational NHS insight, not just a statistic
  • End-to-end pipeline — raw data generation → cleaning → analysis → static charts → interactive dashboard

🔍 Visual Insights

📉 National 4-Hour Performance Decline 2018–2024

National Performance Decline

Analysis: Visualises the systemic erosion of the 95% constitutional standard. The trend shows a steady decline from ~86% in 2018 to a record low of ~65.9% in 2023, highlighting that "winter pressures" have now transitioned into a year-round operational crisis.

🌡️ Seasonal Heatmap — Performance by Month and Year

Seasonal Heatmap

Analysis: Identifies predictable "danger zones" in the calendar. January consistently appears as the highest-risk month across all years, with an average 4-hour performance of 70.7%.

🏆 Trust Performance League Table 2024

Trust League Table

Analysis: Ranks the 15 major trusts by 4-hour compliance. Even the best-performing trust in 2024, Liverpool University Hospitals, reached only 72.8%, failing to meet the 95% target.

❄️ Winter vs Summer Performance Gap and Wait Time Gap

Winter Summer Gap

Analysis: Quantifies the "Seasonal Swing," showing an 8.9 percentage point difference between January and May. This visualization is critical for bed-capacity planning and elective surgery rescheduling strategies.

🦠 COVID-19 Impact on Attendances and Performance

COVID Impact

Analysis: Captures the structural break in early 2020, where attendances dropped by 53% during the lockdown period compared to 2019. Despite lower volume, performance remained under pressure due to systemic infection control and hospital flow constraints.

↔️ Trust Performance Divergence — Best 5 vs Worst 5

Trust Divergence

Analysis: Tracks the widening "Performance Gap" over time between the top and bottom performing trusts. In 2024, the gap remains significant, with the worst performing trust (Oxford University Hospitals) at 65.9%.

🚑 Ambulance Handover Delay vs Breach Rate Correlation

Handover Correlation

Analysis: Proves the "System-Flow" hypothesis with a strong positive correlation of $r = 0.73$ between handover delays and A&E breach rates. This confirms that A&E performance is a downstream symptom of hospital-wide "exit block".


📄 Licence

MIT — free to use and adapt


🙋 Author

Built as a UK data analyst / data scientist portfolio project.

Connect: LinkedIn · GitHub

If this project helped you, please ⭐ star the repo — it helps others find it.

📁 Explore More Projects

About

NHS England A&E performance analysis across 15 major trusts 2018–2024. Seasonal patterns, trust-level gaps, COVID impact & breach rate predictors. Interactive dashboard + Python + SQL.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages