Skip to content

Commit

Permalink
Merge branch 'release/1.20.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
pbchase committed Feb 28, 2024
2 parents aeb2f7b + 998c48b commit a54fc0f
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 268 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: redcapcustodian
Type: Package
Title: Data automation for R-centric workflows with a nod towards REDCap
Version: 1.19.0
Version: 1.20.0
Authors@R: c(
person("Philip", "Chase",
email = "pbc@ufl.edu",
Expand Down
4 changes: 1 addition & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export(get_institutional_person_data)
export(get_job_duration)
export(get_package_scope_var)
export(get_project_life_cycle)
export(get_redcap_credentials)
export(get_redcap_db_connection)
export(get_redcap_email_revisions)
export(get_redcap_emails)
Expand All @@ -40,8 +41,6 @@ export(log_job_failure)
export(log_job_success)
export(mutate_columns_to_posixct)
export(quit_non_interactive_run)
export(read_project_data)
export(read_project_metadata)
export(scrape_user_api_tokens)
export(send_email)
export(set_package_scope_var)
Expand All @@ -59,7 +58,6 @@ export(update_redcap_email_addresses)
export(write_allocations)
export(write_error_log_entry)
export(write_info_log_entry)
export(write_project_data)
export(write_summary_metrics)
export(write_to_sql_db)
importFrom(magrittr,"%>%")
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# redcapcustodian 1.20.0 (released 2024-02-28)
- Add get_redcap_credentials() (@ljwoodley, #149, #151)
- Revert "add redcap wrapper functions" (@ljwoodley, #149, #150)

# redcapcustodian 1.19.0 (released 2024-01-30)
- Add REDCapR wrapper functions (@ljwoodley, #147, #148)

Expand Down
60 changes: 60 additions & 0 deletions R/get_redcap_credentials.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#' Retrieve REDCap Credentials Based on Specified Parameters
#'
#' Fetches REDCap credentials from the CREDENTIALS_DB, allowing filtering based on
#' project ID, server short name, project short name, and username. At least one filtering
#' criterion must be provided.
#'
#' @param project_pid Optional project ID for filtering.
#' @param server_short_name Optional server short name for filtering.
#' @param project_short_name Optional project short name for filtering.
#' @param username Optional username for filtering.
#'
#' @return A dataframe of filtered REDCap credentials, including a 'url' column added for convenience.
#'
#' @examples
#' \dontrun{
#' source_credentials <- get_redcap_credentials(project_pid = "123")
#' prod_credentials <- get_redcap_credentials(server_short_name = "prod")
#' target_credentials <- prod_credentials |>
#' filter(str_detect(project_name, "biospecimens"))
#' }
#'
#' @export
#'
get_redcap_credentials <- function(project_pid = NA,
server_short_name = NA,
project_short_name = NA,
username = NA) {

# Verify that there is at least one parameter
if (
all(is.na(
c(
server_short_name,
username,
project_pid,
project_short_name
)
))
) {
stop("At least one parameter must be defined")
}

credentials_conn <- DBI::dbConnect(RSQLite::SQLite(), Sys.getenv("CREDENTIALS_DB"))

redcap_credentials <- dplyr::tbl(credentials_conn, "credentials") |>
# Filter on any non-NA parameter
# Parameters have to be localized so that will not be seen as columns in the data frame
dplyr::filter(is.na(!!project_pid) | .data$project_id == !!project_pid) |>
dplyr::filter(is.na(!!server_short_name) | .data$server_short_name == !!server_short_name) |>
dplyr::filter(is.na(!!project_short_name) | .data$project_short_name == !!project_short_name) |>
dplyr::filter(is.na(!!username) | .data$username == !!username) |>
dplyr::collect() |>
# Make a copy of redcap_uri to make redcapAPI coding a tiny bit simpler
dplyr::mutate(url = .data$redcap_uri)

DBI::dbDisconnect(credentials_conn)

return(redcap_credentials)
}

46 changes: 0 additions & 46 deletions R/read_project_data.R

This file was deleted.

45 changes: 0 additions & 45 deletions R/read_project_metadata.R

This file was deleted.

42 changes: 0 additions & 42 deletions R/write_project_data.R

This file was deleted.

2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.19.0
1.20.0
39 changes: 39 additions & 0 deletions man/get_redcap_credentials.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 0 additions & 40 deletions man/read_project_data.Rd

This file was deleted.

45 changes: 0 additions & 45 deletions man/read_project_metadata.Rd

This file was deleted.

Loading

0 comments on commit a54fc0f

Please sign in to comment.