---
title: CMT02_PT
subtitle: Concomitant Medications by Preferred Name (WHODrug Coding)
---
------------------------------------------------------------------------
{{< 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)
# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels.
# If you want your missing levels to show as "No Coding Available", please use
adsl <- df_explicit_na(adsl, na_level = "No Coding Available")
adcm <- df_explicit_na(adcm, na_level = "No Coding Available")
# Keep only safety-evaluable patients and concomitant medications
adsl <- adsl %>%
filter(SAFFL == "Y")
# Keep only concomitant medications
adcm <- adcm %>% filter(ATIREL == "CONCOMITANT")
```
```{r include = FALSE}
webr_code_labels <- c("setup")
```
{{< include ../../_utils/webr_no_include.qmd >}}
## Output
:::: panel-tabset
## Standard Table
::: {.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") %>%
add_overall_col("All Patients") %>%
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"
),
show_labels = "hidden"
) %>%
count_occurrences(vars = "CMDECOD") %>%
append_topleft(paste("\nOther Treatment"))
result <- build_table(lyt = lyt, df = adcm, alt_counts_df = adsl) %>%
sort_at_path(
path = c("CMDECOD"),
scorefun = score_occurrences
)
result
```
```{r include = FALSE}
webr_code_labels <- c("variant1")
```
{{< 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("ATC1")
),
llt = choices_selected(
choices = variable_choices(ADCM, c("CMDECOD")),
selected = c("CMDECOD")
),
add_total = TRUE,
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 >}}