Skip to content

Implement Hospital Hierarchy for Multi-Level Bed Demand Predictions #37

@zmek

Description

@zmek

Implement Hospital Hierarchy for Multi-Level Bed Demand Predictions

Problem Statement

The current package provides bed demand predictions at the specialty level (e.g., medical, surgical, haem/onc, paediatric), but hospital operations may require predictions at multiple levels. For example, at UCLH the levels are:

  • Subspecialty level: Individual clinical units (e.g., General Surgery - Upper GI)
  • Reporting unit level: Groups of subspecialties
  • Division level: Groups of reporting units
  • Board level: Groups of divisions
  • Hospital level: Overall hospital

Currently, predictions are computed independently for each specialty without considering the hierarchical relationships between organizational units. This limits the ability to:

  • Aggregate predictions across organizational levels
  • Provide capacity planning at different management levels
  • Support flexible organizational structures that vary between hospitals

Proposed Solution

1. Generic Hierarchy Structure

  • Create a configurable Hierarchy class that can represent any organisational structure
  • Support YAML-based configuration for defining hierarchy levels and relationships
  • Enable dynamic entity types (not hard-coded to specific hospital structures)
  • Provide utilities to populate hierarchy from DataFrames with organisational mappings

2. Flow-Based Prediction Architecture

  • Refactor prediction inputs to use a flow-based model with separate inflows and outflows
  • Create SubspecialtyPredictionInputs dataclass that encapsulates:
    • Inflows: ED admissions, yet-to-arrive patients, internal transfers
    • Outflows: Departures (elective and emergency), transfers out
  • Use probability distributions (PMFs and Poisson) to represent patient flows
  • Enable flexible flow selection (which flows to include in predictions)

3. Hierarchical Aggregation Engine

  • Implement DemandPredictor that uses discrete convolution to aggregate predictions bottom-up
  • Support statistical capping to bound distribution sizes while maintaining accuracy
  • Compute separate predictions for arrivals, departures, and net flow at each level

4. High-Level Prediction Interface

  • Create HierarchicalPredictor class that orchestrates predictions across all levels
  • Support caching of prediction bundles for efficient retrieval
  • Enable predictions for specific organizational entities or entire hierarchy
  • Provide DemandPrediction dataclass with probabilities, expected values, and percentiles

5. Distribution Utilities

  • Implement Distribution class for working with probability mass functions
  • Support operations: convolution, thinning, truncation, statistical capping
  • Enable efficient computation of aggregated distributions

Expected Behavior

After implementation:

  • Users can define custom hospital hierarchies via YAML configuration
  • Predictions are computed at the bottom level (subspecialty) using flow-based inputs
  • Predictions automatically aggregate up the hierarchy using convolution
  • Each level provides probability distributions, expected values, and percentiles
  • The system supports flexible flow selection (e.g., elective-only, emergency-only, all flows)
  • Predictions can be queried at any organizational level

Key Components

  • Hierarchy: Generic hierarchical structure with configurable levels
  • SubspecialtyPredictionInputs: Flow-based input structure for bottom-level predictions
  • FlowInputs: Individual flow representation (PMF or Poisson)
  • DemandPredictor: Core aggregation engine using convolution
  • HierarchicalPredictor: High-level interface for multi-level predictions
  • Distribution: Probability distribution utilities
  • DemandPrediction: Result structure with probabilities and statistics

Acceptance Criteria

  • Hierarchy can be created from YAML configuration file
  • Hierarchy can be populated from DataFrame with organisational relationships
  • Bottom-level predictions use flow-based architecture (inflows/outflows)
  • Predictions aggregate correctly from subspecialty to hospital level
  • Statistical capping prevents unbounded distribution sizes
  • Percentiles are computed correctly at all levels
  • Flow selection allows filtering by flow type and cohort
  • All existing single-level prediction functionality remains intact

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions