#' Get regimen
#'
#' Get_regimen returns the eligible drugs in a line treatment regimen (mono or
#' combo therapy), defined as drugs within a window relative to the first episode.
#'
#' @param df a claims dataframe with \emph{PATIENT_ID ,MED_NAME, MED_START, MED_END} columns.
#' @param r_window threshold number of days for the regimen defining window
#' @return a vector of strings
#' @examples
#' get_regimen(df = test_tmp_data, r_window = 28)
#' @export
get_regimen <- function(df, r_window) {
# Start of line from the first row, which is assumed to be first drug episode (accomplished via snip_dataframe function)
# Later in the code/process, this line start is double checked and challenged if there is an eligible drug switch
tmp_line_start <- df[1, "MED_START"]
# Set the regimen window relative to the line start
regimen_end_date <- tmp_line_start + r_window
# Take the line start date, then project to regimen defining window, and get unique list of medications
tmp_regimen <- df %>% filter(MED_START <= regimen_end_date)
output_regimen <- unique(tmp_regimen$MED_NAME)
############# RETURN #############
return(output_regimen)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.