diff --git a/R/api_create_study.R b/R/api_create_study.R index 9744dcd..0ee2513 100644 --- a/R/api_create_study.R +++ b/R/api_create_study.R @@ -1,6 +1,6 @@ -api__minimization_pocock <- function( # nolint: cyclocomp_linter. +api__minimization_pocock <- function( + # nolint: cyclocomp_linter. identifier, name, method, arms, covariates, p, req, res) { - collection <- checkmate::makeAssertCollection() checkmate::assert( @@ -18,7 +18,8 @@ api__minimization_pocock <- function( # nolint: cyclocomp_linter. checkmate::assert( checkmate::check_choice(method, choices = c("range", "var", "sd")), .var.name = "method", - add = collection) + add = collection + ) checkmate::assert( checkmate::check_list( @@ -55,7 +56,8 @@ api__minimization_pocock <- function( # nolint: cyclocomp_linter. len = 2, ), .var.name = "covariates1", - add = collection) + add = collection + ) checkmate::assert( checkmate::check_names( @@ -63,35 +65,41 @@ api__minimization_pocock <- function( # nolint: cyclocomp_linter. permutation.of = c("weight", "levels"), ), .var.name = "covariates2", - add = collection) + add = collection + ) # check covariate weight checkmate::assert( checkmate::check_numeric(c_content$weight, - lower = 0, - finite = TRUE, - len = 1, - null.ok = FALSE + lower = 0, + finite = TRUE, + len = 1, + null.ok = FALSE ), .var.name = "weight", - add = collection) + add = collection + ) checkmate::assert( checkmate::check_character(c_content$levels, - min.chars = 1, - min.len = 2, - unique = TRUE + min.chars = 1, + min.len = 2, + unique = TRUE ), .var.name = "levels", - add = collection) + add = collection + ) } # check probability checkmate::assert( - checkmate::check_numeric(p, lower = 0, upper = 1, len = 1, - any.missing = FALSE, null.ok = FALSE), + checkmate::check_numeric(p, + lower = 0, upper = 1, len = 1, + any.missing = FALSE, null.ok = FALSE + ), .var.name = "p", - add = collection) + add = collection + ) if (length(collection$getMessages()) > 0) { diff --git a/R/api_randomize.R b/R/api_randomize.R index dcf044d..855b3e6 100644 --- a/R/api_randomize.R +++ b/R/api_randomize.R @@ -89,19 +89,17 @@ api__randomize_patient <- function(study_id, current_state, req, res) { # Dispatch based on randomization method to parse parameters params <- - switch( - method_randomization, + switch(method_randomization, minimisation_pocock = do.call( parse_pocock_parameters, list(db_connection_pool, study_id, current_state) - ) + ) ) arm_name <- - switch( - method_randomization, + switch(method_randomization, minimisation_pocock = do.call( unbiased:::randomize_minimisation_pocock, params - ) + ) ) arm <- dplyr::tbl(db_connection_pool, "arm") |> @@ -109,7 +107,7 @@ api__randomize_patient <- function(study_id, current_state, req, res) { dplyr::select("arm_id" = "id", "name", "ratio") |> dplyr::collect() - randomized_patient <- unbiased:::save_patient(study_id, arm$arm_id) + randomized_patient <- unbiased:::save_patient(study_id, arm$arm_id) if (!is.null(randomized_patient$error)) { res$status <- 503 diff --git a/R/db.R b/R/db.R index c2f6846..0343988 100644 --- a/R/db.R +++ b/R/db.R @@ -139,21 +139,21 @@ create_study <- function( r } -save_patient <- function(study_id, arm_id){ - - r <- tryCatch({ - randomized_patient <- DBI::dbGetQuery( - db_connection_pool, - "INSERT INTO patient (arm_id, study_id) +save_patient <- function(study_id, arm_id) { + r <- tryCatch( + { + randomized_patient <- DBI::dbGetQuery( + db_connection_pool, + "INSERT INTO patient (arm_id, study_id) VALUES ($1, $2) RETURNING id, arm_id", - list(arm_id, study_id) - ) - }, - error = function(cond) { - logger::log_error("Error randomizing patient: {cond}", cond=cond) - list(error = conditionMessage(cond)) - } + list(arm_id, study_id) + ) + }, + error = function(cond) { + logger::log_error("Error randomizing patient: {cond}", cond = cond) + list(error = conditionMessage(cond)) + } ) return(r)