-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calculate study timing given sdtm
data.
#14
Open
samussiah
wants to merge
5
commits into
main
Choose a base branch
from
fix-5
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
.Rproj.user | ||
.Rhistory | ||
.Rdata |
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 = "AESTDTC", | ||
endt_col = "AEENDTC", | ||
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 = 'LBDTC', | ||
dy_col = NULL, | ||
result_col = 'LBSTRESN' | ||
) | ||
} | ||
|
||
if (standard == 'adam') { | ||
settings$aes <- list( | ||
id_col = "USUBJID", | ||
stdt_col = 'ASTDT', | ||
endt_col = 'AENDT', | ||
stdy_col = "ASTDY", | ||
endy_col = "AENDY", | ||
aeterm_col = "AETERM", | ||
decod_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,59 @@ | ||
#' 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 <- params$settings[[ refDomain ]]$id_col | ||
|
||
ref_data <- params$data[[ refDomain ]] %>% | ||
select( | ||
id_col, refDate | ||
) %>% | ||
mutate( | ||
# TODO: add logic around date format... lubridate::ymd? | ||
refDate = as.Date(.data[[ refDate ]]) | ||
) | ||
|
||
domain_data <- params$data[[ domain ]] %>% | ||
left_join( | ||
ref_data, | ||
id_col | ||
) | ||
|
||
getStudyDay <- function(data, date_col) { | ||
data[[ date_col ]] <- as.Date(data[[ date_col ]]) | ||
|
||
data[[ paste0(date_col, '_dy') ]] <- as.numeric( | ||
data[[ date_col ]] - data$refDate | ||
) + ( | ||
data[[ date_col ]] >= data$refDate | ||
) | ||
|
||
data | ||
} | ||
|
||
if (!is.null(domainDate)) | ||
domain_data <- getStudyDay(domain_data, domainDate) | ||
|
||
if (!is.null(domainStartDate)) | ||
domain_data <- getStudyDay(domain_data, domainStartDate) | ||
|
||
if (!is.null(domainEndDate)) | ||
domain_data <- getStudyDay(domain_data, domainEndDate) | ||
|
||
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,85 @@ | ||
#' 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 | ||
){ | ||
|
||
## 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") | ||
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') | ||
) | ||
|
||
standard <- tolower(standard) | ||
|
||
## Create list of default data when undefined. | ||
if (is.null(data)) | ||
data <- getDefaultData(standard) | ||
|
||
## Create list of default settings when undefined. | ||
if (is.null(settings)) | ||
settings <- getDefaultSettings(standard) | ||
|
||
## Calculate study timing. | ||
if (standard == 'sdtm') { | ||
data$aes <- getTiming( | ||
params = list( | ||
data = data, | ||
settings = settings, | ||
standard = standard | ||
), | ||
'aes', | ||
domainStartDate = settings$aes$stdt_col, | ||
domainEndDate = settings$aes$endt_col | ||
) | ||
settings$aes$stdy_col <- paste0(settings$aes$stdt_col, '_dy') | ||
settings$aes$endy_col <- paste0(settings$aes$endt_col, '_dy') | ||
|
||
data$labs <- getTiming( | ||
params = list( | ||
data = data, | ||
settings = settings, | ||
standard = standard | ||
), | ||
'labs', | ||
domainDate = settings$labs$dt_col | ||
) | ||
settings$labs$dy_col <- paste0(settings$labs$dt_col, '_dy') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should treat this more like a utility function. Let's move this to a separate function (
|
||
} | ||
|
||
## create object containing data and setting to pass to server | ||
## 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should be able to use
safetyGraphics::makeMapping
to do this. Let me see if i can get it working.