Skip to content

Commit

Permalink
test repeating instruments w/ sparse records
Browse files Browse the repository at this point in the history
ref #143
  • Loading branch information
wibeasley committed Nov 5, 2021
1 parent d340fd1 commit 7dda338
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 0 deletions.
1 change: 1 addition & 0 deletions inst/misc/example.credentials
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ redcap_uri,username,project_id,token,comment
"https://bbmc.ouhsc.edu/redcap/api/","myusername","2545","0BF11B9CB01F0B8F8EE203B7E07DEFD9","DAG Write"
"https://bbmc.ouhsc.edu/redcap/api/","myusername","2593","1C31398F332FCACA4C0A7B93B18D5CD4","super-wide #2--5,785 columns"
"https://bbmc.ouhsc.edu/redcap/api/","myusername","2597","5C1526186C4D04AE0A0630743E69B53C","super-wide #3--35,000 columns"
"https://bbmc.ouhsc.edu/redcap/api/","myusername","2603","56F43A10D01D6578A46393394D76D88F","Repeating Instruments --Sparse"
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
structure(list(record_id = c(1, 1, 1, 1, 2, 2, 3, 4, 5), redcap_repeat_instrument = c(NA,
"bp", "bp", "bp", NA, "bp", NA, NA, NA), redcap_repeat_instance = c(NA,
1, 2, 3, NA, 1, NA, NA, NA), date_enrolled = structure(c(18183,
NA, NA, NA, 17929, NA, 18935, 18935, NA), class = "Date"), first_name = c("aaa",
NA, NA, NA, "bbb", NA, "empty 3", "empty 4", "empty 5"), dob = structure(c(14896,
NA, NA, NA, 14642, NA, NA, NA, NA), class = "Date"), age = c(8.9,
NA, NA, NA, 9.6, NA, NA, NA, NA), ethnicity = c(1, NA, NA, NA,
0, NA, NA, NA, NA), race = c(4, NA, NA, NA, 6, NA, NA, NA, NA
), sex = c(0, NA, NA, NA, 1, NA, NA, NA, NA), demographics_complete = c(2,
NA, NA, NA, 2, NA, 0, 0, 0), date_bp = structure(c(NA, 18183,
18183, 18183, NA, 12512, NA, NA, NA), class = "Date"), bp_systolic = c(NA,
110, 111, 112, NA, 114, NA, NA, NA), bp_diastolic = c(NA, 100,
101, 102, NA, 104, NA, NA, NA), bp_complete = c(NA, 2, 2, 2,
NA, 2, NA, NA, NA)), row.names = c(NA, -9L), class = "data.frame")
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
structure(list(record_id = c(1, 1, 1, 1, 2, 2, 3, 4, 5), redcap_repeat_instrument = c(NA,
"bp", "bp", "bp", NA, "bp", NA, NA, NA), redcap_repeat_instance = c(NA,
1, 2, 3, NA, 1, NA, NA, NA), date_enrolled = structure(c(18183,
NA, NA, NA, 17929, NA, 18935, 18935, NA), class = "Date"), first_name = c("aaa",
NA, NA, NA, "bbb", NA, "empty 3", "empty 4", "empty 5"), dob = structure(c(14896,
NA, NA, NA, 14642, NA, NA, NA, NA), class = "Date"), age = c(8.9,
NA, NA, NA, 9.6, NA, NA, NA, NA), ethnicity = c(1, NA, NA, NA,
0, NA, NA, NA, NA), race = c(4, NA, NA, NA, 6, NA, NA, NA, NA
), sex = c(0, NA, NA, NA, 1, NA, NA, NA, NA), demographics_complete = c(2,
NA, NA, NA, 2, NA, 0, 0, 0), date_bp = structure(c(NA, 18183,
18183, 18183, NA, 12512, NA, NA, NA), class = "Date"), bp_systolic = c(NA,
110, 111, 112, NA, 114, NA, NA, NA), bp_diastolic = c(NA, 100,
101, 102, NA, 104, NA, NA, NA), bp_complete = c(NA, 2, 2, 2,
NA, 2, NA, NA, NA)), row.names = c(NA, -9L), class = "data.frame")
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
structure(list(record_id = c(1, 1, 1, 1, 2, 2, 3, 4, 5), redcap_repeat_instrument = c(NA,
"bp", "bp", "bp", NA, "bp", NA, NA, NA), redcap_repeat_instance = c(NA,
1, 2, 3, NA, 1, NA, NA, NA), date_enrolled = structure(c(18183,
NA, NA, NA, 17929, NA, 18935, 18935, NA), class = "Date"), first_name = c("aaa",
NA, NA, NA, "bbb", NA, "empty 3", "empty 4", "empty 5"), dob = structure(c(14896,
NA, NA, NA, 14642, NA, NA, NA, NA), class = "Date"), age = c(8.9,
NA, NA, NA, 9.6, NA, NA, NA, NA), ethnicity = c(1, NA, NA, NA,
0, NA, NA, NA, NA), race = c(4, NA, NA, NA, 6, NA, NA, NA, NA
), sex = c(0, NA, NA, NA, 1, NA, NA, NA, NA), demographics_complete = c(2,
NA, NA, NA, 2, NA, 0, 0, 0), date_bp = structure(c(NA, 18183,
18183, 18183, NA, 12512, NA, NA, NA), class = "Date"), bp_systolic = c(NA,
110, 111, 112, NA, 114, NA, NA, NA), bp_diastolic = c(NA, 100,
101, 102, NA, 104, NA, NA, NA), bp_complete = c(NA, 2, 2, 2,
NA, 2, NA, NA, NA)), row.names = c(NA, -9L), class = "data.frame")
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
structure(list(record_id = c(1, 1, 1, 1, 2, 2, 3, 4, 5), redcap_repeat_instrument = c(NA,
"bp", "bp", "bp", NA, "bp", NA, NA, NA), redcap_repeat_instance = c(NA,
1, 2, 3, NA, 1, NA, NA, NA), date_enrolled = structure(c(18183,
NA, NA, NA, 17929, NA, 18935, 18935, NA), class = "Date"), first_name = c("aaa",
NA, NA, NA, "bbb", NA, "empty 3", "empty 4", "empty 5"), dob = structure(c(14896,
NA, NA, NA, 14642, NA, NA, NA, NA), class = "Date"), age = c(8.9,
NA, NA, NA, 9.6, NA, NA, NA, NA), ethnicity = c(1, NA, NA, NA,
0, NA, NA, NA, NA), race = c(4, NA, NA, NA, 6, NA, NA, NA, NA
), sex = c(0, NA, NA, NA, 1, NA, NA, NA, NA), demographics_complete = c(2,
NA, NA, NA, 2, NA, 0, 0, 0), date_bp = structure(c(NA, 18183,
18183, 18183, NA, 12512, NA, NA, NA), class = "Date"), bp_systolic = c(NA,
110, 111, 112, NA, 114, NA, NA, NA), bp_diastolic = c(NA, 100,
101, 102, NA, 104, NA, NA, NA), bp_complete = c(NA, 2, 2, 2,
NA, 2, NA, NA, NA)), row.names = c(NA, -9L), class = "data.frame")
129 changes: 129 additions & 0 deletions tests/testthat/test-read-batch-repeating-sparse.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
library(testthat)

credential <- retrieve_credential_testing(project_id = 2603L)
update_expectation <- FALSE

test_that("smoke test", {
testthat::skip_on_cran()
expect_message(
returned_object <-
redcap_read(
redcap_uri = credential$redcap_uri,
token = credential$token
)
)
})

test_that("default", {
testthat::skip_on_cran()
path_expected <- "test-data/specific-redcapr/read-batch-repeating-sparse/default.R"
expected_outcome_message <- "\\d+ records and \\d+ columns were read from REDCap in \\d+(\\.\\d+\\W|\\W)seconds\\."

expect_message(
regexp = expected_outcome_message,
returned_object <-
redcap_read(
redcap_uri = credential$redcap_uri,
token = credential$token#,
# batch_size = 1
)
)

if (update_expectation) save_expected(returned_object$data, path_expected)
expected_data_frame <- retrieve_expected(path_expected)

expect_equal(returned_object$data, expected=expected_data_frame, label="The returned data.frame should be correct", ignore_attr = TRUE) # dput(returned_object$data)
expect_equal(returned_object$status_code, expected="200")
expect_true(returned_object$records_collapsed=="", "A subset of records was not requested.")
expect_true(returned_object$fields_collapsed=="", "A subset of fields was not requested.")
expect_true(returned_object$filter_logic=="", "A filter was not specified.")
expect_match(returned_object$outcome_message, regexp=expected_outcome_message, perl=TRUE)
expect_true(returned_object$success)
})


test_that("batch size 3", {
testthat::skip_on_cran()
path_expected <- "test-data/specific-redcapr/read-batch-repeating-sparse/batch-size-3.R"
expected_outcome_message <- "\\d+ records and \\d+ columns were read from REDCap in \\d+(\\.\\d+\\W|\\W)seconds\\."

expect_message(
regexp = expected_outcome_message,
returned_object <-
redcap_read(
redcap_uri = credential$redcap_uri,
token = credential$token,
batch_size = 3
)
)

if (update_expectation) save_expected(returned_object$data, path_expected)
expected_data_frame <- retrieve_expected(path_expected)

expect_equal(returned_object$data, expected=expected_data_frame, label="The returned data.frame should be correct", ignore_attr = TRUE) # dput(returned_object$data)
expect_equal(returned_object$status_code, expected="200; 200")
expect_true(returned_object$records_collapsed=="", "A subset of records was not requested.")
expect_true(returned_object$fields_collapsed=="", "A subset of fields was not requested.")
expect_true(returned_object$filter_logic=="", "A filter was not specified.")
expect_match(returned_object$outcome_message, regexp=expected_outcome_message, perl=TRUE)
expect_true(returned_object$success)
})


test_that("batch size 2", {
testthat::skip_on_cran()
path_expected <- "test-data/specific-redcapr/read-batch-repeating-sparse/batch-szie-2.R"
expected_outcome_message <- "\\d+ records and \\d+ columns were read from REDCap in \\d+(\\.\\d+\\W|\\W)seconds\\."

expect_message(
regexp = expected_outcome_message,
returned_object <-
redcap_read(
redcap_uri = credential$redcap_uri,
token = credential$token,
batch_size = 2
)
)

if (update_expectation) save_expected(returned_object$data, path_expected)
expected_data_frame <- retrieve_expected(path_expected)

expect_equal(returned_object$data, expected=expected_data_frame, label="The returned data.frame should be correct", ignore_attr = TRUE) # dput(returned_object$data)
expect_equal(returned_object$status_code, expected="200; 200; 200")
expect_true(returned_object$records_collapsed=="", "A subset of records was not requested.")
expect_true(returned_object$fields_collapsed=="", "A subset of fields was not requested.")
expect_true(returned_object$filter_logic=="", "A filter was not specified.")
expect_match(returned_object$outcome_message, regexp=expected_outcome_message, perl=TRUE)
expect_true(returned_object$success)
})


test_that("batch size 1", {
testthat::skip_on_cran()
path_expected <- "test-data/specific-redcapr/read-batch-repeating-sparse/batch-size-1.R"
expected_outcome_message <- "\\d+ records and \\d+ columns were read from REDCap in \\d+(\\.\\d+\\W|\\W)seconds\\."

expect_message(
regexp = expected_outcome_message,
returned_object <-
redcap_read(
redcap_uri = credential$redcap_uri,
token = credential$token,
batch_size = 1
)
)

if (update_expectation) save_expected(returned_object$data, path_expected)
expected_data_frame <- retrieve_expected(path_expected)

expect_equal(returned_object$data, expected=expected_data_frame, label="The returned data.frame should be correct", ignore_attr = TRUE) # dput(returned_object$data)
expect_equal(returned_object$status_code, expected="200; 200; 200; 200; 200")
expect_true(returned_object$records_collapsed=="", "A subset of records was not requested.")
expect_true(returned_object$fields_collapsed=="", "A subset of fields was not requested.")
expect_true(returned_object$filter_logic=="", "A filter was not specified.")
expect_match(returned_object$outcome_message, regexp=expected_outcome_message, perl=TRUE)
expect_true(returned_object$success)
})

rm(credential)

0 comments on commit 7dda338

Please sign in to comment.