---
title: EUDRAT02
subtitle: Serious Adverse Events, Fatal Serious Adverse Events, and Serious Adverse Events Related to Study Medication
---
------------------------------------------------------------------------
{{< include ../../_utils/envir_hook.qmd >}}
```{r setup, echo = FALSE, warning = FALSE, message = FALSE}
library(tern)
library(dplyr)
adae <- random.cdisc.data::cadae
# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels.
adae <- df_explicit_na(adae)
adae_serious <- adae %>% filter(AESER == "Y", SAFFL == "Y")
adae_serious_arm <- adae_serious %>% filter(ARM == "A: Drug X")
filters_list <- list(
related = with_label(c(AEREL = "Y"), "Events (Related)"),
fatal = with_label(c(AESDTH = "Y"), "Events (Fatal)"),
fatal_related = with_label(c(AEREL = "Y", AESDTH = "Y"), "Events (Fatal & Related)")
)
```
```{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")}
# Define the split function
split_fun <- drop_split_levels
lyt <- basic_table() %>%
summarize_patients_events_in_cols(
filters_list = filters_list,
empty_stats = c("all", "related", "fatal", "fatal_related"),
custom_label = "Total number of patients with at least one serious adverse event"
) %>%
split_rows_by("AEBODSYS",
nested = FALSE,
split_fun = split_fun,
indent_mod = -1L,
label_pos = "topleft",
split_label = obj_label(adae_serious_arm$AEBODSYS)
) %>%
split_rows_by("AEDECOD",
split_fun = split_fun,
label_pos = "topleft",
split_label = obj_label(adae_serious_arm$AEDECOD)
) %>%
summarize_patients_events_in_cols(
filters_list = filters_list,
col_split = FALSE
)
result <- build_table(lyt, adae_serious_arm)
result
```
```{r include = FALSE}
webr_code_labels <- c("variant1")
```
{{< include ../../_utils/webr.qmd >}}
:::
## Data Setup
For illustrative purposes, the `adae` data is filtered by arm `A: Drug X` here.
```{r setup}
#| code-fold: show
```
::::
{{< include ../../_utils/save_results.qmd >}}
{{< include ../../repro.qmd >}}