Please install the latest Pharm package.
install.packages("devtools")
devtools::install_github("DHLab-TSENG/pharm")
library(pharm)
library(dplyr)
A sample data rda file sample_data_subset
is included in Pharm package:
The way to generate the data table sample_data
is to de-identify the source data which is from the US real medication records. Then, resort the order of patient Id in the original data, and time-shift the date of each administration. Next, replace the NDC in part of the administration record which has the same drug but different NDC, which means that the NDC of the drug is different in the NDC history. As a result of the data, a total of 2,747,617 dosing records and 39,989 Id numbers from different patients were generated.
The sample data sample_data_subset
used in the function demonstration of this package is a subset of sample_data
which is SELECT FROM MemberId = 1 AND MemberId = 42
. For the field information in the data set:
MemberId
patient IdDispenseDate
patient`s drug dispensed date, and the time interval is from 2025-12-06 to 2038-01-25NationalDrugCode
drug NDC, total of 17,326 different drug codesQuantity
quantity of patient`s drug dispensedDaysSupply
days of patient`s drug dispensed
knitr::kable(sample_data_subset)
MemberId | DispenseDate | NationalDrugCode | Quantity | DaysSupply |
---|---|---|---|---|
1 | 2031-12-01 | 00186504031 | 30 | 30 |
1 | 2032-01-31 | 00186504031 | 30 | 30 |
1 | 2032-03-25 | 00186504031 | 30 | 30 |
42 | 2032-01-05 | 00186504031 | 30 | 30 |
42 | 2032-03-07 | 00186504031 | 30 | 30 |
42 | 2032-04-30 | 00186504031 | 30 | 30 |
42 | 2032-03-08 | 00006504031 | 90 | 90 |
42 | 2032-04-25 | 00006504031 | 90 | 90 |
The source data is from the U.S. Veterans Administration’s MED-RT
database to establish this function. User can get the RxCui of all drug ingredients for the treatment by input the indication.
Exmaple: User input the indication esophagitis
, the RxCui of all drug ingredients for the treatment can be obtained and stored in the new data table Esophagitis_List
. For the field information in the data set:
RxCui
drug RxCuiName
drug nameMinCooncept.Id
indication IdMinConcept.Name
indication name
Esophagitis_List <- getRxCuiViaMayTreat("esophagitis")
knitr::kable(
head(Esophagitis_List)
)
RxCui | Name | MinConcept.Id | MinConcept.Name |
---|---|---|---|
1792108 | Omeprazole Sodium | D004941 | Esophagitis |
236486 | Omeprazole magnesium | D004941 | Esophagitis |
7646 | Omeprazole | D004941 | Esophagitis |
10156 | Sucralfate | D004941 | Esophagitis |
1487143 | sucralfate malate | D004941 | Esophagitis |
17128 | lansoprazole | D004941 | Esophagitis |
After obtaining the data table of all drug ingredients for the treatment Esophagitis_List
, user can get all the pharmaceutical brands and clinical drugs which has contained these drug ingredients by input the data table Esophagitis_List
.
Exmaple: User input the data table Esophagitis_List
, the converted SBD or SCD RxCui can be obtained and stored in the new data table Esophagitis_SBD_SCD_List
. For the field information in the data set:
RxCui
drug RxCuiName
drug nameMinCooncept.Id
indication IdMinConcept.Name
indication nameSBD.rxcui
drug SBD RxCui
Esophagitis_SBD_SCD_List <- getSBDRxCuiViaRxCui(df = Esophagitis_List[3,],
RxCuiColName = RxCui,
cores = 2)
knitr::kable(
head(Esophagitis_SBD_SCD_List)
)
RxCui | Name | MinConcept.Id | MinConcept.Name | SBD.rxcui |
---|---|---|---|---|
7646 | Omeprazole | D004941 | Esophagitis | 2262026 |
7646 | Omeprazole | D004941 | Esophagitis | 2003656 |
7646 | Omeprazole | D004941 | Esophagitis | 198051 |
7646 | Omeprazole | D004941 | Esophagitis | 199119 |
7646 | Omeprazole | D004941 | Esophagitis | 389171 |
7646 | Omeprazole | D004941 | Esophagitis | 389172 |
Pharm package provides the following drug code conversion:
After obtaining the data table of all drug ingredient SBD or SCD RxCui Esophagitis_SBD_SCD_List
, user can get NDC which has contained these drug ingredients by input the data table Esophagitis_SBD_SCD_List
. However, a drug will have different packaging and NDC because it comes from different pharmaceutical brands. There will be different NDC for the same drug type but different packaging. Hence, the output results will be one-to-many. A drug RxCui will matche to multiple NDC of pharmaceutical brands, and no corresponding NDC will beNA
. This function provides user to get NDC via SBD or SCD RxCui.
Exmaple: User input the data table Esophagitis_SBD_SCD_List
, the converted NDC can be obtained and stored in the new data table Esophagitis_NDC_List
. For the field information in the data set:
RxCui
drug RxCuiName
drug nameMinCooncept.Id
indication IdMinConcept.Name
indication nameSBD.rxcui
drug SBD RxCuiNDC
drug NDC
Esophagitis_NDC_List <- getNDCViaSBDRxCui(df = Esophagitis_SBD_SCD_List[1,],
SBDRxCuiColName = SBD.rxcui,
cores = 2)
knitr::kable(
head(Esophagitis_NDC_List)
)
RxCui | Name | MinConcept.Id | MinConcept.Name | SBD.rxcui | NDC |
---|---|---|---|---|---|
7646 | Omeprazole | D004941 | Esophagitis | 2262026 | NA |
After obtaining the data table of sample data sample_data_subset
, user can get RxCui which has contained these drug ingredients by input the data table sample_data_subset
.
Exmaple: User input the data table sample_data_subset
, the converted RxCui can be obtained and stored in the new data table sample_data_subset_rxcui
. For the field information in the data set:
MemberId
patient IdDispenseDate
patient`s drug dispensed date, and the time interval is from 2025-12-06 to 2038-01-25NationalDrugCode
drug NDC, total of 17,326 different drug codesQuantity
quantity of patient`s drug dispensedDaysSupply
days of patient`s drug dispensedRxCui
drug RxCuindcStatus
drug NDC status
sample_data_subset_rxcui <- getRxCuiViaNDC(df = sample_data_subset,
NdcColName = NationalDrugCode)
knitr::kable(head(sample_data_subset_rxcui))
MemberId | DispenseDate | NationalDrugCode | Quantity | DaysSupply | RxCui | ndcStatus |
---|---|---|---|---|---|---|
1 | 2031-12-01 | 00186504031 | 30 | 30 | 606731 | ACTIVE |
1 | 2032-01-31 | 00186504031 | 30 | 30 | 606731 | ACTIVE |
1 | 2032-03-25 | 00186504031 | 30 | 30 | 606731 | ACTIVE |
42 | 2032-01-05 | 00186504031 | 30 | 30 | 606731 | ACTIVE |
42 | 2032-03-07 | 00186504031 | 30 | 30 | 606731 | ACTIVE |
42 | 2032-04-30 | 00186504031 | 30 | 30 | 606731 | ACTIVE |
WHO Collaborating Center for Drug Statistics Methodology, ATC classification index with DDDs, 2019. Oslo, Norway 2018. After obtaining the data table sample_data_subset_rxcui
, user can get ATC which has contained these drug ingredients by input the data table sample_data_subset_rxcui
. However, the same drug components in ATC might depend on different ATC medication route. Hence, this function also refer to the research of Bodenreider et al. and adds the parameter MatchRoute
for user to consider. If user wants to consider and compare the ATC medication route, input TRUE
in the parameter MatchRoute, otherwise input FALSE
.
Exmaple: User input the data table sample_data_subset_rxcui
and compare the drug route MatchRoute = False
, the converted ATC can be obtained and stored in the new data table sample_data_subset_atc
. For the field information in the data set:
MemberId
patient IdDispenseDate
patient`s drug dispensed date, and the time interval is from 2025-12-06 to 2038-01-25NationalDrugCode
drug NDC, total of 17,326 different drug codesQuantity
quantity of patient`s drug dispensedDaysSupply
days of patient`s drug dispensedRxCui
drug RxCuiATC
drug ATC
sample_data_subset_atc <- getATCViaRxCui(df = sample_data_subset_rxcui,
RxCuiColName = RxCui,
cores = 2,
MatchRoute = FALSE)
knitr::kable(
head(sample_data_subset_atc)
)
User can get RxCui which has contained these drug ingredients by input the data table sample_ATC
.
Exmaple: User input the data table sample_ATC
, the converted RxCui can be obtained and stored in the new data table sample_atc_rxcui
. For the field information in the data set:
RxCui
drug RxCuiATC
drug ATC
sample_atc_rxcui <- getRxCuiViaATC(df = sample_ATC,
AtcColName = ATC,
cores = 2)
knitr::kable(
head(sample_atc_rxcui)
)
ATC | RxCui |
---|---|
G04BX06 | 8120 |
D06AX02 | 2348 |
C01DA02 | 4917 |
G03AB01 | NA |
A12CC05 | 142131 |
User can get NHINo which has contained these drug ingredients by input HC, and no corresponding NHINo will beNA
.
knitr::kable(
head(
getNHINoViaHC(df, HospitalCodeColName, SourceDf, Source_NhinoColName, Source_HospitalCodeColName)
)
)
User can get NHINo which has contained these drug ingredients by input the data table sample_taiwan_drug
, and no corresponding NHINo will beNA
.
Exmaple: User input the data table sample_taiwan_drug
, the converted NHINo can be obtained. For the field information in the data set:
CGMH_CODE
Chang Gung Medical Hospital drug code RCFNoNHINO1
drug NHINo
knitr::kable(
head(
getNHINoViaRCFNo(df = sample_taiwan_drug,
RCFNoColName = CGMH_CODE)
)
)
CGMH_CODE | NHINO1 |
---|---|
P6A780M | BC26139100 |
P6A022E | NA |
P6A741M | NA |
P6A674M | NA |
PBA024P | N002967209 |
PBA024P | A010784209 |
User can get ATC which has contained these drug ingredients by input the data table sample_nhino_code
, and no corresponding ATC will beNA
.
Exmaple: User input the data table sample_nhino_code
, the converted ATC can be obtained. For the field information in the data set:
NHINo
drug NHINoATC_CODE
drug ATC
knitr::kable(
head(
getATCViaNHINo(df = sample_nhino_code,
NHINoColName = NHINo)
)
)
NHINo | ATC_CODE |
---|---|
BC26139100 | L02BX03 |
A014118335 | D07XB01 |
BC26359100 | L01XE18 |
BC25224100 | C01BD07 |
AC22049209 | R06AA02 |
AC45972100 | R06AX27 |
This can be used to merge pharmacy claims data into drug era with defined window and Exposure days will be cacluated, too. An event of the time interval is according to the prescription’s dispense date plus the prescription’s drug supply days. This function provides user to concatenate continuous prescription medications into a single prescription length. There are two calculation models:
1.If the time interval gap between the patient taking the drug exceeds the persistent window, these two events are regarded as two different drug era. 2.If the time interval gap between the patient taking the drug less than the persistent window, these two events are regarded as same drug era.
Example: As the picture 1,Event 1 and Event 2 are less than the defined gap length, so they are regarded as the same Drug Era. In the other hand, Event 2 and Event 3 are greater than the defined gap, so the gap length is regarded as different Drug Era. For the field information in the data set:
MemberId
patient IdDispenseDate
patient`s drug dispensed date, and the time interval is from 2025-12-06 to 2038-01-25NationalDrugCode
drug NDC, total of 17,326 different drug codesQuantity
quantity of patient`s drug dispensedDaysSupply
days of patient`s drug suppliedDrug Era
drug eraDrug Era Start Date
the begin date to calculate drug eraDrug Era End Date
the end date to calculate drug eraGap
the time interval of drug dispensed dateExposure Days
the date of drug eraSupply Days
the days of drug era that patient`s drug supplied
knitr::kable(getDrugEra(MemberIDColName = MemberId,
sample_data_subset,
DrugColName = NationalDrugCode,
DispenseDateColName = DispenseDate,
DaysSupplyColName = DaysSupply))
MemberId | DispenseDate | NationalDrugCode | Quantity | DaysSupply | DrugEra | DrugEraStartDate | DrugEraEndDate | Gap | ExposureDays | SupplyDays |
---|---|---|---|---|---|---|---|---|---|---|
1 | 2031-12-01 | 00186504031 | 30 | 30 | 1 | 2031-12-01 | 2031-12-31 | 0 | 30 days | 30 |
1 | 2032-01-31 | 00186504031 | 30 | 30 | 2 | 2032-01-31 | 2032-04-24 | 0 | 84 days | 60 |
1 | 2032-03-25 | 00186504031 | 30 | 30 | 2 | 2032-01-31 | 2032-04-24 | 24 | 84 days | 60 |
42 | 2032-03-08 | 00006504031 | 90 | 90 | 1 | 2032-03-08 | 2032-07-24 | 0 | 138 days | 180 |
42 | 2032-04-25 | 00006504031 | 90 | 90 | 1 | 2032-03-08 | 2032-07-24 | -42 | 138 days | 180 |
42 | 2032-01-05 | 00186504031 | 30 | 30 | 1 | 2032-01-05 | 2032-02-04 | 0 | 30 days | 30 |
42 | 2032-03-07 | 00186504031 | 30 | 30 | 2 | 2032-03-07 | 2032-05-30 | 0 | 84 days | 60 |
42 | 2032-04-30 | 00186504031 | 30 | 30 | 2 | 2032-03-07 | 2032-05-30 | 24 | 84 days | 60 |
User can calculate DDDs in RxCui via the daily amount of drug taken by the patient.
The calculation model:
The dosage of the drug multiplied by the number of the days of drug taken, and then divided by the number of days of drug supplied.
Example: User input the data table sample_data_subset_atc
. For the field information in the data set:
MemberId
patient IdDispenseDate
patient`s drug dispensed date, and the time interval is from 2025-12-06 to 2038-01-25NationalDrugCode
drug NDC, total of 17,326 different drug codesQuantity
quantity of patient`s drug dispensedDaysSupply
days of patient`s drug suppliedRxCui
drug RxCuiATC
drug ATCDailyDosage
drug DDDsUnit
drug unit
sample_data_subset_atc <- calDDDsViaRxCui(df = sample_data_subset_atc,
RxCuiColName = RxCui,
QuantityColName = Quantity,
DaysSupply = DaysSupply,
cores = 2)
knitr::kable(
head(sample_data_subset_atc)
)
User can calculate patient total amount of DDDs for accumulation medication time by input the data table sample_data_subset_atc
.
Example: User input the data table sample_data_subset_atc
. For the field information in the data set:
MemberId
patient IdDDDs
accumulated DDDs
accumulat_DDD <- calDDDsAccumulation(case = sample_data_subset_atc,
PatientIdColName = MemberId,
DispensingColName = DispenseDate,
AtcCodeColName = ATC,
DailyDosageColName = DailyDosage,
DurationColName = DaysSupply)
knitr::kable(accumulat_DDD)
User can calculate the total amount of DDDs accumulated by the patient in a custom interval period index day
or specific date .
Example: User input the data table sample_data_subset_atc
. For the field information in the data set:
MemberId
patient IdStart_day
the begin date of patient take medicineIndex_Day
the begin date of calculating the DDDsEnd_day
the end date of patient take medicineDDDs_Before_15_Days
calculate DDDs in custom time interval before index 15 dayDDDs_After_30_Days
calculate DDDs in custom time interval after index 30 day
index_DDD <- calDDDsRange(case = sample_data_subset_atc,
index_dayColName = Index_Day,
expo_range_before = 15,
expo_range_after = 30,
idColName = MemberId,
AtcCodeColName = ATC,
DispenseDateColName = DispenseDate,
DaysSupplyColName = DaysSupply,
DailyDosageColName = DailyDosage)
knitr::kable(index_DDD)
The visualization of the data analyzed results can help user quickly understand the content of the data as well as analysis results. In addition, plots can also quickly see the distribution of drug categories in the data, present the results of drug era analysis and the drug history of individual patients.
User can get DDDs in ATC level 1 or 2 histogram plot. A parameter level
is provided that user can choose which level to draw whether the first-order or second-order distribution of ATC. Then, show the plot of its distribution in bar chart.
Example: User input the data table sample_data_ATC1LevelPlot
. For the field information in the data set:
count
numberATC1Level
ATC level, the first-order distribution of ATC
# level distribution 1
getATCLevelPlot(df = sample_data_ATC1LevelPlot,
ATCColName = ATC,
level = 1)
# level distribution 2
getATCLevelPlot(df = sample_data_ATC1LevelPlot,
ATCColName = ATC,
level = 2)
User can get the visualized result of the drug era calculated by get.DrugEra
. User has to consider different drug, drug era, supplied days, and the distribution of the dospensing drug. Then, show the plot that distribution of the patient`s dispensing drug times in bar chart.
Example: User input the data table sample_data_DrugEraPlot
. For the field information in the data set:
Drug Era
number of drug eraTotal Supply Days
length of drug era The values in the bar graph indicate the drug era in this time interval, and the drug records for each drug era are several times.
getDrugEraPlot(df = sample_data_DrugEraPlot,
MemberIDColName = MemberId,
DrugColName = ATC,
DrugEraColName = DrugEra,
SupplyDaysColName = SupplyDays)
User can get specific patient`s drug history plot in bar chart and get separately sub-plots of different drug history. In addition, user can choose to classify drugs, this chart is classified by NDC code. The time interval between each drug record is displayed as a negative number if there is overlap.
Example: User input the data table sample_data_ATC1LevelPlot
. For the field information in the data set:
Dispensing Time
delivery order of the same drugDate
timeline of drug history
getDispensingPlot(df = sample_data_subset,
MemberIDColName = MemberId,
DrugColName = NationalDrugCode,
DispenseDateColName = Dispensing,
Member = 42,
TimeInterval = 20,
Unit = day)
I. Get Drug Ingredient Via Indication
National Health Insurance Administration(2019), 藥品藥理治療分類ATC碼資料集. available at https://data.gov.tw/dataset/9119
WHO(2019d), ATC/DDD Index 2018. available at https://www.whocc.no/atc_ddd_index/
U.S. National Library of Medicine(2019b), RxNorm API. available at https://mor.nlm.nih.gov/download/rxnav/RxNormAPIs.html#
MAYO CLINIC (2019), Esophagitis Diagnosis & Treatment. available at https://www.mayoclinic.org/diseases-conditions/esophagitis/diagnosis-treatment/drc-20361264
II. Drug Code Integration
National Health Insurance Administration(2019), 全民健康保險藥品編碼原則. https://reurl.cc/R0qkZn
Food and Drug Administration (2019), National Drug Code Directory. available at https://www.fda.gov/drugs/informationondrugs/ucm142438.htm
U.S. National Library of Medicine(2019c), RxNav. available at https://mor.nlm.nih.gov/RxNav/
Bodenreider et al. (2014), Analyzing U.S. Prescription Lists with RxNorm and the ATC/DDD Index. AMIA … Annual Symposium proceedings. AMIA Symposium, 2014: 297–306. https://pubmed.ncbi.nlm.nih.gov/25954332/
III. Calculate Drug Data
WHO(2019c), Guidelines for ATC Classification and DDD Assignment 2018. https://www.whocc.no/atc_ddd_index_and_guidelines/guidelines/
Vollmer et al.(2012), Comparison of Pharmacy-Based Measures of Medication Adherence. BMC Health Services Research, 12(1): https://pubmed.ncbi.nlm.nih.gov/22691240/
Dima et al. (2017), Computation of Adherence to Medication and Visualization of Medication Histories in R with AdhereR: Towards Transparent and Reproducible Use of Electronic Healthcare Data. PLoS ONE, 12(4): 1–14. https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0174426
R Foundation (2019), R. available at https://www.r-project.org/
Bender et al. (2015), Pragmatic Trial of Health Care Technologies to Improve Adherence to Pediatric Asthma Treatment a Randomized Clinical Trial. JAMA Pediatrics, 169(4): 317–323. https://pubmed.ncbi.nlm.nih.gov/25664620/