Skip to content

Commit

Permalink
Keep current structure for enabling reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
jthompson-arcus committed Nov 19, 2024
1 parent 2551970 commit d863300
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions R/mod_review_forms.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ mod_review_forms_server <- function(
# it will give a warning. This would be rare since it would mean a datapoint with the same edit date-time was reviewed but another one was not.
# probably better to use defensive coding here to ensure the app does not crash in that case. However we need to define which review status we need to select
# in this case get the reviewed = "No"
review_status <- unique(review_data_active()$reviewed)
review_comment <- unique(review_data_active()$comment)
review_status <- with(review_data_active(), reviewed[edit_date_time == max(as.POSIXct(edit_date_time))]) |> unique()
review_comment <- with(review_data_active(), comment[edit_date_time == max(as.POSIXct(edit_date_time))]) |> unique()
if(length(review_status) != 1) warning("multiple variables in review_status, namely: ",
review_status, "Verify data.")
}
Expand Down Expand Up @@ -187,8 +187,8 @@ mod_review_forms_server <- function(
)
if(!enable_any_review()) return(FALSE)
any(c(
unique(review_data_active()$reviewed) == "No" & input$form_reviewed,
unique(review_data_active()$reviewed) == "Yes" & !input$form_reviewed
unique(with(review_data_active(), reviewed[edit_date_time == max(as.POSIXct(edit_date_time))])) == "No" & input$form_reviewed,
unique(with(review_data_active(), reviewed[edit_date_time == max(as.POSIXct(edit_date_time))])) == "Yes" & !input$form_reviewed
))
})

Expand Down Expand Up @@ -305,7 +305,7 @@ mod_review_forms_server <- function(
"No user name found. Cannot save review"
))
validate(need(
!review_data_active()$reviewed == "Yes",
!unique(with(review_data_active(), reviewed[edit_date_time == max(as.POSIXct(edit_date_time))])) == "Yes",
"Form already reviewed"
))
validate(need(input$form_reviewed, "Requires review"))
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-mod_review_forms.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ describe(
)

updated_rows_db <- db_get_review(
db_path, subject = "885", form = "Adverse events"
db_path, ids = 1:2
)

expect_equal(updated_rows_db$comment, c("test review", "test review"))
Expand Down Expand Up @@ -236,7 +236,7 @@ describe(
expect_true(app$get_js("document.getElementById('test-review_comment').disabled;"))

# review status and reviewer is saved as expected
saved_review_row <- db_get_review(temp_path, subject = "885", form = "Adverse events")
saved_review_row <- db_get_review(temp_path, ids = 1:2)
expect_equal(saved_review_row$status, c("old", "old"))
expect_equal(saved_review_row$reviewer, c("Reviewer 1", "test_name (Medical Monitor)"))
}
Expand Down Expand Up @@ -289,8 +289,8 @@ describe(
dplyr::filter(r$review_data, subject_id == "885", item_group == "Adverse events") |>
dplyr::select(id, dplyr::all_of(idx_cols), edit_date_time, reviewed, comment, status)
)
expect_equal(review_data_active()$item_group, "Adverse events")
expect_equal(nrow(review_data_active()), 1)
expect_equal(review_data_active()$item_group, c("Adverse events", "Adverse events"))
expect_equal(nrow(review_data_active()), 2)
expect_error(output[["save_review_error"]], "Requires review")
})
}
Expand Down

0 comments on commit d863300

Please sign in to comment.