Skip to content

Commit

Permalink
add support for SDTM
Browse files Browse the repository at this point in the history
  • Loading branch information
samussiah committed Jan 13, 2023
1 parent 6b7388c commit 679005c
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 35 deletions.
17 changes: 17 additions & 0 deletions R/getDefaultData.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
getDefaultData <- function(standard) {
data <- list()

if (standard == 'sdtm') {
data$aes <- safetyData::sdtm_ae
data$dm <- safetyData::sdtm_dm
data$labs <- safetyData::sdtm_lb
}

if (standard == 'adam') {
data$aes <- safetyData::adam_adae
data$dm <- safetyData::adam_adsl
data$labs <- safetyData::adam_adlbc
}

data
}
63 changes: 63 additions & 0 deletions R/getDefaultSettings.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
getDefaultSettings <- function(standard) {
settings <- list()

if (standard == 'sdtm') {
settings$aes <- list(
id_col = "USUBJID",
stdt_col = "AESTDT",
endt_col = "AEENDT",
stdy_col = NULL,
endy_col = NULL,
aeterm_col = "AETERM",
decod_col = 'AEDECOD',
bodsys_col = "AEBODSYS",
severity_col = "AESEV"
)

settings$dm <- list(
id_col = "USUBJID",
reference_date_col = 'RFSTDTC',
treatment_col = "ARM"
)

settings$labs <- list(
id_col = "USUBJID",
visit_col = 'VISIT',
visit_order_col = 'VISITNUM',
dt_col = 'LBDT',
dy_col = NULL,
result_col = 'LBSTRESN'
)
}

if (standard == 'adam') {
settings$aes <- list(
id_col = "USUBJID",
stdt_col = NULL,
endt_col = NULL,
stdy_col = "ASTDY",
endy_col = "AENDY",
aeterm_col = "AETERM",
term_col = 'AEDECOD',
bodsys_col = "AEBODSYS",
severity_col = "AESEV"
)

settings$dm <- list(
id_col = "USUBJID",
reference_date_col = 'TRTSDT',
treatment_col = "TRT01P"
)

settings$labs <- list(
id_col = "USUBJID",
visit_col = 'AVISIT',
visit_order_col = 'AVISITN',
dt_col = 'ADT',
dy_col = 'ADY',
result_col = 'AVAL'
)
}

settings
}
60 changes: 60 additions & 0 deletions R/getTiming.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#' Calculate reference timepoint.
#'
#' @param params `list` Reactive list of input data and mappings
#' @param domain `character` Name of data domain with which to calculate reference timepoint
#' @param domainDate `character` Name of date column with which to calculate reference timepoint
#' @param reference `character` Name of data reference with which to calculate reference timepoint
#' @param referenceDate `character` Name of date column with which to calculate reference timepoint

getTiming <- function(
params,
domain,
domainDate = NULL,
refDomain = 'dm',
refDate = 'RFSTDTC',
domainStartDate = NULL,
domainEndDate = NULL
) {
# TODO: add stopifnot() logic

id_col <- reactive({
params()$settings[[ refDomain ]]$id_col
})

ref_data <- params()$data[[ refDomain ]] %>%
select(
id_col, refDate
) %>%
mutate(
refDate = as.Date(.data$refDate)
)

domain_data <- params()$data[[ domain ]] %>%
left_join(
ref_data,
id_col
)

if (!is.null(domainDate)) {
domain_date[[ domainDate ]] <- as.Date(domain_data[[ domainDate ]])

domain_data[[ paste0(domainDate, '_dy') ]] <- as.numeric(domain_data[[ domainDate ]] -
ref_data[[ refDate ]]) + (domain_data[[ domainDate ]] >= ref_data[[ refDate ]])
}

if (!is.null(domainStartDate)) {
domain_date[[ domainStartDate ]] <- as.Date(domain_data[[ domainStartDate ]])

domain_data[[ paste0(domainDate, '_stdy') ]] <- as.numeric(domain_data[[ domainStartDate ]] -
ref_data[[ refDate ]]) + (domain_data[[ domainStartDate ]] >= ref_data[[ refDate ]])
}

if (!is.null(domainEndDate)) {
domain_date[[ domainEndDate ]] <- as.Date(domain_data[[ domainEndDate ]])

domain_data[[ paste0(domainDate, '_endy') ]] <- as.numeric(domain_data[[ domainEndDate ]] -
ref_data[[ refDate ]]) + (domain_data[[ domainEndDate ]] >= ref_data[[ refDate ]])
}

domain_data
}
67 changes: 36 additions & 31 deletions R/profileApp.R
Original file line number Diff line number Diff line change
@@ -1,53 +1,58 @@
#' Safety Profile App
#'
#' @param dfAE AE Data
#' @param dfDemog demog data
#' @param settings safetyGraphics settings
#' @param data `list` Named list of data domains
#' @param settings `list` Named list of data mappings
#' @param standard `character` Name of data standard
#' @param runNow `logical` Run app?
#'
#' @import shiny
#' @return `shiny.appobj` Shiny app
#'
#' @importFrom shiny shinyApp callModule
#'
#' @export

profileApp <- function(
data = list(
aes=safetyData::adam_adae,
dm = safetyData::adam_adsl,
labs=safetyData::adam_adlbc
),
settings=NULL,
runNow=TRUE
){
data = NULL,
settings = NULL,
standard = 'adam',
runNow = TRUE
) {
stopifnot(
'[ standard ] must be a character-classed variable.' =
class(standard) == 'character',
'[ standard ] must be one of "sdtm", "adam", "custom".' =
tolower(standard) %in% c('sdtm', 'adam', 'custom')
)

## create default settings when settings is not defined by default
if(is.null(settings)){
settings<-list(
labs=list(id_col="USUBJID"),
aes=list(id_col="USUBJID", siteid_col="SITEID", trarm_col="TRTA",
bodsys_col="AEBODSYS", term_col = 'AEDECOD',
aeterm_col="AETERM", severity_col="AESEV",
stdy_col="ASTDY", endy_col="AENDY"),
dm=list(id_col="USUBJID", treatment_col="ARM")
)
}
standard <- tolower(standard)

## create list of default data when undefined
if (is.null(data))
data <- getDefaultData(standard)

## create object containing data and setting to pass to server
## create list of default settings when undefined
if (is.null(settings))
settings <- getDefaultSettings(standard)
browser()
## create reactive list of data and settings to pass to server
params <- reactive({
list(
data=data,
settings=settings
data = data,
settings = settings,
standard = standard
)
})

## Create app with ui and server
## Create app with UI and server
app <- shinyApp(
ui = profile_ui("profile"),
server = function(input,output,session){
server = function(input,output,session) {
callModule(profile_server, "profile", params)
}
)

#if(runNow)
if (runNow)
runApp(app)
#else
#app
else
app
}
5 changes: 1 addition & 4 deletions R/profile_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ profile_server <- function(input, output, session, params) {

## set up some basic reactives for convenience
id_col<-reactive({

params()$settings$dm$id_col
})

Expand Down Expand Up @@ -78,9 +77,7 @@ profile_server <- function(input, output, session, params) {
print(params()$data$aes %>% filter(!!sym(id_col()) == input$idSelect))# %in% input$idSelect])
})



# TODO Make this dynamic for any domain provided (use a sub-module?)
# TODO: Make this dynamic for any domain provided (use a sub-module?)
output$overview <- renderDT({domain_choice() %>% filter(!!sym(id_col()) == input$idSelect)})

output$AEplot <- renderPlot({
Expand Down

0 comments on commit 679005c

Please sign in to comment.