Skip to content

Commit 31d35f6

Browse files
committed
add to specs.R and create corresponding test
1 parent a32be6d commit 31d35f6

4 files changed

Lines changed: 150 additions & 1 deletion

File tree

R/mod_patient_profile.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,13 @@ mod_patient_profile <- function(module_id = "",
356356
grading_vals <- get_grading_vals(plots[["range_plots"]], afmm[["data"]])
357357
plots[["palette"]] <- fill_palette(grading_vals, plots[["palette"]])
358358

359+
testing <- isTRUE(getOption("shiny.testmode"))
360+
if (testing) {
361+
filled_palette <<- plots[["palette"]]
362+
gradings <<- grading_vals
363+
shiny::exportTestValues(gradings = gradings, filled_palette = filled_palette)
364+
}
365+
359366
filtered_mapped_datasets <- shiny::reactive(
360367
T_honor_map_to_flag(afmm$filtered_dataset(), mod_patient_profile_API, args)
361368
)

inst/validation/specs.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ specs <- list(
2222
common = list(
2323
tooltips = "Hovering over salient plot elements provides extra information",
2424
palettes = "Plots can be customized by assigning specific colors to elements denoted by text strings",
25-
no_data_message = "Plots explain there is no data when there is no data"
25+
no_data_message = "Plots explain there is no data when there is no data",
26+
palette_is_filled = "Color palette will be completed with colors for all grading values if any are missing."
2627
),
2728
value = list(
2829
parameter_selection = "User can select parameters for value plots"
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
dataset_list <- list("demo" = dv.papo:::prep_safety_data(5))
2+
3+
module_list <- list(
4+
"Papo" = dv.papo::mod_patient_profile(
5+
module_id = "grading_app", subjid_var = "USUBJID", sender_ids = NULL,
6+
subject_level_dataset_name = "adsl",
7+
summary = list(
8+
vars = c("SITEID", "AGE", "SEX", "RACE", "ETHNIC", "ARM", "DCREASCD", "TRT01A"),
9+
column_count = 3
10+
),
11+
plots = list(
12+
timeline_info = c(
13+
trt_start_date = "TRTSDT",
14+
trt_end_date = "TRTEDT",
15+
icf_date = "RFICDT", # optional
16+
part_end_date = "RFENDT" # optional
17+
),
18+
vline_vars = c(
19+
"Informed Consent Day" = "RFICDT", # because optional above
20+
# "Study Treatment Start Day" = "TRTSDT", #added by me
21+
"Study Treatment Stop Day" = "TRTEDT"
22+
),
23+
vline_day_numbers = c("Study Treatment Start Day : Day 1" = 1), # optional
24+
range_plots = list(
25+
"Adverse Events Plot" = list(
26+
dataset = "adae",
27+
vars = c(
28+
start_date = "ASTDT",
29+
end_date = "AENDT",
30+
decode = "AEDECOD",
31+
grading = "AESEV", # optional
32+
serious_ae = "AESER" # optional
33+
),
34+
tooltip = c(
35+
"AE Term: " = "AEDECOD",
36+
"AE Reported Term: " = "AETERM",
37+
"Primary SOC: " = "AESOC",
38+
"Intensity: " = "AESEV",
39+
"Serious Event: " = "AESER",
40+
"AE Start Date: " = "ASTDT",
41+
"AE Stop Date: " = "AENDT",
42+
"AE Start Day: " = "ASTDY",
43+
"AE Stop Day: " = "AENDY"
44+
)
45+
),
46+
"Concomitant Medication Plot" = list(
47+
dataset = "cm",
48+
vars = c(
49+
start_date = "CMSTDT",
50+
end_date = "CMENDT",
51+
decode = "CMDECOD",
52+
grading = "CMINDC"
53+
),
54+
tooltip = c(
55+
"Standardized Medication Name: " = "CMDECOD",
56+
"Indication: " = "CMINDC",
57+
"CM Dose: " = "CMDOSE",
58+
"CM Dose Unit: " = "CMDOSU",
59+
"CM START Date: " = "CMSTDTC",
60+
"CM End Date: " = "CMENDTC",
61+
"CM START Day: " = "CMSTDY",
62+
"CM END Day: " = "CMENDY"
63+
)
64+
)
65+
),
66+
value_plots = list(
67+
"Lab plot" = list(
68+
dataset = "lb",
69+
vars = c(
70+
analysis_param = "PARAM",
71+
analysis_val = "AVAL",
72+
analysis_date = "ADT",
73+
analysis_indicator = "ANRIND",
74+
range_low_limit = "A1LO",
75+
range_high_limit = "A1HI"
76+
),
77+
tooltip = c(
78+
"Lab Parameter: " = "PARAM",
79+
"Lab Test Date: " = "ADT",
80+
"Lab Test Visit :" = "AVISIT",
81+
"<br>High Limit: " = "A1HI",
82+
"Lab Standard Value: " = "AVAL",
83+
"Lower Limit: " = "A1LO",
84+
"<br>Analysis Indicator: " = "ANRIND"
85+
)
86+
),
87+
"Vital Sign Plot" = list(
88+
dataset = "vs",
89+
vars = c(
90+
analysis_param = "PARAM",
91+
analysis_val = "AVAL",
92+
analysis_date = "ADT",
93+
analysis_indicator = "VISIT",
94+
range_low_limit = NULL,
95+
range_high_limit = NULL,
96+
summary_stats = "AVAL_MEAN"
97+
),
98+
tooltip = c(
99+
"Vital sign Parameter: " = "PARAM",
100+
"Vital sign Date: " = "ADT",
101+
"Vital sign Visit: " = "AVISIT",
102+
"<br>Vital sign Value: " = "AVAL",
103+
"Vital sign mean value by visits: " = "AVAL_MEAN"
104+
)
105+
)
106+
)
107+
)
108+
)
109+
)
110+
111+
dv.manager::run_app(
112+
data = dataset_list,
113+
module_list = module_list,
114+
filter_data = "adsl"
115+
)

tests/testthat/test-all.R

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,3 +350,29 @@ test_that(
350350
app$stop()
351351
}
352352
)
353+
354+
test_that(
355+
"Color palette is filled when there are missing entries for grading values" |>
356+
vdoc[["add_spec"]](c(specs$plots$common$palette_is_filled)), {
357+
358+
app <- shinytest2::AppDriver$new(
359+
app_dir = "apps/grading_palette_colors/",
360+
name = "grading_colors_app"
361+
)
362+
363+
app_grading_vals <- setdiff(app$get_value(export = "gradings"), NA)
364+
app_filled_palette <- app$get_value(export = "filled_palette")
365+
366+
expect_true(all(app_grading_vals %in% names(app_filled_palette))) # check all grading vals present in palette.
367+
368+
grading_palette <- app_filled_palette[app_grading_vals]
369+
expect_length(grading_palette |> unique, length(app_grading_vals))
370+
371+
#check colors were filled.
372+
# i. check which grading vals had no color assigned in CONST default palette
373+
unmapped_grading_vals <- setdiff(app_grading_vals, names(dv.papo:::CONST$default_palette))
374+
375+
# ii. check a color was then assigned.
376+
expect_length(grading_palette[unmapped_grading_vals], length(unmapped_grading_vals))
377+
378+
})

0 commit comments

Comments
 (0)