Collection of customized functions


Import selected customized functions for the analysis by sourcing the codes from GitHub (See the link in the source() function for the detailed scripts).


source("https://raw.githubusercontent.com/injuryepi/Utils/master/drug_function_utils.R")


Or you can source the script drug_function_utils.R, saved locally in your working directory, to make all the customized functions available for the analysis


source("drug_function_utils.R")  

Reading the validation hospital dischardge data


Reading the validation dataset HOSPvalid.sas7bdat and apply all the restrictions set in PDO PfS guideline


hosp_valid <- haven::read_sas("HOSPvalid.sas7bdat")

hosp_valid <- hosp_valid %>% 
  set_names(tolower)

hosp_valid_res <- hosp_valid %>%
  filter(discharge_date > as.Date("2013-12-31"), 
         discharge_date < as.Date("2017-01-01"),
         state_res == 50,
         disp != 20,
         str_sub(hosp_id, 1, 1) %in% c("A", "B", "D", "X"))


Adding The Year and Months variables


hosp_valid_res <- hosp_valid_res %>% 
  mutate(dis_year = year(discharge_date),
         months = str_pad(month(discharge_date), width = 2, side = "left", pad = 0 ),
         year_months = paste(dis_year, months, sep = "_"))


Adding federal fiscal years(Oct-Sep) to the data to partition the data into pre and from fiscal year 2016


hosp_valid_res <- hosp_valid_res %>% 
  mutate(fiscal_year = fed_fiscal_year(discharge_date))


Adding the new drug fields as defined for the PDO PfS grant


Finding the fields for the principal diagnosis and all the diagnoses


dx_1 <- grep("dx1$", names(hosp_valid_res), value = F, ignore.case = T) # 12

dx_cols <- grep("dx\\d+", names(hosp_valid_res), value = F, ignore.case = T) # 12 13 14 15 16 17 18 19 20 21


Subsetting the data into a pre-fiscal year 2016 dataset and a fiscal year 2016 dataset and onward


hosp_valid_res_9cm <- hosp_valid_res %>% 
  filter(fiscal_year < 2016)

hosp_valid_res_10cm <- hosp_valid_res %>% 
  filter(fiscal_year > 2015)


Find any_drug, any_opioid, non_heroin_opioid, and heroin cases using the functions od_drug_apr_icd9cm() and od_drug_apr_icd10cm() for the periods of icd9 and icd10cm respectively then recombine the two datasets into one


hosp_valid_res_9cm <- hosp_valid_res_9cm %>% 
  od_drug_apr_icd9cm(., diag_col = dx_1, ecode_col = dx_cols)

hosp_valid_res_10cm <- hosp_valid_res_10cm %>% 
od_drug_apr_icd10cm(., diag_ecode_col = dx_cols)
 
# Recombine the two periods
hosp_valid_a <- hosp_valid_res_9cm %>% 
  bind_rows(hosp_valid_res_10cm)



Below are the results by monthly counts