R/add_subanalysis_flags.R

Defines functions add_subanalysis_flags

Documented in add_subanalysis_flags

#' Flag patients for subanalysis, stratified on exposure to approved drugs for target disease
#' Last updated: 2021-02-10
#'
#'
#' @param indication_drug_exposed A tibble with columns, c('person_id','rxcui_ingr','rxcui_ingr_name','group')
#' @param covariates A tibble with columns, c('person_id','dob','gender_concept_id','race_concept_id','start_date','first_drug_exposure','final_end_date','age')
#' @export

add_subanalysis_flags <- function(indication_drug_exposed, covariates,...) {

  treatment_exposed <- indication_drug_exposed %>% filter(group == "treatment")
  baseline_exposed <- indication_drug_exposed %>% filter(group == "baseline")
  treatment_exposed_new <- anti_join(treatment_exposed, baseline_exposed, by = c("person_id", "rxcui_ingr")) %>%
    arrange(person_id)

  #Flag patients from cohort with indication drug exposures during observation period with "1" = exposed; "0" = not exposed
  covariates <- covariates %>%
    mutate(
      drug_exposed = if_else((person_id %in% indication_drug_exposed$person_id),1,0),
      treatment_new_exposed = if_else((person_id %in% treatment_exposed_new$person_id),1,0)
    )
}
pwatrick/systematicRepurposing documentation built on March 24, 2021, 5:49 p.m.