Care operations · Research feature

A Common Pipeline for Harmonizing Electronic Health Record Data for Translational Research

To address this critical gap, we introduce PEHRT, a common pipeline for harmonizing EHR data for translational research.

Adapted from research by Jessica Gronsbell, Vidul Ayakulangara Panickan, Doudou Zhou and colleagues.

arXiv preprint revision · 2025-12-03 · Attribution & reuse
In this article
Editorial illustration of stack of documents.

Authors’ overview

Despite the growing availability of Electronic Health Record (EHR) data, researchers often face substantial barriers in effectively using these data for translational research due to their complexity, heterogeneity, and lack of standardized tools and documentation. To address this critical gap, we introduce PEHRT, a common pipeline for harmonizing EHR data for translational research. PEHRT is a comprehensive, ready-to-use resource that includes open-source code, visualization tools, and detailed documentation to streamline the process of preparing EHR data for analysis. The pipeline provides tools to harmonize structured and unstructured EHR data to standardized ontologies to ensure consistency across diverse coding systems. In the presence of unmapped or heterogeneous local codes, PEHRT further leverages representation learning and pre-trained language models to generate robust embeddings that capture semantic relationships across sites to mitigate heterogeneity and enable integrative downstream analyses. PEHRT also supports cross-institutional co-training through shared representations, allowing participating sites to collaboratively refine embeddings and enhance generalizability without sharing individual-level data. The framework is data model-agnostic and can be seamlessly deployed across diverse healthcare systems to produce interoperable, research-ready datasets. By lowering the technical barriers to EHR-based research, PEHRT empowers investigators to transform raw clinical data into reproducible, analysis-ready resources for discovery and innovation.

Introduction

The growing availability of data from Electronic Health Records (EHRs) has transformed translational biomedical research. In the past decade, EHR data has been harnessed in a wide range of applications that have improved healthcare delivery and deepened our understanding of human health. These applications include dynamic risk prediction of diseases, real-world treatment comparisons, development of medical knowledge graphs, and a broad range of genomic studies. To fully leverage the potential of these applications, integrative analysis of multi-institutional EHR data is increasingly used to improve the generalizability of scientific findings, boost statistical power, and support the development of robust models for precision medicine. Multi-institutional research was particularly accelerated during the COVID-19 pandemic through the formation of international collaborative networks that conducted rapid, large-scale studies on COVID-19 treatment and management using federated analyses.

Progress notwithstanding, there are numerous barriers to effectively utilizing multi-institutional EHR data in translational applications. A key challenge is the lack of semantic interoperability across EHR systems, which results in substantial heterogeneity in clinical documentation and medical coding practices. The foundation of any collaborative research study therefore rests on careful standardization of data elements across different data sources, a process known as data harmonization. Currently, there are no universally accepted or standardized procedures for harmonizing EHR data for an integrative analysis, despite the importance of such standards for ensuring the validity, transparency, and reproducibility of research findings. The significance of proper data preparation became readily apparent during the COVID-19 pandemic when two high-profile multi-institutional studies published in The Lancet and The New England Journal of Medicine were retracted within months of publication. In spite of passing some of the most rigorous peer reviews, the authors could not verify the data or processing procedures that underscored the validity of their conclusions. These incidents highlight the need for comprehensive and rigorous standards for harmonization to ensure the scientific integrity and credibility of collaborative research.

Existing Tools and Gaps

Following standardization, medical codes are aggregated or “rolled-up” into broader medical concepts to represent clinically meaningful variables as disaggregated data are often too granular for research purposes. For example, codes within standard medical coding systems, such as the International Classification of Diseases (ICD) for diagnoses, are typically rolled-up into higher-level concepts using established ontologies. Code roll-up can be done manually or with machine learning approaches. Lastly, quality assessment of EHR data is conducted using established criteria or open-source tools, such as the Automated Characterization of Health Information at Large-scale Longitudinal Evidence Systems (ACHILLES) or the Data Quality Dashboard (DQD) from the OHDSI network. ehrapy, a modular, open-source Python framework, is the only end-to-end tool currently available for the curation and analysis of EHR data. The framework is designed for exploratory data analysis and consists of modules for data pre-processing and ontology mapping as well as analysis tools for causal inference, survival analysis, and patient stratification.

In spite of the large volume of work devoted to EHR data preparation, significant gaps remain when working with multi-institutional EHR data. Existing tools designed for data from a single institution fail to address the variability in coding practices across institutions. For example, many health systems use local medical codes (i.e., codes specific to their system) that are not mapped to standardized coding systems. Traditionally, standardization has been achieved by mapping local codes to standard coding systems, either manually or using automated tools like Medication Extraction and Normalization (MedXN). Recently, advances in Large Language Models (LLMs) and representation learning have facilitated the generation of semantic embeddings, which are vector representations that capture the meanings of EHR codes and their relationships. Embeddings can be used to significantly enhance the efficiency and accuracy of data standardization, which is a critical aspect of preparing multi-institutional data. However, available pipelines lack user-friendly modules for local code standardization and do not leverage representation learning for harmonization.

PEHRT was developed to address this gap by providing a comprehensive, user-oriented resource. It integrates scalable, adaptable methods, software, visualization tools, and detailed protocols into a unified pipeline that enables researchers to efficiently transform raw EHR data into interoperable, analysis-ready datasets. Specifically, PEHRT contains tools to harmonize structured and unstructured EHR data to standardized ontologies, along with resources that use representation learning and LLM-based embeddings to mitigate heterogeneity and align local, unmapped codes across institutions. The pipeline also supports cross-institutional co-training through representation sharing to facilitate collaborative research without individual-level data exchange. Additionally, PEHRT provides detailed, practical guidance for code roll-up, pre-processing, and integration of diverse structured and unstructured data types (e.g., diagnoses, medications, laboratory results, procedures, and clinical notes). Together, these resources lower the technical barrier to EHR-based research, allowing investigators to focus on scientific discovery rather than data harmonization.

Module 1: Data Pre-processing

Data pre-processing is a meticulous process that involves several sub-steps, including (1.1) data cleaning, (1.2) code mapping and roll-up, (1.3) Natural Language Processing (NLP) of free-text data, and (1.4) cohort creation. Pre-processing is performed on each EHR dataset that is input to PEHRT with the goals of transforming the data to a more usable format and standardizing data across institutions. PEHRT enables processing of a broad range of structured data, including diagnostic codes, medication prescriptions, laboratory tests, and procedure codes, as well as unstructured data in the form of clinical notes.

Step 1.1: Data Cleaning. PEHRT employs a multi-step data cleaning process to enhance the quality of noisy and fragmented EHR data. Following the merging of relevant data tables, variables irrelevant to downstream analytical tasks are excluded to improve computational efficiency and reduce memory usage. Next, duplicate records, which are common in EHR data, are identified and removed. These may include exact duplicates or semantic duplicates, which are distinct records that have equivalent information (e.g., records with different medical codes corresponding to the same clinical concept). De-duplication is also performed after code mapping and roll-up (as described in Step 1.2) to ensure that all redundant information is eliminated prior to analysis. Additionally, erroneous data entries, which are frequent in EHR datasets, are carefully assessed. Obvious errors such as impossible or out-of-range dates are filtered out. However, other data elements, such as laboratory measurements, may appear erroneous due to differing units. In such cases, domain knowledge is applied to normalize units and prevent misclassifying valid data. Lastly, records missing critical elements, such as dates or event information, are removed. For large-scale EHR datasets, we recommend batch processing, which is demonstrated in our online tutorial.

Step 1.2: Code Mapping and Roll-Up. Medical codes are often too specific for research studies. To address this issue, PEHRT standardizes codes by mapping them to recognized coding systems and then aggregating or “rolling-up” the codes into higher-level categories across the domains of interest. Code roll-up provides consistency across diverse EHR datasets while also ensuring data is at an appropriate level of granularity for analysis. PEHRT contains detailed instructions for code roll-up across four domains using established ontologies: diagnoses, medications, laboratory tests, and procedures.

For diagnoses, we use the Phenotype Code (PheCode) hierarchy for ICD codes. The PheCode hierarchy provides 1,875 integer, 1-digit, and 2-digit level codes that capture a wide range of disease conditions while avoiding excessive granularity. The hierarchy also provides parent-child relationships that characterize associations between PheCodes. While there are several versions, we use Phecode v1.2 to map both ICD-9-CM (ICD, Ninth Revision, Clinical Modification) and ICD-10-CM codes for illustration in the tutorial. CM codes are used across the U.S. for billing purposes.

Step 1.4: Cohort Creation. EHR-based studies are typically conducted on a group of patients who meet specific inclusion/exclusion criteria, such as those with certain diagnoses, medications, or procedures. PEHRT streamlines cohort identification by leveraging the standardized and rolled-up codes from Step 1.2. For example, when the cohort is identified based on a particular disease diagnosis, a common strategy for identifying the patient cohort is to use relevant ICD codes. However, ICD codes can be overly granular, which often leads to different studies using inconsistent sets of ICD codes to capture the condition of interest. To address this issue, PEHRT utilizes PheCodes from Step 1.2 to identify patients associated with the condition of interest. Following cohort identification, PEHRT then aggregates the rolled-up codes from Step 1.2 and the CUIs from Step 1.3. For studies involving temporal analysis, we recommend further aggregating patient-level longitudinal data into time windows, such as monthly counts or averages. For example, for chronic conditions like rheumatoid arthritis, monthly aggregation typically provides sufficient granularity while simplifying downstream analysis.

Module 2: Representation Learning

Following data pre-processing, representation learning is used to develop institution-specific embeddings and a joint embedding that leverages the data across institutions without the sharing of individual-level data. PEHRT also incorporates embeddings from pre-trained language models (PLMs) to further enhance the quality of the learned data representations. The embeddings can be used for a variety of downstream tasks within and across institutions, including mapping local codes to recognized coding systems, knowledge graph construction, phenotyping, and predictive modeling (see Supplementary Materials for examples). The module consists of four sub-steps: (2.1) EHR embedding training, (2.2) PLM-based embedding generation, (2.3) joint embedding training, and (2.4) embedding validation.

Step 2.1: EHR Embedding Training. PEHRT first generates institution-specific EHR embeddings from summary-level data using the Singular Value Decomposition of the Pointwise Mutual Information (PMI-SVD) algorithm. This method factorizes the PMI matrix constructed from co-occurrence counts of the codes and CUIs from Module 1. As a variant of the widely adopted word2vec algorithm, PMI-SVD has proven to be highly effective in learning meaningful and interpretable clinical embeddings.

Step 2.2: PLM-based Embeddings. PEHRT generates a second set of embeddings using PLMs to leverage the textual descriptions of codes and CUIs (e.g., CUI C0020538: blood pressure, high). PLMs are trained on large text corpora and, in some cases, further fine-tuned with biomedical knowledge sources such as PubMed articles, clinical notes, and knowledge graphs. The PLM-based embeddings complement the EHR embeddings from Step 2.1 that capture the meaning of codes and CUIs based on their usage within a healthcare institution. PEHRT includes instructions for generating embeddings from several commonly used PLMs, including the Cross-lingual knowledge-infused medical term embedding (CODER), Self-Aligned Pre-trained Bidirectional Encoder Representations from Transformers (SapBERT), PubMedBERT, and BERT for Biomedical Text Mining (BioBERT).

Step 2.3: Joint Embedding Training. To leverage data across institutions, PEHRT uses the BONMI algorithm to derive a shared representation of EHR codes and CUIs by aligning and completing institution-specific SPPMI matrices. Briefly, BONMI constructs an aggregated matrix covering all unique codes and CUIs, assigning weighted averages to overlapping pairs and marking others as missing. The weights are based on data quality using user-defined or data-driven metrics and the missing values are imputed by aligning institution-specific embeddings via orthogonal transformations. The completed matrix is then factorized with an SVD to generate the joint embedding, with rank selection as in Step 2.1. The joint embedding can be integrated with PLM-based embeddings through weighted concatenation as described in Step 2.2.

Step 2.4: Embedding Validation. To evaluate the quality of the trained embeddings, PEHRT provides simple metrics quantifying their performance in discriminating between concept pairs with known relationships against randomly selected pairs. The relationships can be curated from existing ontologies and UMLS. For each pair under consideration, the cosine similarity of the corresponding embedding vectors is calculated to measure their degree of relatedness. Embedding quality is then quantified based on the AUC of the cosine similarity in distinguishing between the related and random pairs (i.e., the probability that a randomly selected related pair will have a higher cosine similarity than a randomly selected random pair). These metrics can be used to evaluate the performance of the institution-specific EHR embeddings, the PLM-based embeddings, as well as the joint embedding. We have found that the joint embeddings generally achieve the highest performance in a wide variety of applications, but recommend comparing their performance with PLM-based embeddings and EHR embeddings for thorough evaluation.

Conclusion

Data harmonization is essential for ensuring the validity, transparency, and reproducibility of multi-institutional EHR-based research. However, significant heterogeneity across data sources complicates harmonization and no comprehensive and standardized procedures currently exist to address this challenge. To fill this gap, we introduced PEHRT, a common pipeline for harmonization of EHR data for translational applications. PEHRT operates entirely on summary-level data to preserve data privacy and is designed for easy implementation through our online tutorial and suite of resources. Our pipeline also leverages representation learning and PLMs to streamline data standardization and support a wide range of applications to advance clinical research and practice, including phenotyping, knowledge graph construction, and federated learning. An example application of PEHRT in several integrative predictive modeling tasks is detailed in the Supplementary Materials to further support users in applying the pipeline for their own purposes.

However, our work is not without limitations. First, the EHR embeddings rely on longitudinal data to compute the co-occurrence matrix. Including additional data sources without repeated observations (e.g., genomic data) requires different methodological approaches. Second, incorporating temporal information (e.g., one diagnosis precedes another) into the EHR embeddings has the potential to improve the applicability of PEHRT. For example, such embeddings would be particularly relevant to studies aimed at identifying comorbidities and risk factors for a disease. Third, the joint embedding training can potentially be improved by incorporating the relative quality of each data source. Lastly, a future direction is to further optimize PEHRT to allow for incremental updating over time using zero-shot or few-shot learning.

Module 1: Data Pre-processing

We used Module 1 of PEHRT to pre-process structured EHR data from all participating institutions. All of the pre-processing steps are demonstrated in our online tutorial using the MIMIC-IV dataset. The tutorial provides guidance on setting up the workspace, obtaining access to MIMIC-IV, and getting familiar with the dataset (link).

The inputs to Module 1 are the original data tables from the MIMIC-IV database and the output is a pre-processed dataset. The pre-processing begins with data cleaning, which involves assessing missingness, standardizing schema across tables, removing irrelevant and redundant information, and constraining the data to the relevant time window (link).

Next, we provide step-by-step instructions to roll-up diagnosis codes, procedure codes, and medications (link). For EHR text processing, we generally recommend NILE software, but utilize a lightweight custom NLP library for illustrative purposes in the tutorial (link). We also demonstrate how to refine the data to a cohort for a specific analysis, using asthma as an example (link).

Integrative Predictive Modeling

Figures 2 and 3 present the AUC for the models for MS disability prediction and time to nursing home admission or death for AD patients at MGB and UPMC, respectively. Consistent with our results measuring the quality of feature selection, models incorporating the BONMI and BONMI+ selected features have the strongest performance. Interestingly, models with features selected by institution-specific EHR embeddings achieved better performance than PLM-based embeddings at MGB, but not at UPMC. This finding underscores our recommendation to validate multiple embeddings as results can vary across tasks and institutions.

We also derived additional pairs from the hierarchical structures of PheCode, RxNorm, and LOINC to capture relationships between similar codes. For PheCodes, more digits indicate greater specificity (e.g., PheCode: 296 for mood disorders is the parent of PheCode: 296.1 for bipolar disorder and PheCode: 296.2 for depression, with PheCode: 296.22 for major depressive disorder as a further refinement). We treated PheCodes sharing the same first three integers as similar relationships. For LOINC, we identified similar relationships that share the same LOINC part parent. For RxNorm leaf codes, we identified similar relationships that share common parents.