-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
177 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters