Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new user fields #528

Merged
merged 19 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Suggests:
License: MIT + file LICENSE
VignetteBuilder: knitr
Encoding: UTF-8
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Roxygen: list(markdown = TRUE)
Config/testthat/edition: 3
Language: en-US
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ The package has been stable for years and should be reflected in the major versi

* Accepts more than one `config_option` element. (Proposed by @BastienRance, #307)
* Fixed calculation of `success` value returned by `redcap_read()` and `redcap_write()` when the parameter `continue_on_error` is true. (Bug found by @llrs, #317)
* [`redcap_survey_link_export_oneshot()`](https://ouhscbbmc.github.io/REDCapR/reference/redcap_survey_link_export_oneshot.html) documentation corrected & improved (@jrob95, #526)

Version 0.11.0 (Released 2020-04-20)
==========================================================
Expand Down
2 changes: 1 addition & 1 deletion R/REDCapR-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#' following projects. We appreciate the support.
#' * *OUHSC CCAN Independent Evaluation of the State of Oklahoma Competitive
#' Maternal, Infant, and Early Childhood Home Visiting
#' ([MIECHV](https://mchb.hrsa.gov/maternal-child-health-initiatives/home-visiting-overview)) Project*.
#' ([MIECHV](https://mchb.hrsa.gov/programs-impact/programs/home-visiting/maternal-infant-early-childhood-home-visiting-miechv-program)) Project*.
#' HRSA/ACF D89MC23154.
#' David Bard, PI, OUHSC; 2011-2015.
#' * *Independent Evaluation of the State of OK MIECHV Evidence Based Home
Expand Down
2 changes: 1 addition & 1 deletion R/helpers-testing.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
retrieve_credential_testing <- function(project_id = 153L, username = NA_character_) {
checkmate::assert_integer(project_id, lower = 1, len = 1, any.missing = FALSE)
REDCapR::retrieve_credential_local(
REDCapR::retrieve_credential_local(
path_credential = system.file("misc/example.credentials", package = "REDCapR"),
project_id = project_id,
username = username
Expand Down
34 changes: 17 additions & 17 deletions R/project-dag-write.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,23 @@ populate_project_dag_write <- function(batch = FALSE, verbose = FALSE) {

# Import the data into the REDCap project
# testthat::expect_message(
returned_object <- if (batch) {
REDCapR::redcap_write(
ds_to_write = ds_to_write,
redcap_uri = project$redcap_uri,
token = project$token,
verbose = verbose,
convert_logical_to_integer = TRUE
)
} else {
REDCapR::redcap_write_oneshot(
ds = ds_to_write,
redcap_uri = project$redcap_uri,
token = project$token,
verbose = verbose,
convert_logical_to_integer = TRUE
)
}
returned_object <- if (batch) {
REDCapR::redcap_write(
ds_to_write = ds_to_write,
redcap_uri = project$redcap_uri,
token = project$token,
verbose = verbose,
convert_logical_to_integer = TRUE
)
} else {
REDCapR::redcap_write_oneshot(
ds = ds_to_write,
redcap_uri = project$redcap_uri,
token = project$token,
verbose = verbose,
convert_logical_to_integer = TRUE
)
}
# )

# # If uploading the data was successful, then upload the image files.
Expand Down
18 changes: 9 additions & 9 deletions R/redcap-delete.R
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,15 @@ redcap_delete <- function(
kernel$raw_text <- ""
} else {
records_affected_count <- 0
error_message <- sprintf(
paste(
"The REDCapR record deletion failed.",
"The http status code was %i.",
"The error message was: '%s'."
),
kernel$status_code,
kernel$raw_text
)
error_message <- sprintf(
paste(
"The REDCapR record deletion failed.",
"The http status code was %i.",
"The error message was: '%s'."
),
kernel$status_code,
kernel$raw_text
)
stop(error_message)
}
} else {
Expand Down
10 changes: 5 additions & 5 deletions R/redcap-event-read.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@
#' }
#' @export
redcap_event_read <- function(
redcap_uri,
token,
verbose = TRUE,
config_options = NULL,
handle_httr = NULL
redcap_uri,
token,
verbose = TRUE,
config_options = NULL,
handle_httr = NULL
) {

checkmate::assert_character(redcap_uri, any.missing=FALSE, len=1, pattern="^.{1,}$")
Expand Down
1 change: 0 additions & 1 deletion R/redcap-log-read.R
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ redcap_log_read <- function(
# where it's under the control of the caller.
silent = TRUE
)
# browser()

if (exists("ds") && inherits(ds, "data.frame")) {
outcome_message <- sprintf(
Expand Down
16 changes: 8 additions & 8 deletions R/redcap-metadata-coltypes.R
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,14 @@ redcap_metadata_coltypes <- function(

#' @importFrom magrittr %>%
redcap_metadata_internal <- function(
redcap_uri,
token,

http_response_encoding = "UTF-8",
locale = readr::default_locale(),
verbose = FALSE,
config_options = NULL,
handle_httr = NULL
redcap_uri,
token,

http_response_encoding = "UTF-8",
locale = readr::default_locale(),
verbose = FALSE,
config_options = NULL,
handle_httr = NULL
) {

checkmate::assert_character(redcap_uri , any.missing=FALSE, len=1, pattern="^.{1,}$")
Expand Down
3 changes: 2 additions & 1 deletion R/redcap-project-info-read.R
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,9 @@ redcap_project_info_read <- function(

# Build a column specification that matches the API response.
col_types <- readr::cols()
for (present_name in present_names)
for (present_name in present_names) {
col_types$cols <- c(col_types$cols, all_col_types$cols[present_name])
}

# Convert the raw text to a dataset.
ds <-
Expand Down
65 changes: 32 additions & 33 deletions R/redcap-read-eav-oneshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -172,31 +172,31 @@
#' @importFrom magrittr %>%
# Intentionally NOT exporting for now: @export
redcap_read_eav_oneshot <- function(
redcap_uri,
token,
records = NULL,
fields = NULL,
forms = NULL,
events = NULL,
# raw_or_label = "raw",
# raw_or_label_headers = "raw",
# export_checkbox_label = FALSE,
# placeholder returnFormat
export_survey_fields = FALSE,
export_data_access_groups = FALSE,
filter_logic = "",
datetime_range_begin = as.POSIXct(NA),
datetime_range_end = as.POSIXct(NA),
blank_for_gray_form_status = FALSE,
# col_types = NULL,
# guess_type = TRUE,
# guess_max = 1000,
http_response_encoding = "UTF-8",
locale = readr::default_locale(),
verbose = TRUE,
config_options = NULL,
handle_httr = NULL
# encode_httr = "multipart"
redcap_uri,
token,
records = NULL,
fields = NULL,
forms = NULL,
events = NULL,
# raw_or_label = "raw",
# raw_or_label_headers = "raw",
# export_checkbox_label = FALSE,
# placeholder returnFormat
export_survey_fields = FALSE,
export_data_access_groups = FALSE,
filter_logic = "",
datetime_range_begin = as.POSIXct(NA),
datetime_range_end = as.POSIXct(NA),
blank_for_gray_form_status = FALSE,
# col_types = NULL,
# guess_type = TRUE,
# guess_max = 1000,
http_response_encoding = "UTF-8",
locale = readr::default_locale(),
verbose = TRUE,
config_options = NULL,
handle_httr = NULL
# encode_httr = "multipart"
) {

checkmate::assert_character(redcap_uri , any.missing=FALSE, len=1, pattern="^.{1,}$")
Expand All @@ -205,11 +205,11 @@ redcap_read_eav_oneshot <- function(
checkmate::assert_character(fields , any.missing=TRUE , min.len=1, pattern="^.{1,}$", null.ok=TRUE)
checkmate::assert_character(forms , any.missing=TRUE , min.len=1, pattern="^.{1,}$", null.ok=TRUE)
checkmate::assert_character(events , any.missing=TRUE , min.len=1, pattern="^.{1,}$", null.ok=TRUE)
# checkmate::assert_character(raw_or_label , any.missing=FALSE, len=1)
# checkmate::assert_subset( raw_or_label , c("raw", "label"))
# checkmate::assert_character(raw_or_label_headers , any.missing=FALSE, len=1)
# checkmate::assert_subset( raw_or_label_headers , c("raw", "label"))
# checkmate::assert_logical( export_checkbox_label , any.missing=FALSE, len=1)
# checkmate::assert_character(raw_or_label , any.missing=FALSE, len=1)
# checkmate::assert_subset( raw_or_label , c("raw", "label"))
# checkmate::assert_character(raw_or_label_headers , any.missing=FALSE, len=1)
# checkmate::assert_subset( raw_or_label_headers , c("raw", "label"))
# checkmate::assert_logical( export_checkbox_label , any.missing=FALSE, len=1)
# placeholder: returnFormat
checkmate::assert_logical( export_survey_fields , any.missing=FALSE, len=1)
checkmate::assert_logical( export_data_access_groups , any.missing=FALSE, len=1)
Expand All @@ -218,8 +218,8 @@ redcap_read_eav_oneshot <- function(
checkmate::assert_posixct( datetime_range_end , any.missing=TRUE , len=1, null.ok=TRUE)
checkmate::assert_logical( blank_for_gray_form_status , any.missing=FALSE, len=1)

# checkmate::assert_logical( guess_type , any.missing=FALSE, len=1)
# checkmate::assert_numeric( guess_max , any.missing=FALSE, len=1, lower=1)
# checkmate::assert_logical( guess_type , any.missing=FALSE, len=1)
# checkmate::assert_numeric( guess_max , any.missing=FALSE, len=1, lower=1)

checkmate::assert_character(http_response_encoding , any.missing=FALSE, len=1)
checkmate::assert_class( locale, "locale" , null.ok = FALSE)
Expand Down Expand Up @@ -284,7 +284,6 @@ redcap_read_eav_oneshot <- function(
readr::read_csv(
file = I(kernel$raw_text),
col_types = readr::cols(.default = readr::col_character()),
# guess_max = guess_max,
locale = locale,
show_col_types = FALSE
) %>%
Expand Down
2 changes: 1 addition & 1 deletion R/redcap-read-oneshot-eav.R
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ redcap_read_oneshot_eav <- function(
) %>%
dplyr::full_join(ds_possible_checkbox_rows, by=c("record", "field_name", "field_type", "event_id")) %>%
dplyr::mutate(
value =
value =
dplyr::if_else(
!is.na(.data$field_type) & (.data$field_type == "checkbox"),
as.character(!is.na(.data$value)),
Expand Down
2 changes: 1 addition & 1 deletion R/redcap-read.R
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ redcap_read <- function(
if (!is.null(events)) {
if (!metadata$longitudinal) {
"This project is NOT longitudinal, so do not pass a value to the `event` argument." %>%
stop(call. = FALSE)
stop(call. = FALSE)
} else {
events_in_project <-
redcap_event_read(
Expand Down
19 changes: 11 additions & 8 deletions R/redcap-survey-link-export-oneshot.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#' @title
#' Download a file from a REDCap project record
#' Get survey link from REDCap
#'
#' @description
#' This function uses REDCap's API to download a file.
#' This function uses REDCap's API to get the link for a survey.
#'
#' @param redcap_uri The
#' [uri](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier)/url
Expand All @@ -11,10 +11,12 @@
#' Required.
#' @param token The user-specific string that serves as the password for a
#' project. Required.
#' @param record The record ID where the file is to be imported. Required
#' @param record The record ID associated with the
#' survey link. Required
#' @param instrument The name of the instrument associated with the
#' survey link. Required
#' @param event The name of the event where the file is saved in REDCap.
#' @param event The name of the event associated with the
#' survey link.
#' Optional
#' @param verbose A boolean value indicating if `message`s should be printed
#' to the R console during the operation. Optional.
Expand All @@ -27,21 +29,22 @@
#'
#' @return
#' Currently, a list is returned with the following elements,
#' * `survey_link`: a character string containing the URL for the survey.
#' * `success`: A boolean value indicating if the operation was apparently
#' successful.
#' * `status_code`: The
#' [http status code](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes)
#' of the operation.
#' * `outcome_message`: A human readable string indicating the operation's
#' outcome.
#' * `records_affected_count`: The number of records inserted or updated.
#' * `affected_ids`: The subject IDs of the inserted or updated records.
#' * `instrument`: The instrument associated with the survey link.
#' * `records_affected_count`: The number of records associated with
#' the survey link.
#' * `affected_ids`: The subject IDs associated with the survey link.
#' * `elapsed_seconds`: The duration of the function.
#' * `raw_text`: If an operation is NOT successful, the text returned by
#' REDCap. If an operation is successful, the `raw_text` is returned as an
#' empty string to save RAM.
#' * `file_name`: The name of the file persisted to disk. This is useful if
#' the name stored in REDCap is used (which is the default).
#'
#' @details
#' Currently, the function doesn't modify any variable types to conform to
Expand Down
2 changes: 2 additions & 0 deletions R/redcap-users-export.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,13 @@ redcap_users_export <- function(
data_import_tool = readr::col_logical(),
data_comparison_tool = readr::col_logical(),
logging = readr::col_logical(),
email_logging = readr::col_logical(), # added 14.6.0
file_repository = readr::col_logical(),
data_quality_create = readr::col_logical(),
data_quality_execute = readr::col_logical(),
api_export = readr::col_logical(),
api_import = readr::col_logical(),
api_modules = readr::col_logical(), # added 14.6.0 maybe
mobile_app = readr::col_logical(),
mobile_app_download_data = readr::col_logical(),
record_create = readr::col_logical(),
Expand Down
4 changes: 2 additions & 2 deletions R/validate.R
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ assert_field_names <- function(field_names) {
"a letter. The bad names are {%s}.",
collapse = ""
) %>%
sprintf(length(bad_names), paste(bad_names, collapse = ", ")) %>%
stop()
sprintf(length(bad_names), paste(bad_names, collapse = ", ")) %>%
stop()
}
}

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[REDCapR](https://github.com/OuhscBbmc/REDCapR) <img src="man/figures/logo.png" align="right" width="130" />
[REDCapR](https://github.com/OuhscBbmc/REDCapR) <img src="man/figures/logo.png" align="right" width="130" alt="REDCapR logo"/>
=======

We’ve been using R with [REDCap](https://projectredcap.org/)'s API since 2012 and have developed [`REDCapR`](https://github.com/OuhscBbmc/REDCapR). Before encapsulating these functions in a package, we were replicating 50+ lines of code to contact REDCap and robustly transform the returned [csv](https://en.wikipedia.org/wiki/Comma-separated_values) into an R `data.frame`; it took twice that much to implement batching. All this can be done in one call to [`redcap_read()`](https://ouhscbbmc.github.io/REDCapR/reference/redcap_read.html):
Expand Down Expand Up @@ -60,7 +60,7 @@ We'd like to thank the following developers for their [advice](https://github.co

Much of this package has been developed to support the needs of the following projects. We appreciate the support. (So far) the primary developers of REDCapR are the external evaluators for [Oklahoma's MIECHV](https://oklahoma.gov/health/health-education/children---family-health/family-support-and-prevention-service/miechv-program-federal-home-visiting-grant.html) program. See the preliminary CQI reports (many of which use REDCapR) at <https://ouhscbbmc.github.io/MReportingPublic/>.

* *OUHSC CCAN Independent Evaluation of the State of Oklahoma Competitive Maternal, Infant, and Early Childhood Home Visiting ([MIECHV](https://mchb.hrsa.gov/maternal-child-health-initiatives/home-visiting-overview)) Project*. HRSA/ACF D89MC23154. David Bard, PI, OUHSC; 2011-2015.
* *OUHSC CCAN Independent Evaluation of the State of Oklahoma Competitive Maternal, Infant, and Early Childhood Home Visiting ([MIECHV](https://mchb.hrsa.gov/programs-impact/programs/home-visiting/maternal-infant-early-childhood-home-visiting-miechv-program)) Project*. HRSA/ACF D89MC23154. David Bard, PI, OUHSC; 2011-2015.
* *Independent Evaluation of the State of OK MIECHV Evidence Based Home Visitation Project*, [NIH](https://www.nih.gov/)-sponsored collaboration with [OSDH](https://oklahoma.gov/health.html). David Bard, PI, OUHSC; 2015-2017.
* *OSDH ParentPRO Pilot Evaluation*, federally-sponsored collaboration with [OSDH](https://oklahoma.gov/health.html). David Bard, PI, OUHSC; 2015-2017.
* *Title IV-E Waiver Project*, [HRSA/MCHB](https://mchb.hrsa.gov/)-sponsored collaboration with [OKDHS](https://oklahoma.gov/okdhs.html); David Bard, PI, OUHSC; 2014-2017.
Expand Down
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
url: https://ouhscbbmc.github.io/REDCapR

template:
bootstrap: 5
params:
bootswatch: simplex
docsearch:
Expand Down
Loading