diff --git a/R/api_randomize.R b/R/api_randomize.R index 68e561f..b4884ef 100644 --- a/R/api_randomize.R +++ b/R/api_randomize.R @@ -89,7 +89,9 @@ 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, used = TRUE) |> + select(-used) if (!is.null(randomized_patient$error)) { res$status <- 503 diff --git a/R/db.R b/R/db.R index e169868..9c5da33 100644 --- a/R/db.R +++ b/R/db.R @@ -147,15 +147,15 @@ create_study <- function( r } -save_patient <- function(study_id, arm_id) { +save_patient <- function(study_id, arm_id, used) { 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) + "INSERT INTO patient (arm_id, study_id, used) + VALUES ($1, $2, $3) + RETURNING id, arm_id, used", + list(arm_id, study_id, used) ) }, error = function(cond) { diff --git a/tests/testthat/test-E2E-study-minimisation-pocock.R b/tests/testthat/test-E2E-study-minimisation-pocock.R index 556481c..a821a7a 100644 --- a/tests/testthat/test-E2E-study-minimisation-pocock.R +++ b/tests/testthat/test-E2E-study-minimisation-pocock.R @@ -68,6 +68,14 @@ test_that("correct request with the structure of the returned result", { len = 3, type = c("numeric", "numeric", "character") ) + + checkmate::test_true( + dplyr::tbl(db_connection_pool, "patient") |> + dplyr::slice_max(id) |> + dplyr::collect() |> + dplyr::pull(used), + TRUE + ) }) test_that("request with one covariate at two levels", {