Skip to content

Commit

Permalink
Issue #67: used = TRUE after randomization
Browse files Browse the repository at this point in the history
  • Loading branch information
salatak committed Feb 22, 2024
1 parent e94c746 commit 0d6cdf4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 3 additions & 1 deletion R/api_randomize.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions R/db.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 0d6cdf4

Please sign in to comment.