---
title: CMT01A
subtitle: Concomitant Medications by Medication Class and Preferred Name
---
------------------------------------------------------------------------
{{< include ../../_utils/envir_hook.qmd >}}
```{r setup, echo = FALSE, warning = FALSE, message = FALSE}
library(dplyr)
library(tern)
adsl <- random.cdisc.data::cadsl
adcm <- random.cdisc.data::cadcm
adcm$CMSEQ <- as.factor(adcm$CMSEQ)
adsl <- df_explicit_na(adsl)
adcm <- df_explicit_na(adcm)
# Keep only safety-evaluable patients and concomitant medications
adsl <- adsl %>%
filter(SAFFL == "Y")
adcm <- adcm %>%
filter(SAFFL == "Y" & ATIREL == "CONCOMITANT") %>%
var_relabel(CMDECOD = "Other Treatment")
```
```{r include = FALSE}
webr_code_labels <- c("setup")
```
{{< include ../../_utils/webr_no_include.qmd >}}
## Output
::::::: panel-tabset
## Standard Table, <br/> Safety-Evaluable Patients
::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview
```{r variant1, test = list(result_v1 = "result")}
split_fun <- drop_split_levels
lyt <- basic_table(show_colcounts = TRUE) %>%
split_cols_by("ACTARM") %>%
analyze_num_patients(
vars = "USUBJID",
count_by = "CMSEQ",
.stats = c("unique", "nonunique"),
.labels = c(
unique = "Total number of patients with at least one treatment",
nonunique = "Total number of treatments"
)
) %>%
split_rows_by(
"ATC2",
child_labels = "visible",
nested = FALSE,
split_fun = split_fun,
label_pos = "topleft",
split_label = obj_label(adcm$ATC2)
) %>%
summarize_num_patients(
var = "USUBJID",
count_by = "CMSEQ",
.stats = c("unique", "nonunique"),
.labels = c(
unique = "Total number of patients with at least one treatment",
nonunique = "Total number of treatments"
)
) %>%
count_occurrences(vars = "CMDECOD", .indent_mods = -1L) %>%
append_varlabels(adcm, "CMDECOD", indent = 1L)
result <- build_table(lyt = lyt, df = adcm, alt_counts_df = adsl) %>%
prune_table() %>%
# Sort lowest level terms by descending frequency.
sort_at_path(
path = c("ATC2", "*", "CMDECOD"),
scorefun = score_occurrences
)
result
```
```{r include = FALSE}
webr_code_labels <- c("variant1")
```
{{< include ../../_utils/webr.qmd >}}
:::
## Table Changing <br/> ATC Class Level
::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview
```{r variant2, test = list(result_v2 = "result")}
split_fun <- drop_split_levels
lyt <- basic_table(show_colcounts = TRUE) %>%
split_cols_by("ACTARM") %>%
analyze_num_patients(
vars = "USUBJID",
count_by = "CMSEQ",
.stats = c("unique", "nonunique"),
.labels = c(
unique = "Total number of patients with at least one treatment",
nonunique = "Total number of treatments"
)
) %>%
split_rows_by(
"ATC1",
child_labels = "visible",
nested = FALSE,
split_fun = split_fun,
label_pos = "topleft",
split_label = obj_label(adcm$ATC1)
) %>%
summarize_num_patients(
var = "USUBJID",
count_by = "CMSEQ",
.stats = c("unique", "nonunique"),
.labels = c(
unique = "Total number of patients with at least one treatment",
nonunique = "Total number of treatments"
)
) %>%
count_occurrences(vars = "CMDECOD", .indent_mods = -1L) %>%
append_varlabels(adcm, "CMDECOD", indent = 1L)
result <- build_table(lyt = lyt, df = adcm, alt_counts_df = adsl) %>%
prune_table() %>%
# Sort lowest level terms by descending frequency.
sort_at_path(
path = c("ATC1", "*", "CMDECOD"),
scorefun = score_occurrences
)
result
```
```{r include = FALSE}
webr_code_labels <- c("variant2")
```
{{< include ../../_utils/webr.qmd >}}
:::
## Table with Classes <br/> Sorted by Frequency
::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview
```{r variant3, test = list(result_v3 = "result")}
split_fun <- drop_split_levels
lyt <- basic_table(show_colcounts = TRUE) %>%
split_cols_by("ACTARM") %>%
analyze_num_patients(
vars = "USUBJID",
count_by = "CMSEQ",
.stats = c("unique", "nonunique"),
.labels = c(
unique = "Total number of patients with at least one treatment",
nonunique = "Total number of treatments"
)
) %>%
split_rows_by(
"ATC2",
child_labels = "visible",
nested = FALSE,
split_fun = split_fun,
label_pos = "topleft",
split_label = obj_label(adcm$ATC2)
) %>%
summarize_num_patients(
var = "USUBJID",
count_by = "CMSEQ",
.stats = c("unique", "nonunique"),
.labels = c(
unique = "Total number of patients with at least one treatment",
nonunique = "Total number of treatments"
)
) %>%
count_occurrences(vars = "CMDECOD", .indent_mods = -1L) %>%
append_varlabels(adcm, "CMDECOD", indent = 1L)
result <- build_table(lyt = lyt, df = adcm, alt_counts_df = adsl) %>%
prune_table() %>%
sort_at_path(path = c("ATC2"), scorefun = cont_n_allcols) %>%
sort_at_path(path = c("ATC2", "*", "CMDECOD"), scorefun = score_occurrences)
result
```
```{r include = FALSE}
webr_code_labels <- c("variant3")
```
{{< include ../../_utils/webr.qmd >}}
:::
## Table with Total Number of Treatments <br/> per Medication Class Suppressed
::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview
```{r variant4, test = list(result_v4 = "result")}
split_fun <- drop_split_levels
lyt <- basic_table(show_colcounts = TRUE) %>%
split_cols_by("ACTARM") %>%
analyze_num_patients(
vars = "USUBJID",
count_by = "CMSEQ",
.stats = c("unique", "nonunique"),
.labels = c(
unique = "Total number of patients with at least one treatment",
nonunique = "Total number of treatments"
)
) %>%
split_rows_by(
"ATC2",
child_labels = "visible",
nested = FALSE,
split_fun = split_fun,
label_pos = "topleft",
split_label = obj_label(adcm$ATC2)
) %>%
summarize_num_patients(
var = "USUBJID",
count_by = "CMSEQ",
.stats = c("unique"),
.labels = c(
unique = "Total number of patients with at least one treatment"
)
) %>%
count_occurrences(vars = "CMDECOD", .indent_mods = -1L) %>%
append_varlabels(adcm, "CMDECOD", indent = 1L)
result <- build_table(lyt = lyt, df = adcm, alt_counts_df = adsl) %>%
prune_table() %>%
# Sort lowest level terms by descending frequency.
sort_at_path(
path = c("ATC2", "*", "CMDECOD"),
scorefun = score_occurrences
)
result
```
```{r include = FALSE}
webr_code_labels <- c("variant4")
```
{{< include ../../_utils/webr.qmd >}}
:::
## Data Setup
```{r setup}
#| code-fold: show
```
:::::::
{{< include ../../_utils/save_results.qmd >}}
## `teal` App
::: {.panel-tabset .nav-justified}
## {{< fa regular file-lines fa-sm fa-fw >}} Preview
```{r teal, opts.label = c("skip_if_testing", "app")}
library(teal.modules.clinical)
adcm_keys <- c("STUDYID", "USUBJID", "ASTDTM", "CMSEQ", "ATC1", "ATC2", "ATC3", "ATC4")
## Data reproducible code
data <- teal_data()
data <- within(data, {
ADSL <- random.cdisc.data::cadsl
ADCM <- random.cdisc.data::cadcm
ADCM$CMSEQ <- as.integer(ADCM$CMSEQ)
ADSL <- df_explicit_na(ADSL)
ADCM <- df_explicit_na(ADCM)
})
datanames <- c("ADSL", "ADCM")
names(data) <- datanames
join_keys(data) <- default_cdisc_join_keys[datanames]
join_keys(data)["ADCM", "ADCM"] <- adcm_keys
## Reusable Configuration For Modules
ADCM <- data[["ADCM"]]
## Setup App
app <- init(
data = data,
modules = modules(
tm_t_mult_events(
label = "Concomitant Medications by Medication Class and Preferred Name",
dataname = "ADCM",
arm_var = choices_selected(c("ARM", "ARMCD"), "ARM"),
seq_var = choices_selected("CMSEQ", selected = "CMSEQ", fixed = TRUE),
hlt = choices_selected(
choices = variable_choices(ADCM, c("ATC1", "ATC2", "ATC3", "ATC4")),
selected = c("ATC2")
),
llt = choices_selected(
choices = variable_choices(ADCM, c("CMDECOD")),
selected = c("CMDECOD")
),
add_total = FALSE,
event_type = "treatment"
)
),
filter = teal_slices(
teal_slice("ADSL", "SAFFL", selected = "Y"),
teal_slice("ADCM", "ATIREL", selected = "CONCOMITANT")
)
)
shinyApp(app$ui, app$server)
```
{{< include ../../_utils/shinylive.qmd >}}
:::
{{< include ../../repro.qmd >}}