R/download_records.R

Defines functions download_redcap_records

Documented in download_redcap_records

#' Download Records from Long-Term Care Facility REDcap Project
#'
#' `download_redcap_records()` downloads the records from the CFR REDcap
#' project, which contains information on long term care facility cases.
#'
#' @param api_token API token for CFR REDcap project
#'
#' @return A `tibble` containing all data in the CFR REDcap project
#'
#' @export
download_redcap_records <- function(
  api_token = Sys.getenv("redcap_CFR_token")
) {

  # URL base for API
  api_uri <- "https://redcap.health.tn.gov/redcap/api/"

  api_params <- list(
    token = api_token,
    content = "record",
    format = "json",
    type = "flat"
  )

  httr::RETRY(
    "POST",
    api_uri,
    body = api_params,
    times = 12L,
    pause_cap = 300L
  ) %>%
    httr::stop_for_status() %>%
    httr::content(as = "text") %>%
    jsonlite::fromJSON() %>%
    dplyr::as_tibble()
}
jesse-smith/covidCFR documentation built on Jan. 21, 2021, 2:32 a.m.