diff --git a/.gitignore b/.gitignore index 86747a5f..e4676d16 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.vscode/ .Rproj.user .Rhistory .RData diff --git a/DESCRIPTION b/DESCRIPTION index 2304048a..ca1913f7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -37,7 +37,6 @@ License: Apache License (>= 2) Encoding: UTF-8 LazyData: true Imports: - bit64, dplyr, jsonlite, lubridate, diff --git a/NAMESPACE b/NAMESPACE index a78c225b..0c2f7d94 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,7 +4,6 @@ export(connect_to_rcc_billing_db) export(draft_communication_record_from_line_item) export(fix_data_in_invoice_line_item) export(fix_data_in_invoice_line_item_communication) -export(fix_data_in_redcap_log_event) export(fix_data_in_redcap_projects) export(fix_data_in_redcap_user_information) export(get_bad_emails_from_log) diff --git a/R/data.R b/R/data.R index d2d19668..8f6f45f9 100644 --- a/R/data.R +++ b/R/data.R @@ -33,74 +33,6 @@ #' @source \url{https://github.com/ctsit/rcc.billing/issues/3} "invoice_line_item_test_data" -#' Sample data for service_instance table -#' -#' @format -#' \describe{ -#' \item{service_instance_id}{the primary key} -#' \item{service_type_code}{a numeric code that uniquely identifies the service_type} -#' \item{service_identifier}{either a redcap project ID, or redcap username} -#' \item{ctsi_study_id}{CSBT’s unique identifier for a service} -#' \item{active}{a boolean indicating if we expect to continue billing for this service} -#' } -#' -#' @source \url{https://github.com/ctsit/rcc.billing/issues/2} -"service_instance_test_data" - -#' Sample data for service_type table -#' -#' @format -#' \describe{ -#' \item{service_type_code}{a numeric code that uniquely identifies the service_type} -#' \item{service_type}{short name describing the service_type, in snake case} -#' \item{price}{price for one unit of the service, in US dollars} -#' \item{billing_frequency}{frequency at which this service ir billed, in months} -#' } -#' -#' @source \url{https://github.com/ctsit/rcc.billing/issues/1} -"service_type_test_data" - -#' @title invoice_line_item_communications_test_data -#' @description A test dataset for testing functions that write or read invoice_line_item_communications -#' @format A data frame with 26 rows and 32 variables: -#' \describe{ -#' \item{\code{id}}{double: the primary key} -#' \item{\code{service_identifier}}{character: either a redcap project ID, or redcap username} -#' \item{\code{service_type_code}}{double: a numeric code that uniquely identifies the service_type} -#' \item{\code{service_instance_id}}{character: a numeric code that uniquely identifies the service_instance} -#' \item{\code{ctsi_study_id}}{double: CSBT's unique identifier for a service} -#' \item{\code{name_of_service}}{character: name of the service} -#' \item{\code{name_of_service_instance}}{character: name of the study} -#' \item{\code{other_system_invoicing_comments}}{character: additional invoice information, either project url, or sponsor and pi} -#' \item{\code{price_of_service}}{double: price of the service, in US dollars} -#' \item{\code{qty_provided}}{double: quantity provided} -#' \item{\code{amount_due}}{double: amount due, in US dollars} -#' \item{\code{fiscal_year}}{character: fiscal year of the invoice} -#' \item{\code{month_invoiced}}{character: month of the invoice} -#' \item{\code{pi_last_name}}{character: last name of the person invoiced} -#' \item{\code{pi_first_name}}{character: first name of the person invoiced} -#' \item{\code{pi_email}}{character: email of the person invoiced} -#' \item{\code{gatorlink}}{character: gatorlink of the person invoiced} -#' \item{\code{crc_number}}{double: Clinical Research Center number} -#' \item{\code{ids_number}}{character: Investigational Drug Service number} -#' \item{\code{ocr_number}}{character: Office of Clinical Research study number} -#' \item{\code{invoice_number}}{double: invoice number} -#' \item{\code{je_number}}{character: journal entry number} -#' \item{\code{je_posting_date}}{POSIXct: journal entry posting date} -#' \item{\code{reason}}{character: reason for the invoice} -#' \item{\code{status}}{character: status of the invoice} -#' \item{\code{created}}{POSIXct: created at timestamp} -#' \item{\code{updated}}{POSIXct: updated at timestamp} -#' \item{\code{sender}}{character: message sender, typically an email address} -#' \item{\code{recipient}}{character: message recipient, typically an email address} -#' \item{\code{date_sent}}{POSIXct: date CTSI sent the message} -#' \item{\code{date_received}}{POSIXct: date CTSIT received the email} -#' \item{\code{script_name}}{character: the script that created this record} -#' } -#' -#' @source \url{https://github.com/ctsit/rcc.billing/issues/7} -"invoice_line_item_communications_test_data" - #' @title CTS-IT Staff #' @description usernames of CTS-IT staff #' @format A data frame with 6 rows and 1 variable: @@ -434,87 +366,6 @@ #' } "projects_table_fragment" -#' @title redcap_user_information_test_data -#' @description Test dataset for redcap_user_information -#' @format A data frame with 5 rows and 49 variables: -#' \describe{ -#' \item{\code{ui_id}}{integer primary key} -#' \item{\code{username}}{character redcap username} -#' \item{\code{user_email}}{character primary email address} -#' \item{\code{user_email2}}{character} -#' \item{\code{user_email3}}{character} -#' \item{\code{user_phone}}{character} -#' \item{\code{user_phone_sms}}{character} -#' \item{\code{user_firstname}}{character} -#' \item{\code{user_lastname}}{character} -#' \item{\code{user_inst_id}}{character} -#' \item{\code{super_user}}{integer} -#' \item{\code{account_manager}}{integer} -#' \item{\code{access_system_config}}{integer} -#' \item{\code{access_system_upgrade}}{integer} -#' \item{\code{access_external_module_install}}{integer} -#' \item{\code{admin_rights}}{integer} -#' \item{\code{access_admin_dashboards}}{integer} -#' \item{\code{user_creation}}{double} -#' \item{\code{user_firstvisit}}{double} -#' \item{\code{user_firstactivity}}{double} -#' \item{\code{user_lastactivity}}{double} -#' \item{\code{user_lastlogin}}{double} -#' \item{\code{user_suspended_time}}{double} -#' \item{\code{user_expiration}}{double} -#' \item{\code{user_access_dashboard_view}}{double} -#' \item{\code{user_access_dashboard_email_queued}}{character} -#' \item{\code{user_sponsor}}{character} -#' \item{\code{user_comments}}{character} -#' \item{\code{allow_create_db}}{integer} -#' \item{\code{email_verify_code}}{character} -#' \item{\code{email2_verify_code}}{character} -#' \item{\code{email3_verify_code}}{character} -#' \item{\code{datetime_format}}{character} -#' \item{\code{number_format_decimal}}{character} -#' \item{\code{number_format_thousands_sep}}{character} -#' \item{\code{csv_delimiter}}{character} -#' \item{\code{two_factor_auth_secret}}{character} -#' \item{\code{display_on_email_users}}{integer} -#' \item{\code{two_factor_auth_twilio_prompt_phone}}{integer} -#' \item{\code{two_factor_auth_code_expiration}}{integer} -#' \item{\code{api_token}}{character} -#' \item{\code{messaging_email_preference}}{character} -#' \item{\code{messaging_email_urgent_all}}{integer} -#' \item{\code{messaging_email_ts}}{double} -#' \item{\code{messaging_email_general_system}}{integer} -#' \item{\code{messaging_email_queue_time}}{double} -#' \item{\code{ui_state}}{character} -#' \item{\code{api_token_auto_request}}{integer} -#' \item{\code{fhir_data_mart_create_project}}{integer} -#' } -#' @details DETAILS -"redcap_user_information_test_data" - -#' @title redcap_log_event_test_data -#' @description a named list of redcap_log_event tables with project lifecycle test data -#' @format A named list of 10 dataframes each with a 0 or more rows of 15 variables. -#' Each dataframe is structured as described here. -#' \describe{ -#' \item{\code{log_event_id}}{integer primary key} -#' \item{\code{project_id}}{integer REDCap project_id} -#' \item{\code{ts}}{double a timestamp in the format YYYYMMDDHHMMSS in local time} -#' \item{\code{user}}{character the REDCap username who initiated this event} -#' \item{\code{ip}}{character IP address of that REDCap user} -#' \item{\code{page}}{character relative REDCap URL that initiated this event} -#' \item{\code{event}}{character the type of event. e.g DATA_EXPORT, DELETE, ERROR, INSERT, MANAGE, OTHER, UPDATE} -#' \item{\code{object_type}}{character a REDCap object type e.g., NA, redcap_arms, redcap_auth, redcap_data, redcap_docs, redcap_event_forms, redcap_events, redcap_events_metadata, redcap_metadata, redcap_metadata_temp, redcap_projects, redcap_user_rights} -#' \item{\code{sql_log}}{character the SQL code executed during this event} -#' \item{\code{pk}}{character the primary key of the effected object} -#' \item{\code{event_id}}{integer the REDCap event_id if relevant} -#' \item{\code{data_values}}{character} -#' \item{\code{description}}{character description of the event} -#' \item{\code{legacy}}{integer} -#' \item{\code{change_reason}}{character} -#' } -#' @details DETAILS -"redcap_log_event_test_data" - #' @title csbt_column_names #' @description Column names useful for CTSI-IT billing #' @format A data frame with 12 rows and 2 variables: @@ -524,25 +375,6 @@ #'} "csbt_column_names" -#' @title invoice_line_item_reasons -#' @description Provides text for new invoice line items -#' @format A data frame with 3 rows and 2 variables: -#' \describe{ -#' \item{\code{code}}{character: A short, static name for the string} -#' \item{\code{label}}{character: A friendly human-readable string} -#'} -"invoice_line_item_reasons" - -#' @title invoice_line_item_statuses -#' @description Describes valid invoice line item statuses -#' @format A data frame with 5 rows and 2 variables: -#' \describe{ -#' \item{\code{status}}{character: A short, static name for the status code} -#' \item{\code{description}}{character: A human-readable description of the status} -#'} -#' @details DETAILS -"invoice_line_item_statuses" - #' @title fiscal_years #' @description A dataframe of fiscal years and labels from 2019-2020 to 2039-2040 #' @format A data frame with 21 rows and 2 variables: @@ -558,14 +390,3 @@ #' @format A vector with 9 elements #' @details DETAILS "log_event_tables" - -#' @title redcap_rights_test_data -#' @description A named list of dataframes used to test the functions written for redcap_rights.R -#' @format A named list of 3 dataframes: -#' \describe{ -#' \item{\code{redcap_user_information}}{REDCap Core table} -#' \item{\code{redcap_user_rights}}{REDCap Core table} -#' \item{\code{redcap_user_roles}}{REDCap Core table} -#' } -#' @details DETAILS -"redcap_rights_test_data" diff --git a/R/transform.R b/R/transform.R index 83f267eb..a68caf32 100644 --- a/R/transform.R +++ b/R/transform.R @@ -175,39 +175,6 @@ fix_data_in_redcap_user_information <- function(data) { return(mutate_columns_to_posixct(data, time_columns)) } -#' fix_data_in_redcap_log_event -#' -#' Fixes column data types that can vary between MySQL/MariaDB and SQLite3. -#' This allows testing in SQLite3 while production is MariaDB -#' -#' @param data - a dataframe containing data from the redcap_log_event tables -#' -#' @return The input dataframe with revised data types -#' @export -#' -#' @examples -#' \dontrun{ -#' fix_data_in_redcap_log_event(redcap_log_event_test_data) -#' } -fix_data_in_redcap_log_event <- function(data) { - integer64_columns <- c( - "ts" - ) - if (nrow(data) == 0) { # zero-row SQLite3 tables get the wrong data type on ts - result <- data |> - dplyr::mutate( - dplyr::across( - dplyr::any_of(integer64_columns), - bit64::as.integer64 - ) - ) - } else { - result <- data - } - - return(result) -} - #' Renames columns of a dataframe from CTSIT format to CSBT format #' #' Excludes non-CSBT columns and renames CTSIT column names to the corresponding CSBT names. diff --git a/data-raw/invoice_line_items.R b/data-raw/invoice_line_items.R deleted file mode 100644 index 4fc49031..00000000 --- a/data-raw/invoice_line_items.R +++ /dev/null @@ -1,31 +0,0 @@ -library(dplyr) - -invoice_line_item_reasons <- tibble::tribble( - ~code, ~label, - "new_item", "New item to be invoiced", - "deleted", "Project deleted", - "reassigned", "PI reassigned", - "seeking_voucher", "seeking voucher", - # values from do not bill reason - "17", "17. Withdrawn/Canceled", - "21", "21. Duplicate Charge", - "24", "24. Project/Data deleted after invoice creation.", - "27", "27. PI no longer with UF", - "41", "41. Write-Off (True Write-Off, not billing issues)", - "45", "45. PI Left UF and project should have been sequestered/not invoiced.", - "46", "46. Did not meet billing criteria.", - "47", "47. Reassigned to new project owner who decided to delete within 30 days." -) - -usethis::use_data(invoice_line_item_reasons, overwrite = TRUE) - -invoice_line_item_statuses <- tribble( - ~status, ~description, - "draft", "draft invoices line items that have not yet been sent", - "sent", "the invoice line item has been sent to CSBT", - "canceled", "the invoice line item does not need to be paid", - "unreconciled", "CSBT says the line item is paid, but this has not yet been verified by CTS-IT", - "paid", "CTS-IT has verified the line item has been paid" -) - -usethis::use_data(invoice_line_item_statuses, overwrite = TRUE) diff --git a/data-raw/redcap_log_event_test_data.R b/data-raw/redcap_log_event_test_data.R deleted file mode 100644 index 9a2746bf..00000000 --- a/data-raw/redcap_log_event_test_data.R +++ /dev/null @@ -1,57 +0,0 @@ -# Create redcap_log_event_test_data with a subset of logged data -# that shows the entire logged project life-cycle across every -# redcap_log_event* table - -library(redcapcustodian) -library(rcc.billing) -library(tidyverse) -library(DBI) -library(RMariaDB) -library(dotenv) - -project_event_descriptions <- - c( - "Approve production project modifications (automatic)", - "Create project", - "Delete project", - "Request approval for production project modifications", - "Send request to move project to production status", - "Move project to production status", - "Permanently delete project", - "Copy project", - "Approve production project modifications", - "Create project using template", - "Archive project", - "Send request to create project", - "Set project as inactive", - "Reject production project modifications", - "Move project back to development status", - "Return project to production from inactive status", - "Reset production project modifications", - "Send request to copy project", - "Restore/undelete project", - "Create project (API)" - ) - -# run this once against a test redcap to extract the part we need -conn <- connect_to_redcap_db() - -base_table <- "redcap_log_event" -redcap_log_event_test_data <- list() -for (i in seq(1:9)) { - my_table <- if_else(i == 1, base_table, paste0(base_table, i)) - single_log_table <- - tbl(conn, my_table) %>% - filter(description %in% project_event_descriptions) %>% - collect() - redcap_log_event_test_data[[my_table]] <- single_log_table - - # write the schema - DBI::dbGetQuery(conn, paste("show create table", my_table))$`Create Table` %>% - write(file = paste0("inst/schema/", my_table, ".sql")) -} - -# write the test data -usethis::use_data(redcap_log_event_test_data, overwrite = T) - -dbDisconnect(conn) diff --git a/data-raw/redcap_user_information.R b/data-raw/redcap_user_information.R deleted file mode 100644 index 2fa4e0de..00000000 --- a/data-raw/redcap_user_information.R +++ /dev/null @@ -1,28 +0,0 @@ -## Create redcap_user_information from the database of a testing system - -library(redcapcustodian) -library(rcc.billing) -library(tidyverse) -library(lubridate) -library(DBI) -library(RMariaDB) -library(dotenv) - -my_table <- "redcap_user_information" - -# # run this once against a test redcap to extract the part we need -# conn <- connect_to_redcap_db() -# data <- tbl(conn, my_table) -# -# redcap_user_information_test_data <- data %>% -# collect() %>% -# filter(ui_id >= 3) -# -# # write the test data -# usethis::use_data(redcap_user_information_test_data, overwrite = T) -# -# # write the schema -# DBI::dbGetQuery(conn, paste("show create table", my_table))$`Create Table` %>% -# write(file = paste0("inst/schema/", my_table, ".sql")) -# -# dbDisconnect(conn) diff --git a/data/invoice_line_item_communications_test_data.rda b/data/invoice_line_item_communications_test_data.rda deleted file mode 100644 index ec22fabf..00000000 Binary files a/data/invoice_line_item_communications_test_data.rda and /dev/null differ diff --git a/data/invoice_line_item_reasons.rda b/data/invoice_line_item_reasons.rda deleted file mode 100644 index 5f707b68..00000000 Binary files a/data/invoice_line_item_reasons.rda and /dev/null differ diff --git a/data/invoice_line_item_statuses.rda b/data/invoice_line_item_statuses.rda deleted file mode 100644 index e3446365..00000000 Binary files a/data/invoice_line_item_statuses.rda and /dev/null differ diff --git a/data/redcap_log_event_test_data.rda b/data/redcap_log_event_test_data.rda deleted file mode 100644 index 7f0820f8..00000000 Binary files a/data/redcap_log_event_test_data.rda and /dev/null differ diff --git a/data/redcap_rights_test_data.rda b/data/redcap_rights_test_data.rda deleted file mode 100644 index 02dd2893..00000000 Binary files a/data/redcap_rights_test_data.rda and /dev/null differ diff --git a/data/redcap_user_information_test_data.rda b/data/redcap_user_information_test_data.rda deleted file mode 100644 index b3ea9f55..00000000 Binary files a/data/redcap_user_information_test_data.rda and /dev/null differ diff --git a/data/service_instance_test_data.rda b/data/service_instance_test_data.rda deleted file mode 100644 index 4957a5a5..00000000 Binary files a/data/service_instance_test_data.rda and /dev/null differ diff --git a/data/service_type_test_data.rda b/data/service_type_test_data.rda deleted file mode 100644 index 01614ad0..00000000 Binary files a/data/service_type_test_data.rda and /dev/null differ diff --git a/examples/ctsit_staff.R b/examples/ctsit_staff.R deleted file mode 100644 index 1ba09038..00000000 --- a/examples/ctsit_staff.R +++ /dev/null @@ -1,15 +0,0 @@ -library(DBI) -library(rcc.billing) - -table_name <- "ctsit_staff" -conn <- DBI::dbConnect(RSQLite::SQLite(), dbname = ":memory:") - -sqlite_schema <- convert_schema_to_sqlite(table_name = table_name) -create_table( - conn = conn, - schema = sqlite_schema -) -result <- populate_table( - conn = conn, - table_name = table_name -) diff --git a/examples/invoice_line_item.R b/examples/invoice_line_item.R deleted file mode 100644 index 454fccac..00000000 --- a/examples/invoice_line_item.R +++ /dev/null @@ -1,16 +0,0 @@ -library(DBI) -library(rcc.billing) - -table_name <- "invoice_line_item" -conn <- DBI::dbConnect(RSQLite::SQLite(), dbname = ":memory:") - -sqlite_schema <- convert_schema_to_sqlite(table_name = table_name) -create_table( - conn = conn, - schema = sqlite_schema -) -populate_table( - conn = conn, - table_name = table_name, - use_test_data = TRUE -) diff --git a/examples/invoice_line_item_communications.R b/examples/invoice_line_item_communications.R deleted file mode 100644 index 1fc27c3c..00000000 --- a/examples/invoice_line_item_communications.R +++ /dev/null @@ -1,16 +0,0 @@ -library(DBI) -library(rcc.billing) - -table_name <- "invoice_line_item_communications" -conn <- DBI::dbConnect(RSQLite::SQLite(), dbname = ":memory:") - -sqlite_schema <- convert_schema_to_sqlite(table_name = table_name) -create_table( - conn = conn, - schema = sqlite_schema -) -populate_table( - conn = conn, - table_name = table_name, - use_test_data = TRUE -) diff --git a/examples/redcap_projects.R b/examples/redcap_projects.R deleted file mode 100644 index 8f0be353..00000000 --- a/examples/redcap_projects.R +++ /dev/null @@ -1,18 +0,0 @@ -library(DBI) -library(rcc.billing) - -table_name <- "redcap_projects" -conn <- DBI::dbConnect(RSQLite::SQLite(), dbname = ":memory:") - -sqlite_schema <- convert_schema_to_sqlite(table_name = table_name) -create_table( - conn = conn, - schema = sqlite_schema -) -results <- populate_table( - conn = conn, - table_name = table_name, - use_test_data = TRUE -) - -DBI::dbDisconnect(conn) diff --git a/examples/service_instance.R b/examples/service_instance.R deleted file mode 100644 index ded79e8d..00000000 --- a/examples/service_instance.R +++ /dev/null @@ -1,16 +0,0 @@ -library(DBI) -library(rcc.billing) - -table_name <- "service_instance" -conn <- DBI::dbConnect(RSQLite::SQLite(), dbname = ":memory:") - -sqlite_schema <- convert_schema_to_sqlite(table_name = table_name) -create_table( - conn = conn, - schema = sqlite_schema -) -populate_table( - conn = conn, - table_name = table_name, - use_test_data = TRUE -) diff --git a/examples/service_type.R b/examples/service_type.R deleted file mode 100644 index e161841e..00000000 --- a/examples/service_type.R +++ /dev/null @@ -1,16 +0,0 @@ -library(DBI) -library(rcc.billing) - -table_name <- "service_type" -conn <- DBI::dbConnect(RSQLite::SQLite(), dbname = ":memory:") - -sqlite_schema <- convert_schema_to_sqlite(table_name = table_name) -create_table( - conn = conn, - schema = sqlite_schema -) -populate_table( - conn = conn, - table_name = table_name, - use_test_data = TRUE -) diff --git a/man/fix_data_in_redcap_log_event.Rd b/man/fix_data_in_redcap_log_event.Rd deleted file mode 100644 index 03f510dc..00000000 --- a/man/fix_data_in_redcap_log_event.Rd +++ /dev/null @@ -1,23 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/transform.R -\name{fix_data_in_redcap_log_event} -\alias{fix_data_in_redcap_log_event} -\title{fix_data_in_redcap_log_event} -\usage{ -fix_data_in_redcap_log_event(data) -} -\arguments{ -\item{data}{- a dataframe containing data from the redcap_log_event tables} -} -\value{ -The input dataframe with revised data types -} -\description{ -Fixes column data types that can vary between MySQL/MariaDB and SQLite3. -This allows testing in SQLite3 while production is MariaDB -} -\examples{ -\dontrun{ -fix_data_in_redcap_log_event(redcap_log_event_test_data) -} -} diff --git a/man/invoice_line_item_communications_test_data.Rd b/man/invoice_line_item_communications_test_data.Rd deleted file mode 100644 index 34095b56..00000000 --- a/man/invoice_line_item_communications_test_data.Rd +++ /dev/null @@ -1,53 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data.R -\docType{data} -\name{invoice_line_item_communications_test_data} -\alias{invoice_line_item_communications_test_data} -\title{invoice_line_item_communications_test_data} -\format{ -A data frame with 26 rows and 32 variables: -\describe{ - \item{\code{id}}{double: the primary key} - \item{\code{service_identifier}}{character: either a redcap project ID, or redcap username} - \item{\code{service_type_code}}{double: a numeric code that uniquely identifies the service_type} - \item{\code{service_instance_id}}{character: a numeric code that uniquely identifies the service_instance} - \item{\code{ctsi_study_id}}{double: CSBT's unique identifier for a service} - \item{\code{name_of_service}}{character: name of the service} - \item{\code{name_of_service_instance}}{character: name of the study} - \item{\code{other_system_invoicing_comments}}{character: additional invoice information, either project url, or sponsor and pi} - \item{\code{price_of_service}}{double: price of the service, in US dollars} - \item{\code{qty_provided}}{double: quantity provided} - \item{\code{amount_due}}{double: amount due, in US dollars} - \item{\code{fiscal_year}}{character: fiscal year of the invoice} - \item{\code{month_invoiced}}{character: month of the invoice} - \item{\code{pi_last_name}}{character: last name of the person invoiced} - \item{\code{pi_first_name}}{character: first name of the person invoiced} - \item{\code{pi_email}}{character: email of the person invoiced} - \item{\code{gatorlink}}{character: gatorlink of the person invoiced} - \item{\code{crc_number}}{double: Clinical Research Center number} - \item{\code{ids_number}}{character: Investigational Drug Service number} - \item{\code{ocr_number}}{character: Office of Clinical Research study number} - \item{\code{invoice_number}}{double: invoice number} - \item{\code{je_number}}{character: journal entry number} - \item{\code{je_posting_date}}{POSIXct: journal entry posting date} - \item{\code{reason}}{character: reason for the invoice} - \item{\code{status}}{character: status of the invoice} - \item{\code{created}}{POSIXct: created at timestamp} - \item{\code{updated}}{POSIXct: updated at timestamp} - \item{\code{sender}}{character: message sender, typically an email address} - \item{\code{recipient}}{character: message recipient, typically an email address} - \item{\code{date_sent}}{POSIXct: date CTSI sent the message} - \item{\code{date_received}}{POSIXct: date CTSIT received the email} - \item{\code{script_name}}{character: the script that created this record} -} -} -\source{ -\url{https://github.com/ctsit/rcc.billing/issues/7} -} -\usage{ -invoice_line_item_communications_test_data -} -\description{ -A test dataset for testing functions that write or read invoice_line_item_communications -} -\keyword{datasets} diff --git a/man/invoice_line_item_reasons.Rd b/man/invoice_line_item_reasons.Rd deleted file mode 100644 index 790152a3..00000000 --- a/man/invoice_line_item_reasons.Rd +++ /dev/null @@ -1,20 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data.R -\docType{data} -\name{invoice_line_item_reasons} -\alias{invoice_line_item_reasons} -\title{invoice_line_item_reasons} -\format{ -A data frame with 3 rows and 2 variables: -\describe{ - \item{\code{code}}{character: A short, static name for the string} - \item{\code{label}}{character: A friendly human-readable string} -} -} -\usage{ -invoice_line_item_reasons -} -\description{ -Provides text for new invoice line items -} -\keyword{datasets} diff --git a/man/invoice_line_item_statuses.Rd b/man/invoice_line_item_statuses.Rd deleted file mode 100644 index c92d724a..00000000 --- a/man/invoice_line_item_statuses.Rd +++ /dev/null @@ -1,23 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data.R -\docType{data} -\name{invoice_line_item_statuses} -\alias{invoice_line_item_statuses} -\title{invoice_line_item_statuses} -\format{ -A data frame with 5 rows and 2 variables: -\describe{ - \item{\code{status}}{character: A short, static name for the status code} - \item{\code{description}}{character: A human-readable description of the status} -} -} -\usage{ -invoice_line_item_statuses -} -\description{ -Describes valid invoice line item statuses -} -\details{ -DETAILS -} -\keyword{datasets} diff --git a/man/redcap_log_event_test_data.Rd b/man/redcap_log_event_test_data.Rd deleted file mode 100644 index 7eee9545..00000000 --- a/man/redcap_log_event_test_data.Rd +++ /dev/null @@ -1,37 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data.R -\docType{data} -\name{redcap_log_event_test_data} -\alias{redcap_log_event_test_data} -\title{redcap_log_event_test_data} -\format{ -A named list of 10 dataframes each with a 0 or more rows of 15 variables. - Each dataframe is structured as described here. -\describe{ - \item{\code{log_event_id}}{integer primary key} - \item{\code{project_id}}{integer REDCap project_id} - \item{\code{ts}}{double a timestamp in the format YYYYMMDDHHMMSS in local time} - \item{\code{user}}{character the REDCap username who initiated this event} - \item{\code{ip}}{character IP address of that REDCap user} - \item{\code{page}}{character relative REDCap URL that initiated this event} - \item{\code{event}}{character the type of event. e.g DATA_EXPORT, DELETE, ERROR, INSERT, MANAGE, OTHER, UPDATE} - \item{\code{object_type}}{character a REDCap object type e.g., NA, redcap_arms, redcap_auth, redcap_data, redcap_docs, redcap_event_forms, redcap_events, redcap_events_metadata, redcap_metadata, redcap_metadata_temp, redcap_projects, redcap_user_rights} - \item{\code{sql_log}}{character the SQL code executed during this event} - \item{\code{pk}}{character the primary key of the effected object} - \item{\code{event_id}}{integer the REDCap event_id if relevant} - \item{\code{data_values}}{character} - \item{\code{description}}{character description of the event} - \item{\code{legacy}}{integer} - \item{\code{change_reason}}{character} -} -} -\usage{ -redcap_log_event_test_data -} -\description{ -a named list of redcap_log_event tables with project lifecycle test data -} -\details{ -DETAILS -} -\keyword{datasets} diff --git a/man/redcap_rights_test_data.Rd b/man/redcap_rights_test_data.Rd deleted file mode 100644 index b1042366..00000000 --- a/man/redcap_rights_test_data.Rd +++ /dev/null @@ -1,24 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data.R -\docType{data} -\name{redcap_rights_test_data} -\alias{redcap_rights_test_data} -\title{redcap_rights_test_data} -\format{ -A named list of 3 dataframes: -\describe{ - \item{\code{redcap_user_information}}{REDCap Core table} - \item{\code{redcap_user_rights}}{REDCap Core table} - \item{\code{redcap_user_roles}}{REDCap Core table} -} -} -\usage{ -redcap_rights_test_data -} -\description{ -A named list of dataframes used to test the functions written for redcap_rights.R -} -\details{ -DETAILS -} -\keyword{datasets} diff --git a/man/redcap_user_information_test_data.Rd b/man/redcap_user_information_test_data.Rd deleted file mode 100644 index ae0ef7fc..00000000 --- a/man/redcap_user_information_test_data.Rd +++ /dev/null @@ -1,70 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data.R -\docType{data} -\name{redcap_user_information_test_data} -\alias{redcap_user_information_test_data} -\title{redcap_user_information_test_data} -\format{ -A data frame with 5 rows and 49 variables: -\describe{ - \item{\code{ui_id}}{integer primary key} - \item{\code{username}}{character redcap username} - \item{\code{user_email}}{character primary email address} - \item{\code{user_email2}}{character} - \item{\code{user_email3}}{character} - \item{\code{user_phone}}{character} - \item{\code{user_phone_sms}}{character} - \item{\code{user_firstname}}{character} - \item{\code{user_lastname}}{character} - \item{\code{user_inst_id}}{character} - \item{\code{super_user}}{integer} - \item{\code{account_manager}}{integer} - \item{\code{access_system_config}}{integer} - \item{\code{access_system_upgrade}}{integer} - \item{\code{access_external_module_install}}{integer} - \item{\code{admin_rights}}{integer} - \item{\code{access_admin_dashboards}}{integer} - \item{\code{user_creation}}{double} - \item{\code{user_firstvisit}}{double} - \item{\code{user_firstactivity}}{double} - \item{\code{user_lastactivity}}{double} - \item{\code{user_lastlogin}}{double} - \item{\code{user_suspended_time}}{double} - \item{\code{user_expiration}}{double} - \item{\code{user_access_dashboard_view}}{double} - \item{\code{user_access_dashboard_email_queued}}{character} - \item{\code{user_sponsor}}{character} - \item{\code{user_comments}}{character} - \item{\code{allow_create_db}}{integer} - \item{\code{email_verify_code}}{character} - \item{\code{email2_verify_code}}{character} - \item{\code{email3_verify_code}}{character} - \item{\code{datetime_format}}{character} - \item{\code{number_format_decimal}}{character} - \item{\code{number_format_thousands_sep}}{character} - \item{\code{csv_delimiter}}{character} - \item{\code{two_factor_auth_secret}}{character} - \item{\code{display_on_email_users}}{integer} - \item{\code{two_factor_auth_twilio_prompt_phone}}{integer} - \item{\code{two_factor_auth_code_expiration}}{integer} - \item{\code{api_token}}{character} - \item{\code{messaging_email_preference}}{character} - \item{\code{messaging_email_urgent_all}}{integer} - \item{\code{messaging_email_ts}}{double} - \item{\code{messaging_email_general_system}}{integer} - \item{\code{messaging_email_queue_time}}{double} - \item{\code{ui_state}}{character} - \item{\code{api_token_auto_request}}{integer} - \item{\code{fhir_data_mart_create_project}}{integer} -} -} -\usage{ -redcap_user_information_test_data -} -\description{ -Test dataset for redcap_user_information -} -\details{ -DETAILS -} -\keyword{datasets} diff --git a/man/service_instance_test_data.Rd b/man/service_instance_test_data.Rd deleted file mode 100644 index f3a19fc0..00000000 --- a/man/service_instance_test_data.Rd +++ /dev/null @@ -1,25 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data.R -\docType{data} -\name{service_instance_test_data} -\alias{service_instance_test_data} -\title{Sample data for service_instance table} -\format{ -\describe{ - \item{service_instance_id}{the primary key} - \item{service_type_code}{a numeric code that uniquely identifies the service_type} - \item{service_identifier}{either a redcap project ID, or redcap username} - \item{ctsi_study_id}{CSBT’s unique identifier for a service} - \item{active}{a boolean indicating if we expect to continue billing for this service} -} -} -\source{ -\url{https://github.com/ctsit/rcc.billing/issues/2} -} -\usage{ -service_instance_test_data -} -\description{ -Sample data for service_instance table -} -\keyword{datasets} diff --git a/man/service_type_test_data.Rd b/man/service_type_test_data.Rd deleted file mode 100644 index 0d775a78..00000000 --- a/man/service_type_test_data.Rd +++ /dev/null @@ -1,24 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data.R -\docType{data} -\name{service_type_test_data} -\alias{service_type_test_data} -\title{Sample data for service_type table} -\format{ -\describe{ - \item{service_type_code}{a numeric code that uniquely identifies the service_type} - \item{service_type}{short name describing the service_type, in snake case} - \item{price}{price for one unit of the service, in US dollars} - \item{billing_frequency}{frequency at which this service ir billed, in months} -} -} -\source{ -\url{https://github.com/ctsit/rcc.billing/issues/1} -} -\usage{ -service_type_test_data -} -\description{ -Sample data for service_type table -} -\keyword{datasets} diff --git a/data-raw/redcap_rights_test_data.R b/tests/testthat/get_user_rights_and_info_v1/make_test_data.R similarity index 54% rename from data-raw/redcap_rights_test_data.R rename to tests/testthat/get_user_rights_and_info_v1/make_test_data.R index 6748406f..2802c48b 100644 --- a/data-raw/redcap_rights_test_data.R +++ b/tests/testthat/get_user_rights_and_info_v1/make_test_data.R @@ -10,10 +10,26 @@ redcap_user_information <- tbl(conn, "redcap_user_information") %>% collect() redcap_user_rights <- tbl(conn, "redcap_user_rights") %>% collect() redcap_user_roles <- tbl(conn, "redcap_user_roles") %>% collect() -redcap_rights_test_data <- lst( +saveRDS( redcap_user_information, + testthat::test_path( + "get_user_rights_and_info_v1", + "redcap_user_information.rds" + ) +) + +saveRDS( redcap_user_rights, - redcap_user_roles + testthat::test_path( + "get_user_rights_and_info_v1", + "redcap_user_rights.rds" + ) ) -usethis::use_data(redcap_rights_test_data, overwrite = TRUE) +saveRDS( + redcap_user_roles, + testthat::test_path( + "get_user_rights_and_info_v1", + "redcap_user_roles.rds" + ) +) diff --git a/tests/testthat/get_user_rights_and_info_v1/redcap_user_information.rds b/tests/testthat/get_user_rights_and_info_v1/redcap_user_information.rds new file mode 100644 index 00000000..a729bb1a Binary files /dev/null and b/tests/testthat/get_user_rights_and_info_v1/redcap_user_information.rds differ diff --git a/tests/testthat/get_user_rights_and_info_v1/redcap_user_rights.rds b/tests/testthat/get_user_rights_and_info_v1/redcap_user_rights.rds new file mode 100644 index 00000000..4ba2dfa6 Binary files /dev/null and b/tests/testthat/get_user_rights_and_info_v1/redcap_user_rights.rds differ diff --git a/tests/testthat/get_user_rights_and_info_v1/redcap_user_roles.rds b/tests/testthat/get_user_rights_and_info_v1/redcap_user_roles.rds new file mode 100644 index 00000000..d615b939 Binary files /dev/null and b/tests/testthat/get_user_rights_and_info_v1/redcap_user_roles.rds differ diff --git a/tests/testthat/helper-package-specific.R b/tests/testthat/helper-package-specific.R index bbc2262a..6ad419a9 100644 --- a/tests/testthat/helper-package-specific.R +++ b/tests/testthat/helper-package-specific.R @@ -23,155 +23,3 @@ get_user_rights_and_info_test_tables <- c( "redcap_user_rights", "redcap_user_roles" ) - -#' Locates a MySQL schema file for table_name, converts it to a sqlite schema -#' and returns that schema. -#' -#' @param table_name, the name of the table to convert -#' -#' @returns sqlite schema for table_name -#' -#' @examples -#' \dontrun{ -#' convert_schema_to_sqlite(table_name = "service_type") -#' } -#' @export -convert_schema_to_sqlite <- function(table_name) { - schema_file_name <- paste0(table_name, ".sql") - pl_to_sqlite <- system.file("", "to_sqlite.pl", package = "rcc.billing") - - # read original - original_schema_file <- system.file("schema", schema_file_name, package = "rcc.billing") - - if (original_schema_file == "") { - stop(paste("Schema file does not exist for", table_name)) - } - - # convert to sqlite - cmd <- paste("cat", original_schema_file, "|", "perl", pl_to_sqlite) - - result <- system(cmd, intern = TRUE) |> paste(collapse = "") - return(result) -} - -#' converts an in-memory schema to a sqlite schema -#' and returns that schema. -#' -#' @param schema, a MySQL/MariaDB Schema -#' -#' @returns sqlite schema for `schema` -#' -#' @examples -#' \dontrun{ -#' mysql_schema_to_sqlite(schema) -#' } -#' @export -mysql_schema_to_sqlite <- function(schema) { - # find the perl script that does the conversion - pl_to_sqlite <- system.file("", "to_sqlite.pl", package = "rcc.billing") - - # construct conversion command - cmd <- paste("perl", pl_to_sqlite) - - result <- system(cmd, input = schema, intern = TRUE) |> paste(collapse = "") - return(result) -} - -#' Creates a table based on a schema. -#' -#' @param conn, a DBI connection object -#' @param schema, the ddl to execute against conn -#' -#' @examples -#' \dontrun{ -#' table_name <- "service_type" -#' conn <- DBI::dbConnect(RSQLite::SQLite(), dbname = ":memory:") -#' -#' schema <- convert_schema_to_sqlite(table_name) -#' create_table(conn = conn, schema = schema) -#' } -#' @export -create_table <- function(conn, schema) { - schemata <- stringr::str_split(schema, pattern = ";\n+")[[1]] - schemata <- schemata[schemata != ""] - - for (schema in schemata) { - # create table - result <- DBI::dbSendQuery(conn, schema) - # close result set to avoid warning - DBI::dbClearResult(result) - } -} - -#' Populates table_name with the corresponding test data found in /data. -#' -#' @param conn, a DBI connection object -#' @param table_name, the table to populate with test data -#' @param use_test_data, whether to use "_test_data" -#' -#' @examples -#' \dontrun{ -#' conn <- DBI::dbConnect(RSQLite::SQLite(), dbname = ":memory:") -#' populate_table(conn = conn, table_name = "service_type") -#' } -#' @export -populate_table <- function(conn, table_name, use_test_data = FALSE) { - data_ref <- table_name - - if (isTRUE(use_test_data)) { - data_ref <- paste0(data_ref, "_test_data") - } - - # get test data - data <- get0(data_ref) - - # write sample data - result <- DBI::dbAppendTable( - conn = conn, - name = table_name, - value = data, - overwrite = TRUE - ) - - result <- DBI::dbGetQuery(conn, paste("select * from", table_name)) - return(result) -} - -#' create_and_load_test_table -#' -#' Create a named table for which we have stored schema and optionally load the stored test data into it -#' -#' @param conn, a DBI Connection object -#' @param table_name, the name of the table -#' @param load_test_data, a logical to indicate if test data should be loaded -#' @param is_sqllite, a logical to indicate if the DBI object is a a SQLLite DB -#' -#' @return The test data as read back from the new table or NULL -#' @export -#' -#' @examples -#' conn <- DBI::dbConnect(RSQLite::SQLite(), dbname = ":memory:") -#' result <- create_and_load_test_table( -#' conn = conn, -#' table_name = "invoice_line_item_communications", -#' is_sqllite = TRUE -#' ) -create_and_load_test_table <- function(conn, table_name, load_test_data = TRUE, is_sqllite = FALSE) { - schema_file_name <- paste0(table_name, ".sql") - original_schema_file <- system.file("schema", schema_file_name, package = "rcc.billing") - schema <- dplyr::if_else(is_sqllite, - convert_schema_to_sqlite(table_name = table_name), - readr::read_file(original_schema_file) - ) - create_table( - conn = conn, - schema = schema - ) - if (load_test_data) { - populate_table( - conn = conn, - table_name = table_name, - use_test_data = T - ) - } -} diff --git a/tests/testthat/invoice_line_item/invoice_line_item_reasons.rds b/tests/testthat/invoice_line_item/invoice_line_item_reasons.rds new file mode 100644 index 00000000..5b9b3602 Binary files /dev/null and b/tests/testthat/invoice_line_item/invoice_line_item_reasons.rds differ diff --git a/tests/testthat/invoice_line_item/invoice_line_item_statuses.rds b/tests/testthat/invoice_line_item/invoice_line_item_statuses.rds new file mode 100644 index 00000000..986c6116 Binary files /dev/null and b/tests/testthat/invoice_line_item/invoice_line_item_statuses.rds differ diff --git a/tests/testthat/invoice_line_item/make_test_data.R b/tests/testthat/invoice_line_item/make_test_data.R index 5c077144..978bd617 100644 --- a/tests/testthat/invoice_line_item/make_test_data.R +++ b/tests/testthat/invoice_line_item/make_test_data.R @@ -36,3 +36,45 @@ saveRDS( "invoice_line_item.rds" ) ) + +invoice_line_item_reasons <- tibble::tribble( + ~code, ~label, + "new_item", "New item to be invoiced", + "deleted", "Project deleted", + "reassigned", "PI reassigned", + "seeking_voucher", "seeking voucher", + # values from do not bill reason + "17", "17. Withdrawn/Canceled", + "21", "21. Duplicate Charge", + "24", "24. Project/Data deleted after invoice creation.", + "27", "27. PI no longer with UF", + "41", "41. Write-Off (True Write-Off, not billing issues)", + "45", "45. PI Left UF and project should have been sequestered/not invoiced.", + "46", "46. Did not meet billing criteria.", + "47", "47. Reassigned to new project owner who decided to delete within 30 days." +) + +saveRDS( + invoice_line_item_reasons, + testthat::test_path( + "invoice_line_item", + "invoice_line_item_reasons.rds" + ) +) + +invoice_line_item_statuses <- tribble( + ~status, ~description, + "draft", "draft invoices line items that have not yet been sent", + "sent", "the invoice line item has been sent to CSBT", + "canceled", "the invoice line item does not need to be paid", + "unreconciled", "CSBT says the line item is paid, but this has not yet been verified by CTS-IT", + "paid", "CTS-IT has verified the line item has been paid" +) + +saveRDS( + invoice_line_item_statuses, + testthat::test_path( + "invoice_line_item", + "invoice_line_item_statuses.rds" + ) +) diff --git a/tests/testthat/redcap_user_information/make_test_data.R b/tests/testthat/redcap_user_information/make_test_data.R new file mode 100644 index 00000000..ce805016 --- /dev/null +++ b/tests/testthat/redcap_user_information/make_test_data.R @@ -0,0 +1,30 @@ +## Create redcap_user_information from the database of a testing system +library(redcapcustodian) +library(rcc.billing) +library(tidyverse) +library(lubridate) +library(DBI) +library(RMariaDB) +library(dotenv) + +my_table <- "redcap_user_information" + +# run this once against a test redcap to extract the part we need +conn <- connect_to_redcap_db() +data <- tbl(conn, my_table) + +redcap_user_information <- data |> + dplyr::collect() |> + dplyr::filter(ui_id >= 3) + +# write the test data +saveRDS( + redcap_user_information, + testthat::test_path("redcap_user_information", "redcap_user_information.rds") +) + +# write the schema +DBI::dbGetQuery(conn, paste("show create table", my_table))$`Create Table` |> + write(file = paste0("inst/schema/", my_table, ".sql")) + +dbDisconnect(conn) diff --git a/data-raw/service_instance_test_data.R b/tests/testthat/service_instance/make_test_data.R similarity index 81% rename from data-raw/service_instance_test_data.R rename to tests/testthat/service_instance/make_test_data.R index 627fff4f..0ed971ef 100644 --- a/data-raw/service_instance_test_data.R +++ b/tests/testthat/service_instance/make_test_data.R @@ -1,4 +1,3 @@ -## code to prepare `service_instance` dataset goes here library(tibble) library(usethis) @@ -19,4 +18,7 @@ service_instance_test_data <- tribble( "5-2345", 5, "2345", 787878, T ) -usethis::use_data(service_instance_test_data, overwrite = TRUE) +saveRDS( + service_instance_test_data, + testthat::test_path("service_instance", "service_instance.rds") +) diff --git a/tests/testthat/service_instance/service_instance.rds b/tests/testthat/service_instance/service_instance.rds new file mode 100644 index 00000000..42e3af7e Binary files /dev/null and b/tests/testthat/service_instance/service_instance.rds differ diff --git a/data-raw/service_type_test_data.R b/tests/testthat/service_type/make_test_data.R similarity index 71% rename from data-raw/service_type_test_data.R rename to tests/testthat/service_type/make_test_data.R index d5368355..d7d33517 100644 --- a/data-raw/service_type_test_data.R +++ b/tests/testthat/service_type/make_test_data.R @@ -2,7 +2,7 @@ library(tibble) library(usethis) -service_type_test_data <- tribble( +service_type <- tribble( ~service_type_code, ~service_type, ~price, @@ -11,4 +11,10 @@ service_type_test_data <- tribble( 2, 'REDCap consulting', 130, 0 ) -usethis::use_data(service_type_test_data, overwrite = TRUE) +saveRDS( + service_type, + testthat::test_path( + "service_type", + "service_type.rds" + ) +) diff --git a/tests/testthat/service_type/service_type.rds b/tests/testthat/service_type/service_type.rds new file mode 100644 index 00000000..106e6b64 Binary files /dev/null and b/tests/testthat/service_type/service_type.rds differ diff --git a/tests/testthat/test-invoice_line_item.R b/tests/testthat/test-invoice_line_item.R deleted file mode 100644 index 60be6624..00000000 --- a/tests/testthat/test-invoice_line_item.R +++ /dev/null @@ -1,31 +0,0 @@ -testthat::test_that("service_type sqlite schema is created and correct test data is returned", { - table_name <- "invoice_line_item" - conn <- DBI::dbConnect(RSQLite::SQLite(), dbname = ":memory:") - test_data <- readRDS( - testthat::test_path( - table_name, paste0(table_name, ".rds") - ) - ) - test_data <- dplyr::mutate(test_data, - je_posting_date = as.POSIXct(je_posting_date, tz = "UTC"), - created = as.POSIXct(created, tz = "UTC"), - updated = as.POSIXct(updated, tz = "UTC"), - date_sent = as.POSIXct(date_sent, tz = "UTC"), - date_received = as.POSIXct(date_received, tz = "UTC") - ) - - sqlite_schema <- convert_schema_to_sqlite(table_name) - create_table( - conn = conn, - schema = sqlite_schema - ) - results <- populate_table( - conn = conn, - table_name = table_name, - use_test_data = TRUE - ) |> fix_data_in_invoice_line_item() - - expect_identical(test_data, dplyr::as_tibble(results)) - DBI::dbDisconnect(conn) -}) - diff --git a/tests/testthat/test-invoice_line_item_communications.R b/tests/testthat/test-invoice_line_item_communications.R deleted file mode 100644 index 977ada8c..00000000 --- a/tests/testthat/test-invoice_line_item_communications.R +++ /dev/null @@ -1,29 +0,0 @@ -testthat::test_that("service_type sqlite schema is created and correct test data is returned", { - table_name <- "invoice_line_item_communications" - mem_conn <- DBI::dbConnect(RSQLite::SQLite(), dbname = ":memory:") - test_data <- readRDS( - testthat::test_path( - table_name, paste0(table_name, ".rds") - ) - ) - test_data <- dplyr::mutate(test_data, - je_posting_date = as.POSIXct(je_posting_date, tz = "UTC"), - created = as.POSIXct(created, tz = "UTC"), - updated = as.POSIXct(updated, tz = "UTC"), - date_sent = as.POSIXct(date_sent, tz = "UTC"), - date_received = as.POSIXct(date_received, tz = "UTC") - ) - sqlite_schema <- convert_schema_to_sqlite(table_name) - create_table( - conn = mem_conn, - schema = sqlite_schema - ) - results <- populate_table( - conn = mem_conn, - table_name = table_name, - use_test_data = T - ) %>% fix_data_in_invoice_line_item_communication() - - expect_identical(test_data, dplyr::as_tibble(results)) - DBI::dbDisconnect(mem_conn) -}) diff --git a/tests/testthat/test-redcap_log_event.R b/tests/testthat/test-redcap_log_event.R deleted file mode 100644 index 50642dd5..00000000 --- a/tests/testthat/test-redcap_log_event.R +++ /dev/null @@ -1,27 +0,0 @@ -test_that("redcap_log_event sqlite schemata are created and correct test data is returned", { - table_name <- "redcap_log_event" - test_data <- get0(paste0(table_name, "_test_data")) - conn <- DBI::dbConnect(RSQLite::SQLite(), dbname = ":memory:") - - for (log_table in names(redcap_log_event_test_data)) { - sqlite_schema <- convert_schema_to_sqlite(table_name = log_table) - create_table( - conn = conn, - schema = sqlite_schema - ) - - result <- DBI::dbAppendTable( - conn = conn, - name = log_table, - value = test_data[[log_table]], - overwrite = TRUE - ) - - results <- DBI::dbGetQuery(conn, paste("select * from", log_table)) %>% - fix_data_in_redcap_log_event() - - testthat::expect_equal(dplyr::as_tibble(results), test_data[[log_table]]) - } - - DBI::dbDisconnect(conn) -}) diff --git a/tests/testthat/test-redcap_rights.R b/tests/testthat/test-redcap_rights.R index 52e9b418..1eb92944 100644 --- a/tests/testthat/test-redcap_rights.R +++ b/tests/testthat/test-redcap_rights.R @@ -1,8 +1,30 @@ testthat::test_that("get_user_rights_and_info_v1 works", { + +redcap_user_information <- readRDS( + testthat::test_path( + "get_user_rights_and_info_v1", + "redcap_user_information.rds" + ) +) + +redcap_user_rights <- readRDS( + testthat::test_path( + "get_user_rights_and_info_v1", + "redcap_user_rights.rds" + ) +) + +redcap_user_roles <- readRDS( + testthat::test_path( + "get_user_rights_and_info_v1", + "redcap_user_roles.rds" + ) +) + result <- get_user_rights_and_info_v1( - redcap_user_rights = redcap_rights_test_data$redcap_user_rights, - redcap_user_roles = redcap_rights_test_data$redcap_user_roles, - redcap_user_information = redcap_rights_test_data$redcap_user_information + redcap_user_rights = redcap_user_rights, + redcap_user_roles = redcap_user_roles, + redcap_user_information = redcap_user_information ) limited_result <- result %>% diff --git a/tests/testthat/test-redcap_user_information.R b/tests/testthat/test-redcap_user_information.R deleted file mode 100644 index 2fc10c57..00000000 --- a/tests/testthat/test-redcap_user_information.R +++ /dev/null @@ -1,20 +0,0 @@ -test_that("redcap_user_information sqlite schema is created and correct test data is returned", { - table_name <- "redcap_user_information" - test_data <- get0(paste0(table_name, "_test_data")) - conn <- DBI::dbConnect(RSQLite::SQLite(), dbname = ":memory:") - - sqlite_schema <- convert_schema_to_sqlite(table_name = table_name) - create_table( - conn = conn, - schema = sqlite_schema - ) - results <- populate_table( - conn = conn, - table_name = table_name, - use_test_data = T - ) %>% - fix_data_in_redcap_user_information() - - DBI::dbDisconnect(conn) - testthat::expect_equal(dplyr::as_tibble(results), test_data) -}) diff --git a/tests/testthat/test-service_instance.R b/tests/testthat/test-service_instance.R deleted file mode 100644 index ef798f3a..00000000 --- a/tests/testthat/test-service_instance.R +++ /dev/null @@ -1,20 +0,0 @@ -test_that("service_type sqlite schema is created and correct test data is returned", { - table_name <- "service_instance" - test_data <- get0(paste0(table_name, "_test_data")) - conn <- DBI::dbConnect(RSQLite::SQLite(), dbname = ":memory:") - - sqlite_schema <- convert_schema_to_sqlite(table_name = table_name) - create_table( - conn = conn, - schema = sqlite_schema - ) - results <- populate_table( - conn = conn, - table_name = table_name, - use_test_data = TRUE - ) - results$active <- as.logical(results$active) - - DBI::dbDisconnect(conn) - expect_identical(test_data, dplyr::as_tibble(results)) -}) diff --git a/tests/testthat/test-service_type.R b/tests/testthat/test-service_type.R deleted file mode 100644 index 80ac5885..00000000 --- a/tests/testthat/test-service_type.R +++ /dev/null @@ -1,19 +0,0 @@ -test_that("service_type sqlite schema is created and correct test data is returned", { - table_name <- "service_type" - test_data <- get0(paste0(table_name, "_test_data")) - conn <- DBI::dbConnect(RSQLite::SQLite(), dbname = ":memory:") - - sqlite_schema <- convert_schema_to_sqlite(table_name = table_name) - create_table( - conn = conn, - schema = sqlite_schema - ) - results <- populate_table( - conn = conn, - table_name = table_name, - use_test_data = TRUE - ) - - DBI::dbDisconnect(conn) - expect_identical(test_data, dplyr::as_tibble(results)) -}) diff --git a/tests/testthat/test-transform.R b/tests/testthat/test-transform.R index 23dc17c6..a5656c09 100644 --- a/tests/testthat/test-transform.R +++ b/tests/testthat/test-transform.R @@ -1,13 +1,35 @@ test_that("invoice_line_item_df_from invoice_line_item_communications works properly", { + + invoice_line_item_test_data <- readRDS(file = testthat::test_path( + "invoice_line_item", + "invoice_line_item.rds" + )) + + invoice_line_item_communications_test_data <- readRDS(file = testthat::test_path( + "invoice_line_item_communications", + "invoice_line_item_communications.rds" + )) |> + dplyr::mutate(dplyr::across(c( + "je_posting_date", + "date_sent", + "date_received", + "created", + "updated" + ), lubridate::ymd_hms)) + expect_identical( invoice_line_item_test_data, invoice_line_item_df_from(invoice_line_item_communications_test_data) ) }) - test_that("transform_invoice_line_items_for_csbt correctly converts all column names in CTSIT to CSBT format", { + invoice_line_item_test_data <- readRDS(file = testthat::test_path( + "invoice_line_item", + "invoice_line_item.rds" + )) + initial_colnames <- invoice_line_item_test_data %>% colnames() %>% sort() @@ -24,6 +46,11 @@ test_that("transform_invoice_line_items_for_csbt correctly converts all column n test_that("transform_invoice_line_items_for_ctsit correctly converts all column names in CSBT to CTSIT format", { + invoice_line_item_test_data <- readRDS(file = testthat::test_path( + "invoice_line_item", + "invoice_line_item.rds" + )) + csbt_test_data <- invoice_line_item_test_data %>% transform_invoice_line_items_for_csbt() @@ -43,6 +70,12 @@ test_that("transform_invoice_line_items_for_ctsit correctly converts all column test_that("draft_communication_record_from_line_item correctly adds requisite columns", { + + invoice_line_item_test_data <- readRDS(file = testthat::test_path( + "invoice_line_item", + "invoice_line_item.rds" + )) + csbt_line_items <- invoice_line_item_test_data %>% transform_invoice_line_items_for_csbt() @@ -62,7 +95,7 @@ test_that("draft_communication_record_from_line_item correctly adds requisite co redcapcustodian::set_script_run_time() expect_true( - all( added_columns %in% colnames(communication_records) ) + all(added_columns %in% colnames(communication_records)) ) })