Merck/metalite.ae

Display item if AE term has `NA` in AE specific

Closed this issue · 4 comments

Display item if AE term has `NA` in AE specific

Let's leave this for our 2nd CRAN release.

Could we show the desired output in the task description?

In the PR #166 , this promblem is address. To try out the new NULL feature, please run the following code:

library(metalite)
library(metalite.ae)
# --------------- #
#   ADSL data
# --------------- #
adsl <- r2rtf::r2rtf_adsl
adsl$TRTA <- adsl$TRT01A
adsl$TRTA <- factor(
  adsl$TRTA,
  levels = c("Placebo", "Xanomeline Low Dose", "Xanomeline High Dose"),
  labels = c("Placebo", "Low Dose", "High Dose")
)
adsl$RACE <- tools::toTitleCase(adsl$RACE)

# --------------- #
#    ADAE data
# --------------- #
adae <- r2rtf::r2rtf_adae

adae$TRTA <- factor(
  adae$TRTA,
  levels = c("Placebo", "Xanomeline Low Dose", "Xanomeline High Dose"),
  labels = c("Placebo", "Low Dose", "High Dose")
)
adae$RACE <- tools::toTitleCase(adae$RACE)

# Manually add NULL to AEDECOD and AEBODSYS
# !! THIS IS THE ONLY DIFFERENCE with meta_ae_example() 
adae$AEDECOD[1:5] <- NA
adae$AEBODSYS[1:5] <- NA

# Drug-related AE values
adae$related <- ifelse(
  adae$AEREL == "RELATED",
  "Y",
  ifelse(
    toupper(adae$AEREL) == "NOT RELATED",
    "N",
    tools::toTitleCase(tolower(adae$AEREL))
  )
)
# AE outcome
for (i in seq_along(adae$AEOUT)) {
  adae$outcome <- switch(adae$AEOUT[i],
                         "RECOVERED/RESOLVED" = "Resolved",
                         "RECOVERING/RESOLVING" = "Resolving",
                         "RECOVERED/RESOLVED WITH SEQUELAE" = "Sequelae",
                         "NOT RECOVERED/NOT RESOLVED" = "Not Resolved",
                         tools::toTitleCase(tolower(adae$AEOUT[i]))
  )
}
# AE action
adae$AEACN <- gsub("", "DOSE NOT CHANGED", adae$AEACN)
for (i in seq_along(adae$AEACN)) {
  adae$action_taken[i] <- switch(adae$AEACN[i],
                                 "DOSE NOT CHANGED" = "None",
                                 "DOSE REDUCED" = "Reduced",
                                 "DRUG INTERRUPTED" = "Interrupted",
                                 "DOSE INCREASED" = "Increased",
                                 "NOT APPLICABLE" = "N/A",
                                 "UNKNOWN" = "Unknown",
                                 "''" = "None",
                                 tools::toTitleCase(tolower(adae$AEACN[i]))
  )
}
# AE duration with unit
adae$duration <- paste(
  ifelse(
    is.na(adae$ADURN),
    "",
    as.character(adae$ADURN)
  ),
  tools::toTitleCase(tolower(adae$ADURU)),
  sep = " "
)
for (i in seq_along(adae$duration)) {
  if (is.na(adae$ADURN[i])) {
    adae$duration[i] <- ifelse(
      charmatch(toupper(adae$AEOUT[i]), "RECOVERING/RESOLVING") > 0 |
        charmatch(toupper(adae$AEOUT[i]), "NOT RECOVERED/NOT RESOLVED") > 0,
      "Continuing",
      "Unknown"
    )
  }
}

# AE subject line
adae$subline <- paste0(
  "Subject ID = ", adae$USUBJID,
  ", Gender = ", adae$SEX,
  ", Race = ", adae$RACE,
  ", AGE = ", adae$AGE, " Years",
  ", TRT = ", adae$TRTA
)

# Assign label
adae <- metalite::assign_label(
  adae,
  var = c("related", "outcome", "duration", "AESEV", "AESER", "AEDECOD", "action_taken"),
  label = c("Related", "Outcome", "Duration", "Intensity", "Serious", "Adverse Event", "Action Taken")
)




# --------------- #
# Define plan  
# --------------- #
plan <- plan(
  analysis = "ae_summary", population = "apat",
  observation = c("wk12", "wk24"), parameter = "any;rel;ser"
) |>
  add_plan(
    analysis = "ae_specific", population = "apat",
    observation = c("wk12", "wk24"),
    parameter = c("any", "aeosi", "rel", "ser")
  ) |>
  add_plan(
    analysis = "ae_listing", population = "apat",
    observation = c("wk12", "wk24"), parameter = c("any", "rel", "ser")
  ) |>
  add_plan(
    analysis = "ae_exp_adj", population = "apat",
    observation = c("wk12", "wk24"), parameter = "any;rel;ser"
  )

# --------------- #
# Create meta_adam
# --------------- #
meta <- meta_adam(
  population = adsl,
  observation = adae
) |>
  define_plan(plan = plan) |>
  define_population(
    name = "apat",
    group = "TRTA",
    subset = quote(SAFFL == "Y")
  ) |>
  define_observation(
    name = "wk12",
    group = "TRTA",
    subset = quote(SAFFL == "Y"),
    label = "Weeks 0 to 12"
  ) |>
  define_observation(
    name = "wk24",
    group = "TRTA",
    subset = quote(AOCC01FL == "Y"), # Just for demo, another flag should be used
    label = "Weeks 0 to 24"
  ) |>
  define_parameter(
    name = "rel",
    subset = quote(AEREL %in% c("POSSIBLE", "PROBABLE"))
  ) |>
  define_parameter(
    name = "aeosi",
    subset = quote(AEOSI == "Y"),
    var = "AEDECOD",
    soc = "AEBODSYS",
    term1 = "",
    term2 = "of special interest",
    label = "adverse events of special interest"
  ) |>
  define_analysis(
    name = "ae_summary",
    title = "Summary of Adverse Events"
  ) |>
  define_analysis(
    name = "ae_listing",
    var_name = c(
      "USUBJID", "ASTDY", "AEDECOD", "duration",
      "AESEV", "AESER", "related", "action_taken", "outcome"
    ),
    subline_by = NULL,
    group_by = c("USUBJID", "ASTDY"),
    page_by = c("TRTA", "subline")
  ) |>
  define_analysis(
    name = "ae_exp_adj",
    label = "Exposure Adjusted Incident Rate",
    title = "Exposure-Adjusted Adverse Event Summary"
  ) |>
  meta_build()



x <- prepare_ae_specific(
  meta,
  population = "apat",
  observation = "wk12",
  parameter = "rel"
  ) |> 
  format_ae_specific() |>
  tlf_ae_specific(
    source = "Source:  [CDISCpilot: adam-adsl; adae]",
    meddra_version = "24.0",
    path_outdata = "./test.Rdata",
    path_outtable = "./test.rtf")
  )

And you will get a table like this (I only show the last few rows of the table):
image