Skip to content

Commit

Permalink
fix #5
Browse files Browse the repository at this point in the history
  • Loading branch information
samussiah committed Jan 27, 2023
1 parent 679005c commit 4d17e57
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 31 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.Rproj.user
.Rhistory
.Rdata
12 changes: 6 additions & 6 deletions R/getDefaultSettings.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ getDefaultSettings <- function(standard) {
if (standard == 'sdtm') {
settings$aes <- list(
id_col = "USUBJID",
stdt_col = "AESTDT",
endt_col = "AEENDT",
stdt_col = "AESTDTC",
endt_col = "AEENDTC",
stdy_col = NULL,
endy_col = NULL,
aeterm_col = "AETERM",
Expand All @@ -24,7 +24,7 @@ getDefaultSettings <- function(standard) {
id_col = "USUBJID",
visit_col = 'VISIT',
visit_order_col = 'VISITNUM',
dt_col = 'LBDT',
dt_col = 'LBDTC',
dy_col = NULL,
result_col = 'LBSTRESN'
)
Expand All @@ -33,12 +33,12 @@ getDefaultSettings <- function(standard) {
if (standard == 'adam') {
settings$aes <- list(
id_col = "USUBJID",
stdt_col = NULL,
endt_col = NULL,
stdt_col = 'ASTDT',
endt_col = 'AENDT',
stdy_col = "ASTDY",
endy_col = "AENDY",
aeterm_col = "AETERM",
term_col = 'AEDECOD',
decod_col = 'AEDECOD',
bodsys_col = "AEBODSYS",
severity_col = "AESEV"
)
Expand Down
41 changes: 20 additions & 21 deletions R/getTiming.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,43 @@ getTiming <- function(
) {
# TODO: add stopifnot() logic

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

ref_data <- params()$data[[ refDomain ]] %>%
ref_data <- params$data[[ refDomain ]] %>%
select(
id_col, refDate
) %>%
mutate(
refDate = as.Date(.data$refDate)
# TODO: add logic around date format... lubridate::ymd?
refDate = as.Date(.data[[ refDate ]])
)

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

if (!is.null(domainDate)) {
domain_date[[ domainDate ]] <- as.Date(domain_data[[ domainDate ]])
getStudyDay <- function(data, date_col) {
data[[ date_col ]] <- as.Date(data[[ date_col ]])

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 ]])
data[[ paste0(date_col, '_dy') ]] <- as.numeric(
data[[ date_col ]] - data$refDate
) + (
data[[ date_col ]] >= data$refDate
)

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

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

domain_data[[ paste0(domainDate, '_endy') ]] <- as.numeric(domain_data[[ domainEndDate ]] -
ref_data[[ refDate ]]) + (domain_data[[ domainEndDate ]] >= ref_data[[ refDate ]])
}
if (!is.null(domainStartDate))
domain_data <- getStudyDay(domain_data, domainStartDate)

if (!is.null(domainEndDate))
domain_data <- getStudyDay(domain_data, domainEndDate)

domain_data
}
35 changes: 31 additions & 4 deletions R/profileApp.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,42 @@ profileApp <- function(

standard <- tolower(standard)

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

## create list of default settings when undefined
## 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

## 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')
}

## Create reactive list of data and settings to pass to server
params <- reactive({
list(
data = data,
Expand Down

0 comments on commit 4d17e57

Please sign in to comment.