Examples of Drug Dosing Data

This tutorial introduces the various expected formats for medication dosing data.

Leena Choi

Overview of Drug Dosing Data

for most recent version, install from GitHub

remotes::install_github('choileena/EHR/EHR')

introduce data formats

IV Dosing, Implied Schedule

run_MedStrI

input to run_Build_PK_IV/run_Build_PK

flow <- data.frame(mod_id=c(1,1,2,2,2),
                  mod_id_visit=c(46723,46723,84935,84935,84935),
                  record.date=c("07/05/2019 5:25","07/05/2019 6:01",
                                "09/04/2020 3:21", "09/04/2020 4:39",
                                "09/04/2020 5:32"),
                  Final.Weight=c(6.75,6.75,4.5,4.5,4.5),
                  Final.Rate=c(rep("1 mcg/kg/hr",2),
                                rep("0.5 mcg/kg/hr",3)),
                  Final.Units=c("3.375","6.5",
                                "2.25","2.25","2.25")
)
flow[,'Perform.Date'] <- pkdata::parse_dates(flow[,'record.date'])
flow[,'pd'] <- pkdata::parse_dates(flow[,'record.date'], tz = 'UTC')
flow[,'unit'] <- sub('.*[ ]', '', flow[,'Final.Rate'])
flow[,'rate'] <- as.numeric(sub('([0-9.]+).*', '\\1', flow[,'Final.Rate']))

mar <- data.frame(mod_id=rep(1,5),
                  Date=rep("2019-07-05",5),
                  Time=c("07:12","07:31","08:47","09:16","10:22"),
                  `med:mDrug`=c("Fakedrug2","Fakedrug1","Fakedrug2",
                                "Fakedrug3","Fakedrug4"),
                  `med:dosage`=c("30 mg","0.5 mcg","1 mg",
                                "20 mg","3 mcg/kg/min"),
                  `med:route`=rep("IV",5),
                  `med:given`=rep("Given",5),
                  check.names=FALSE
)
mar[,'dt'] <- as.POSIXct(paste(mar$Date, mar$Time), tz = 'UTC')
mar[,'dosage'] <- c(30,0.5,1,20,3)
mar[,'unit'] <- c('mg','mcg','mg','mg','mcg/kg/min')

Oral Dosing, Actual Schedule

run_MedStrII

input to run_Build_PK_Oral/run_Build_PK

erx_data <- data.frame(GRID=paste0("ID",c(1,1,2,2,2,2)),
  MED_NAME=c("fakedrug","fakedrug","fakedrug","Brandname","fakedrug","fakedrug"),
  RX_DOSE=c(1,2,1,'2 tabs',1,'1+1.5+1'),
  FREQUENCY=c(rep("bid",3),"qam","bid","brkfst,lunch,dinner"),
  ENTRY_DATE=c("2018-02-15","2018-03-14","2017-07-01","2017-07-01","2017-09-15","2017-11-01"),
  STRENGTH_AMOUNT=c("100","100","200","100mg","100","100"),
  DESCRIPTION=c("fakedrug 100 mg tablet","fakedrug 100 mg tablet",
                "fakedrug 200 mg tablet (also known as brandname)",
                "Brandname 100mg tablet", "fakedrug 100 mg tablet",
                "fakedrug 100 mg tablet")
)

IV Dosing, Actual Schedule

run_MedStrIII

input to run_Build_PK_IV/run_Build_PK

doseData <- structure(list(id = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
  dt = c("2020-01-01 08:00", "2020-01-02 08:00", "2020-01-02 20:00",
    "2020-01-02 20:00", "2020-01-03 08:00", "2020-01-05 08:00", "2020-01-05 08:00",
    "2020-01-05 08:00", "2020-01-05 20:00", "2020-01-06 08:00", "2020-01-06 08:00",
    "2020-01-06 20:00", "2020-01-07 20:00", "2020-01-07 20:00"),
  dose = c(30, 10, 20, 30, 10, 10, 20, 30, 10, 20, 10, 10, 20, 20),
  dur = c(3600, 7200, 1800, 3600, 3600, 7200, 1800, 3600, 7200, 1800, 1800, 1800, 1800, 3600)),
  class = "data.frame", row.names = c(NA, -14L)
)

Oral (+?) Dosing, Implied Schedule

run_MedStrIV/makepk

set.seed(250)
n <- 10
isOP <- rbinom(n, 1, 0.8)
id <- sample(150, n, replace = TRUE)
rxopt <- c(
'amoxicillin 875 MG / clavulanate 125 MG Oral Tablet [Augmentin]',
'amoxicillin 80 MG/ML Oral Suspension [Amoxil]',
'amoxicillin 500 MG Oral Capsule',
'amoxicillin 120 MG/ML / clavulanate 8.58 MG/ML Oral Suspension'
)
pickrx <- sample(rxopt, n, replace = TRUE, prob = c(.4,.35,.15,.1))
rxid <- match(pickrx, rxopt)
dose_u <- character(n)
dose_u[rxid==1] <- 'tablet'
dose_u[rxid==3] <- 'mg'
dose_u[rxid==2] <- sample(c('mg/kg','mg/kg/day','mg'), sum(rxid==2), replace = TRUE)
dose_u[rxid==4] <- sample(c('mg/kg','mg/kg/day','mg','mL'), sum(rxid==4), replace = TRUE)
dose_n <- numeric(n)
dose_n[rxid==1] <- 1
dose_n[rxid==3] <- sample(c(500,1000,2000), sum(rxid==3), replace = TRUE)
du <- match(dose_u, c('mg/kg','mg/kg/day','mg','mL'))
dose_n[rxid==2 & du==1] <- sample(c(45, 50, 10, 25), sum(rxid==2 & du==1), replace = TRUE)
dose_n[rxid==2 & du==2] <- sample(c(90, 50, 80, 25), sum(rxid==2 & du==2), replace = TRUE)
dose_n[rxid==2 & du==3] <- sample(c(500, 1000, 800, 400), sum(rxid==2 & du==3), replace = TRUE)
dose_n[rxid==4 & du==1] <- 435
dose_n[rxid==4 & du==2] <- sample(c(90, 80, 40), sum(rxid==4 & du==2), replace = TRUE)
dose_n[rxid==4 & du==3] <- sample(c(875, 600), sum(rxid==4 & du==3), replace = TRUE)
dose_n[rxid==4 & du==4] <- 5
qnt <- numeric(n)
qnt[rxid %in% c(1,3)] <- sample(c(1:30, 60, 90, 180), sum(rxid %in% c(1,3)), replace = TRUE)
qnt[rxid %in% c(2,4)] <- sample(600, sum(rxid %in% c(2,4)), replace = TRUE)
time <- as.POSIXct(sample(100, n, replace = TRUE) * 86400, origin = '2020-01-01', tz = 'UTC')
time <- as.POSIXct(format(time, '%Y-%m-%d %H:%M'))
endtime <- rep(as.POSIXct(NA), n)
endtime[isOP==1] <- time[isOP==1] + sample(0:10, sum(isOP==1), replace = TRUE) * 86400
drug <- data.frame(
  MRN=id,
  DRUG_EXPOSURE_ID=NA,
  PERSON_ID=id,
  DRUG_CONCEPT_ID=rxid,
  CONCEPT_DRUG_NAME=pickrx,
  DRUG_TYPE_CONCEPT_ID=c(38000180,38000177)[isOP+1],
  DRUG_EXPOSURE_START_DATETIME=time,
  DRUG_EXPOSURE_END_DATETIME=endtime,
  STOP_REASON=NA,
  REFILLS=0,
  QUANTITY=qnt,
  DAYS_SUPPLY=NA,
  ROUTE_SOURCE_VALUE='oral',
  DOSE_UNIT_SOURCE_VALUE=dose_u,
  X_DOC_TYPE=c('EPIC IP ADMIN','EPIC OP ORDER')[isOP+1],
  X_DOC_STYPE=NA,
  X_DOSE=dose_n,
  X_DRUG_FORM='tablet',
  X_STRENGTH=c('875-125 mg','400 mg/5 mL','500 mg','600-42.9 mg/5 mL')[rxid],
  X_FREQUENCY=sample(c('daily','Every 12 hours scheduled'), n, replace = TRUE),
  X_QUANTITY_UNIT=c('tablet','mL','capsule','mL')[rxid],
  X_DURATION=NA
)

uid <- sort(unique(id))
demo <- data.frame(MRN=uid, birthDate=as.Date(sample(20*365.25, length(uid), replace = TRUE), origin = '2000-01-01'))

wgts <- data.frame(
  id=uid,
  dt=as.Date(sample(365, length(uid), replace = TRUE), origin = '2020-01-01'),
  val=sample(10:20, length(uid), replace = TRUE)
)

References

references

Corrections

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