Skip to content
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

Closes #1228 produce bmi records for more visits #1957

Merged
merged 8 commits into from
Jun 28, 2023
138 changes: 117 additions & 21 deletions R/derive_advs_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,15 @@ compute_map <- function(diabp, sysbp, hr = NULL) {
#'
#' Permitted Values: character value
#'
#' @param constant_height HEIGHT parameter is constant
manciniedoardo marked this conversation as resolved.
Show resolved Hide resolved
#'
#' If the HEIGHT value is considered constant (e.g. measured once at screening),
#' the values of BSA will be calculated for each WEIGHT value.
manciniedoardo marked this conversation as resolved.
Show resolved Hide resolved
#'
#' Permitted Values: logical scalar
#'
#' Default Values: FALSE
jeffreyad marked this conversation as resolved.
Show resolved Hide resolved
#'
jeffreyad marked this conversation as resolved.
Show resolved Hide resolved
#' @inheritParams derive_param_computed
#'
#' @inheritParams derive_param_qtc
Expand Down Expand Up @@ -305,14 +314,29 @@ compute_map <- function(diabp, sysbp, hr = NULL) {
#' ),
#' get_unit_expr = extract_unit(PARAM)
#' )
#'
#' derive_param_bsa(
#' advs,
#' by_vars = exprs(USUBJID, VISIT),
#' method = "Mosteller",
#' set_values_to = exprs(
#' PARAMCD = "BSA",
#' PARAM = "Body Surface Area (m^2)"
#' ),
#' get_unit_expr = extract_unit(PARAM),
#' constant_height = TRUE,
#' constant_by_vars = exprs(USUBJID)
#' )
derive_param_bsa <- function(dataset,
by_vars,
method,
set_values_to = exprs(PARAMCD = "BSA"),
height_code = "HEIGHT",
weight_code = "WEIGHT",
get_unit_expr,
filter = NULL) {
filter = NULL,
constant_height = FALSE,
constant_by_vars = NULL) {
assert_vars(by_vars)
assert_data_frame(dataset, required_vars = exprs(!!!by_vars, PARAMCD, AVAL))
assert_character_scalar(
Expand All @@ -328,6 +352,8 @@ derive_param_bsa <- function(dataset,
assert_character_scalar(weight_code)
get_unit_expr <- assert_expr(enexpr(get_unit_expr))
filter <- assert_filter_cond(enexpr(filter), optional = TRUE)
assert_vars(constant_by_vars, optional = TRUE)
assert_logical_scalar(constant_height)

assert_unit(
dataset,
Expand All @@ -350,14 +376,33 @@ derive_param_bsa <- function(dataset,
)
)

derive_param_computed(
dataset,
filter = !!filter,
parameters = c(height_code, weight_code),
by_vars = by_vars,
analysis_value = !!bsa_formula,
set_values_to = set_values_to
)
if (constant_height == FALSE) {
derive_param_computed(
dataset,
filter = !!filter,
parameters = c(height_code, weight_code),
by_vars = by_vars,
analysis_value = !!bsa_formula,
set_values_to = set_values_to
)
jeffreyad marked this conversation as resolved.
Show resolved Hide resolved
} else {
if (is.null(constant_by_vars)) {
abort(
"constant_by_vars is expected when constant_height is TRUE"
)
} else {
derive_param_computed(
dataset,
filter = !!filter,
parameters = c(weight_code),
by_vars = by_vars,
analysis_value = !!bsa_formula,
set_values_to = set_values_to,
constant_parameters = c(height_code),
constant_by_vars = constant_by_vars
)
}
}
}

#' Compute Body Surface Area (BSA)
Expand Down Expand Up @@ -486,6 +531,15 @@ compute_bsa <- function(height = height,
#'
#' Permitted Values: character value
#'
#' @param constant_height HEIGHT parameter is constant
#'
#' If the HEIGHT value is considered constant (e.g. measured once at screening),
#' the values of BSA will be calculated for each WEIGHT value.
#'
#' Permitted Values: logical scalar
#'
#' Default Values: FALSE
#'
#' @inheritParams derive_param_computed
#'
#' @inheritParams derive_param_qtc
Expand Down Expand Up @@ -530,13 +584,30 @@ compute_bsa <- function(height = height,
#' ),
#' get_unit_expr = extract_unit(PARAM)
#' )
#'
jeffreyad marked this conversation as resolved.
Show resolved Hide resolved
#' # Example 2: Derive BMI where height is measured only once
jeffreyad marked this conversation as resolved.
Show resolved Hide resolved
#' derive_param_bmi(
#' advs,
#' by_vars = exprs(USUBJID, AVISIT),
#' weight_code = "WEIGHT",
#' height_code = "HEIGHT",
#' set_values_to = exprs(
#' PARAMCD = "BMI",
#' PARAM = "Body Mass Index (kg/m^2)"
#' ),
#' get_unit_expr = extract_unit(PARAM),
#' constant_height = TRUE,
#' constant_by_vars = exprs(USUBJID)
#' )
derive_param_bmi <- function(dataset,
by_vars,
set_values_to = exprs(PARAMCD = "BMI"),
weight_code = "WEIGHT",
height_code = "HEIGHT",
get_unit_expr,
filter = NULL) {
filter = NULL,
constant_height = FALSE,
constant_by_vars = NULL) {
assert_vars(by_vars)
assert_data_frame(dataset, required_vars = exprs(!!!by_vars, PARAMCD, AVAL))
assert_varval_list(set_values_to, required_elements = "PARAMCD")
Expand All @@ -545,6 +616,9 @@ derive_param_bmi <- function(dataset,
assert_character_scalar(height_code)
get_unit_expr <- assert_expr(enexpr(get_unit_expr))
filter <- assert_filter_cond(enexpr(filter), optional = TRUE)
assert_vars(constant_by_vars, optional = TRUE)
assert_logical_scalar(constant_height)


assert_unit(
dataset,
Expand All @@ -559,17 +633,39 @@ derive_param_bmi <- function(dataset,
get_unit_expr = !!get_unit_expr
)

derive_param_computed(
dataset,
filter = !!filter,
parameters = c(weight_code, height_code),
by_vars = by_vars,
analysis_value = compute_bmi(
height = !!sym(paste0("AVAL.", height_code)),
weight = !!sym(paste0("AVAL.", weight_code))
),
set_values_to = set_values_to
)
if (constant_height == FALSE) {
derive_param_computed(
dataset,
filter = !!filter,
parameters = c(weight_code, height_code),
by_vars = by_vars,
analysis_value = compute_bmi(
height = !!sym(paste0("AVAL.", height_code)),
weight = !!sym(paste0("AVAL.", weight_code))
),
set_values_to = set_values_to
)
} else {
if (is.null(constant_by_vars)) {
abort(
"constant_by_vars is expected when constant_height is TRUE"
)
} else {
derive_param_computed(
dataset,
filter = !!filter,
parameters = c(weight_code),
by_vars = by_vars,
analysis_value = compute_bmi(
height = !!sym(paste0("AVAL.", height_code)),
weight = !!sym(paste0("AVAL.", weight_code))
),
set_values_to = set_values_to,
constant_parameters = c(height_code),
constant_by_vars = constant_by_vars
)
}
}
}

#' Compute Body Mass Index (BMI)
Expand Down
35 changes: 34 additions & 1 deletion man/derive_param_bmi.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 32 additions & 1 deletion man/derive_param_bsa.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading