Skip to content

Commit

Permalink
Merge branch 'devel' into 43_codeowners@devel
Browse files Browse the repository at this point in the history
  • Loading branch information
kaz462 committed Aug 28, 2023
2 parents 24ecc4c + 8061842 commit 226e1c2
Show file tree
Hide file tree
Showing 51 changed files with 462 additions and 264 deletions.
71 changes: 71 additions & 0 deletions R/get_terms.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#' An example function as expected by the `get_terms_fun` parameter of
#' `admiral::create_query_data()`
#'
#' @param basket_select A basket_select object defining the terms
#'
#' @param version MedDRA version
#'
#' @param keep_id Should `GRPID` be included in the output?
#'
#' @param temp_env Temporary environment
get_terms <- function(basket_select,
version,
keep_id,
temp_env) {
if (basket_select$type == "smq") {
if (is.null(temp_env$smq_db)) {
data("smq_db", envir = temp_env)
}
if (!is.null(basket_select$name)) {
is_in_smq <- temp_env$smq_db$smq_name == basket_select$name
} else {
is_in_smq <- temp_env$smq_db$smq_id == basket_select$id
}
if (basket_select$scope == "NARROW") {
is_in_scope <- temp_env$smq_db$scope == "narrow"
} else {
is_in_scope <- rep(TRUE, nrow(temp_env$smq_db))
}
if (keep_id) {
select_id <- c(GRPID = "smq_id")
} else {
select_id <- NULL
}
keep_cols <- c(
TERMNAME = "termname",
SRCVAR = "termvar",
GRPNAME = "smq_name",
select_id
)

structure(
temp_env$smq_db[is_in_smq & is_in_scope, keep_cols],
names = names(keep_cols)
)
} else if (basket_select$type == "sdg") {
if (is.null(temp_env$sdg_db)) {
data("sdg_db", envir = temp_env)
}
if (!is.null(basket_select$name)) {
is_in_sdq <- temp_env$sdg_db$sdg_name == basket_select$name
} else {
is_in_sdq <- temp_env$sdg_db$sdg_id == basket_select$id
}
if (keep_id) {
select_id <- c(GRPID = "sdg_id")
} else {
select_id <- NULL
}
keep_cols <- c(
TERMNAME = "termname",
SRCVAR = "termvar",
GRPNAME = "sdg_name",
select_id
)

structure(
temp_env$sdg_db[is_in_sdq, keep_cols],
names = names(keep_cols)
)
}
}
14 changes: 11 additions & 3 deletions data-raw/ae.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
# from CDISC pilot study ----
# Datasets: ae, suppae
# Description: Standard AE, SUPPAE datasets from CDISC pilot study

# Load libraries -----
library(dplyr)
library(metatools)
library(haven)
library(admiral)

# Create ae, suppae ----
raw_ae <- read_xpt("https://github.com/cdisc-org/sdtm-adam-pilot-project/blob/master/updated-pilot-submission-package/900172/m5/datasets/cdiscpilot01/tabulations/sdtm/ae.xpt?raw=true") # nolint
raw_suppae <- read_xpt("https://github.com/cdisc-org/sdtm-adam-pilot-project/blob/master/updated-pilot-submission-package/900172/m5/datasets/cdiscpilot01/tabulations/sdtm/suppae.xpt?raw=true") # nolint
ae <- convert_blanks_to_na(raw_ae)
suppae <- convert_blanks_to_na(raw_suppae)

# Save dataset ----
save(ae, file = "data/ae.rda", compress = "bzip2")
# Label dataset ----
attr(ae, "label") <- "Adverse Events"
attr(suppae, "label") <- "Supplemental Qualifiers for AE"

# Save datasets ----
usethis::use_data(ae, overwrite = TRUE)
usethis::use_data(suppae, overwrite = TRUE)
15 changes: 10 additions & 5 deletions data-raw/ae_ophtha.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
# Update AE by adding AELAT variable for admiralophtha package
# Dataset: ae_ophtha
# Description: Add ophtha-specific AELAT variable to existing AE dataset

# Load libraries -----
library(dplyr)
library(admiral)
library(metatools)
library(haven)

# Create ae_ophtha ----
# Start from standard AE dataset from this package - this should be
# in the environment already if devtools::load_all() has been run
ae_ophtha <- ae

# create possible AELAT values - as collected on CRF ----
## Create possible AELAT values - as collected on CRF ----
lat <- c("LEFT", "RIGHT", "BOTH")

# create AELAT variable ----
# with random assignment of lat values where AESOC is "EYE DISORDERS"
## Create AELAT variable ----
# Use random assignment of lat values where AESOC is "EYE DISORDERS"
# Set seed so that result stays the same for each run
set.seed(1)

Expand All @@ -24,7 +28,8 @@ ae_ophtha$AELAT <- if_else(ae_ophtha$AESOC == "EYE DISORDERS",
ae_ophtha <- ae_ophtha %>%
add_labels(AELAT = "Laterality")

# Label dataset ----
attr(ae_ophtha, "label") <- "Adverse Events"

# Save dataset ----
save(ae_ophtha, file = "data/ae_ophtha.rda", compress = "bzip2")
usethis::use_data(ae_ophtha, overwrite = TRUE)
11 changes: 10 additions & 1 deletion data-raw/cm.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
# from CDISC pilot study ----
# Dataset: cm
# Description: Standard CM dataset from CDISC pilot study

# Load libraries -----
library(haven)
library(admiral)

# Create cm ----
raw_cm <- read_xpt("https://github.com/cdisc-org/sdtm-adam-pilot-project/blob/master/updated-pilot-submission-package/900172/m5/datasets/cdiscpilot01/tabulations/sdtm/cm.xpt?raw=true") # nolint
cm <- convert_blanks_to_na(raw_cm)

# Label dataset ----
attr(cm, "label") <- "Concomitant Medications"

# Save dataset ----
usethis::use_data(cm, overwrite = TRUE)
12 changes: 11 additions & 1 deletion data-raw/dm.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
# from CDISC pilot study ----
# Datasets: dm, suppdm
# Description: Standard DM, SUPPDM datasets from CDISC pilot study

# Load libraries -----
library(haven)
library(admiral)

# Create dm, suppdm ----
sdtm_path <- "https://github.com/cdisc-org/sdtm-adam-pilot-project/blob/master/updated-pilot-submission-package/900172/m5/datasets/cdiscpilot01/tabulations/sdtm/" # nolint
raw_dm <- read_xpt(paste0(sdtm_path, "dm", ".xpt?raw=true"))
raw_suppdm <- read_xpt(paste0(sdtm_path, "suppdm", ".xpt?raw=true"))
dm <- convert_blanks_to_na(raw_dm)
suppdm <- convert_blanks_to_na(raw_suppdm)

# Label dataset ----
attr(dm, "label") <- "Demographics"
attr(suppdm, "label") <- "Supplemental Qualifiers for DM"

# Save datasets ----
usethis::use_data(dm, overwrite = TRUE)
usethis::use_data(suppdm, overwrite = TRUE)
77 changes: 40 additions & 37 deletions data-raw/ds.R
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
# Update DS by adding DSDECOD=RANDOMIZED rows
# Datasets: ds, suppds
# Description: Standard DS, SUPPDS datasets from CDISC pilot study with added DSDECOD = RANDOMIZED rows

# Load libraries -----
library(dplyr)
library(tidyselect)
library(labelled)
library(admiral)
library(metatools)
library(haven)

# Create ds ----
data("dm")
sdtm_path <- "https://github.com/cdisc-org/sdtm-adam-pilot-project/blob/master/updated-pilot-submission-package/900172/m5/datasets/cdiscpilot01/tabulations/sdtm/" # nolint
raw_ds <- read_xpt(paste0(sdtm_path, "ds", ".xpt?raw=true"))
raw_suppds <- read_xpt(paste0(sdtm_path, "suppds", ".xpt?raw=true"))

# Converting blank to NA
## Converting blank to NA ----
dm <- convert_blanks_to_na(dm)
ds1a <- convert_blanks_to_na(raw_ds)
suppds1a <- convert_blanks_to_na(raw_suppds)

# Creating full DS data
## Creating full DS data ----
ds1a <- ds1a %>%
mutate(DSSEQ = as.character(DSSEQ))
ds1 <- combine_supp(ds1a, suppds1a) %>%
mutate(DSSEQ = as.numeric(DSSEQ))

# Creating RANDOMIZED records
dsnames <- names(ds1a)

## Creating RANDOMIZED records ----
dm1 <- select(dm, c(STUDYID, USUBJID, RFSTDTC)) %>%
filter(!is.na(RFSTDTC)) %>%
mutate(
Expand All @@ -41,7 +46,7 @@ dm1 <- select(dm, c(STUDYID, USUBJID, RFSTDTC)) %>%

ds2 <- bind_rows(ds1, select(dm1, -c(RFSTDTC)))

# Adding labels
## Adding labels ----
dslab <- var_label(ds1a)
var_label(ds2) <- dslab

Expand All @@ -56,7 +61,15 @@ ds3 <- ds2 %>%
) %>%
ungroup()

# Creating SUPPDS
ds4 <- ds3 %>%
select(all_of(dsnames))

## Label dataset ----
attr(ds4, "label") <- "Disposition"

ds <- ds4

# Creating SUPPDS ----
suppds1 <- select(ds3, c("STUDYID", "USUBJID", "DSSEQ", "DOMAIN", "ENTCRIT")) %>%
filter(!is.na(ENTCRIT))

Expand All @@ -68,38 +81,28 @@ suppds2 <- rename(suppds1, "RDOMAIN" = "DOMAIN") %>%
"QNAM" = "ENTCRIT",
"QLABEL" = "PROTOCOL ENTRY CRITERIA NOT MET",
"QORIG" = "CRF"
)
) %>%
select(STUDYID, RDOMAIN, USUBJID, IDVAR, IDVARVAL, QNAM, QLABEL, QVAL, QORIG)

suppds <- select(
suppds2,
c(
STUDYID, RDOMAIN, USUBJID,
IDVAR, IDVARVAL, QNAM, QLABEL,
QVAL, QORIG
## Adding labels ----
suppds3 <- suppds2 %>%
add_labels(
STUDYID = "Study Identifier",
RDOMAIN = "Related Domain Abbreviation",
USUBJID = "Unique Subject Identifier",
IDVAR = "Identifying Variable",
IDVARVAL = "Identifying Variable Value",
QNAM = "Qualifier Variable Name",
QLABEL = "Qualifier Variable Label",
QVAL = "Data Value",
QORIG = "Origin"
)
)

admiral_suppds <- suppds %>% add_labels(
STUDYID = "Study Identifier",
RDOMAIN = "Related Domain Abbreviation",
USUBJID = "Unique Subject Identifier",
IDVAR = "Identifying Variable",
IDVARVAL = "Identifying Variable Value",
QNAM = "Qualifier Variable Name",
QLABEL = "Qualifier Variable Label",
QVAL = "Data Value",
QORIG = "Origin"
)

attr(admiral_suppds, "label") <- "Supplemental Disposition"

# Creating DS
dsnames <- names(ds1a)
admiral_ds <- select(ds3, all_of(dsnames))

attr(admiral_ds, "label") <- "Disposition"
## Label dataset ----
attr(suppds3, "label") <- "Supplemental Qualifiers for DS"

suppds <- suppds3

ds <- admiral_ds
suppds <- admiral_suppds
save(ds, file = "data/ds.rda", compress = "bzip2")
save(suppds, file = "data/suppds.rda", compress = "bzip2")
# Save datasets ----
usethis::use_data(ds, overwrite = TRUE)
usethis::use_data(suppds, overwrite = TRUE)
11 changes: 10 additions & 1 deletion data-raw/ex.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
# from CDISC pilot study ----
# Dataset: ex
# Description: Standard EX dataset from CDISC pilot study

# Load libraries -----
library(haven)
library(admiral)

# Create ex ----
raw_ex <- read_xpt("https://github.com/cdisc-org/sdtm-adam-pilot-project/blob/master/updated-pilot-submission-package/900172/m5/datasets/cdiscpilot01/tabulations/sdtm/ex.xpt?raw=true") # nolint
ex <- convert_blanks_to_na(raw_ex)

# Label dataset ----
attr(ex, "label") <- "Exposure"

# Save dataset ----
usethis::use_data(ex, overwrite = TRUE)
21 changes: 15 additions & 6 deletions data-raw/ex_ophtha.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
# Dataset: ex_ophtha
# Description: Add ophtha-specific EXLOC, EXLAT variables to existing EX dataset
# and modify EXROUTE, EXDOSFRM, EXDOSFRQ to something eye-related

# Load libraries -----
library(dplyr)
library(tidyselect)

# Make ex_ophtha dataset
data("dm")
data("ex")

# Make ex_ophtha dataset
ex_ophtha <- dm %>%
# Start by merging on ophtha_dm to use the SUBJID variable
## Merge on ophtha_dm to use the SUBJID variable ----
select(USUBJID, SUBJID) %>%
right_join(ex, by = c("USUBJID"), multiple = "all") %>%
# Create EXLOC & EXLAT, change EXROUTE & EXDOSFRM to something eye-related
## Create EXLOC & EXLAT, change EXROUTE & EXDOSFRM ----
mutate(
EXLOC = "EYE",
EXDOSFRM = "INJECTION",
Expand All @@ -24,12 +30,15 @@ ex_ophtha <- dm %>%
"EXENDTC", "EXSTDY", "EXENDY"
)

# Label new variables
## Label new variables ----
attr(ex_ophtha$EXLOC, "label") <- "Location of Dose Administration"
attr(ex_ophtha$EXLAT, "label") <- "Laterality"
attr(ex_ophtha$EXROUTE, "label") <- "Route of Administration"
attr(ex_ophtha$EXDOSFRM, "label") <- "Dose Form"
attr(ex_ophtha$EXDOSFRQ, "label") <- "Dose Frequency per Interval"

# Save Dataset
save(ex_ophtha, file = file.path("data", "ex_ophtha.rda"), compress = "bzip2")
# Label dataset ----
attr(ex_ophtha, "label") <- "Exposure"

# Save dataset ----
usethis::use_data(ex_ophtha, overwrite = TRUE)
Loading

0 comments on commit 226e1c2

Please sign in to comment.