Repository: pharmaverse/admiralneuro
Pull request #23: Closes #20 test data admiralneuro_adsl
Author: login: Fanny-Gautier
Created: 2025-05-05T13:29:30Z | Merged: 2025-05-14T07:45:40Z

Thank you for your Pull Request! We have developed this task checklist from the [Development Process Guide](https://pharmaverse.github.io/admiral/CONTRIBUTING.html#detailed-development-process) to help with the final steps of the process. Completing the below tasks helps to ensure our reviewers can maximize their time on your code as well as making sure the admiral family codebase remains robust and consistent.   

Please check off each taskbox as an acknowledgment that you completed the task or check off that it is not relevant to your Pull Request. This checklist is part of the Github Action workflows and the Pull Request will not be merged into the `main` branch until you have checked off each task.

- [x] Place Closes #<insert_issue_number> into the beginning of your Pull Request Title (Use Edit button in top-right if you need to update)
- [x] Code is formatted according to the [tidyverse style guide](https://style.tidyverse.org/). Run `styler::style_file()` to style R and Rmd files
- [x] Updated relevant unit tests or have written new unit tests, which should consider realistic data scenarios and edge cases, e.g. empty datasets, errors, boundary cases etc. - See [Unit Test Guide](https://pharmaverse.github.io/admiraldev/articles/unit_test_guidance.html#tests-should-be-robust-to-cover-realistic-data-scenarios)
- [x] If you removed/replaced any function and/or function parameters, did you fully follow the [deprecation guidance](https://pharmaverse.github.io/admiraldev/articles/programming_strategy.html#deprecation)?
- [x] Update to all relevant roxygen headers and examples, including keywords and families. Refer to the [categorization of functions](https://pharmaverse.github.io/admiraldev/articles/programming_strategy.html#categorization-of-functions) to tag appropriate keyword/family.
- [x] Run `devtools::document()` so all `.Rd` files in the `man` folder and the `NAMESPACE` file in the project root are updated appropriately
- [x] Address any updates needed for vignettes and/or templates
- [x] Update `NEWS.md` under the header `# admiral<ext> (development version)` if the changes pertain to a user-facing function (i.e. it has an `@export` tag) or documentation aimed at users (rather than developers)
- [x] Build site `pkgdown::build_site()` and check that all affected examples are displayed correctly and that all new functions occur on the Reference page. 
- [x] Address or fix all lintr warnings and errors - `lintr::lint_package()`
- [x] Run `R CMD check` locally and address all errors and warnings - `devtools::check()`
- [x] Link the issue in the Development Section on the right hand side.
- [x] Address all merge conflicts and resolve appropriately
- [x] Pat yourself on the back for a job well done! Much love to your accomplishment!


Linked issue #20: Test data: `admiralneuro_adsl`
Create a very simple `admiralneuro_adsl` based on `dm_neuro` with all vars needed for a standard BDS template to work (from [here](https://github.com/pharmaverse/admiral/blob/main/inst/templates/ad_advs.R), looks like TRTSDT. TRTESDT, TRT01A, TRT01P, etc).
Linked issue comments: user: login: Fanny-Gautier
created_at: 2025-05-02T10:32:07Z
body: @pharmaverse/admiralneuro should I use `EX` domain to create the Treatment Start and Treatment End dates and apply updates for the patients where `DM.ARMNRS = 'Observational Study'` or is it ok to use on `DM_NEURO` only ?
author_association: CONTRIBUTOR
user: login: Fanny-Gautier
created_at: 2025-05-02T10:34:09Z
body: @manciniedoardo should I first create it in [`data`](https://github.com/pharmaverse/admiralneuro/tree/main/data) that the team can use it while developing `ADPET`? 
author_association: CONTRIBUTOR
user: login: manciniedoardo
created_at: 2025-05-02T10:44:34Z
body: @Fanny-Gautier If `pharmaversesdtm::ex` has the right records for our neuro patients in `dm_neuro`, then you could use that to derive trt dates. I think the files and datasets for `admiralneuro_adsl` should follow the same convention as what we have done for our SDTM data.
author_association: COLLABORATOR

Diff:
diff --git a/R/data.R b/R/data.R
index aac5725..1eb6c3c 100644
--- a/R/data.R
+++ b/R/data.R
@@ -106,3 +106,10 @@
 #'  }
 #' @source Constructed using `nv_neuro` from `{admiralneuro}` package
 "ag_neuro"
+
+#' Subject Level Analysis Dataset-updated
+#'
+#' An updated ADaM ADSL dataset with Alzheimer's Disease patients
+#' @keywords datasets
+#' @family datasets
+"adsl_neuro"
diff --git a/data-raw/adsl_neuro.R b/data-raw/adsl_neuro.R
new file mode 100644
index 0000000..5a55106
--- /dev/null
+++ b/data-raw/adsl_neuro.R
@@ -0,0 +1,161 @@
+# Dataset: adsl_neuro
+# Description: Create ADSL test Analysis Dataset for Alzheimer's Disease (Neuro)
+
+# Load libraries -----
+library(admiral)
+library(pharmaversesdtm) # Contains example datasets from the CDISC pilot project
+library(dplyr)
+library(lubridate)
+library(stringr)
+
+# Read input test data from pharmaversesdtm ----
+data(dm_neuro)
+ex <- pharmaversesdtm::ex
+
+# Convert blank to NA ----
+dm_neuro <- convert_blanks_to_na(dm_neuro)
+ex <- convert_blanks_to_na(ex)
+
+# Select patients from DM Neuro only
+dm_neuro_pat <- dm_neuro %>%
+  pull(unique(USUBJID))
+
+ex <- ex %>%
+  filter(USUBJID %in% dm_neuro_pat)
+
+# Derive Treatment Variables ----
+adsl <- dm_neuro %>%
+  # Select all necessary variables only
+  select(
+    STUDYID, USUBJID, SUBJID, SITEID, COUNTRY, AGE, AGEU, SEX, RACE, ETHNIC, ARM,
+    ARMCD, ACTARM, ACTARMCD, ARMNRS, DTHDTC, DTHFL
+  ) %>%
+  mutate(
+    TRT01P = if_else(!is.na(ARMNRS), "No Treatment", ARM),
+    TRT01PN = case_when(
+      TRT01P == "No Treatment" ~ 3,
+      TRT01P == "Placebo" ~ 2,
+      TRUE ~ 1
+    ),
+    TRT01A = if_else(!is.na(ARMNRS), "No Treatment", ACTARM),
+    TRT01AN = case_when(
+      TRT01A == "No Treatment" ~ 3,
+      TRT01A == "Placebo" ~ 2,
+      TRUE ~ 1
+    )
+  )
+
+# Treatment Start and End Dates ----
+ex_ext <- ex %>%
+  derive_vars_dtm(
+    dtc = EXSTDTC,
+    new_vars_prefix = "EXST"
+  ) %>%
+  derive_vars_dtm(
+    dtc = EXENDTC,
+    new_vars_prefix = "EXEN",
+    time_imputation = "last"
+  ) %>%
+  # Merge DM.ARMNRS to not derive treatment dates for these patients
+  left_join(dm_neuro %>% select(USUBJID, ARMNRS), by = "USUBJID")
+
+adsl <- adsl %>%
+  # Treatment Start Datetime
+  derive_vars_merged(
+    dataset_add = ex_ext,
+    filter_add = (is.na(ARMNRS)),
+    new_vars = exprs(TRTSDTM = EXSTDTM, TRTSTMF = EXSTTMF),
+    order = exprs(EXSTDTM, EXSEQ),
+    mode = "first",
+    by_vars = exprs(STUDYID, USUBJID)
+  ) %>%
+  # Treatment End Datetime
+  derive_vars_merged(
+    dataset_add = ex_ext,
+    filter_add = (is.na(ARMNRS)),
+    new_vars = exprs(TRTEDTM = EXENDTM, TRTETMF = EXENTMF),
+    order = exprs(EXENDTM, EXSEQ),
+    mode = "last",
+    by_vars = exprs(STUDYID, USUBJID)
+  ) %>%
+  # Convert Datetime variables to date
+  derive_vars_dtm_to_dt(source_vars = exprs(TRTSDTM, TRTEDTM)) %>%
+  # Treatment Start Time
+  derive_vars_dtm_to_tm(source_vars = exprs(TRTSDTM)) %>%
+  # Treatment Duration
+  derive_var_trtdurd()
+
+# Derive Age Grouping ----
+agegr1_lookup <- exprs(
+  ~condition,   ~AGEGR1, ~AGEGR1N,
+  is.na(AGE), "Missing",        3,
+  AGE < 65,       "<65",        1,
+  !is.na(AGE),   ">=65",        2
+)
+
+adsl <- derive_vars_cat(
+  dataset = adsl,
+  definition = agegr1_lookup
+)
+
+# Derive Intent-To-Treat and Safety Population Flags ----
+adsl <- adsl %>%
+  mutate(ITTFL = "Y") %>%
+  derive_var_merged_exist_flag(
+    dataset_add = adsl,
+    by_vars = exprs(STUDYID, USUBJID),
+    new_var = SAFFL,
+    false_value = "N",
+    condition = (!is.na(TRTSDT))
+  )
+
+# Derive DTHDT & DTHADY ----
+adsl <- adsl %>%
+  derive_vars_dt(
+    new_vars_prefix = "DTH",
+    dtc = DTHDTC,
+    highest_imputation = "M",
+    date_imputation = "first"
+  ) %>%
+  derive_vars_duration(
+    new_var = DTHADY,
+    start_date = TRTSDT,
+    end_date = DTHDT
+  )
+
+adsl_neuro <- adsl
+
+# Assign the labels for created variables
+labels <- list(
+  DTHDTC = "Date/Time of Death",
+  DTHFL = "Subject Death Flag",
+  TRT01P = "Planned Treatment for Period 01",
+  TRT01PN = "Planned Treatment for Period 01 (N)",
+  TRT01A = "Actual Treatment for Period 01",
+  TRT01AN = "Actual Treatment for Period 01 (N)",
+  TRTSDTM = "Datetime of First Exposure to Treatment",
+  TRTSTMF = "Time 1st Exposure Period Imput. Flag",
+  TRTEDTM = "Datetime of Last Exposure to Treatment",
+  TRTETMF = "Time Last Exposure Period Imput. Flag",
+  TRTSDT = "Date of First Exposure to Treatment",
+  TRTEDT = "Date of Last Exposure to Treatment",
+  TRTSTM = "Time of First Exposure to Treatment",
+  TRTDURD = "Treatment Duration",
+  AGEGR1 = "Pooled Age Group 1",
+  AGEGR1N = "Pooled Age Group 1 (N)",
+  ITTFL = "Intent-To-Treat Population Flag",
+  SAFFL = "Safety Population Flag",
+  DTHDT = "Date of Death",
+  DTHDTF = "Date of Death Imputation Flag",
+  DTHADY = "Relative Day of Death"
+)
+
+for (var in names(labels)) {
+  attr(adsl_neuro[[var]], "label") <- labels[[var]]
+}
+
+# Label dataset ----
+attr(adsl_neuro, "label") <- "Subject-Level Analysis Dataset"
+
+# Save dataset ----
+usethis::use_data(adsl_neuro, overwrite = TRUE)
diff --git a/data/adsl_neuro.rda b/data/adsl_neuro.rda
new file mode 100644
index 0000000..93875c7
Binary files /dev/null and b/data/adsl_neuro.rda differ
diff --git a/inst/WORDLIST b/inst/WORDLIST
index 9c61628..3f03d7c 100644
--- a/inst/WORDLIST
+++ b/inst/WORDLIST
@@ -29,7 +29,9 @@ repo
 roxygen
 Template
 neuro
+Neuro
 interventional
+ADSL
 NVDTC
 NVDY
 USUBJID
diff --git a/man/adsl_neuro.Rd b/man/adsl_neuro.Rd
new file mode 100644
index 0000000..bc305fc
--- /dev/null
+++ b/man/adsl_neuro.Rd
@@ -0,0 +1,24 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/data.R
+\docType{data}
+\name{adsl_neuro}
+\alias{adsl_neuro}
+\title{Subject Level Analysis Dataset-updated}
+\format{
+An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 15 rows and 36 columns.
+}
+\usage{
+adsl_neuro
+}
+\description{
+An updated ADaM ADSL dataset with Alzheimer's Disease patients
+}
+\seealso{
+Other datasets: 
+\code{\link{ag_neuro}},
+\code{\link{dm_neuro}},
+\code{\link{nv_neuro}},
+\code{\link{suppnv_neuro}}
+}
+\concept{datasets}
+\keyword{datasets}
diff --git a/man/ag_neuro.Rd b/man/ag_neuro.Rd
index 647d699..cce8fe4 100644
--- a/man/ag_neuro.Rd
+++ b/man/ag_neuro.Rd
@@ -38,6 +38,7 @@ A SDTM AG domain dataset
 }
 \seealso{
 Other datasets: 
+\code{\link{adsl_neuro}},
 \code{\link{dm_neuro}},
 \code{\link{nv_neuro}},
 \code{\link{suppnv_neuro}}
diff --git a/man/dm_neuro.Rd b/man/dm_neuro.Rd
index c592d3e..b23227f 100644
--- a/man/dm_neuro.Rd
+++ b/man/dm_neuro.Rd
@@ -15,6 +15,7 @@ An updated SDTM DM dataset subset with age appropriate Alzheimer's Disease patie
 }
 \seealso{
 Other datasets: 
+\code{\link{adsl_neuro}},
 \code{\link{ag_neuro}},
 \code{\link{nv_neuro}},
 \code{\link{suppnv_neuro}}
diff --git a/man/nv_neuro.Rd b/man/nv_neuro.Rd
index 663716d..aea5596 100644
--- a/man/nv_neuro.Rd
+++ b/man/nv_neuro.Rd
@@ -46,6 +46,7 @@ A SDTM NV domain dataset for Alzheimer's disease observational and interventiona
 }
 \seealso{
 Other datasets: 
+\code{\link{adsl_neuro}},
 \code{\link{ag_neuro}},
 \code{\link{dm_neuro}},
 \code{\link{suppnv_neuro}}
diff --git a/man/suppnv_neuro.Rd b/man/suppnv_neuro.Rd
index e13ced8..fee16a2 100644
--- a/man/suppnv_neuro.Rd
+++ b/man/suppnv_neuro.Rd
@@ -35,6 +35,7 @@ A SDTM SUPPNV domain dataset
 }
 \seealso{
 Other datasets: 
+\code{\link{adsl_neuro}},
 \code{\link{ag_neuro}},
 \code{\link{dm_neuro}},
 \code{\link{nv_neuro}}


Reviews:
user: login: jwang-lilly
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-05-09T17:38:18Z
user: login: jwang-lilly
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-05-09T18:00:20Z
user: login: jwang-lilly
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-05-09T18:01:21Z
user: login: jwang-lilly
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-05-09T18:01:41Z
user: login: Fanny-Gautier
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-12T09:58:11Z
user: login: Fanny-Gautier
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-12T09:59:10Z
user: login: Fanny-Gautier
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-12T09:59:40Z
user: login: Fanny-Gautier
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-12T09:59:49Z
user: login: manciniedoardo
state: APPROVED
author_association: COLLABORATOR
submitted_at: 2025-05-14T07:45:26Z

Review comments:
diff_hunk: @@ -0,0 +1,160 @@
+# Dataset: adsl_neuro
+# Description: Create ADSL test Analysis Dataset for Alzheimer's Disease (Neuro)
+
+# Load libraries -----
+library(admiral)
+library(pharmaversesdtm) # Contains example datasets from the CDISC pilot project
+library(dplyr)
+library(lubridate)
+library(stringr)
+
+# Read input test data from pharmaversesdtm ----
+data(dm_neuro)
+ex <- pharmaversesdtm::ex
+
+# Convert blank to NA ----
+dm_neuro <- convert_blanks_to_na(dm_neuro)
+ex <- convert_blanks_to_na(ex)
+
+# Select patients from DM Neuro only
+dm_neuro_pat <- dm_neuro %>%
+  pull(unique(USUBJID))
+
+ex <- ex %>%
+  filter(USUBJID %in% dm_neuro_pat)
+
+# Derive Treatment Variables ----
+adsl <- dm_neuro %>%
+  # Select all necessary variables only
+  select(
+    STUDYID, USUBJID, SUBJID, SITEID, COUNTRY, AGE, AGEU, SEX, RACE, ETHNIC, ARM,
+    ARMCD, ACTARM, ACTARMCD, ARMNRS, DTHDTC, DTHFL
+  ) %>%
+  mutate(
+    TRT01P = if_else(!is.na(ARMNRS), "No Treatment", ARM),
+    TRT01PN = case_when(
+      TRT01P == "No Treatment" ~ 3,
+      TRT01P == "Placebo" ~ 2,
+      TRUE ~ 1
+    ),
+    TRT01A = if_else(!is.na(ARMNRS), "No Treatment", ACTARM),
+    TRT01AN = case_when(
+      TRT01A == "No Treatment" ~ 3,
+      TRT01A == "Placebo" ~ 2,
+      TRUE ~ 1
+    )
+  )
+
+# Treatment Start and End Dates ----
+ex_ext <- ex %>%
+  derive_vars_dtm(
+    dtc = EXSTDTC,
+    new_vars_prefix = "EXST"
+  ) %>%
+  derive_vars_dtm(
+    dtc = EXENDTC,
+    new_vars_prefix = "EXEN",
+    time_imputation = "last"
+  ) %>%
+  # Merge DM.ARMNRS to not derive treatment dates for these patients
+  left_join(dm_neuro %>% select(USUBJID, ARMNRS), by = "USUBJID")
+
+adsl <- adsl %>%
+  # Treatment Start Datetime
+  derive_vars_merged(
+    dataset_add = ex_ext,
+    filter_add = (is.na(ARMNRS)),
+    new_vars = exprs(TRTSDTM = EXSTDTM, TRTSTMF = EXSTTMF),
+    order = exprs(EXSTDTM, EXSEQ),
+    mode = "first",
+    by_vars = exprs(STUDYID, USUBJID)
+  ) %>%
+  # Treatment End Datetime
+  derive_vars_merged(
+    dataset_add = ex_ext,
+    filter_add = (is.na(ARMNRS)),
+    new_vars = exprs(TRTEDTM = EXENDTM, TRTETMF = EXENTMF),
+    order = exprs(EXENDTM, EXSEQ),
+    mode = "last",
+    by_vars = exprs(STUDYID, USUBJID)
+  ) %>%
+  # Convert Datetime variables to date
+  derive_vars_dtm_to_dt(source_vars = exprs(TRTSDTM, TRTEDTM)) %>%
+  # Treatment Start Time
+  derive_vars_dtm_to_tm(source_vars = exprs(TRTSDTM)) %>%
+  # Treatment Duration
+  derive_var_trtdurd()
+
+# Derive Age Grouping ----
+agegr1_lookup <- exprs(
+  ~condition,            ~AGEGR1, ~AGEGR1N,
+  is.na(AGE),          "Missing",        3,
+  AGE < 65,                "<65",        1,
+  !is.na(AGE),            ">=65",        2
+)
+
+adsl <- derive_vars_cat(
+  dataset = adsl,
+  definition = agegr1_lookup
+)
+
+# Derive Intent-to-Treat and Safety Population Flags ----
+adsl <- adsl %>%
+  mutate(ITTFL = "Y") %>%
+  derive_var_merged_exist_flag(
+    dataset_add = adsl,
+    by_vars = exprs(STUDYID, USUBJID),
+    new_var = SAFFL,
path: data-raw/adsl_neuro.R
user: login: jwang-lilly
body: AD0026: For subject-level character population flag variables such as SAFFL: N = no (not included), Y = yes (included). Null values are not allowed. The 5 NA should be changed to N.
created_at: 2025-05-09T17:38:18Z
author_association: COLLABORATOR
diff_hunk: @@ -0,0 +1,160 @@
+# Dataset: adsl_neuro
+# Description: Create ADSL test Analysis Dataset for Alzheimer's Disease (Neuro)
+
+# Load libraries -----
+library(admiral)
+library(pharmaversesdtm) # Contains example datasets from the CDISC pilot project
+library(dplyr)
+library(lubridate)
+library(stringr)
+
+# Read input test data from pharmaversesdtm ----
+data(dm_neuro)
+ex <- pharmaversesdtm::ex
+
+# Convert blank to NA ----
+dm_neuro <- convert_blanks_to_na(dm_neuro)
+ex <- convert_blanks_to_na(ex)
+
+# Select patients from DM Neuro only
+dm_neuro_pat <- dm_neuro %>%
+  pull(unique(USUBJID))
+
+ex <- ex %>%
+  filter(USUBJID %in% dm_neuro_pat)
+
+# Derive Treatment Variables ----
+adsl <- dm_neuro %>%
+  # Select all necessary variables only
+  select(
+    STUDYID, USUBJID, SUBJID, SITEID, COUNTRY, AGE, AGEU, SEX, RACE, ETHNIC, ARM,
+    ARMCD, ACTARM, ACTARMCD, ARMNRS, DTHDTC, DTHFL
+  ) %>%
+  mutate(
+    TRT01P = if_else(!is.na(ARMNRS), "No Treatment", ARM),
+    TRT01PN = case_when(
+      TRT01P == "No Treatment" ~ 3,
+      TRT01P == "Placebo" ~ 2,
+      TRUE ~ 1
+    ),
+    TRT01A = if_else(!is.na(ARMNRS), "No Treatment", ACTARM),
+    TRT01AN = case_when(
+      TRT01A == "No Treatment" ~ 3,
+      TRT01A == "Placebo" ~ 2,
+      TRUE ~ 1
+    )
+  )
+
+# Treatment Start and End Dates ----
+ex_ext <- ex %>%
+  derive_vars_dtm(
+    dtc = EXSTDTC,
+    new_vars_prefix = "EXST"
+  ) %>%
+  derive_vars_dtm(
+    dtc = EXENDTC,
+    new_vars_prefix = "EXEN",
+    time_imputation = "last"
+  ) %>%
+  # Merge DM.ARMNRS to not derive treatment dates for these patients
+  left_join(dm_neuro %>% select(USUBJID, ARMNRS), by = "USUBJID")
+
+adsl <- adsl %>%
+  # Treatment Start Datetime
+  derive_vars_merged(
+    dataset_add = ex_ext,
+    filter_add = (is.na(ARMNRS)),
+    new_vars = exprs(TRTSDTM = EXSTDTM, TRTSTMF = EXSTTMF),
+    order = exprs(EXSTDTM, EXSEQ),
+    mode = "first",
+    by_vars = exprs(STUDYID, USUBJID)
+  ) %>%
+  # Treatment End Datetime
+  derive_vars_merged(
+    dataset_add = ex_ext,
+    filter_add = (is.na(ARMNRS)),
+    new_vars = exprs(TRTEDTM = EXENDTM, TRTETMF = EXENTMF),
+    order = exprs(EXENDTM, EXSEQ),
+    mode = "last",
+    by_vars = exprs(STUDYID, USUBJID)
+  ) %>%
+  # Convert Datetime variables to date
+  derive_vars_dtm_to_dt(source_vars = exprs(TRTSDTM, TRTEDTM)) %>%
+  # Treatment Start Time
+  derive_vars_dtm_to_tm(source_vars = exprs(TRTSDTM)) %>%
+  # Treatment Duration
+  derive_var_trtdurd()
+
+# Derive Age Grouping ----
+agegr1_lookup <- exprs(
+  ~condition,            ~AGEGR1, ~AGEGR1N,
+  is.na(AGE),          "Missing",        3,
+  AGE < 65,                "<65",        1,
+  !is.na(AGE),            ">=65",        2
+)
+
+adsl <- derive_vars_cat(
+  dataset = adsl,
+  definition = agegr1_lookup
+)
+
+# Derive Intent-to-Treat and Safety Population Flags ----
+adsl <- adsl %>%
+  mutate(ITTFL = "Y") %>%
+  derive_var_merged_exist_flag(
+    dataset_add = adsl,
+    by_vars = exprs(STUDYID, USUBJID),
+    new_var = SAFFL,
+    condition = (!is.na(TRTSDT))
+  )
+
+# Derive DTHDT & DTHADY ----
+adsl <- adsl %>%
+  derive_vars_dt(
+    new_vars_prefix = "DTH",
+    dtc = DTHDTC,
+    highest_imputation = "M",
+    date_imputation = "first"
+  ) %>%
+  derive_vars_duration(
+    new_var = DTHADY,
+    start_date = TRTSDT,
+    end_date = DTHDT
+  )
+
+adsl_neuro <- adsl
+
+# Assign the labels for created variables
+labels <- list(
+  DTHDTC = "Date/Time of Death",
+  DTHFL = "Subject Death Flag",
+  TRT01P = "Planned Treatment for Period 01",
+  TRT01PN = "Planned Treatment for Period 01 (N)",
+  TRT01A = "Actual Treatment for Period 01",
+  TRT01AN = "Actual Treatment for Period 01 (N)",
+  TRTSDTM = "Datetime of First Exposure to Treatment",
+  TRTSTMF = "Time 1st Exposure Period Imput. Flag",
+  TRTEDTM = "Datetime of Last Exposure to Treatment",
+  TRTETMF = "Time Last Exposure Period Imput. Flag",
+  TRTSDT = "Date of First Exposure to Treatment",
+  TRTEDT = "Date of Last Exposure to Treatment",
+  TRTSTM = "Time of First Exposure to Treatment",
+  TRTDURD = "Treatment Duration",
+  AGEGR1 = "Age Group 1",
+  AGEGR1N = "Age Group 1 (N)",
+  ITTFL = "Intent-to-Treat Flag",
path: data-raw/adsl_neuro.R
user: login: jwang-lilly
body: ITTFL's label is Intent-to-Treat Population Flag
created_at: 2025-05-09T18:00:20Z
author_association: COLLABORATOR
diff_hunk: @@ -0,0 +1,160 @@
+# Dataset: adsl_neuro
+# Description: Create ADSL test Analysis Dataset for Alzheimer's Disease (Neuro)
+
+# Load libraries -----
+library(admiral)
+library(pharmaversesdtm) # Contains example datasets from the CDISC pilot project
+library(dplyr)
+library(lubridate)
+library(stringr)
+
+# Read input test data from pharmaversesdtm ----
+data(dm_neuro)
+ex <- pharmaversesdtm::ex
+
+# Convert blank to NA ----
+dm_neuro <- convert_blanks_to_na(dm_neuro)
+ex <- convert_blanks_to_na(ex)
+
+# Select patients from DM Neuro only
+dm_neuro_pat <- dm_neuro %>%
+  pull(unique(USUBJID))
+
+ex <- ex %>%
+  filter(USUBJID %in% dm_neuro_pat)
+
+# Derive Treatment Variables ----
+adsl <- dm_neuro %>%
+  # Select all necessary variables only
+  select(
+    STUDYID, USUBJID, SUBJID, SITEID, COUNTRY, AGE, AGEU, SEX, RACE, ETHNIC, ARM,
+    ARMCD, ACTARM, ACTARMCD, ARMNRS, DTHDTC, DTHFL
+  ) %>%
+  mutate(
+    TRT01P = if_else(!is.na(ARMNRS), "No Treatment", ARM),
+    TRT01PN = case_when(
+      TRT01P == "No Treatment" ~ 3,
+      TRT01P == "Placebo" ~ 2,
+      TRUE ~ 1
+    ),
+    TRT01A = if_else(!is.na(ARMNRS), "No Treatment", ACTARM),
+    TRT01AN = case_when(
+      TRT01A == "No Treatment" ~ 3,
+      TRT01A == "Placebo" ~ 2,
+      TRUE ~ 1
+    )
+  )
+
+# Treatment Start and End Dates ----
+ex_ext <- ex %>%
+  derive_vars_dtm(
+    dtc = EXSTDTC,
+    new_vars_prefix = "EXST"
+  ) %>%
+  derive_vars_dtm(
+    dtc = EXENDTC,
+    new_vars_prefix = "EXEN",
+    time_imputation = "last"
+  ) %>%
+  # Merge DM.ARMNRS to not derive treatment dates for these patients
+  left_join(dm_neuro %>% select(USUBJID, ARMNRS), by = "USUBJID")
+
+adsl <- adsl %>%
+  # Treatment Start Datetime
+  derive_vars_merged(
+    dataset_add = ex_ext,
+    filter_add = (is.na(ARMNRS)),
+    new_vars = exprs(TRTSDTM = EXSTDTM, TRTSTMF = EXSTTMF),
+    order = exprs(EXSTDTM, EXSEQ),
+    mode = "first",
+    by_vars = exprs(STUDYID, USUBJID)
+  ) %>%
+  # Treatment End Datetime
+  derive_vars_merged(
+    dataset_add = ex_ext,
+    filter_add = (is.na(ARMNRS)),
+    new_vars = exprs(TRTEDTM = EXENDTM, TRTETMF = EXENTMF),
+    order = exprs(EXENDTM, EXSEQ),
+    mode = "last",
+    by_vars = exprs(STUDYID, USUBJID)
+  ) %>%
+  # Convert Datetime variables to date
+  derive_vars_dtm_to_dt(source_vars = exprs(TRTSDTM, TRTEDTM)) %>%
+  # Treatment Start Time
+  derive_vars_dtm_to_tm(source_vars = exprs(TRTSDTM)) %>%
+  # Treatment Duration
+  derive_var_trtdurd()
+
+# Derive Age Grouping ----
+agegr1_lookup <- exprs(
+  ~condition,            ~AGEGR1, ~AGEGR1N,
+  is.na(AGE),          "Missing",        3,
+  AGE < 65,                "<65",        1,
+  !is.na(AGE),            ">=65",        2
+)
+
+adsl <- derive_vars_cat(
+  dataset = adsl,
+  definition = agegr1_lookup
+)
+
+# Derive Intent-to-Treat and Safety Population Flags ----
+adsl <- adsl %>%
+  mutate(ITTFL = "Y") %>%
+  derive_var_merged_exist_flag(
+    dataset_add = adsl,
+    by_vars = exprs(STUDYID, USUBJID),
+    new_var = SAFFL,
+    condition = (!is.na(TRTSDT))
+  )
+
+# Derive DTHDT & DTHADY ----
+adsl <- adsl %>%
+  derive_vars_dt(
+    new_vars_prefix = "DTH",
+    dtc = DTHDTC,
+    highest_imputation = "M",
+    date_imputation = "first"
+  ) %>%
+  derive_vars_duration(
+    new_var = DTHADY,
+    start_date = TRTSDT,
+    end_date = DTHDT
+  )
+
+adsl_neuro <- adsl
+
+# Assign the labels for created variables
+labels <- list(
+  DTHDTC = "Date/Time of Death",
+  DTHFL = "Subject Death Flag",
+  TRT01P = "Planned Treatment for Period 01",
+  TRT01PN = "Planned Treatment for Period 01 (N)",
+  TRT01A = "Actual Treatment for Period 01",
+  TRT01AN = "Actual Treatment for Period 01 (N)",
+  TRTSDTM = "Datetime of First Exposure to Treatment",
+  TRTSTMF = "Time 1st Exposure Period Imput. Flag",
+  TRTEDTM = "Datetime of Last Exposure to Treatment",
+  TRTETMF = "Time Last Exposure Period Imput. Flag",
+  TRTSDT = "Date of First Exposure to Treatment",
+  TRTEDT = "Date of Last Exposure to Treatment",
+  TRTSTM = "Time of First Exposure to Treatment",
+  TRTDURD = "Treatment Duration",
+  AGEGR1 = "Age Group 1",
path: data-raw/adsl_neuro.R
user: login: jwang-lilly
body: Pooled Age Group 1
created_at: 2025-05-09T18:01:21Z
author_association: COLLABORATOR
diff_hunk: @@ -0,0 +1,160 @@
+# Dataset: adsl_neuro
+# Description: Create ADSL test Analysis Dataset for Alzheimer's Disease (Neuro)
+
+# Load libraries -----
+library(admiral)
+library(pharmaversesdtm) # Contains example datasets from the CDISC pilot project
+library(dplyr)
+library(lubridate)
+library(stringr)
+
+# Read input test data from pharmaversesdtm ----
+data(dm_neuro)
+ex <- pharmaversesdtm::ex
+
+# Convert blank to NA ----
+dm_neuro <- convert_blanks_to_na(dm_neuro)
+ex <- convert_blanks_to_na(ex)
+
+# Select patients from DM Neuro only
+dm_neuro_pat <- dm_neuro %>%
+  pull(unique(USUBJID))
+
+ex <- ex %>%
+  filter(USUBJID %in% dm_neuro_pat)
+
+# Derive Treatment Variables ----
+adsl <- dm_neuro %>%
+  # Select all necessary variables only
+  select(
+    STUDYID, USUBJID, SUBJID, SITEID, COUNTRY, AGE, AGEU, SEX, RACE, ETHNIC, ARM,
+    ARMCD, ACTARM, ACTARMCD, ARMNRS, DTHDTC, DTHFL
+  ) %>%
+  mutate(
+    TRT01P = if_else(!is.na(ARMNRS), "No Treatment", ARM),
+    TRT01PN = case_when(
+      TRT01P == "No Treatment" ~ 3,
+      TRT01P == "Placebo" ~ 2,
+      TRUE ~ 1
+    ),
+    TRT01A = if_else(!is.na(ARMNRS), "No Treatment", ACTARM),
+    TRT01AN = case_when(
+      TRT01A == "No Treatment" ~ 3,
+      TRT01A == "Placebo" ~ 2,
+      TRUE ~ 1
+    )
+  )
+
+# Treatment Start and End Dates ----
+ex_ext <- ex %>%
+  derive_vars_dtm(
+    dtc = EXSTDTC,
+    new_vars_prefix = "EXST"
+  ) %>%
+  derive_vars_dtm(
+    dtc = EXENDTC,
+    new_vars_prefix = "EXEN",
+    time_imputation = "last"
+  ) %>%
+  # Merge DM.ARMNRS to not derive treatment dates for these patients
+  left_join(dm_neuro %>% select(USUBJID, ARMNRS), by = "USUBJID")
+
+adsl <- adsl %>%
+  # Treatment Start Datetime
+  derive_vars_merged(
+    dataset_add = ex_ext,
+    filter_add = (is.na(ARMNRS)),
+    new_vars = exprs(TRTSDTM = EXSTDTM, TRTSTMF = EXSTTMF),
+    order = exprs(EXSTDTM, EXSEQ),
+    mode = "first",
+    by_vars = exprs(STUDYID, USUBJID)
+  ) %>%
+  # Treatment End Datetime
+  derive_vars_merged(
+    dataset_add = ex_ext,
+    filter_add = (is.na(ARMNRS)),
+    new_vars = exprs(TRTEDTM = EXENDTM, TRTETMF = EXENTMF),
+    order = exprs(EXENDTM, EXSEQ),
+    mode = "last",
+    by_vars = exprs(STUDYID, USUBJID)
+  ) %>%
+  # Convert Datetime variables to date
+  derive_vars_dtm_to_dt(source_vars = exprs(TRTSDTM, TRTEDTM)) %>%
+  # Treatment Start Time
+  derive_vars_dtm_to_tm(source_vars = exprs(TRTSDTM)) %>%
+  # Treatment Duration
+  derive_var_trtdurd()
+
+# Derive Age Grouping ----
+agegr1_lookup <- exprs(
+  ~condition,            ~AGEGR1, ~AGEGR1N,
+  is.na(AGE),          "Missing",        3,
+  AGE < 65,                "<65",        1,
+  !is.na(AGE),            ">=65",        2
+)
+
+adsl <- derive_vars_cat(
+  dataset = adsl,
+  definition = agegr1_lookup
+)
+
+# Derive Intent-to-Treat and Safety Population Flags ----
+adsl <- adsl %>%
+  mutate(ITTFL = "Y") %>%
+  derive_var_merged_exist_flag(
+    dataset_add = adsl,
+    by_vars = exprs(STUDYID, USUBJID),
+    new_var = SAFFL,
+    condition = (!is.na(TRTSDT))
+  )
+
+# Derive DTHDT & DTHADY ----
+adsl <- adsl %>%
+  derive_vars_dt(
+    new_vars_prefix = "DTH",
+    dtc = DTHDTC,
+    highest_imputation = "M",
+    date_imputation = "first"
+  ) %>%
+  derive_vars_duration(
+    new_var = DTHADY,
+    start_date = TRTSDT,
+    end_date = DTHDT
+  )
+
+adsl_neuro <- adsl
+
+# Assign the labels for created variables
+labels <- list(
+  DTHDTC = "Date/Time of Death",
+  DTHFL = "Subject Death Flag",
+  TRT01P = "Planned Treatment for Period 01",
+  TRT01PN = "Planned Treatment for Period 01 (N)",
+  TRT01A = "Actual Treatment for Period 01",
+  TRT01AN = "Actual Treatment for Period 01 (N)",
+  TRTSDTM = "Datetime of First Exposure to Treatment",
+  TRTSTMF = "Time 1st Exposure Period Imput. Flag",
+  TRTEDTM = "Datetime of Last Exposure to Treatment",
+  TRTETMF = "Time Last Exposure Period Imput. Flag",
+  TRTSDT = "Date of First Exposure to Treatment",
+  TRTEDT = "Date of Last Exposure to Treatment",
+  TRTSTM = "Time of First Exposure to Treatment",
+  TRTDURD = "Treatment Duration",
+  AGEGR1 = "Age Group 1",
+  AGEGR1N = "Age Group 1 (N)",
path: data-raw/adsl_neuro.R
user: login: jwang-lilly
body: Pooled Age Group 1 (N)
created_at: 2025-05-09T18:01:41Z
author_association: COLLABORATOR
diff_hunk: @@ -0,0 +1,160 @@
+# Dataset: adsl_neuro
+# Description: Create ADSL test Analysis Dataset for Alzheimer's Disease (Neuro)
+
+# Load libraries -----
+library(admiral)
+library(pharmaversesdtm) # Contains example datasets from the CDISC pilot project
+library(dplyr)
+library(lubridate)
+library(stringr)
+
+# Read input test data from pharmaversesdtm ----
+data(dm_neuro)
+ex <- pharmaversesdtm::ex
+
+# Convert blank to NA ----
+dm_neuro <- convert_blanks_to_na(dm_neuro)
+ex <- convert_blanks_to_na(ex)
+
+# Select patients from DM Neuro only
+dm_neuro_pat <- dm_neuro %>%
+  pull(unique(USUBJID))
+
+ex <- ex %>%
+  filter(USUBJID %in% dm_neuro_pat)
+
+# Derive Treatment Variables ----
+adsl <- dm_neuro %>%
+  # Select all necessary variables only
+  select(
+    STUDYID, USUBJID, SUBJID, SITEID, COUNTRY, AGE, AGEU, SEX, RACE, ETHNIC, ARM,
+    ARMCD, ACTARM, ACTARMCD, ARMNRS, DTHDTC, DTHFL
+  ) %>%
+  mutate(
+    TRT01P = if_else(!is.na(ARMNRS), "No Treatment", ARM),
+    TRT01PN = case_when(
+      TRT01P == "No Treatment" ~ 3,
+      TRT01P == "Placebo" ~ 2,
+      TRUE ~ 1
+    ),
+    TRT01A = if_else(!is.na(ARMNRS), "No Treatment", ACTARM),
+    TRT01AN = case_when(
+      TRT01A == "No Treatment" ~ 3,
+      TRT01A == "Placebo" ~ 2,
+      TRUE ~ 1
+    )
+  )
+
+# Treatment Start and End Dates ----
+ex_ext <- ex %>%
+  derive_vars_dtm(
+    dtc = EXSTDTC,
+    new_vars_prefix = "EXST"
+  ) %>%
+  derive_vars_dtm(
+    dtc = EXENDTC,
+    new_vars_prefix = "EXEN",
+    time_imputation = "last"
+  ) %>%
+  # Merge DM.ARMNRS to not derive treatment dates for these patients
+  left_join(dm_neuro %>% select(USUBJID, ARMNRS), by = "USUBJID")
+
+adsl <- adsl %>%
+  # Treatment Start Datetime
+  derive_vars_merged(
+    dataset_add = ex_ext,
+    filter_add = (is.na(ARMNRS)),
+    new_vars = exprs(TRTSDTM = EXSTDTM, TRTSTMF = EXSTTMF),
+    order = exprs(EXSTDTM, EXSEQ),
+    mode = "first",
+    by_vars = exprs(STUDYID, USUBJID)
+  ) %>%
+  # Treatment End Datetime
+  derive_vars_merged(
+    dataset_add = ex_ext,
+    filter_add = (is.na(ARMNRS)),
+    new_vars = exprs(TRTEDTM = EXENDTM, TRTETMF = EXENTMF),
+    order = exprs(EXENDTM, EXSEQ),
+    mode = "last",
+    by_vars = exprs(STUDYID, USUBJID)
+  ) %>%
+  # Convert Datetime variables to date
+  derive_vars_dtm_to_dt(source_vars = exprs(TRTSDTM, TRTEDTM)) %>%
+  # Treatment Start Time
+  derive_vars_dtm_to_tm(source_vars = exprs(TRTSDTM)) %>%
+  # Treatment Duration
+  derive_var_trtdurd()
+
+# Derive Age Grouping ----
+agegr1_lookup <- exprs(
+  ~condition,            ~AGEGR1, ~AGEGR1N,
+  is.na(AGE),          "Missing",        3,
+  AGE < 65,                "<65",        1,
+  !is.na(AGE),            ">=65",        2
+)
+
+adsl <- derive_vars_cat(
+  dataset = adsl,
+  definition = agegr1_lookup
+)
+
+# Derive Intent-to-Treat and Safety Population Flags ----
+adsl <- adsl %>%
+  mutate(ITTFL = "Y") %>%
+  derive_var_merged_exist_flag(
+    dataset_add = adsl,
+    by_vars = exprs(STUDYID, USUBJID),
+    new_var = SAFFL,
path: data-raw/adsl_neuro.R
user: login: Fanny-Gautier
body: Good catch, `false_value` argument added
created_at: 2025-05-12T09:58:11Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,160 @@
+# Dataset: adsl_neuro
+# Description: Create ADSL test Analysis Dataset for Alzheimer's Disease (Neuro)
+
+# Load libraries -----
+library(admiral)
+library(pharmaversesdtm) # Contains example datasets from the CDISC pilot project
+library(dplyr)
+library(lubridate)
+library(stringr)
+
+# Read input test data from pharmaversesdtm ----
+data(dm_neuro)
+ex <- pharmaversesdtm::ex
+
+# Convert blank to NA ----
+dm_neuro <- convert_blanks_to_na(dm_neuro)
+ex <- convert_blanks_to_na(ex)
+
+# Select patients from DM Neuro only
+dm_neuro_pat <- dm_neuro %>%
+  pull(unique(USUBJID))
+
+ex <- ex %>%
+  filter(USUBJID %in% dm_neuro_pat)
+
+# Derive Treatment Variables ----
+adsl <- dm_neuro %>%
+  # Select all necessary variables only
+  select(
+    STUDYID, USUBJID, SUBJID, SITEID, COUNTRY, AGE, AGEU, SEX, RACE, ETHNIC, ARM,
+    ARMCD, ACTARM, ACTARMCD, ARMNRS, DTHDTC, DTHFL
+  ) %>%
+  mutate(
+    TRT01P = if_else(!is.na(ARMNRS), "No Treatment", ARM),
+    TRT01PN = case_when(
+      TRT01P == "No Treatment" ~ 3,
+      TRT01P == "Placebo" ~ 2,
+      TRUE ~ 1
+    ),
+    TRT01A = if_else(!is.na(ARMNRS), "No Treatment", ACTARM),
+    TRT01AN = case_when(
+      TRT01A == "No Treatment" ~ 3,
+      TRT01A == "Placebo" ~ 2,
+      TRUE ~ 1
+    )
+  )
+
+# Treatment Start and End Dates ----
+ex_ext <- ex %>%
+  derive_vars_dtm(
+    dtc = EXSTDTC,
+    new_vars_prefix = "EXST"
+  ) %>%
+  derive_vars_dtm(
+    dtc = EXENDTC,
+    new_vars_prefix = "EXEN",
+    time_imputation = "last"
+  ) %>%
+  # Merge DM.ARMNRS to not derive treatment dates for these patients
+  left_join(dm_neuro %>% select(USUBJID, ARMNRS), by = "USUBJID")
+
+adsl <- adsl %>%
+  # Treatment Start Datetime
+  derive_vars_merged(
+    dataset_add = ex_ext,
+    filter_add = (is.na(ARMNRS)),
+    new_vars = exprs(TRTSDTM = EXSTDTM, TRTSTMF = EXSTTMF),
+    order = exprs(EXSTDTM, EXSEQ),
+    mode = "first",
+    by_vars = exprs(STUDYID, USUBJID)
+  ) %>%
+  # Treatment End Datetime
+  derive_vars_merged(
+    dataset_add = ex_ext,
+    filter_add = (is.na(ARMNRS)),
+    new_vars = exprs(TRTEDTM = EXENDTM, TRTETMF = EXENTMF),
+    order = exprs(EXENDTM, EXSEQ),
+    mode = "last",
+    by_vars = exprs(STUDYID, USUBJID)
+  ) %>%
+  # Convert Datetime variables to date
+  derive_vars_dtm_to_dt(source_vars = exprs(TRTSDTM, TRTEDTM)) %>%
+  # Treatment Start Time
+  derive_vars_dtm_to_tm(source_vars = exprs(TRTSDTM)) %>%
+  # Treatment Duration
+  derive_var_trtdurd()
+
+# Derive Age Grouping ----
+agegr1_lookup <- exprs(
+  ~condition,            ~AGEGR1, ~AGEGR1N,
+  is.na(AGE),          "Missing",        3,
+  AGE < 65,                "<65",        1,
+  !is.na(AGE),            ">=65",        2
+)
+
+adsl <- derive_vars_cat(
+  dataset = adsl,
+  definition = agegr1_lookup
+)
+
+# Derive Intent-to-Treat and Safety Population Flags ----
+adsl <- adsl %>%
+  mutate(ITTFL = "Y") %>%
+  derive_var_merged_exist_flag(
+    dataset_add = adsl,
+    by_vars = exprs(STUDYID, USUBJID),
+    new_var = SAFFL,
+    condition = (!is.na(TRTSDT))
+  )
+
+# Derive DTHDT & DTHADY ----
+adsl <- adsl %>%
+  derive_vars_dt(
+    new_vars_prefix = "DTH",
+    dtc = DTHDTC,
+    highest_imputation = "M",
+    date_imputation = "first"
+  ) %>%
+  derive_vars_duration(
+    new_var = DTHADY,
+    start_date = TRTSDT,
+    end_date = DTHDT
+  )
+
+adsl_neuro <- adsl
+
+# Assign the labels for created variables
+labels <- list(
+  DTHDTC = "Date/Time of Death",
+  DTHFL = "Subject Death Flag",
+  TRT01P = "Planned Treatment for Period 01",
+  TRT01PN = "Planned Treatment for Period 01 (N)",
+  TRT01A = "Actual Treatment for Period 01",
+  TRT01AN = "Actual Treatment for Period 01 (N)",
+  TRTSDTM = "Datetime of First Exposure to Treatment",
+  TRTSTMF = "Time 1st Exposure Period Imput. Flag",
+  TRTEDTM = "Datetime of Last Exposure to Treatment",
+  TRTETMF = "Time Last Exposure Period Imput. Flag",
+  TRTSDT = "Date of First Exposure to Treatment",
+  TRTEDT = "Date of Last Exposure to Treatment",
+  TRTSTM = "Time of First Exposure to Treatment",
+  TRTDURD = "Treatment Duration",
+  AGEGR1 = "Age Group 1",
+  AGEGR1N = "Age Group 1 (N)",
+  ITTFL = "Intent-to-Treat Flag",
path: data-raw/adsl_neuro.R
user: login: Fanny-Gautier
body: updated as per IG v1.3
created_at: 2025-05-12T09:59:10Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,160 @@
+# Dataset: adsl_neuro
+# Description: Create ADSL test Analysis Dataset for Alzheimer's Disease (Neuro)
+
+# Load libraries -----
+library(admiral)
+library(pharmaversesdtm) # Contains example datasets from the CDISC pilot project
+library(dplyr)
+library(lubridate)
+library(stringr)
+
+# Read input test data from pharmaversesdtm ----
+data(dm_neuro)
+ex <- pharmaversesdtm::ex
+
+# Convert blank to NA ----
+dm_neuro <- convert_blanks_to_na(dm_neuro)
+ex <- convert_blanks_to_na(ex)
+
+# Select patients from DM Neuro only
+dm_neuro_pat <- dm_neuro %>%
+  pull(unique(USUBJID))
+
+ex <- ex %>%
+  filter(USUBJID %in% dm_neuro_pat)
+
+# Derive Treatment Variables ----
+adsl <- dm_neuro %>%
+  # Select all necessary variables only
+  select(
+    STUDYID, USUBJID, SUBJID, SITEID, COUNTRY, AGE, AGEU, SEX, RACE, ETHNIC, ARM,
+    ARMCD, ACTARM, ACTARMCD, ARMNRS, DTHDTC, DTHFL
+  ) %>%
+  mutate(
+    TRT01P = if_else(!is.na(ARMNRS), "No Treatment", ARM),
+    TRT01PN = case_when(
+      TRT01P == "No Treatment" ~ 3,
+      TRT01P == "Placebo" ~ 2,
+      TRUE ~ 1
+    ),
+    TRT01A = if_else(!is.na(ARMNRS), "No Treatment", ACTARM),
+    TRT01AN = case_when(
+      TRT01A == "No Treatment" ~ 3,
+      TRT01A == "Placebo" ~ 2,
+      TRUE ~ 1
+    )
+  )
+
+# Treatment Start and End Dates ----
+ex_ext <- ex %>%
+  derive_vars_dtm(
+    dtc = EXSTDTC,
+    new_vars_prefix = "EXST"
+  ) %>%
+  derive_vars_dtm(
+    dtc = EXENDTC,
+    new_vars_prefix = "EXEN",
+    time_imputation = "last"
+  ) %>%
+  # Merge DM.ARMNRS to not derive treatment dates for these patients
+  left_join(dm_neuro %>% select(USUBJID, ARMNRS), by = "USUBJID")
+
+adsl <- adsl %>%
+  # Treatment Start Datetime
+  derive_vars_merged(
+    dataset_add = ex_ext,
+    filter_add = (is.na(ARMNRS)),
+    new_vars = exprs(TRTSDTM = EXSTDTM, TRTSTMF = EXSTTMF),
+    order = exprs(EXSTDTM, EXSEQ),
+    mode = "first",
+    by_vars = exprs(STUDYID, USUBJID)
+  ) %>%
+  # Treatment End Datetime
+  derive_vars_merged(
+    dataset_add = ex_ext,
+    filter_add = (is.na(ARMNRS)),
+    new_vars = exprs(TRTEDTM = EXENDTM, TRTETMF = EXENTMF),
+    order = exprs(EXENDTM, EXSEQ),
+    mode = "last",
+    by_vars = exprs(STUDYID, USUBJID)
+  ) %>%
+  # Convert Datetime variables to date
+  derive_vars_dtm_to_dt(source_vars = exprs(TRTSDTM, TRTEDTM)) %>%
+  # Treatment Start Time
+  derive_vars_dtm_to_tm(source_vars = exprs(TRTSDTM)) %>%
+  # Treatment Duration
+  derive_var_trtdurd()
+
+# Derive Age Grouping ----
+agegr1_lookup <- exprs(
+  ~condition,            ~AGEGR1, ~AGEGR1N,
+  is.na(AGE),          "Missing",        3,
+  AGE < 65,                "<65",        1,
+  !is.na(AGE),            ">=65",        2
+)
+
+adsl <- derive_vars_cat(
+  dataset = adsl,
+  definition = agegr1_lookup
+)
+
+# Derive Intent-to-Treat and Safety Population Flags ----
+adsl <- adsl %>%
+  mutate(ITTFL = "Y") %>%
+  derive_var_merged_exist_flag(
+    dataset_add = adsl,
+    by_vars = exprs(STUDYID, USUBJID),
+    new_var = SAFFL,
+    condition = (!is.na(TRTSDT))
+  )
+
+# Derive DTHDT & DTHADY ----
+adsl <- adsl %>%
+  derive_vars_dt(
+    new_vars_prefix = "DTH",
+    dtc = DTHDTC,
+    highest_imputation = "M",
+    date_imputation = "first"
+  ) %>%
+  derive_vars_duration(
+    new_var = DTHADY,
+    start_date = TRTSDT,
+    end_date = DTHDT
+  )
+
+adsl_neuro <- adsl
+
+# Assign the labels for created variables
+labels <- list(
+  DTHDTC = "Date/Time of Death",
+  DTHFL = "Subject Death Flag",
+  TRT01P = "Planned Treatment for Period 01",
+  TRT01PN = "Planned Treatment for Period 01 (N)",
+  TRT01A = "Actual Treatment for Period 01",
+  TRT01AN = "Actual Treatment for Period 01 (N)",
+  TRTSDTM = "Datetime of First Exposure to Treatment",
+  TRTSTMF = "Time 1st Exposure Period Imput. Flag",
+  TRTEDTM = "Datetime of Last Exposure to Treatment",
+  TRTETMF = "Time Last Exposure Period Imput. Flag",
+  TRTSDT = "Date of First Exposure to Treatment",
+  TRTEDT = "Date of Last Exposure to Treatment",
+  TRTSTM = "Time of First Exposure to Treatment",
+  TRTDURD = "Treatment Duration",
+  AGEGR1 = "Age Group 1",
path: data-raw/adsl_neuro.R
user: login: Fanny-Gautier
body: thanks, updated as suggested and per IG v1.3
created_at: 2025-05-12T09:59:40Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,160 @@
+# Dataset: adsl_neuro
+# Description: Create ADSL test Analysis Dataset for Alzheimer's Disease (Neuro)
+
+# Load libraries -----
+library(admiral)
+library(pharmaversesdtm) # Contains example datasets from the CDISC pilot project
+library(dplyr)
+library(lubridate)
+library(stringr)
+
+# Read input test data from pharmaversesdtm ----
+data(dm_neuro)
+ex <- pharmaversesdtm::ex
+
+# Convert blank to NA ----
+dm_neuro <- convert_blanks_to_na(dm_neuro)
+ex <- convert_blanks_to_na(ex)
+
+# Select patients from DM Neuro only
+dm_neuro_pat <- dm_neuro %>%
+  pull(unique(USUBJID))
+
+ex <- ex %>%
+  filter(USUBJID %in% dm_neuro_pat)
+
+# Derive Treatment Variables ----
+adsl <- dm_neuro %>%
+  # Select all necessary variables only
+  select(
+    STUDYID, USUBJID, SUBJID, SITEID, COUNTRY, AGE, AGEU, SEX, RACE, ETHNIC, ARM,
+    ARMCD, ACTARM, ACTARMCD, ARMNRS, DTHDTC, DTHFL
+  ) %>%
+  mutate(
+    TRT01P = if_else(!is.na(ARMNRS), "No Treatment", ARM),
+    TRT01PN = case_when(
+      TRT01P == "No Treatment" ~ 3,
+      TRT01P == "Placebo" ~ 2,
+      TRUE ~ 1
+    ),
+    TRT01A = if_else(!is.na(ARMNRS), "No Treatment", ACTARM),
+    TRT01AN = case_when(
+      TRT01A == "No Treatment" ~ 3,
+      TRT01A == "Placebo" ~ 2,
+      TRUE ~ 1
+    )
+  )
+
+# Treatment Start and End Dates ----
+ex_ext <- ex %>%
+  derive_vars_dtm(
+    dtc = EXSTDTC,
+    new_vars_prefix = "EXST"
+  ) %>%
+  derive_vars_dtm(
+    dtc = EXENDTC,
+    new_vars_prefix = "EXEN",
+    time_imputation = "last"
+  ) %>%
+  # Merge DM.ARMNRS to not derive treatment dates for these patients
+  left_join(dm_neuro %>% select(USUBJID, ARMNRS), by = "USUBJID")
+
+adsl <- adsl %>%
+  # Treatment Start Datetime
+  derive_vars_merged(
+    dataset_add = ex_ext,
+    filter_add = (is.na(ARMNRS)),
+    new_vars = exprs(TRTSDTM = EXSTDTM, TRTSTMF = EXSTTMF),
+    order = exprs(EXSTDTM, EXSEQ),
+    mode = "first",
+    by_vars = exprs(STUDYID, USUBJID)
+  ) %>%
+  # Treatment End Datetime
+  derive_vars_merged(
+    dataset_add = ex_ext,
+    filter_add = (is.na(ARMNRS)),
+    new_vars = exprs(TRTEDTM = EXENDTM, TRTETMF = EXENTMF),
+    order = exprs(EXENDTM, EXSEQ),
+    mode = "last",
+    by_vars = exprs(STUDYID, USUBJID)
+  ) %>%
+  # Convert Datetime variables to date
+  derive_vars_dtm_to_dt(source_vars = exprs(TRTSDTM, TRTEDTM)) %>%
+  # Treatment Start Time
+  derive_vars_dtm_to_tm(source_vars = exprs(TRTSDTM)) %>%
+  # Treatment Duration
+  derive_var_trtdurd()
+
+# Derive Age Grouping ----
+agegr1_lookup <- exprs(
+  ~condition,            ~AGEGR1, ~AGEGR1N,
+  is.na(AGE),          "Missing",        3,
+  AGE < 65,                "<65",        1,
+  !is.na(AGE),            ">=65",        2
+)
+
+adsl <- derive_vars_cat(
+  dataset = adsl,
+  definition = agegr1_lookup
+)
+
+# Derive Intent-to-Treat and Safety Population Flags ----
+adsl <- adsl %>%
+  mutate(ITTFL = "Y") %>%
+  derive_var_merged_exist_flag(
+    dataset_add = adsl,
+    by_vars = exprs(STUDYID, USUBJID),
+    new_var = SAFFL,
+    condition = (!is.na(TRTSDT))
+  )
+
+# Derive DTHDT & DTHADY ----
+adsl <- adsl %>%
+  derive_vars_dt(
+    new_vars_prefix = "DTH",
+    dtc = DTHDTC,
+    highest_imputation = "M",
+    date_imputation = "first"
+  ) %>%
+  derive_vars_duration(
+    new_var = DTHADY,
+    start_date = TRTSDT,
+    end_date = DTHDT
+  )
+
+adsl_neuro <- adsl
+
+# Assign the labels for created variables
+labels <- list(
+  DTHDTC = "Date/Time of Death",
+  DTHFL = "Subject Death Flag",
+  TRT01P = "Planned Treatment for Period 01",
+  TRT01PN = "Planned Treatment for Period 01 (N)",
+  TRT01A = "Actual Treatment for Period 01",
+  TRT01AN = "Actual Treatment for Period 01 (N)",
+  TRTSDTM = "Datetime of First Exposure to Treatment",
+  TRTSTMF = "Time 1st Exposure Period Imput. Flag",
+  TRTEDTM = "Datetime of Last Exposure to Treatment",
+  TRTETMF = "Time Last Exposure Period Imput. Flag",
+  TRTSDT = "Date of First Exposure to Treatment",
+  TRTEDT = "Date of Last Exposure to Treatment",
+  TRTSTM = "Time of First Exposure to Treatment",
+  TRTDURD = "Treatment Duration",
+  AGEGR1 = "Age Group 1",
+  AGEGR1N = "Age Group 1 (N)",
path: data-raw/adsl_neuro.R
user: login: Fanny-Gautier
body: thanks, updated as suggested and per IG v1.3
created_at: 2025-05-12T09:59:49Z
author_association: CONTRIBUTOR

PR comments:
user: login: github-actions[bot]
created_at: 2025-05-05T13:32:23Z
body: ![Code Coverage](https://img.shields.io/badge/Code%20Coverage-100%25-success?style=flat)

Package | Line Rate | Health
-------- | --------- | ------
admiralneuro | 100% | ✔
**Summary** | **100%** (3 / 3) | ✔

<!-- Sticky Pull Request Commentcode-coverage -->
author_association: NONE
user: login: manciniedoardo
created_at: 2025-05-08T08:34:22Z
body: @Fanny-Gautier do we actually want to provide need a template for `adsl` as well in `inst/templates`? If the intention is just to provide an `admiralneuro_adsl` dataset for use in ADPET templates, then I'd think having a script in `data-raw` that we don't expose to the users is enough?

@pharmaverse/admiralneuro thoughts? 
author_association: COLLABORATOR
user: login: Fanny-Gautier
created_at: 2025-05-08T15:20:13Z
body: > @Fanny-Gautier do we actually want to provide need a template for `adsl` as well in `inst/templates`? If the intention is just to provide an `admiralneuro_adsl` dataset for use in ADPET templates, then I'd think having a script in `data-raw` that we don't expose to the users is enough?
> 
> @pharmaverse/admiralneuro thoughts?

There's no need for the template. It was initially set up to create the ADaM in the usual way, but since it's only needed for `ADPET`, I can remove it.
author_association: CONTRIBUTOR
user: login: jwang-lilly
created_at: 2025-05-09T18:04:41Z
body: @Fanny-Gautier, great job with the adsl_neuro.  I completed my review, with a few minor comments.
author_association: COLLABORATOR
user: login: jwang-lilly
created_at: 2025-05-12T13:36:07Z
body: @Fanny-Gautier, perfect! Without further comments.
author_association: COLLABORATOR
user: login: manciniedoardo
created_at: 2025-05-13T12:05:43Z
body: @jwang-lilly please can you approve? then I will merge
author_association: COLLABORATOR