T-Rx: A toolbox for reproducible processing of prescriptions (Rx) from electronic health records
Authors:
Preprint
Abstract
Linkage between population-wide biobanks and electronic health records (EHRs) opens new opportunities to study the genetic and epidemiological underpinnings of treatment outcomes, a key step forward in delivering precision medicine. However, challenges include complexities in data extraction for longitudinal analyses, and the absence of reproducible phenotyping algorithms. Here, we present T-Rx, an open-source R package to streamline the processing of prescription and dispensing records, to enable reproducible and scalable analysis across EHR databases. T-Rx consists of three modules to derive treatment-related phenotypes from uncleaned prescription records: (1) Extraction and Imputation Module for extracting and imputing prescription details; (2) Exposure Ascertainment Module for converting prescriptions to longitudinal exposure periods; and (3) Phenotyping Module for creating reproducible proxy phenotypes that capture treatment and response patterns. We tested the utility of T-Rx in UK Biobank primary care records, with strength and quantity information extracted and imputed for 2,721,921 antidepressant and 430,705 antipsychotic prescriptions. The extraction functions were validated using oral hypoglycemic agent prescriptions in Clinical Practice Research Datalink Aurum, showing comparable performances to extraction using the NHS Dictionary of Medicines and Devices (dm+d) codes. The Exposure Ascertainment Module of T-Rx converts discrete prescription or dispensing events into longitudinal exposure periods in one-line R commands, with customizable parameters to account for real-world treatment complexities. The Phenotyping Module takes prescriptions as direct user input and returns analysis -ready data frames. Current phenotyping algorithms include antidepressant switching and treatment-resistant depression. The phenotyping functions also allow flexible parameter choices, such as treatment episode windows, definitions for switching and quality control criteria. Researchers can contribute phenotyping algorithms to T-Rx for reproducible use. T-Rx improves the accessibility of prescription information in biobanks, and analysis of dosage- and treatment-patterns across therapeutic areas. T-Rx contributes to open science through harmonized phenotypic definitions and reproducible analyses of proxy treatment outcomes.Keywords
Funding Information
- Wellcome Trust (226770/Z/22/Z)
- Wellcome Trust (222811/Z/21/Z)
This publication has 39 references indexed in Scilit:
- Genetic Correlates of Treatment-Resistant DepressionJAMA Psychiatry, 2025
- Association of Treatment-Resistant Depression With Patient Outcomes and Health Care Resource Utilization in a Population-Wide StudyJAMA Psychiatry, 2023
- Pharmacological and epidemiological considerations while constructing treatment episodes using observational data: A simulation studyPharmacoepidemiology and Drug Safety, 2021
- Med7: A transferable clinical natural language processing model for electronic health recordsArtificial Intelligence in Medicine, 2021
- Imputation of Missing Data in Electronic Health Records Based on Patients’ SimilaritiesJournal of Healthcare Informatics Research, 2020
- Development of a System for Postmarketing Population Pharmacokinetic and Pharmacodynamic Studies Using Real‐World Data From Electronic Health RecordsClinical Pharmacology & Therapeutics, 2020
- Methods for constructing treatment episodes and impact on exposure-outcome associationsEuropean Journal of Clinical Pharmacology, 2019
- Measurement Error and Misclassification in Electronic Medical Records: Methods to Mitigate BiasCurrent Epidemiology Reports, 2018
- Assumptions made when preparing drug exposure data for analysis have an impact on results: An unreported step in pharmacoepidemiology studiesPharmacoepidemiology and Drug Safety, 2018
- The use of electronic health records for psychiatric phenotyping and genomicsAmerican Journal of Medical Genetics Part B: Neuropsychiatric Genetics, 2017