An open-source framework for end-to-end analysis of electronic health record data

Lukas Heumos, Philipp Ehmele, Tim Treis, Julius Upmeier zu Belzen, Eljas Roellin, L T May, Altana Namsaraeva, Nastassya Horlava, Vladimir A. Shitov, Xinyue Zhang, Luke Zappia, Rainer Knoll, Niklas J. Lang, Leon Hetzel, Isaac Virshup, Lisa Sikkema, Fabiola Curion, Roland Eils, Herbert B. Schiller, Anne Hilgendorff, Fabian J. TheisNature Medicine 2024 · DOI

TL;DR

Electronic health records (EHRs) are a treasure trove of health data, but analyzing them is hindered by their heterogeneity and complexity. This paper introduces ehrapy, a new open-source Python framework that provides a standardized, modular, and extensible pipeline for end-to-end exploratory analysis of EHR data, making it easier to uncover insights and build foundational models in biomedical research.

What Problem Does This Paper Address?

The increasing digitalization of healthcare systems has led to the massive collection of electronic health records (EHRs). However, analyzing this data is a significant challenge due to its inherent heterogeneity. EHRs come in various formats, contain diverse data types (demographics, lab results, imaging, notes, etc.), and suffer from issues like missing data, inconsistencies, and biases. Existing analysis pipelines are often fragmented, vendor-specific, or lack comprehensive features for exploratory analysis. This gap prevents researchers from fully leveraging EHR data for comprehensive insights, leading to underexplored datasets and potentially biased or inaccurate findings. The authors aim to bridge this gap by providing a unified, open-source framework that addresses these challenges.

Methods

ehrapy is built as a modular Python framework designed for exploratory EHR data analysis. Its core components include:

  • Data Ingestion and Preparation: It can read various data formats (CSV, OMOP, SQL) and stores them in the AnnData object, a standard for single-cell omics data, ensuring compatibility with existing tools. It includes modules for quality control, imputation (e.g., KNN, MissForest), and data encoding (One-Hot, Label Encoding).
  • Dimensionality Reduction and Visualization: ehrapy leverages established methods like PCA, t-SNE, and UMAP for creating lower-dimensional representations of complex data, enabling visualization of patient landscapes.
  • Statistical Analysis Modules: It offers a rich set of statistical tools for differential comparisons between patient clusters, survival analysis (Kaplan-Meier, Cox Hazard Models), and causal inference (based on the dowhy library).
  • Ontology Integration: ehrapy can map data against ontologies and extract key terms from free text notes, facilitating semantic understanding.
  • Extensibility: The modular design allows for easy integration of community software packages and extension for new challenges, such as training deep learning models.

What's new is the integration of these diverse functionalities into a single, cohesive, and user-friendly framework specifically tailored for the complexities of EHR data, building upon established omics data standards.

Datasets

The framework was developed and demonstrated using several publicly available datasets:

  • Pediatric Intensive Care (PIC) database: Used for stratifying pneumonia patients and analyzing medication effects.
  • UK Biobank (UKB): A large population-scale cohort used for analyzing cardiovascular risks across multiple data modalities (genomics, metabolomics, imaging).
  • BrixIA dataset: Used for analyzing COVID-19 chest X-ray images and reconstructing disease trajectories.
  • Diabetes 130-US Hospitals dataset: Used to demonstrate bias detection and mitigation in EHR data.
  • MIMIC-II: Mentioned as an additional use case.

Key Insights and Ideas

  • Standardization is Key: The AnnData object, commonly used in single-cell genomics, provides a robust and versatile structure for handling heterogeneous EHR data, enabling seamless integration with existing omics analysis tools.
  • Bias is Pervasive: EHR data is rife with various biases (selection, surveillance, information, etc.) that can significantly skew results. ehrapy provides tools to detect and, in some cases, mitigate these biases.
  • Multimodality is Powerful: Combining data from different sources (clinical, imaging, genomics, metabolomics) significantly improves predictive performance for complex diseases.
  • Trajectory Inference for Disease Progression: Advanced methods like pseudotime ordering can be adapted from omics to reconstruct and understand disease progression from sequential EHR data, even from imaging.
  • Causal Inference for Treatment Effects: ehrapy facilitates moving beyond associations to quantify the causal effects of interventions (like medication classes) on outcomes (like length of stay).

Key Results

  • Pneumonia Phenotyping: ehrapy successfully stratified patients with "unspecified pneumonia" into four distinct clinically relevant groups ('sepsis-like', 'severe pneumonia with co-infection', 'viral pneumonia', 'mild pneumonia'), revealing associated biomarkers and survival differences.
  • Medication Effects: Quantified medication-class effects on length of stay, finding that corticosteroids, antivirals, and carbapenems were associated with shorter ICU stays, while penicillins and cephalosporins were associated with longer stays.
  • Cardiovascular Risk Prediction: In the UK Biobank, combining multiple modalities (genetics, clinical data, imaging) improved the predictive performance for myocardial infarction, achieving a C-index of 0.81.
  • COVID-19 Severity Trajectories: Disease severity trajectories were successfully reconstructed from chest X-ray images, demonstrating the ability to order cases from mild to critical.
  • Bias Detection: Identified and demonstrated mitigation of selection and surveillance biases in the Diabetes 130-US Hospitals dataset, and showed how normalization strategies can mask or reveal important differences.

Limitations and Future Work

  • Data Quality and Completeness: Limitations include the lack of control for informative missingness, potential information loss from translation (PIC database), incompleteness of certain data types (e.g., radiology images in PIC), and underrepresentation of certain demographic groups.
  • Generalizability: The generalizability of findings is limited by the specific datasets used and potential biases inherent in population-based cohorts (e.g., UK Biobank).
  • Causal Inference Constraints: The causal inference use case was limited by missing variables (e.g., SOFA scores) and potential dataset constraints.
  • Future Work: The authors envision ehrapy evolving to support joint analysis of EHR, genetics, and molecular data, develop EHR-specific reference datasets, and incorporate more advanced modules for time-series data and natural language processing. They also aim to improve out-of-core computation for large datasets and support the development of foundational models for medical AI.

Summary updated

Abstract

With progressive digitalization of healthcare systems worldwide, large-scale collection of electronic health records (EHRs) has become commonplace. However, an extensible framework for comprehensive exploratory analysis that accounts for data heterogeneity is missing. Here we introduce ehrapy, a modular open-source Python framework designed for exploratory analysis of heterogeneous epidemiology and EHR data. ehrapy incorporates a series of analytical steps, from data extraction and quality control to the generation of low-dimensional representations. Complemented by rich statistical modules, ehrapy facilitates associating patients with disease states, differential comparison between patient clusters, survival analysis, trajectory inference, causal inference and more. Leveraging ontologies, ehrapy further enables data sharing and training EHR deep learning models, paving the way for foundational models in biomedical research. We demonstrate ehrapy's features in six distinct examples. We applied ehrapy to stratify patients affected by unspecified pneumonia into finer-grained phenotypes. Furthermore, we reveal biomarkers for significant differences in survival among these groups. Additionally, we quantify medication-class effects of pneumonia medications on length of stay. We further leveraged ehrapy to analyze cardiovascular risks across different data modalities. We reconstructed disease state trajectories in patients with severe acute respiratory syndrome coronavirus 2 (SARS-CoV-2) based on imaging data. Finally, we conducted a case study to demonstrate how ehrapy can detect and mitigate biases in EHR data. ehrapy, thus, provides a framework that we envision will standardize analysis pipelines on EHR data and serve as a cornerstone for the community.
BibTeX
@inproceedings{heumos2024open,
  author = {Lukas Heumos and Philipp Ehmele and Tim Treis and Julius Upmeier zu Belzen and Eljas Roellin and L T May and Altana Namsaraeva and Nastassya Horlava and Vladimir A. Shitov and Xinyue Zhang and Luke Zappia and Rainer Knoll and Niklas J. Lang and Leon Hetzel and Isaac Virshup and Lisa Sikkema and Fabiola Curion and Roland Eils and Herbert B. Schiller and Anne Hilgendorff and Fabian J. Theis},
  title = {{An open-source framework for end-to-end analysis of electronic health record data}},
  booktitle = {Nature Medicine},
  year = {2024},
  doi = {10.1038/s41591-024-03214-0},
}
Figure