Skip to content

Commit

Permalink
add test-export.R
Browse files Browse the repository at this point in the history
  • Loading branch information
dewittpe committed Sep 19, 2024
1 parent 95b92b5 commit 06e5de5
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tests/test-export.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
library(REDCapExporter)

# Tests rely on publicly available REDCap and tokens published
# https://github.com/redcap-tools/redcap-test-datasets/tree/master

# project_name token server_url pid server read_only operational notes
# archer 9A81268476645C4E5F03428B8AC3AA7B https://bbmc.ouhsc.edu/redcap/api/ 153 oklahoma-bbmc TRUE TRUE simple structure; read-only
# archer D70F9ACD1EDD6F151C6EA78683944E98 https://bbmc.ouhsc.edu/redcap/api/ 213 oklahoma-bbmc FALSE TRUE simple structure; read & write
# archer 0434F0E9CF53ED0587847AB6E51DE762 https://bbmc.ouhsc.edu/redcap/api/ 212 oklahoma-bbmc TRUE TRUE longitudinal structure; read-only
# archer D72C6485B52FE9F75D27B696977FBA43 https://bbmc.ouhsc.edu/redcap/api/ 268 oklahoma-bbmc TRUE TRUE Russian characters; read-only

archer01_csv <- export_core(uri = 'https://bbmc.ouhsc.edu/redcap/api/', token = '9A81268476645C4E5F03428B8AC3AA7B')
archer01_json <- export_core(uri = 'https://bbmc.ouhsc.edu/redcap/api/', token = '9A81268476645C4E5F03428B8AC3AA7B', format = "json")

stopifnot(
inherits(archer01_csv, "rcer_rccore"),
inherits(archer01_json, "rcer_rccore"),
inherits(archer01_csv$project_raw, "rcer_raw_project"),
inherits(archer01_json$project_raw, "rcer_raw_project"),
inherits(archer01_csv$metadata_raw, "rcer_raw_metadata"),
inherits(archer01_json$metadata_raw, "rcer_raw_metadata"),
inherits(archer01_csv$project_raw, "rcer_raw_project"),
inherits(archer01_json$project_raw, "rcer_raw_project"),
inherits(archer01_csv$record_raw, "rcer_raw_record"),
inherits(archer01_json$record_raw, "rcer_raw_record"),
grepl("text/csv", attr(archer01_csv$record_raw, "Content-Type")),
grepl("application/json", attr(archer01_json$record_raw, "Content-Type"))
)

a1 <- format_record(archer01_csv)
a2 <- format_record(archer01_json)

# apparently the end of line characters are exported differently
a1$address <- gsub('\n', ' ', gsub('\r', '', a1$address))
a2$address <- gsub('\n', ' ', gsub('\r', '', a2$address))
a1$comments <- gsub('\n', ' ', gsub('\r', '', a1$comments))
a2$comments <- gsub('\n', ' ', gsub('\r', '', a2$comments))

stopifnot(isTRUE(all.equal(a1, a2)))




#
#archer02 <- export_core(uri = 'https://bbmc.ouhsc.edu/redcap/api/', token = 'D70F9ACD1EDD6F151C6EA78683944E98')
#archer02 <- format_record(archer02)
#
#archer03 <- export_core(uri = 'https://bbmc.ouhsc.edu/redcap/api/', token = '0434F0E9CF53ED0587847AB6E51DE762')
#archer03 <- format_record(archer03)
#
#archer04 <- export_core(uri = 'https://bbmc.ouhsc.edu/redcap/api/', token = 'D72C6485B52FE9F75D27B696977FBA43')
#archer04 <- format_record(archer04)

0 comments on commit 06e5de5

Please sign in to comment.