Skip to content

Commit 81e3fc0

Browse files
authored
Merge pull request #12 from Boehringer-Ingelheim/rc/1.1.0
Rc/1.1.0
2 parents 6cda460 + 60cd0b1 commit 81e3fc0

37 files changed

Lines changed: 566 additions & 154 deletions

DESCRIPTION

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: dv.clinlines
22
Title: DaVinci's Clinical Timelines
3-
Version: 1.0.4
3+
Version: 1.1.0
44
Authors@R:
55
c(
66
person("Boehringer-Ingelheim Pharma GmbH & Co.KG", role = c("cph", "fnd")),
@@ -21,7 +21,7 @@ Imports:
2121
bslib (>= 0.6.1),
2222
checkmate (>= 2.3.1),
2323
dplyr (>= 1.1.0),
24-
dv.manager (>= 2.1.0),
24+
dv.manager (>= 2.1.4),
2525
ggplot2 (>= 3.4.4),
2626
lubridate (>= 1.9.3),
2727
magrittr (>= 2.0.3),
@@ -46,7 +46,6 @@ Suggests:
4646
testthat (>= 3.2.1)
4747
Config/testthat/edition: 3
4848
Roxygen: list(markdown = TRUE)
49-
RoxygenNote: 7.3.1
50-
Remotes: boehringer-ingelheim/dv.manager@v2.1.2
49+
RoxygenNote: 7.3.2
50+
Remotes: boehringer-ingelheim/dv.manager@v2.1.4
5151
VignetteBuilder: knitr
52-

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export("%>%")
44
export(default_basic_info)
55
export(default_drug_admin)
66
export(default_mapping)
7+
export(mock_clinical_timelines_app)
78
export(mock_with_mm_app)
89
export(mod_clinical_timelines)
910
export(mod_clinical_timelines_UI)

NEWS.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# dv.clinlines 1.1.0
2+
3+
* Display drug administration information in different colors, depending on the treatment name.
4+
* Allow for customized color palettes.
5+
* Use dv.manager's switch2mod() instead of deprecated switch2() function.
6+
* Export mock app.
7+
* Fix error occurring in case only timepoints (i.e., no intervals) are specified.
8+
19
# dv.clinlines 1.0.4
210

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

R/data_prep.R

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ prep_data <- function(data_list,
1919
drug_admin = default_drug_admin(),
2020
subjid_var = "USUBJID",
2121
filter = NULL) {
22+
2223
if (is.null(drug_admin)) {
2324
empty_drug_admin <- data.frame(
2425
subjects = character(),
26+
treatment = character(),
2527
start = lubridate::ymd_hm(),
2628
end = lubridate::ymd_hm(),
2729
details = character(),
@@ -34,6 +36,7 @@ prep_data <- function(data_list,
3436

3537
drug_admin <- list(
3638
dataset_name = "no_da",
39+
trt_var = "treatment",
3740
start_var = "start",
3841
end_var = "end",
3942
detail_var = "details",
@@ -324,11 +327,14 @@ set_events_intern <- function(data_list, mapping = default_mapping(), subjid_var
324327
set_exp_intervals <- function(data_list, mapping = default_drug_admin(), subjid_var) {
325328
col_list <- mapping[!names(mapping) %in% c("dataset_name")]
326329

327-
cols <- c(col_list$start_var, col_list$end_var, col_list$detail_var)
330+
cols <- c(col_list$start_var, col_list$end_var, col_list$detail_var, col_list$trt_var)
328331
data <- data_list[[mapping$dataset_name]]
329332

333+
check_names(data, cols, subjid_var)
334+
check_date_type(data, c(col_list$start_var, col_list$end_var))
335+
330336
data <- data %>%
331-
dplyr::group_by(get(subjid_var)) %>%
337+
dplyr::group_by(get(subjid_var), get(col_list$trt_var)) %>%
332338
dplyr::mutate(
333339
exp_dose = dplyr::case_when(
334340
is.na(dplyr::lag(get(col_list$dose_var))) ~ "start/equal",
@@ -338,22 +344,25 @@ set_exp_intervals <- function(data_list, mapping = default_drug_admin(), subjid_
338344
)
339345
) %>%
340346
dplyr::ungroup()
341-
342-
check_names(data, cols, subjid_var)
343-
check_date_type(data, c(col_list$start_var, col_list$end_var))
344-
345347
interval_df <- data %>%
346348
dplyr::mutate(
347349
detail_var = paste(
348350
.data[[col_list$detail_var]], "-",
349351
.data[[col_list$dose_var]],
350352
.data[[col_list$dose_unit_var]]
351-
)
353+
),
354+
trt_var = .data[[col_list$trt_var]]
352355
) %>%
353356
dplyr::select(
354-
tidyselect::all_of(c(subjid_var, cols[1:2], "set_id", "exp_dose", "detail_var"))
357+
tidyselect::all_of(c(subjid_var, cols[1:2], "set_id", "exp_dose", "detail_var", "trt_var"))
358+
) %>%
359+
dplyr::mutate(
360+
group = dplyr::if_else(
361+
!is.na(.data[["trt_var"]]),
362+
paste0(col_list$label, ": ", .data[["trt_var"]]),
363+
NA
364+
)
355365
) %>%
356-
tibble::add_column(group = rep(col_list$label)) %>%
357366
dplyr::rename(
358367
start_exp = tidyselect::all_of(col_list$start_var),
359368
end_exp = tidyselect::all_of(col_list$end_var)

R/helpers.R

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,25 +77,28 @@ set_event <- function(start_dt_var,
7777
#'
7878
#' @param dataset_name Character name of the data frame that holds drug administration data
7979
#' (e.g. ex domain) as it is called in the \code{data_list} parameter.
80+
#' @param trt_var Character name of the variable that contains the treatment name.
81+
#' Must be present in the data frame mentioned in the \code(dataset_name) element.
8082
#' @param start_var Character name of the variable that contains the start dates
81-
#' (e.g. exposure start dates). Must be present in the data frame mentioned in the name
82-
#' element.
83+
#' (e.g. exposure start dates). Must be present in the data frame mentioned in the
84+
#' \code(dataset_name) element.
8385
#' @param end_var Character name of the variable that contains the end dates
84-
#' (e.g. exposure start dates). Must be present in the data frame mentioned in the name
85-
#' element.
86+
#' (e.g. exposure start dates). Must be present in the data frame mentioned in the
87+
#' \code(dataset_name) element.
8688
#' @param detail_var Character name of the variable that contains the treatment
87-
#' information. Must exist in the dataset mentioned in the name element.
89+
#' information. Must exist in the dataset mentioned in the \code(dataset_name) element.
8890
#' @param label Free-text character label for the drug administration event.
8991
#' @param dose_var Character name of the variable that contains the dosis level
90-
#' information. Must exist in the dataset mentioned in the name element.
92+
#' information. Must exist in the dataset mentioned in the \code(dataset_name) element.
9193
#' @param dose_unit_var Character name of the variable that contains the dosis unit.
92-
#' Must exist in the dataset mentioned in the name element.
94+
#' Must exist in the dataset mentioned in the \code(dataset_name) element.
9395
#'
9496
#' @return A list that could directly be used as input for the \code{drug_admin} parameter
9597
#' of \code{mod_clinical_timelines()} and \code{mod_clinical_timelines_server()}.
9698
#' @export
9799
#'
98100
set_drug_admin <- function(dataset_name,
101+
trt_var,
99102
start_var,
100103
end_var,
101104
detail_var,
@@ -105,6 +108,7 @@ set_drug_admin <- function(dataset_name,
105108
return(
106109
list(
107110
dataset_name = dataset_name,
111+
trt_var = trt_var,
108112
start_var = start_var,
109113
end_var = end_var,
110114
detail_var = detail_var,

R/mock_clinical_timelines.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ mock_clinical_timelines_UI <- function(id = NULL) { # nolint
1010

1111
ui <- shiny::fluidPage(
1212
theme = bslib::bs_theme(version = "4"),
13-
shiny::tags$h1("BI Clinical Timelines", class = "mod-title"),
13+
shiny::tags$h1("DaVinci's Clinical Timelines Module", class = "mod-title"),
1414
mod_clinical_timelines_UI(
1515
ns("clin_tl"),
1616
list("serious_ae_var", "soc_var", "pref_term_var", "drug_rel_ae_var")
@@ -69,6 +69,7 @@ mock_clinical_timelines_server <- function(input, output, session) {
6969
),
7070
drug_admin = list(
7171
dataset_name = "exp",
72+
trt_var = "EXTRT",
7273
start_var = "EXSTDTC",
7374
end_var = "EXENDTC",
7475
detail_var = "EXTRT",
@@ -87,6 +88,7 @@ mock_clinical_timelines_server <- function(input, output, session) {
8788
drug_rel_ae_var = "AEREL"
8889
)
8990
),
91+
start_day = -5,
9092
ms = 50
9193
)
9294
}
@@ -98,6 +100,7 @@ mock_clinical_timelines_server <- function(input, output, session) {
98100
#' \code{mock_clinical_timelines_app()} runs the \pkg{dv.clinlines} module
99101
#' with dummy data. Local adverse event filters included.
100102
#'
103+
#' @export
101104
mock_clinical_timelines_app <- function() {
102105
shiny::shinyApp(
103106
ui = mock_clinical_timelines_UI,

R/mock_with_mm.R

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@
44
#' module manager surface. Displays data from the \pkg{pharmaverseadam} package.
55
#'
66
#' @export
7-
#' @keywords internal
8-
#'
97
mock_with_mm_app <- function() {
10-
# Specifiy dataset list for modulemanager
8+
# Specifiy dataset list for module manager
119
dataset_list <- list(
1210
dummyData1 = prep_dummy_data(20),
1311
dummyData2 = prep_dummy_data(200)
1412
)
1513

1614

17-
# Define module list for modulemanager
15+
# Define module list for module manager
1816
module_list <- list(
1917
"Clinical Timelines" = mod_clinical_timelines(
2018
module_id = "mod1",
@@ -60,6 +58,7 @@ mock_with_mm_app <- function() {
6058
),
6159
drug_admin = list(
6260
dataset_name = "exp",
61+
trt_var = "EXTRT",
6362
start_var = "EXSTDTC",
6463
end_var = "EXENDTC",
6564
detail_var = "EXTRT",
@@ -84,6 +83,16 @@ mock_with_mm_app <- function() {
8483
start_day = -5,
8584
boxheight_val = 60
8685
)
86+
# nolint start: commented_code_linter
87+
# color_palette = c(
88+
# "Treatment End" = "blue",
89+
# "Treatment Start" = "red",
90+
# "Drug Administration: PLACEBO" = "yellow",
91+
# "Drug Administration: XANOMELINE" = "green",
92+
# "Informed Consent" = "purple",
93+
# "Adverse Events" = "orange"
94+
# )
95+
# nolint end
8796
)
8897
)
8998

R/mod_clinical_timelines.R

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ mod_clinical_timelines_server <- function(module_id,
105105
filter = NULL,
106106
subjid_var = "USUBJID",
107107
start_day = NULL,
108+
color_palette = NULL,
108109
ms = 1000,
109110
receiver_id = NULL,
110111
afmm_param = NULL) {
@@ -137,7 +138,13 @@ mod_clinical_timelines_server <- function(module_id,
137138
checkmate::assert_list(drug_admin, types = "character", null.ok = TRUE, add = ac)
138139
checkmate::assert_subset(
139140
names(drug_admin),
140-
choices = c("dataset_name", "start_var", "end_var", "detail_var", "label", "dose_var", "dose_unit_var"),
141+
choices = c(
142+
"dataset_name",
143+
"trt_var",
144+
"start_var", "end_var",
145+
"detail_var", "label",
146+
"dose_var", "dose_unit_var"
147+
),
141148
add = ac
142149
)
143150
checkmate::assert_list(filter, types = "list", null.ok = TRUE, add = ac)
@@ -153,7 +160,10 @@ mod_clinical_timelines_server <- function(module_id,
153160
checkmate::assert_numeric(ms, len = 1, add = ac)
154161
checkmate::assert_string(receiver_id, min.chars = 1, null.ok = TRUE, add = ac)
155162
checkmate::assert_list(afmm_param, null.ok = TRUE, add = ac)
163+
checkmate::assert_character(color_palette, null.ok = TRUE, add = ac)
164+
checkmate::assert_character(names(color_palette), null.ok = TRUE, unique = TRUE, add = ac)
156165
checkmate::reportAssertions(ac)
166+
check_valid_color(color_palette)
157167

158168
shiny::moduleServer(
159169
module_id,
@@ -201,7 +211,9 @@ mod_clinical_timelines_server <- function(module_id,
201211

202212
# Set a fixed color for each group
203213
colors_groups <- shiny::reactive({
204-
if (nrow(pre_data()) > 0) color_lookup(unique(pre_data()$group))
214+
if (nrow(pre_data()) > 0) {
215+
color_lookup(unique(pre_data()$group), color_palette)
216+
}
205217
})
206218

207219
# Add adverse event data that are relevant for filtering
@@ -239,7 +251,7 @@ mod_clinical_timelines_server <- function(module_id,
239251
type = "message"
240252
)
241253
} else if (!is.null(receiver_id)) {
242-
afmm_param$utils$switch2(afmm_param$module_names[[receiver_id]])
254+
afmm_param$utils$switch2mod(receiver_id)
243255
}
244256
})
245257

@@ -294,7 +306,11 @@ mod_clinical_timelines_server <- function(module_id,
294306
#' (defaults to NULL, using the day of the earliest event to be displayed),
295307
#' \code{boxheight_val} contains a value between 30 and 150 defining the initial height of
296308
#' the individual timeline plot boxes at app launch (defaults to 60).
309+
#' @param color_palette `[character(1+) | NULL]`
297310
#'
311+
#' A named vector that specifies the colors for drawing events or intervals.
312+
#' Each name in the vector should correspond to an entry in the legend.
313+
#' If \code{NULL} (default), the default color palette is used.
298314
#' @param ms `[numeric(1)]`
299315
#'
300316
#' Single numeric value indicating how many milliseconds to wait before the plot
@@ -377,19 +393,22 @@ mod_clinical_timelines_server <- function(module_id,
377393
#' \item{\code{dataset_name}: Character name of the dataset that holds drug administration data
378394
#' (e.g. ex domain), as it is called in the datalist that is provided to the
379395
#' \pkg{modulemanager}.}
396+
#' \item{\code{trt_var}: Character name of the variable that contains the
397+
#' treatment name which must be present in the dataset mentioned in the
398+
#' \code{dataset_name} element.}
380399
#' \item{\code{start_var}: Character name of the variable that contains the start dates
381400
#' (e.g. exposure start dates) which must be present in the dataset mentioned in the
382-
#' \code{name} element.}
401+
#' \code{dataset_name} element.}
383402
#' \item{\code{end_var}: Character name of the variable that contains the end dates
384403
#' (e.g. exposure end dates) which must be present in the dataset mentioned in the
385-
#' \code{name} element.}
404+
#' \code{dataset_name} element.}
386405
#' \item{\code{detail_var}: Character name of the variable that contains the treatment
387-
#' information. Must exist in the dataset mentioned in the \code{name} element.}
406+
#' information. Must exist in the dataset mentioned in the \code{dataset_name} element.}
388407
#' \item{\code{label}: Free-text character label for the drug administration event.}
389408
#' \item{\code{dose_var}: Character name of the variable that contains the dosis level
390-
#' information. Must exist in the dataset mentioned in the \code{name} element.}
409+
#' information. Must exist in the dataset mentioned in the \code{dataset_name} element.}
391410
#' \item{\code{dose_unit_var}: Character name of the variable that contains the dosis
392-
#' unit. Must exist in the dataset mentioned in the \code{name} element.}
411+
#' unit. Must exist in the dataset mentioned in the \code{dataset_name} element.}
393412
#' }
394413
#'
395414
#' \cr
@@ -443,6 +462,7 @@ mod_clinical_timelines <- function(module_id,
443462
start_day = NULL,
444463
boxheight_val = 60
445464
),
465+
color_palette = NULL,
446466
ms = 1000,
447467
receiver_id = NULL) {
448468
# Check validity of arguments that won't be checked in UI/server
@@ -481,6 +501,7 @@ mod_clinical_timelines <- function(module_id,
481501
filter = filter,
482502
subjid_var = subjid_var,
483503
start_day = default_plot_settings$start_day,
504+
color_palette = color_palette,
484505
ms = ms,
485506
receiver_id = receiver_id,
486507
afmm_param = list(utils = afmm$utils, module_names = afmm$module_names)

R/mod_main_view.R

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,19 @@ mod_main_view_server <- function(module_id, initial_data, changed,
194194
cache$date_day_range <<- list(
195195
date = c(
196196
min(initial_data()$date_min),
197-
max(c(initial_data()$end_dt_var, initial_data()$end_exp), na.rm = TRUE)
197+
max(c(
198+
initial_data()$start_dt_var,
199+
initial_data()$end_dt_var,
200+
initial_data()$start_exp,
201+
initial_data()$end_exp
202+
), na.rm = TRUE)
198203
),
199-
day = c(start_day, max(c(initial_data()$end_dy_var, initial_data()$end_exp_day), na.rm = TRUE))
204+
day = c(start_day, max(c(
205+
initial_data()$start_dy_var,
206+
initial_data()$end_dy_var,
207+
initial_data()$start_exp_day,
208+
initial_data()$end_exp_day
209+
), na.rm = TRUE))
200210
)
201211
}
202212

@@ -358,6 +368,22 @@ mod_main_view_server <- function(module_id, initial_data, changed,
358368
subject
359369
})
360370

371+
testing <- isTRUE(getOption("shiny.testmode"))
372+
if (testing) {
373+
subject_id_orig <- subject_id
374+
375+
trigger <- shiny::reactiveVal(0)
376+
shiny::observeEvent(input[["debug_select_subject"]], trigger(trigger() + 1))
377+
subject_id <- shiny::reactive({
378+
res <- NULL
379+
if (trigger()) {
380+
res <- shiny::isolate(input[["debug_select_subject"]])
381+
} else {
382+
res <- subject_id_orig()
383+
}
384+
return(res)
385+
})
386+
}
361387

362388
# For exchange with receiver module
363389
return(

0 commit comments

Comments
 (0)