#' Get drug summary
#'
#' Get_drug_summary function summarizes patient drug dosage information in the line.
#'
#' @param df a claims dataframe with \emph{PATIENT_ID ,MED_NAME, MED_START, MED_END} columns
#' @param input_r_window threshold number of days for the regimen defining window to detect combination drugs
#' @param line_end_date line end date: current line \emph{MED_END}
#' @return drug summary dataframe with \emph{MED_NAME, LAST_SEEN, FIRST_SEEN, DROPPED} columns
#' @export
get_drug_summary <- function(df, input_r_window, line_end_date) {
line_df <- df %>%
filter(MED_START <= line_end_date) %>%
arrange(MED_START)
drug_summary <- line_df %>%
group_by(MED_NAME) %>%
summarise(
LAST_SEEN = max(MED_END),
FIRST_SEEN = min(MED_START)
) %>%
ungroup() %>%
suppressWarnings()
drug_summary$DROPPED <- 0
drug_summary$DROPPED[line_end_date - drug_summary$LAST_SEEN > input_r_window] <- 1
drug_summary$PATIENT_ID <- line_df[1, "PATIENT_ID"]
############# RETURN #############
return(drug_summary)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.