Skip to content

Commit

Permalink
Merge pull request #4 from Boehringer-Ingelheim/rc/1.0.4
Browse files Browse the repository at this point in the history
Rc/1.0.4
  • Loading branch information
mattkorb authored Oct 11, 2024
2 parents 82d3e78 + 932d217 commit 5ba3d1c
Show file tree
Hide file tree
Showing 35 changed files with 436 additions and 386 deletions.
6 changes: 6 additions & 0 deletions .lintr
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
linters: linters_with_defaults(
line_length_linter(120),
object_usage_linter = NULL,
indentation_linter = NULL,
trailing_whitespace_linter = NULL
)
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: dv.clinlines
Title: DaVinci's Clinical Timelines
Version: 1.0.3
Version: 1.0.4
Authors@R:
c(
person("Boehringer-Ingelheim Pharma GmbH & Co.KG", role = c("cph", "fnd")),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# dv.clinlines 1.0.4

* Adapt basic_info, filter, and drug_admin parameter to adhere module standard

# dv.clinlines 1.0.3

* Initial release of dv.clinlines package to GitHub.
Expand Down
57 changes: 28 additions & 29 deletions R/data_prep.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ prep_data <- function(data_list,
data_list <- append(data_list, list(no_da = empty_drug_admin))

drug_admin <- list(
name = "no_da",
dataset_name = "no_da",
start_var = "start",
end_var = "end",
detail_var = "details",
label = "",
exp_dose = "dose",
exp_dose_unit = "unit"
dose_var = "dose",
dose_unit_var = "unit"
)
}

Expand Down Expand Up @@ -176,21 +176,21 @@ add_ids <- function(data_list) {
#' @keywords internal
set_basics <- function(data_list, basic_info = default_basic_info(), subjid_var) {
# Extract subject level dataset from data_list
data <- data_list[[basic_info$data]]
data <- data_list[[basic_info$subject_level_dataset_name]]

check_names(
data,
var_names = c(basic_info$trt_start, basic_info$trt_end, basic_info$icf_date),
var_names = c(basic_info$trt_start_var, basic_info$trt_end_var, basic_info$icf_date_var),
subjid_var = subjid_var
)
check_date_type(data, c(basic_info$trt_start, basic_info$trt_end, basic_info$icf_date))
check_date_type(data, c(basic_info$trt_start_var, basic_info$trt_end_var, basic_info$icf_date_var))

return(
list(
data = dplyr::rename(data, dplyr::all_of(c(subject_id = subjid_var))),
trt_start = basic_info$trt_start,
trt_end = basic_info$trt_end,
icf_date = basic_info$icf_date
trt_start = basic_info$trt_start_var,
trt_end = basic_info$trt_end_var,
icf_date = basic_info$icf_date_var
)
)
}
Expand Down Expand Up @@ -299,9 +299,9 @@ set_events_intern <- function(data_list, mapping = default_mapping(), subjid_var
#' \item{\code{detail_var}: Character name of the variable that contains the treatment
#' information. Must exist in the dataset mentioned in the \code{name} element.}
#' \item{\code{label}: Free-text character label for the drug administration event.}
#' \item{\code{exp_dose}: Character name of the variable that contains the dosis level
#' \item{\code{dose_var}: Character name of the variable that contains the dosis level
#' information. Must exist in the dataset mentioned in the \code{name} element.}
#' \item{\code{exp_dose_unit}: Character name of the variable that contains the dosis
#' \item{\code{dose_unit_var}: Character name of the variable that contains the dosis
#' unit. Must exist in the dataset mentioned in the \code{name} element.}
#' }
#'
Expand All @@ -314,27 +314,27 @@ set_events_intern <- function(data_list, mapping = default_mapping(), subjid_var
#' \item{\code{detail_var}: Information about drug name and dosage.}
#' \item{\code{set}: Name of the dataset the data origins from.}
#' \item{\code{set_id}: Row ID's of the related dataset.}
#' \item{\code{exp_dose}: Indicates whether the dose of the treatment has increased,
#' \item{\code{dose_var}: Indicates whether the dose of the treatment has increased,
#' decreased or stayed the same compared to the last dose at the same subject.}
#' \item{\code{group}: Label for the event types.}
#' }
#'
#' @keywords internal
#'
set_exp_intervals <- function(data_list, mapping = default_drug_admin(), subjid_var) {
col_list <- mapping[!names(mapping) %in% c("name")]
col_list <- mapping[!names(mapping) %in% c("dataset_name")]

cols <- c(col_list$start_var, col_list$end_var, col_list$detail_var)
data <- data_list[[mapping$name]]
data <- data_list[[mapping$dataset_name]]

data <- data %>%
dplyr::group_by(get(subjid_var)) %>%
dplyr::mutate(
exp_dose = dplyr::case_when(
is.na(dplyr::lag(get(col_list$exp_dose))) ~ "start/equal",
dplyr::lag(get(col_list$exp_dose)) == get(col_list$exp_dose) ~ "start/equal",
dplyr::lag(get(col_list$exp_dose)) < get(col_list$exp_dose) ~ "increase",
dplyr::lag(get(col_list$exp_dose)) > get(col_list$exp_dose) ~ "decrease"
is.na(dplyr::lag(get(col_list$dose_var))) ~ "start/equal",
dplyr::lag(get(col_list$dose_var)) == get(col_list$dose_var) ~ "start/equal",
dplyr::lag(get(col_list$dose_var)) < get(col_list$dose_var) ~ "increase",
dplyr::lag(get(col_list$dose_var)) > get(col_list$dose_var) ~ "decrease"
)
) %>%
dplyr::ungroup()
Expand All @@ -346,8 +346,8 @@ set_exp_intervals <- function(data_list, mapping = default_drug_admin(), subjid_
dplyr::mutate(
detail_var = paste(
.data[[col_list$detail_var]], "-",
.data[[col_list$exp_dose]],
.data[[col_list$exp_dose_unit]]
.data[[col_list$dose_var]],
.data[[col_list$dose_unit_var]]
)
) %>%
dplyr::select(
Expand All @@ -358,10 +358,9 @@ set_exp_intervals <- function(data_list, mapping = default_drug_admin(), subjid_
start_exp = tidyselect::all_of(col_list$start_var),
end_exp = tidyselect::all_of(col_list$end_var)
) %>%
dplyr::mutate(set = mapping$name) %>%
dplyr::mutate(set = mapping$dataset_name) %>%
dplyr::rename(dplyr::all_of(c(subject_id = subjid_var)))


return(interval_df)
}

Expand Down Expand Up @@ -578,26 +577,26 @@ complete_events <- function(combined_data, trt_start, trt_end) {
set_filter_dataset <- function(filter, data_list, mapping, subjid_var) {
# Check for inconsistencies on modul definition side
if (length(filter$ae_filter) < 3) stop("No ae_filter defined for Clinical Timelines!")
if (!filter$ae_filter$data_name %in% names(data_list)) {
if (!filter$ae_filter$dataset_name %in% names(data_list)) {
msg <- paste0(
"Clinical Timelines (dv.clinlines) cannot find ",
filter$ae_filter$data_name,
filter$ae_filter$dataset_name,
" in your data list."
)

stop(msg)
}

only_filters <- filter$ae_filter[!names(filter$ae_filter) %in% c("data_name", "label")]
only_filters <- filter$ae_filter[!names(filter$ae_filter) %in% c("dataset_name", "label")]

check_names(data_list[[filter$ae_filter$data_name]],
unlist(only_filters), # drop data_name
check_names(data_list[[filter$ae_filter$dataset_name]],
unlist(only_filters), # drop dataset_name
subjid_var = subjid_var
)

ae_info <- mapping[[filter$ae_filter$data_name]][[filter$ae_filter$label]]
ae_info <- mapping[[filter$ae_filter$dataset_name]][[filter$ae_filter$label]]

filter_dataset <- data_list[[filter$ae_filter$data_name]] %>%
filter_dataset <- data_list[[filter$ae_filter$dataset_name]] %>%
dplyr::select(
dplyr::all_of(
c(
Expand Down
41 changes: 23 additions & 18 deletions R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,27 @@
#'
#' Helper function to support configuration of a Clinical Timelines module.
#'
#' @param data Character name of the subject level analysis dataset (e.g. "adsl", "dm")
#' @param subject_level_dataset_name Character name of the subject level analysis dataset (e.g. "adsl", "dm")
#' as it is called in the \code{data_list} parameter.
#' @param trt_start Character name of the variable that contains treatment start dates.
#' Must be present in the data frame mentioned in the \code{data} element.
#' @param trt_end Character name of the variable that contains treatment end dates.
#' Must be present in the data frame mentioned in the \code{data} element.
#' @param icf_date Character name of the variable that contains informed consent dates.
#' Must be present in the data frame mentioned in the \code{data} element.
#' @param trt_start_var Character name of the variable that contains treatment start dates.
#' Must be present in the data frame mentioned in the \code{subject_level_dataset_name} element.
#' @param trt_end_var Character name of the variable that contains treatment end dates.
#' Must be present in the data frame mentioned in the \code{subject_level_dataset_name} element.
#' @param icf_date_var Character name of the variable that contains informed consent dates.
#' Must be present in the data frame mentioned in the \code{subject_level_dataset_name} element.
#'
#' @return A list that could directly be used as input for the \code{basic_info} parameter
#' of \code{mod_clinical_timelines()} and \code{mod_clinical_timelines_server()}.
#' @export
#'
set_basic_info <- function(data, trt_start, trt_end, icf_date) {
set_basic_info <- function(subject_level_dataset_name, trt_start_var, trt_end_var, icf_date_var) {
return(
list(data = data, trt_start = trt_start, trt_end = trt_end, icf_date = icf_date)
list(
subject_level_dataset_name = subject_level_dataset_name,
trt_start_var = trt_start_var,
trt_end_var = trt_end_var,
icf_date_var = icf_date_var
)
)
}

Expand Down Expand Up @@ -70,7 +75,7 @@ set_event <- function(start_dt_var,
#'
#' Helper function to support configuration of a Clinical Timelines module.
#'
#' @param name Character name of the data frame that holds drug administration data
#' @param dataset_name Character name of the data frame that holds drug administration data
#' (e.g. ex domain) as it is called in the \code{data_list} parameter.
#' @param start_var Character name of the variable that contains the start dates
#' (e.g. exposure start dates). Must be present in the data frame mentioned in the name
Expand All @@ -81,31 +86,31 @@ set_event <- function(start_dt_var,
#' @param detail_var Character name of the variable that contains the treatment
#' information. Must exist in the dataset mentioned in the name element.
#' @param label Free-text character label for the drug administration event.
#' @param exp_dose Character name of the variable that contains the dosis level
#' @param dose_var Character name of the variable that contains the dosis level
#' information. Must exist in the dataset mentioned in the name element.
#' @param exp_dose_unit Character name of the variable that contains the dosis unit.
#' @param dose_unit_var Character name of the variable that contains the dosis unit.
#' Must exist in the dataset mentioned in the name element.
#'
#' @return A list that could directly be used as input for the \code{drug_admin} parameter
#' of \code{mod_clinical_timelines()} and \code{mod_clinical_timelines_server()}.
#' @export
#'
set_drug_admin <- function(name,
set_drug_admin <- function(dataset_name,
start_var,
end_var,
detail_var,
label,
exp_dose,
exp_dose_unit) {
dose_var,
dose_unit_var) {
return(
list(
name = name,
dataset_name = dataset_name,
start_var = start_var,
end_var = end_var,
detail_var = detail_var,
label = label,
exp_dose = exp_dose,
exp_dose_unit = exp_dose_unit
dose_var = dose_var,
dose_unit_var = dose_unit_var
)
)
}
8 changes: 4 additions & 4 deletions R/local_filter_setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#'
local_filters <- function(ns) {
ui_list <- list(
serious_AE = shiny::radioButtons(
ns("serious_AE"),
serious_ae = shiny::radioButtons(
ns("serious_ae"),
label = "Serious Adverse Events?",
choices = c("Yes" = "Y", "No" = "N", "All" = "all"),
selected = "all"
Expand All @@ -27,8 +27,8 @@ local_filters <- function(ns) {
multiple = TRUE,
options = list(placeholder = "All PT's selected")
),
drug_rel_AE = shiny::radioButtons(
ns("drug_rel_AE"),
drug_rel_ae = shiny::radioButtons(
ns("drug_rel_ae"),
label = "Drug related Adverse Events?",
choices = c("Yes" = "Y", "No" = "N", "All" = "all"),
selected = "all"
Expand Down
26 changes: 13 additions & 13 deletions R/mock_clinical_timelines.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mock_clinical_timelines_UI <- function(id = NULL) { # nolint
shiny::tags$h1("BI Clinical Timelines", class = "mod-title"),
mod_clinical_timelines_UI(
ns("clin_tl"),
list("serious_AE", "soc", "pref_term", "drug_rel_AE")
list("serious_ae_var", "soc_var", "pref_term_var", "drug_rel_ae_var")
)
)

Expand All @@ -35,10 +35,10 @@ mock_clinical_timelines_server <- function(input, output, session) {
data_name = shiny::reactive("dummyData"),
data_list,
basic_info = list(
data = "adsl",
trt_start = "TRTSDT",
trt_end = "TRTEDT",
icf_date = "RFICDT"
subject_level_dataset_name = "adsl",
trt_start_var = "TRTSDT",
trt_end_var = "TRTEDT",
icf_date_var = "RFICDT"
),
mapping = list(
adsl = list(
Expand Down Expand Up @@ -68,23 +68,23 @@ mock_clinical_timelines_server <- function(input, output, session) {
)
),
drug_admin = list(
name = "exp",
dataset_name = "exp",
start_var = "EXSTDTC",
end_var = "EXENDTC",
detail_var = "EXTRT",
label = "Drug Administration",
exp_dose = "EXDOSE",
exp_dose_unit = "EXDOSU"
dose_var = "EXDOSE",
dose_unit_var = "EXDOSU"
),
subjid_var = "USUBJID",
filter = list(
ae_filter = list(
data_name = "adae",
dataset_name = "adae",
label = "Adverse Events",
soc = "AESOC",
serious_AE = "AESER",
pref_term = "AEDECOD",
drug_rel_AE = "AEREL"
soc_var = "AESOC",
serious_ae_var = "AESER",
pref_term_var = "AEDECOD",
drug_rel_ae_var = "AEREL"
)
),
ms = 50
Expand Down
5 changes: 3 additions & 2 deletions R/mock_local_filter.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mock_local_filter_UI <- function(request) { # nolint
shiny::bookmarkButton(),
mod_local_filter_UI(
"filter",
list("soc", "pref_term", "drug_rel_AE", "serious_AE")
list("soc_var", "pref_term_var", "drug_rel_ae_var", "serious_ae_var")
),
shiny::tableOutput("table")
)
Expand Down Expand Up @@ -69,7 +69,8 @@ mock_local_filter_server <- function(input, output, session) {
filtered_data <- mod_local_filter_server(
"filter",
filter = list(ae_filter = list(
data_name = "adae", soc = "AESOC", pref_term = "AEDECOD", drug_rel_AE = "AEREL", serious_AE = "AESER"
dataset_name = "adae", soc_var = "AESOC", pref_term_var = "AEDECOD", drug_rel_ae_var = "AEREL",
serious_ae_var = "AESER"
)),
joined_data = initial_data,
changed = shiny::reactive(1)
Expand Down
Loading

0 comments on commit 5ba3d1c

Please sign in to comment.