## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  comment = "#>",
  collapse = TRUE,
  out.width = "100%",
  dpi = 150
)

## ----setup, message=FALSE-----------------------------------------------------
library(metalite.sl)
library(metalite.ae)
library(metalite)
library(dplyr)

## -----------------------------------------------------------------------------
adsl <- metalite_sl_adsl
adae <- metalite_sl_adae

ae_plan <- plan(
  analysis = "ae_specific",
  population = "apat",
  observation = "wk12",
  parameter = "any"
)

metadata_ae <- meta_adam(observation = adae, population = adsl) |>
  define_plan(ae_plan) |>
  define_population(
    name = "apat",
    group = "TRTA",
    subset = SAFFL == "Y",
    label = "All Participants as Treated"
  ) |>
  define_observation(
    name = "wk12",
    group = "TRTA",
    subset = SAFFL == "Y",
    label = "Weeks 0 to 12"
  ) |>
  define_parameter(
    name = "any",
    term1 = "",
    term2 = "",
    var = "AEDECOD",
    soc = "AEBODSYS",
    label = "All AEs"
  ) |>
  define_analysis(
    name = "ae_specific",
    title = "Participants With Adverse Events"
  ) |>
  meta_build()

head(adsl)

## -----------------------------------------------------------------------------
plan <- plan(
  analysis = "disp", population = "apat",
  observation = "apat", parameter = "disposition;medical-disposition"
)

## -----------------------------------------------------------------------------
meta <- meta_adam(
  population = adsl,
  observation = adsl
) |>
  define_plan(plan = plan) |>
  define_population(
    name = "apat",
    group = "TRTA",
    subset = quote(SAFFL == "Y")
  ) |>
  define_parameter(
    name = "disposition",
    var = "EOSSTT",
    label = "Trial Disposition",
    var_lower = "DCSREAS"
  ) |>
  define_parameter(
    name = "medical-disposition",
    var = "EOTSTT",
    label = "Participant Study Medication Disposition",
    var_lower = "DCTREAS"
  ) |>
  define_analysis(
    name = "disp",
    title = "Disposition of Participant",
    label = "disposition table"
  ) |>
  meta_build()

## -----------------------------------------------------------------------------
react_disposition(
  metadata_sl = meta,
  metadata_ae = metadata_ae,
  width = 1200
)

