Pro-Med-Str - Part I

This tutorial describes how to process structured medication data, especially focusing on intravenously given dose data.

Introduction

This tutorial describes how to use the Pro-Med-Str - Part I module in EHR2PKPD system to process intravenous (IV) dose data (see Choi et al.\(^{1}\) for details).

To begin we load the EHR package,

# load EHR package
library(EHR)

Input Raw Dose Data

We will use example dose data to demonstrate the Pro-Med-Str Part I module. The raw data is shown below.

mar.in0 <- read.csv(system.file("examples", "str_ex2","MAR_DATA.csv", package="EHR"), check.names = FALSE)
head(mar.in0)
   Uniq.Id       Date  Time                 med:mDrug   med:dosage med:route med:freq med:given
1 28579217 2017-02-04 19:15               Nicardipine 3 mcg/kg/min        IV     <NA>     Given
2 28579217 2011-10-02 22:11                Famotidine       4.5 mg        IV   q12hrs     Given
3 28579217 2011-10-02 20:17          Morphine sulfate         1 mg        IV  q2h prn     Given
4 28579217 2011-10-03 02:28 Diphenhydramine injection        12 mg        IV      now     Given
5 28579217 2011-10-02 22:11                 Cefazolin       225 mg        IV    q8hrs     Given
6 28579217 2011-10-02 23:30          Morphine sulfate         1 mg        IV  q2h prn     Given

This data consists of a patient ID, date, time, medication name, dosage, route, frequency, and medication given.

The patient ID may need to be renamed so that all input datasets have the same name for the patient ID. This is necessary when combining the datasets to create a crosswalk between the original ID variables and the new ID variables used in the Pro-Med-Str Part I module. We demonstrate how to rename the patient ID variable below.

mar.new <- dataTransformation(mar.in0, rename = c('Uniq.Id' = 'subject_uid'))

Preparing Raw Dose Data

In practice, the dose data will need to be combined with other input datasets. This process involves creating a crosswalk between original ID variables and new ID variables. The new ID variables that are required to be the same across all datasets are mod_id, mod_visit, and mod_id_visit. See “2. EHR Vignette for Structured Data” of EHR package and “Build-PK-IV - Comprehensive Workshop” for examples of this process.

For simplicity, we will skip this step in this tutorial.

We save our dataset as an RDS file using saveRDS as shown below (CSV or RData is also acceptable data form). Here, we create a temporary directory to store the files using tempdir. We define two directories, dataDir for processed data and checkDir containing files used for interactive checking (optional). Instead of using a temporary directory, dataDir and checkDir can be specific directories on your computer.

# define 2 directories
td <- tempdir()
dataDir <- file.path(td, 'data') # directory for processed data
dir.create(dataDir)
checkDir <- file.path(td, 'checks') # directory for interactive checking
dir.create(checkDir)
saveRDS(mar.new, file=file.path(dataDir,"mar_new.rds"))

The next section demonstrates how to use the run_MedStrI function to run the Pro-Med-Str module.

Running run_MedStrI()

Below we show how we would run run_MedStrI() using the cleaned IV dose dataset, “mar_new.rds”, as input.

# define parameters
drugname <- 'fent'

ivdose.out <- run_MedStrI(
    mar.path=file.path(dataDir,"mar_new.rds"),
    mar.columns = list(id='subject_uid', datetime=c('Date','Time'), dose='med:dosage', drug='med:mDrug', given='med:given'),
    medGivenReq = TRUE,
    medchk.path = file.path(system.file("examples", "str_ex2", package="EHR"), sprintf('medChecked-%s.csv', drugname)),
    demo.list = NULL,
    demo.columns = list(),
    check.path=checkDir, 
    failunit_fn = 'Unit',
    infusion.unit = 'mcg/kg/hr',
    bolus.unit = 'mcg',
    bol.rate.thresh = Inf,
    rateunit = "mcg/hr",
    ratewgtunit = "mcg/kg/hr",
    weightunit = "kg",
    drugname = drugname
    )
no units other than mcg/kg/hr or mcg, file /var/folders/06/0qv1dr5508j_tbzqdjfqjf680000gn/T//RtmpqLJ9qE/checks/failUnit-fent.csv not created
#########################
75 rows from 2 subjects with "kg" in infusion unit but missing weight, see file /var/folders/06/0qv1dr5508j_tbzqdjfqjf680000gn/T//RtmpqLJ9qE/checks/failNoWgt-fent.csv AND create /var/folders/06/0qv1dr5508j_tbzqdjfqjf680000gn/T//RtmpqLJ9qE/checks/fixNoWgt-fent.csv
#########################
#########################
censor dates created, please see /var/folders/06/0qv1dr5508j_tbzqdjfqjf680000gn/T//RtmpqLJ9qE/checks/CensorTime-fent.csv
#########################

After run_MedStrI() is executed, it provides messages such as those shown above, which contain some information about data checking.

Output of run_MedStrI()

head(ivdose.out)
  subject_uid  date.dose infuse.time.real infuse.time infuse.dose          bolus.time bolus.dose given.dose maxint weight
1    28579217 2011-10-02             <NA>        <NA>          NA 2011-10-02 15:35:00         25         NA      0     NA
2    28579217 2011-10-02             <NA>        <NA>          NA 2011-10-02 17:26:00         25         NA      0     NA
3    28579217 2017-02-04             <NA>        <NA>          NA 2017-02-04 16:15:00         50         NA      0     NA
4    28579217 2017-02-04             <NA>        <NA>          NA 2017-02-04 16:30:00         20         NA      0     NA
5    28579217 2017-02-04             <NA>        <NA>          NA 2017-02-04 20:57:00         20         NA      0     NA
6    34161967 2016-07-18             <NA>        <NA>          NA 2016-07-18 14:56:00        100         NA      0     NA

This output is the input of run_Build_PK_IV() function in Build-PK-IV module. In the above output, all variables except given.dose are the necessary variables that should be reserved to use run_Build_PK_IV().

References

  1. Choi L, Beck C, McNeer E, Weeks HL, Williams ML, James NT, Niu X, Abou-Khalil BW, Birdwell KA, Roden DM, Stein CM. Development of a System for Post-marketing Population Pharmacokinetic and Pharmacodynamic Studies using Real-World Data from Electronic Health Records. Clinical Pharmacology & Therapeutics. 2020 Apr;107(4):934-43. doi: 10.1002/cpt.1787.

Corrections

If you see mistakes or want to suggest changes, please create an issue on the source repository.