diff --git a/DESCRIPTION b/DESCRIPTION index 00917d0..f797ca1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: castoRedc Title: Wraps Castor API for easy data access -Version: 2.0.1 +Version: 2.1.0 Authors@R: c( person("Thomas", "Johnson", role = "aut"), person("Reinier", "van Linschoten", @@ -26,10 +26,11 @@ Imports: glue Suggests: knitr, - testthat + testthat (>= 3.0.0) RoxygenNote: 7.3.0 Collate: 'imports.R' 'utils.R' 'CastorData.R' 'CastorAPIWrapper.R' +Config/testthat/edition: 3 diff --git a/R/CastorData.R b/R/CastorData.R index 0a159b7..5a123fd 100644 --- a/R/CastorData.R +++ b/R/CastorData.R @@ -498,15 +498,19 @@ CastorData <- R6::R6Class("CastorData", "returning data frame with just participant metadata.") empty.df <- data.frame( - "Site Abbreviation" = - participant_metadata[["_embedded"]][["site"]][["abbreviation"]], - "Randomization Group" = - ifelse(is.null(participant_metadata[["randomization_group"]]), NA, - participant_metadata[["randomization_group"]]), - "Participant Creation" = participant_metadata[["created_on"]][["date"]], - "Participant_ID" = participant_id + "institute" = + participant_metadata[["_embedded"]][["site"]][["name"]], + "randomisation_group" = + ifelse(is.null(participant_metadata[["randomization_group_name"]]), + NA, + participant_metadata[["randomization_group_name"]]), + "participant_id" = participant_id, + "archived" = participant_metadata[["archived"]], + "randomisation_datetime" = + ifelse(is.null(participant_metadata[["randomizated_on"]]), + NA, + participant_metadata[["randomizated_on"]]) ) - return(empty.df) } # Filter out any field types that are specified in the filter_types @@ -524,55 +528,81 @@ CastorData <- R6::R6Class("CastorData", stringsAsFactors = FALSE) # Add the participant id as a column to the data. - study_data_points.df[["Participant_ID"]] <- participant_id + study_data_points.df[["participant_id"]] <- participant_id # Randomization ID should be in participant data. - study_data_points.df[["Site_Abbreviation"]] <- - participant_metadata[["_embedded"]][["site"]][["abbreviation"]] - study_data_points.df[["Randomization_Group"]] <- - ifelse(is.null(participant_metadata[["randomization_group"]]), + study_data_points.df[["institute"]] <- + participant_metadata[["_embedded"]][["site"]][["name"]] + study_data_points.df[["archived"]] <- + participant_metadata[["archived"]] + study_data_points.df[["randomisation_group"]] <- + ifelse(is.null(participant_metadata[["randomization_group_name"]]), + NA, + participant_metadata[["randomization_group_name"]]) + study_data_points.df[["randomisation_datetime"]] <- + ifelse(is.null(participant_metadata[["randomizated_on"]]), NA, - participant_metadata[["randomization_group"]]) - study_data_points.df[["Participant_Creation"]] <- - participant_metadata[["created_on"]][["date"]] + participant_metadata[["randomizated_on"]]) return(study_data_points.df) }, - getStudyDataBulk = function(study_id., field_info., participant_metadata) { - study_data <- self$getStudyDataPointsBulk(study_id.) - if (isTRUE(nrow(study_data) > 0)) { - study_data_field_info <- distinct(left_join(study_data, field_info., by = "field_id")) - study_data_long <- select(study_data_field_info, - field_variable_name, participant_id, field_value) - study_data_wide <- spread(study_data_long, - field_variable_name, field_value) - study_data_complete_cases <- filter_all(study_data_wide, - any_vars(!is.na(.))) - - # Add randomized on date for studies without randomization - # Is not retrieved from API, but needs to exist for further steps - if (!("randomized_on.date" %in% names(participant_metadata))) { - participant_metadata <- participant_metadata %>% - mutate(randomized_on.date = NA_character_) - } - - rename( - left_join( - select( - participant_metadata, - participant_id, - Randomization_Group = randomization_group, - Randomization_Group_Name = randomization_group_name, - Randomized_On = randomized_on.date, - Site_Abbreviation = `_embedded.site.abbreviation`, - Participant_Creation = created_on.date), - study_data_complete_cases, - by="participant_id" + getStudyDataBulk = function(study_id, field_info=NULL, participant_metadata=NULL) { + # Extract the necessary info that wasnt given to the function + if (is.null(field_info)) {self$getFields(study_id)} + if (is.null(participant_metadata)) {self$getParticipants(study_id)} + + # Extract all study data points in long format + # One row per datapoint + study_data <- self$getStudyDataPointsBulk(study_id) + + # If there is study data + if (nrow(study_data) > 0) { + # Add the field names to the field ids and values in long format + study_data <- left_join(select(study_data, -updated_on), + select(field_info, c(field_variable_name, field_id)), + by = "field_id") + + # Move from long (each data point has a row) to wide format per participant + study_data <- pivot_wider(select(study_data, -field_id), + names_from = field_variable_name, + values_from = field_value) + + # Add participant metadata to the dataframe + study_data <- left_join( + select( + participant_metadata, + participant_id, + `_embedded.site.name`, + archived, + randomization_group_name, + randomized_on, ), - Participant_ID = participant_id + study_data, + by = "participant_id" ) - } else - NULL + + study_data <- rename(study_data, + randomisation_group = randomization_group_name, + randomisation_datetime = randomized_on, + institute = `_embedded.site.name` + ) + } else { + # If no study data, only return participant information + study_data <- + rename(select( + participant_metadata, + participant_id, + `_embedded.site.name`, + archived, + randomization_group_name, + randomized_on, + ), + randomisation_group = randomization_group_name, + randomisation_datetime = randomized_on, + institute = `_embedded.site.name` + ) + } + study_data }, generateFieldMetadata = function(study_id, field_info) { forms <- self$getForms(study_id) @@ -683,8 +713,8 @@ CastorData <- R6::R6Class("CastorData", all_data_points.df <- self$getStudyDataBulk(study_id, field_info, participant_metadata) } else { - # Get study data from getStudyDataPoints and collect them by participant in a - # list. + # Get study data from getStudyDataPoints + # Collect them by participant in a list study_data <- lapply(participant_metadata$participant_id, function(participant) { if (self$verbose) message("getting participant ", participant) return(self$getStudyDataPoints(study_id, participant, filter_types)) @@ -693,10 +723,6 @@ CastorData <- R6::R6Class("CastorData", all_data_points.df <- bind_rows(study_data) } } else { - all_data_points.df <- NULL - } - - if (is.null(all_data_points.df)) { all_data_points.df <- rename( select( participant_metadata, diff --git a/create_testing_credentials.R b/create_testing_credentials.R index 22a96f7..4a8e961 100644 --- a/create_testing_credentials.R +++ b/create_testing_credentials.R @@ -1,7 +1,7 @@ creds = list( client_id = "", client_secret = "", - example_study = "", + output_study = "", base_url = "https://data.castoredc.com", example_field = "", example_visit = "", @@ -14,7 +14,7 @@ creds = list( ) castor_api <- CastorData$new(key=creds$client_id, secret=creds$client_secret, base_url=creds$base_url) -entire_study <- castor_api$getStudyData(creds$example_study) +entire_study <- castor_api$getStudyData(creds$output_study) study_hash <- digest::digest(entire_study) creds$study_hash <- study_hash diff --git a/tests/test_files/files_output/CastorAdverseEvent (noLabel).csv b/tests/test_files/files_output/CastorAdverseEvent (noLabel).csv new file mode 100644 index 0000000..053c14d --- /dev/null +++ b/tests/test_files/files_output/CastorAdverseEvent (noLabel).csv @@ -0,0 +1,3 @@ +participant_id,institute,created_on,custom_name,parent,archived,AE_type,AE_startdate,AE_stopdate,AE_severity,AE_relation,AE_action,AE_outcome,AE_expected,AE_SAE +110001,Franciscus Gasthuis & Vlietland,22-06-2021 09:58:13,Adverse event - 22-06-2021 09:58:12,No parent,FALSE,,,,,,,,, +110001,Franciscus Gasthuis & Vlietland,22-06-2021 09:55:13,Adverse event - 22-06-2021 09:55:12,Follow-up Visit,FALSE,A bug in the API,23-06-2021,24-06-2021,4,4,2,1,1,1 diff --git a/tests/test_files/files_output/CastorAdverseEvent.csv b/tests/test_files/files_output/CastorAdverseEvent.csv new file mode 100644 index 0000000..6674029 --- /dev/null +++ b/tests/test_files/files_output/CastorAdverseEvent.csv @@ -0,0 +1,3 @@ +participant_id,institute,created_on,custom_name,parent,archived,AE_type,AE_startdate,AE_stopdate,AE_severity,AE_relation,AE_action,AE_outcome,AE_expected,AE_SAE +110001,Franciscus Gasthuis & Vlietland,22-06-2021 09:58:13,Adverse event - 22-06-2021 09:58:12,No parent,FALSE,,,,,,,,, +110001,Franciscus Gasthuis & Vlietland,22-06-2021 09:55:13,Adverse event - 22-06-2021 09:55:12,Follow-up Visit,FALSE,A bug in the API,23-06-2021,24-06-2021,Life-threatening,Definitely related,Medical intervention,Resolved,Yes,Yes diff --git a/tests/test_files/files_output/CastorComorbidities (noLabel).csv b/tests/test_files/files_output/CastorComorbidities (noLabel).csv new file mode 100644 index 0000000..1962c39 --- /dev/null +++ b/tests/test_files/files_output/CastorComorbidities (noLabel).csv @@ -0,0 +1,2 @@ +participant_id,institute,created_on,custom_name,parent,archived,comorbidities +110001,Franciscus Gasthuis & Vlietland,22-06-2021 09:56:07,Comorbidities - 22-06-2021 09:56:06,No parent,FALSE,-- Uploaded File: comorbidities.txt -- diff --git a/tests/test_files/files_output/CastorComorbidities.csv b/tests/test_files/files_output/CastorComorbidities.csv new file mode 100644 index 0000000..1962c39 --- /dev/null +++ b/tests/test_files/files_output/CastorComorbidities.csv @@ -0,0 +1,2 @@ +participant_id,institute,created_on,custom_name,parent,archived,comorbidities +110001,Franciscus Gasthuis & Vlietland,22-06-2021 09:56:07,Comorbidities - 22-06-2021 09:56:06,No parent,FALSE,-- Uploaded File: comorbidities.txt -- diff --git a/tests/test_files/files_output/CastorMedication (noLabel).csv b/tests/test_files/files_output/CastorMedication (noLabel).csv new file mode 100644 index 0000000..46c64e3 --- /dev/null +++ b/tests/test_files/files_output/CastorMedication (noLabel).csv @@ -0,0 +1,3 @@ +participant_id,institute,created_on,custom_name,parent,archived,med_name,med_start,med_stop,med_dose,med_units,med_other_unit +110001,Franciscus Gasthuis & Vlietland,22-06-2021 09:54:28,Medication - 22-06-2021 09:54:28,Unscheduled visits and Medication,FALSE,Diclofenac,25-06-2021,28-06-2021,150,2, +110001,Franciscus Gasthuis & Vlietland,22-06-2021 09:58:27,Medication - 22-06-2021 09:58:26,No parent,FALSE,,,,,, diff --git a/tests/test_files/files_output/CastorMedication.csv b/tests/test_files/files_output/CastorMedication.csv new file mode 100644 index 0000000..34e5075 --- /dev/null +++ b/tests/test_files/files_output/CastorMedication.csv @@ -0,0 +1,3 @@ +participant_id,institute,created_on,custom_name,parent,archived,med_name,med_start,med_stop,med_dose,med_units,med_other_unit +110001,Franciscus Gasthuis & Vlietland,22-06-2021 09:54:28,Medication - 22-06-2021 09:54:28,Unscheduled visits and Medication,FALSE,Diclofenac,25-06-2021,28-06-2021,150,mg/day, +110001,Franciscus Gasthuis & Vlietland,22-06-2021 09:58:27,Medication - 22-06-2021 09:58:26,No parent,FALSE,,,,,, diff --git a/tests/test_files/files_output/CastorQOLSurvey (noLabel).csv b/tests/test_files/files_output/CastorQOLSurvey (noLabel).csv new file mode 100644 index 0000000..c157315 --- /dev/null +++ b/tests/test_files/files_output/CastorQOLSurvey (noLabel).csv @@ -0,0 +1,3 @@ +participant_id,institute,survey_name,survey_instance_id,created_on,sent_on,progress,completed_on,package_id,package_name,archived,SF12_1,SF12_2,SF12_3,SF12_12,VAS +110001,Franciscus Gasthuis & Vlietland,QOL Survey,4FF130AD-274C-4C8F-A4A0-A7816A5A88E9,22-06-2021 10:12:19,22-06-2021 10:12:19,100,22-06-2021 10:12:44,0761A9BA-9802-483D-8EB3-D07233A56F2B,My first survey package,FALSE,5,2,2,5,85 +110001,Franciscus Gasthuis & Vlietland,QOL Survey,B99F0082-1B20-456B-8D4D-47D16867B211,22-06-2021 10:13:01,22-06-2021 10:13:01,0,,5B3FE56F-89FA-4C6D-A638-E8FA46113EB0,My first survey package,FALSE,,,,, diff --git a/tests/test_files/files_output/CastorQOLSurvey.csv b/tests/test_files/files_output/CastorQOLSurvey.csv new file mode 100644 index 0000000..2685903 --- /dev/null +++ b/tests/test_files/files_output/CastorQOLSurvey.csv @@ -0,0 +1,3 @@ +participant_id,institute,survey_name,survey_instance_id,created_on,sent_on,progress,completed_on,package_id,package_name,archived,SF12_1,SF12_2,SF12_3,SF12_12,VAS +110001,Franciscus Gasthuis & Vlietland,QOL Survey,4FF130AD-274C-4C8F-A4A0-A7816A5A88E9,22-06-2021 10:12:19,22-06-2021 10:12:19,100,22-06-2021 10:12:44,0761A9BA-9802-483D-8EB3-D07233A56F2B,My first survey package,FALSE,Excellent,Mostly,Mostly,Rarely,85 +110001,Franciscus Gasthuis & Vlietland,QOL Survey,B99F0082-1B20-456B-8D4D-47D16867B211,22-06-2021 10:13:01,22-06-2021 10:13:01,0,,5B3FE56F-89FA-4C6D-A638-E8FA46113EB0,My first survey package,FALSE,,,,, diff --git a/tests/test_files/files_output/CastorStudy (noLabel).csv b/tests/test_files/files_output/CastorStudy (noLabel).csv new file mode 100644 index 0000000..370aa86 --- /dev/null +++ b/tests/test_files/files_output/CastorStudy (noLabel).csv @@ -0,0 +1,3 @@ +participant_id,archived,institute,randomisation_group,randomisation_datetime,ic_date,ic_versions#Main study CF,ic_versions#Other,ic_main_version,ic_other_version,ic_language#English,ic_language#Dutch,ic_language#French,ic_language#Other,inc_ic,inc_trials,inc_age,inc_dx,inc_criteria,pat_birth_year,pat_sex,pat_race,pat_height,his_cvd,his_diabetes,his_smoke,his_smoke_start,his_smoke_dose,his_family#None,his_family#Unknown,his_family#Deafness,his_family#(Cardio)myopathy,his_family#Encephalopathy,his_family#Diabetes Mellitus,his_family#Hypertension/Cardiovascular disease,his_family#Thrombosis,his_family#Malignancy,randalloc,randdisp,disp_datetime,base_date,onset_stroke,onset_trombectomy,base_weight,base_bmi,base_sbp,base_dbp,base_hr,base_bl_date,base_hb,base_ht,base_leucoc,base_tromboc,base_urea,base_creat,base_CRP,fac_V_leiden_number,fac_V_leiden_date,base_gluc,fu_date,fu_weight,fu_bmi,fu_sbp,fu_dbp,fu_hr,fu_bl_date,fu_hb,fu_ht,fu_leucoc,fu_tromboc,fu_urea,fu_creat,fu_CRP,fu_gluc,unscheduled,conc_med +110001,FALSE,Franciscus Gasthuis & Vlietland,,,22-06-2021,TRUE,FALSE,2.5,,FALSE,FALSE,TRUE,FALSE,1,0,1,0,Yes,1996,0,2,1.75,1,0,0,,,FALSE,FALSE,FALSE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,,,,22-06-2021,21-06-2021 01:15,01:30,88,28.7,120,65,66,22-06-2021,7.4,0.23,4.1,252,4.6,88,2.1,55,22-06-2021,5.4,29-06-2021,66,21.6,132,72,69,29-06-2021,8.1,0.36,9.5,366,8.2,99,4.4,3.1,1,1 +110002,FALSE,Franciscus Gasthuis & Vlietland,,,,FALSE,FALSE,,,-99,-99,-99,-99,,,,,,,,,-95,,,,,,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,,,,31-12-2999,,,,,,,,,,,,,,,,-96,01-01-2996,,,,,,,,,,,,,,,,,, diff --git a/tests/test_files/files_output/CastorStudy.csv b/tests/test_files/files_output/CastorStudy.csv new file mode 100644 index 0000000..808f809 --- /dev/null +++ b/tests/test_files/files_output/CastorStudy.csv @@ -0,0 +1,3 @@ +participant_id,archived,institute,randomisation_group,randomisation_datetime,ic_date,ic_versions#Main study CF,ic_versions#Other,ic_main_version,ic_other_version,ic_language#English,ic_language#Dutch,ic_language#French,ic_language#Other,inc_ic,inc_trials,inc_age,inc_dx,inc_criteria,pat_birth_year,pat_sex,pat_race,pat_height,his_cvd,his_diabetes,his_smoke,his_smoke_start,his_smoke_dose,his_family#None,his_family#Unknown,his_family#Deafness,his_family#(Cardio)myopathy,his_family#Encephalopathy,his_family#Diabetes Mellitus,his_family#Hypertension/Cardiovascular disease,his_family#Thrombosis,his_family#Malignancy,randalloc,randdisp,disp_datetime,base_date,onset_stroke,onset_trombectomy,base_weight,base_bmi,base_sbp,base_dbp,base_hr,base_bl_date,base_hb,base_ht,base_leucoc,base_tromboc,base_urea,base_creat,base_CRP,fac_V_leiden_number,fac_V_leiden_date,base_gluc,fu_date,fu_weight,fu_bmi,fu_sbp,fu_dbp,fu_hr,fu_bl_date,fu_hb,fu_ht,fu_leucoc,fu_tromboc,fu_urea,fu_creat,fu_CRP,fu_gluc,unscheduled,conc_med +110001,FALSE,Franciscus Gasthuis & Vlietland,,,22-06-2021,TRUE,FALSE,2.5,,FALSE,FALSE,TRUE,FALSE,Yes,No,Yes,No,Yes,1996,Female,African/black,1.75,Yes,No,No,,,FALSE,FALSE,FALSE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,,,,22-06-2021,21-06-2021 01:15,01:30,88,28.7,120,65,66,22-06-2021,7.4,0.23,4.1,252,4.6,88,2.1,55,22-06-2021,5.4,29-06-2021,66,21.6,132,72,69,29-06-2021,8.1,0.36,9.5,366,8.2,99,4.4,3.1,Yes,Yes +110002,FALSE,Franciscus Gasthuis & Vlietland,,,,FALSE,FALSE,,,-99,-99,-99,-99,,,,,,,,,-95,,,,,,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,,,,31-12-2999,,,,,,,,,,,,,,,,-96,01-01-2996,,,,,,,,,,,,,,,,,, diff --git a/tests/test_files/files_output/CastorUnscheduledVisit (noLabel).csv b/tests/test_files/files_output/CastorUnscheduledVisit (noLabel).csv new file mode 100644 index 0000000..9e8ca98 --- /dev/null +++ b/tests/test_files/files_output/CastorUnscheduledVisit (noLabel).csv @@ -0,0 +1,2 @@ +participant_id,institute,created_on,custom_name,parent,archived,unsvis_type,unsvis_date,unsvis_weight,unsvis_sbp,unsvis_dbp,unsvis_hr,unslab_date,unslab_s_hb,unslab_ht,unslab_leucoc,unslab_tromboc,unslab_urea,unslab_creat,unslab_CRP,unslab_gluc +110001,Franciscus Gasthuis & Vlietland,22-06-2021 09:57:38,Unscheduled visit - 22-06-2021 09:57:36,Unscheduled visits and Medication,FALSE,3,24-06-2021,98.3,233,156,112,,,,,,,,, diff --git a/tests/test_files/files_output/CastorUnscheduledVisit.csv b/tests/test_files/files_output/CastorUnscheduledVisit.csv new file mode 100644 index 0000000..0ad24e3 --- /dev/null +++ b/tests/test_files/files_output/CastorUnscheduledVisit.csv @@ -0,0 +1,2 @@ +participant_id,institute,created_on,custom_name,parent,archived,unsvis_type,unsvis_date,unsvis_weight,unsvis_sbp,unsvis_dbp,unsvis_hr,unslab_date,unslab_s_hb,unslab_ht,unslab_leucoc,unslab_tromboc,unslab_urea,unslab_creat,unslab_CRP,unslab_gluc +110001,Franciscus Gasthuis & Vlietland,22-06-2021 09:57:38,Unscheduled visit - 22-06-2021 09:57:36,Unscheduled visits and Medication,FALSE,admission to day-care,24-06-2021,98.3,233,156,112,,,,,,,,, diff --git a/tests/testthat/test_fields.R b/tests/testthat/test_fields.R index 2680273..f7bb40f 100644 --- a/tests/testthat/test_fields.R +++ b/tests/testthat/test_fields.R @@ -1,33 +1,54 @@ -context("Test Field related methods.") - creds <- readRDS("testing_credentials.Rds") castor_api <- CastorData$new(key=creds$client_id, secret=creds$client_secret, base_url=creds$base_url) test_that("getField returns an appropriate object.", { - field <- castor_api$getField(creds$example_study, creds$example_field) + field <- castor_api$getField(creds$output_study, creds$example_field) - expect_is(field, "list") + expect_type(field, "list") expect_equal(field$field_id, creds$example_field) expect_gt(length(field), 0) }) +test_that("getField fails appropriately", { + error <- expect_error(castor_api$getField(creds$output_study, creds$fail_field)) + expect_match(error$message, "Error code: 404") +}) + + test_that("getFieldsPages returns an appropriate object.", { - fields <- castor_api$getFieldsPages(creds$example_study) - one_field <- castor_api$getFieldsPages(creds$example_study, page = 1) - - expect_is(fields, "list") - expect_is(one_field, "list") - expect_true(length(one_field) == 1) - expect_error(castor_api$getFieldsPages(creds$example_study, page = -1)) - expect_error(castor_api$getFieldsPages(creds$example_study, page = 100000000)) - expect_error(castor_api$getFieldsPages(creds$example_study, page = pi)) + fields <- castor_api$getFieldsPages(creds$output_study) + expect_type(fields, "list") }) +test_that("getFieldPages returns an appropriate object when retrieving a single page.", { + one_page <- castor_api$getFieldsPages(creds$output_study, page = 1) + expect_type(one_page, "list") + expect_true(length(one_page) == 1) +}) + +test_that("getFieldPages fails appropriately", { + error1 <- expect_error(castor_api$getFieldsPages(creds$output_study, page = -1)) + expect_match(error1$message, "Error code: 400") + + error2 <- expect_error(castor_api$getFieldsPages(creds$output_study, page = 100000000)) + expect_match(error2$message, "Error code: 409") + + error3 <- expect_error(castor_api$getFieldsPages(creds$output_study, page = pi)) + expect_match(error3$message, "page must be an integer") +}) + + + test_that("getFields returns an appropriate object.", { - field_data <- castor_api$getFields(creds$example_study) + field_data <- castor_api$getFields(creds$output_study) - expect_is(field_data, "data.frame") - expect_gt(nrow(field_data), 0) - expect_gt(ncol(field_data), 0) - expect_error(castor_api$getFields("this is not a study id")) + expect_s3_class(field_data, "data.frame") + expect_equal(nrow(field_data), 115) + expect_equal(ncol(field_data), 37) }) + +test_that("getFields fails appropriately", { + error <- expect_error(castor_api$getFields("THISISNOTASTUDYID")) + expect_match(error$message, "Error code: 404") +}) + diff --git a/tests/testthat/test_forms.R b/tests/testthat/test_forms.R index 0d50dc3..95806c6 100644 --- a/tests/testthat/test_forms.R +++ b/tests/testthat/test_forms.R @@ -1,10 +1,11 @@ +# TODO: Needs updates to tests context("Test Form related methods.") creds <- readRDS("testing_credentials.Rds") castor_api <- CastorData$new(key=creds$client_id, secret=creds$client_secret, base_url=creds$base_url) test_that("getForm returns an appropriate object.", { - form <- castor_api$getForm(creds$example_study, creds$example_form) + form <- castor_api$getForm(creds$output_study, creds$example_form) expect_is(form, "list") expect_equal(form$form_id, creds$example_form) @@ -12,19 +13,19 @@ test_that("getForm returns an appropriate object.", { }) test_that("getFormsPages returns an appropriate object.", { - forms <- castor_api$getFormsPages(creds$example_study) - one_form <- castor_api$getFormsPages(creds$example_study, page = 1) + forms <- castor_api$getFormsPages(creds$output_study) + one_form <- castor_api$getFormsPages(creds$output_study, page = 1) expect_is(forms, "list") expect_is(one_form, "list") expect_true(length(one_form) == 1) - expect_error(castor_api$getFormsPages(creds$example_study, page = -1)) - expect_error(castor_api$getFormsPages(creds$example_study, page = 100000000)) - expect_error(castor_api$getFormsPages(creds$example_study, page = pi)) + expect_error(castor_api$getFormsPages(creds$output_study, page = -1)) + expect_error(castor_api$getFormsPages(creds$output_study, page = 100000000)) + expect_error(castor_api$getFormsPages(creds$output_study, page = pi)) }) test_that("getForms returns an appropriate object.", { - form_data <- castor_api$getForms(creds$example_study) + form_data <- castor_api$getForms(creds$output_study) expect_is(form_data, "data.frame") expect_gt(nrow(form_data), 0) diff --git a/tests/testthat/test_getStudyData.R b/tests/testthat/test_getStudyData.R deleted file mode 100644 index bd37d70..0000000 --- a/tests/testthat/test_getStudyData.R +++ /dev/null @@ -1,10 +0,0 @@ -context("Test getStudyData in all its glory.") - -creds <- readRDS("testing_credentials.Rds") -castor_api <- CastorData$new(key=creds$client_id, secret=creds$client_secret, base_url=creds$base_url) - -test_that("getStudyData returns an appropriate object.", { - sdf <- castor_api$getStudyData(creds$example_study) - - expect_equal(creds$study_hash, digest::digest(sdf)) -}) diff --git a/tests/testthat/test_getStudyData/test_getStudyData.R b/tests/testthat/test_getStudyData/test_getStudyData.R new file mode 100644 index 0000000..3bc3db9 --- /dev/null +++ b/tests/testthat/test_getStudyData/test_getStudyData.R @@ -0,0 +1,39 @@ +creds <- readRDS("../testing_credentials.Rds") +castor_api <- CastorData$new(key=creds$client_id, secret=creds$client_secret, base_url=creds$base_url) +complete_study_output <- castor_api$getStudyData(creds$output_study) + +test_that("getStudyData returns the expected study data.", { + actual <- complete_study_output$Study + expected <- read.csv("../../test_files/files_output/CastorStudy.csv", check.names=F) + expect_identical(actual, expected) +}) + +test_that("getStudyData returns the expected data for the repeated measure Unscheduled Visit", { + actual <- complete_study_output$`Repeating data`$`Unscheduled visit` + expected <- read.csv("../../test_files/files_output/CastorUnscheduledVisit.csv", check.names=F) + expect_identical(actual, expected) +}) + +test_that("getStudyData returns the expected data for the repeated measure Medication", { + actual <- complete_study_output$`Repeating data`$Medication + expected <- read.csv("../../test_files/files_output/CastorMedication.csv", check.names=F) + expect_identical(actual, expected) +}) + +test_that("getStudyData returns the expected data for the repeated measure Comorbidities", { + actual <- complete_study_output$`Repeating data`$Comorbidities + expected <- read.csv("../../test_files/files_output/CastorUnscheduledVisit.csv", check.names=F) + expect_identical(actual, expected) +}) + +test_that("getStudyData returns the expected data for the repeated measure Adverse Events", { + actual <- complete_study_output$`Repeating data`$`Adverse event` + expected <- read.csv("../../test_files/files_output/CastorAdverseEvent.csv", check.names=F) + expect_identical(actual, expected) +}) + +test_that("getStudyData returns the expected data for the survey Quality of Life", { + actual <- complete_study_output$Surveys$`QOL Survey` + expected <- read.csv("../../test_files/files_output/CastorQOLSurvey.csv", check.names=F) + expect_identical(actual, expected) +}) diff --git a/tests/testthat/test_getStudyData/test_getStudyData_Parts.R b/tests/testthat/test_getStudyData/test_getStudyData_Parts.R new file mode 100644 index 0000000..e683da3 --- /dev/null +++ b/tests/testthat/test_getStudyData/test_getStudyData_Parts.R @@ -0,0 +1,124 @@ +creds <- readRDS("../testing_credentials.Rds") +castor_api <- CastorData$new(key=creds$client_id, secret=creds$client_secret, base_url=creds$base_url) +study_output_nostudy <- castor_api$getStudyData(creds$output_study, load_study_data=FALSE) +study_output_nosurveys <- castor_api$getStudyData(creds$output_study, survey_instances=FALSE) +study_output_norepeatingdata <- castor_api$getStudyData(creds$output_study, repeating_data_instances=FALSE) + +test_that("getStudyData returns the expected study data when omitting study data.", { + actual <- study_output_nostudy$Study + # if study data is omitted, we should only retrieve participant metadata + expected <- read.csv("../../test_files/files_output/CastorStudy.csv", check.names=F)[c("participant_id", "archived", "institute", "randomisation_group", "randomisation_datetime")] + expect_identical(actual, expected) +}) + +test_that("getStudyData returns the expected study data when omitting surveys.", { + actual <- study_output_nosurveys$Study + expected <- read.csv("../../test_files/files_output/CastorStudy.csv", check.names=F) + expect_identical(actual, expected) +}) + +test_that("getStudyData returns the expected study data when omitting repeating data.", { + actual <- study_output_norepeatingdata$Study + expected <- read.csv("../../test_files/files_output/CastorStudy.csv", check.names=F) + expect_identical(actual, expected) +}) + + + +test_that("getStudyData returns the expected data for the repeated measure Unscheduled Visit when omitting study data", { + actual <- study_output_nostudy$`Repeating data`$`Unscheduled visit` + expected <- read.csv("../../test_files/files_output/CastorUnscheduledVisit.csv", check.names=F) + expect_identical(actual, expected) +}) + +test_that("getStudyData returns the expected data for the repeated measure Unscheduled Visit when omitting surveys", { + actual <- study_output_nosurveys$`Repeating data`$`Unscheduled visit` + expected <- read.csv("../../test_files/files_output/CastorUnscheduledVisit.csv", check.names=F) + expect_identical(actual, expected) +}) + +test_that("getStudyData returns the expected data for the repeated measure Unscheduled Visit when omitting repeated data", { + actual <- study_output_norepeatingdata$`Repeating data`$`Unscheduled visit` + expected <- NULL + expect_identical(actual, expected) +}) + + + +test_that("getStudyData returns the expected data for the repeated measure Medication when omitting study data", { + actual <- study_output_nostudy$`Repeating data`$Medication + expected <- read.csv("../../test_files/files_output/CastorMedication.csv", check.names=F) + expect_identical(actual, expected) +}) + +test_that("getStudyData returns the expected data for the repeated measure Medication when omitting surveys", { + actual <- study_output_nosurveys$`Repeating data`$Medication + expected <- read.csv("../../test_files/files_output/CastorMedication.csv", check.names=F) + expect_identical(actual, expected) +}) + +test_that("getStudyData returns the expected data for the repeated measure Medication when omitting repeated data", { + actual <- study_output_norepeatingdata$`Repeating data`$Medication + expected <- NULL + expect_identical(actual, expected) +}) + + + +test_that("getStudyData returns the expected data for the repeated measure Comorbidities when omitting study data", { + actual <- study_output_nostudy$`Repeating data`$Comorbidities + expected <- read.csv("../../test_files/files_output/CastorUnscheduledVisit.csv", check.names=F) + expect_identical(actual, expected) +}) + +test_that("getStudyData returns the expected data for the repeated measure Comorbidities when omitting surveys", { + actual <- study_output_nosurveys$`Repeating data`$Comorbidities + expected <- read.csv("../../test_files/files_output/CastorUnscheduledVisit.csv", check.names=F) + expect_identical(actual, expected) +}) + +test_that("getStudyData returns the expected data for the repeated measure Comorbidities when omitting repeated data", { + actual <- study_output_norepeatingdata$`Repeating data`$Comorbidities + expected <- NULL + expect_identical(actual, expected) +}) + + + +test_that("getStudyData returns the expected data for the repeated measure Adverse Events when omitting study data", { + actual <- study_output_nostudy$`Repeating data`$`Adverse event` + expected <- read.csv("../../test_files/files_output/CastorAdverseEvent.csv", check.names=F) + expect_identical(actual, expected) +}) + +test_that("getStudyData returns the expected data for the repeated measure Adverse Events when omitting surveys", { + actual <- study_output_nosurveys$`Repeating data`$`Adverse event` + expected <- read.csv("../../test_files/files_output/CastorAdverseEvent.csv", check.names=F) + expect_identical(actual, expected) +}) + +test_that("getStudyData returns the expected data for the repeated measure Adverse Events when omitting repeated data", { + actual <- study_output_norepeatingdata$`Repeating data`$`Adverse event` + expected <- NULL + expect_identical(actual, expected) +}) + + + +test_that("getStudyData returns the expected data for the survey Quality of Life when omitting study data", { + actual <- study_output_nostudy$Surveys$`QOL Survey` + expected <- read.csv("../../test_files/files_output/CastorQOLSurvey.csv", check.names=F) + expect_identical(actual, expected) +}) + +test_that("getStudyData returns the expected data for the survey Quality of Life when omitting surveys", { + actual <- study_output_nosurveys$Surveys$`QOL Survey` + expected <- NULL + expect_identical(actual, expected) +}) + +test_that("getStudyData returns the expected data for the survey Quality of Life when omitting repeated data", { + actual <- study_output_norepeatingdata$Surveys$`QOL Survey` + expected <- read.csv("../../test_files/files_output/CastorQOLSurvey.csv", check.names=F) + expect_identical(actual, expected) +}) diff --git a/tests/testthat/test_getStudyData/test_getStudyData_noBulk.R b/tests/testthat/test_getStudyData/test_getStudyData_noBulk.R new file mode 100644 index 0000000..4551902 --- /dev/null +++ b/tests/testthat/test_getStudyData/test_getStudyData_noBulk.R @@ -0,0 +1,39 @@ +creds <- readRDS("../testing_credentials.Rds") +castor_api <- CastorData$new(key=creds$client_id, secret=creds$client_secret, base_url=creds$base_url) +complete_study_output <- castor_api$getStudyData(creds$output_study, bulk=FALSE) + +test_that("getStudyData returns the expected study data when not using bulk.", { + actual <- complete_study_output$Study + expected <- read.csv("../../test_files/files_output/CastorStudy.csv", check.names=F) + expect_identical(actual, expected) +}) + +test_that("getStudyData returns the expected data for the repeated measure Unscheduled Visit when not using bulk", { + actual <- complete_study_output$`Repeating data`$`Unscheduled visit` + expected <- read.csv("../../test_files/files_output/CastorUnscheduledVisit.csv", check.names=F) + expect_identical(actual, expected) +}) + +test_that("getStudyData returns the expected data for the repeated measure Medication when not using bulk", { + actual <- complete_study_output$`Repeating data`$Medication + expected <- read.csv("../../test_files/files_output/CastorMedication.csv", check.names=F) + expect_identical(actual, expected) +}) + +test_that("getStudyData returns the expected data for the repeated measure Comorbidities when not using bulk", { + actual <- complete_study_output$`Repeating data`$Comorbidities + expected <- read.csv("../../test_files/files_output/CastorUnscheduledVisit.csv", check.names=F) + expect_identical(actual, expected) +}) + +test_that("getStudyData returns the expected data for the repeated measure Adverse Events when not using bulk", { + actual <- complete_study_output$`Repeating data`$`Adverse event` + expected <- read.csv("../../test_files/files_output/CastorAdverseEvent.csv", check.names=F) + expect_identical(actual, expected) +}) + +test_that("getStudyData returns the expected data for the survey Quality of Life when not using bulk", { + actual <- complete_study_output$Surveys$`QOL Survey` + expected <- read.csv("../../test_files/files_output/CastorQOLSurvey.csv", check.names=F) + expect_identical(actual, expected) +}) diff --git a/tests/testthat/test_getStudyData/test_getStudyData_noLabels.R b/tests/testthat/test_getStudyData/test_getStudyData_noLabels.R new file mode 100644 index 0000000..6f06126 --- /dev/null +++ b/tests/testthat/test_getStudyData/test_getStudyData_noLabels.R @@ -0,0 +1,39 @@ +creds <- readRDS("../testing_credentials.Rds") +castor_api <- CastorData$new(key=creds$client_id, secret=creds$client_secret, base_url=creds$base_url) +complete_study_output <- castor_api$getStudyData(creds$output_study, translate_option_values = FALSE) + +test_that("getStudyData returns the expected study data when not translating checkboxes.", { + actual <- complete_study_output$Study + expected <- read.csv("../../test_files/files_output/CastorStudy (noLabel).csv", check.names=F) + expect_identical(actual, expected) +}) + +test_that("getStudyData returns the expected data for the repeated measure Unscheduled Visit when not translating checkboxes", { + actual <- complete_study_output$`Repeating data`$`Unscheduled visit` + expected <- read.csv("../../test_files/files_output/CastorUnscheduledVisit (noLabel).csv", check.names=F) + expect_identical(actual, expected) +}) + +test_that("getStudyData returns the expected data for the repeated measure Medication when not translating checkboxes", { + actual <- complete_study_output$`Repeating data`$Medication + expected <- read.csv("../../test_files/files_output/CastorMedication (noLabel).csv", check.names=F) + expect_identical(actual, expected) +}) + +test_that("getStudyData returns the expected data for the repeated measure Comorbidities when not translating checkboxes", { + actual <- complete_study_output$`Repeating data`$Comorbidities + expected <- read.csv("../../test_files/files_output/CastorUnscheduledVisit (noLabel).csv", check.names=F) + expect_identical(actual, expected) +}) + +test_that("getStudyData returns the expected data for the repeated measure Adverse Events when not translating checkboxes", { + actual <- complete_study_output$`Repeating data`$`Adverse event` + expected <- read.csv("../../test_files/files_output/CastorAdverseEvent (noLabel).csv", check.names=F) + expect_identical(actual, expected) +}) + +test_that("getStudyData returns the expected data for the survey Quality of Life when not translating checkboxes", { + actual <- complete_study_output$Surveys$`QOL Survey` + expected <- read.csv("../../test_files/files_output/CastorQOLSurvey (noLabel).csv", check.names=F) + expect_identical(actual, expected) +}) diff --git a/tests/testthat/test_get_study_data_bulk.R b/tests/testthat/test_get_study_data_bulk.R new file mode 100644 index 0000000..d1e6020 --- /dev/null +++ b/tests/testthat/test_get_study_data_bulk.R @@ -0,0 +1,100 @@ +creds <- readRDS("testing_credentials.Rds") +castor_api <- CastorData$new( + key = creds$client_id, + secret = creds$client_secret, + base_url = creds$base_url +) + +test_that("getStudyDataPointsBulk returns an appropriate object.", { + study_data_points_bulk <- castor_api$getStudyDataPointsBulk(creds$output_study) + + expect_s3_class(study_data_points_bulk, "data.frame") + expect_equal(nrow(study_data_points_bulk), 56) + expect_equal(ncol(study_data_points_bulk), 4) +}) + +test_that("getStudyDataPointsBulk fails appropriately", { + error <- expect_error(castor_api$getStudyDataPointsBulk("THISISNOTASTUDYID")) + expect_match(error$message, "Error code: 404") +}) + + +test_that("getStudyDataBulk returns an appropriate object.", { + field_info <- castor_api$getFields(creds$output_study) + participant_info <- castor_api$getParticipants(creds$output_study) + study_data_bulk <- castor_api$getStudyDataBulk(creds$output_study, field_info, participant_info) + + expect_s3_class(study_data_bulk, "data.frame") + expect_equal(nrow(study_data_bulk), 2) + expect_equal(ncol(study_data_bulk), 57) + expect_named( + study_data_bulk, + c( + "participant_id", + "archived", + "randomisation_group" , + "randomisation_datetime" , + "institute" , + "base_bl_date", + "base_bmi" , + "base_creat" , + "base_CRP" , + "base_date" , + "base_dbp" , + "base_gluc" , + "base_hb", + "base_hr" , + "base_ht" , + "base_leucoc" , + "base_sbp" , + "base_tromboc" , + "base_urea" , + "base_weight", + "conc_med" , + "fac_V_leiden" , + "fu_bl_date" , + "fu_bmi" , + "fu_creat" , + "fu_CRP" , + "fu_date", + "fu_dbp" , + "fu_gluc" , + "fu_hb" , + "fu_hr" , + "fu_ht" , + "fu_leucoc" , + "fu_sbp", + "fu_tromboc" , + "fu_urea" , + "fu_weight" , + "his_cvd" , + "his_diabetes" , + "his_family" , + "his_smoke", + "ic_date" , + "ic_language" , + "ic_main_version" , + "ic_versions" , + "inc_age" , + "inc_criteria" , + "inc_dx", + "inc_ic" , + "inc_trials" , + "onset_stroke" , + "onset_trombectomy" , + "pat_birth_year" , + "pat_height" , + "pat_race", + "pat_sex" , + "unscheduled" + ), + ignore.order=T + ) +}) + +test_that("getStudyDataBulk fails appropriately", { + field_info <- castor_api$getFields(creds$output_study) + participant_info <- castor_api$getParticipants(creds$output_study) + error <- expect_error(castor_api$getStudyDataBulk("THISISNOTASTUDYID", field_info, participant_info)) + expect_match(error$message, "Error code: 404") +}) diff --git a/tests/testthat/test_get_study_data_points.R b/tests/testthat/test_get_study_data_points.R new file mode 100644 index 0000000..e4139e7 --- /dev/null +++ b/tests/testthat/test_get_study_data_points.R @@ -0,0 +1,82 @@ +creds <- readRDS("testing_credentials.Rds") +castor_api <- CastorData$new( + key = creds$client_id, + secret = creds$client_secret, + base_url = creds$base_url +) + +test_that("getStudyDataPoints returns an appropriate object.", { + study_data_points <- castor_api$getStudyDataPoints(creds$output_study, creds$example_participant) + + expect_s3_class(study_data_points, "data.frame") + expect_equal(nrow(study_data_points), 1) + expect_equal(ncol(study_data_points), 57) + expect_named( + study_data_points, + c( + "participant_id", + "archived", + "randomisation_group" , + "randomisation_datetime" , + "institute" , + "base_bl_date", + "base_bmi" , + "base_creat" , + "base_CRP" , + "base_date" , + "base_dbp" , + "base_gluc" , + "base_hb", + "base_hr" , + "base_ht" , + "base_leucoc" , + "base_sbp" , + "base_tromboc" , + "base_urea" , + "base_weight", + "conc_med" , + "fac_V_leiden" , + "fu_bl_date" , + "fu_bmi" , + "fu_creat" , + "fu_CRP" , + "fu_date", + "fu_dbp" , + "fu_gluc" , + "fu_hb" , + "fu_hr" , + "fu_ht" , + "fu_leucoc" , + "fu_sbp", + "fu_tromboc" , + "fu_urea" , + "fu_weight" , + "his_cvd" , + "his_diabetes" , + "his_family" , + "his_smoke", + "ic_date" , + "ic_language" , + "ic_main_version" , + "ic_versions" , + "inc_age" , + "inc_criteria" , + "inc_dx", + "inc_ic" , + "inc_trials" , + "onset_stroke" , + "onset_trombectomy" , + "pat_birth_year" , + "pat_height" , + "pat_race", + "pat_sex" , + "unscheduled" + ), + ignore.order=T + ) +}) + +test_that("getStudyDataPoints fails appropriately", { + error <- expect_error(castor_api$getStudyDataPoints("THISISNOTASTUDYID", creds$example_participant)) + expect_match(error$message, "Error code: 404") +}) diff --git a/tests/testthat/test_instantiation.R b/tests/testthat/test_instantiation.R index a154f49..bb3da20 100644 --- a/tests/testthat/test_instantiation.R +++ b/tests/testthat/test_instantiation.R @@ -1,3 +1,4 @@ +# TODO: Needs updates to tests context("Test instantiation and authentication.") test_that("Castor object instantiation produces valid R6 class object.", { diff --git a/tests/testthat/test_participants.R b/tests/testthat/test_participants.R index 134a935..c2b5831 100644 --- a/tests/testthat/test_participants.R +++ b/tests/testthat/test_participants.R @@ -1,33 +1,58 @@ -context("Test Participant related methods.") - creds <- readRDS("testing_credentials.Rds") castor_api <- CastorData$new(key=creds$client_id, secret=creds$client_secret, base_url=creds$base_url) test_that("getParticipant returns an appropriate object.", { - participant <- castor_api$getParticipant(creds$example_study, creds$example_participant) + participant <- castor_api$getParticipant(creds$output_study, creds$example_participant) - expect_is(participant, "list") + expect_type(participant, "list") expect_equal(participant$participant_id, creds$example_participant) expect_gt(length(participant), 0) }) +test_that("getParticipant fails appropriately", { + error <- expect_error(castor_api$getParticipant(creds$output_study, creds$fail_participant)) + expect_match(error$message, "Error code: 404") +}) + test_that("getParticipantsPages returns an appropriate object.", { - participants <- castor_api$getParticipantsPages(creds$example_study) - one_participant <- castor_api$getParticipantsPages(creds$example_study, page = 1) + participants <- castor_api$getParticipantsPages(creds$output_study) + expect_type(participants, "list") +}) - expect_is(participants, "list") - expect_is(one_participant, "list") - expect_true(length(one_participant) == 1) - expect_error(castor_api$getParticipantsPages(creds$example_study, page = -1)) - expect_error(castor_api$getParticipantsPages(creds$example_study, page = 100000000)) - expect_error(castor_api$getParticipantsPages(creds$example_study, page = pi)) +test_that("getParticipantsPages returns an appropriate object when retrieving a single page.", { + one_page <- castor_api$getParticipantsPages(creds$output_study, page = 1) + expect_type(one_page, "list") + expect_true(length(one_page) == 1) +}) + +test_that("getParticipantsPages fails appropriately", { + error1 <- expect_error(castor_api$getParticipantsPages(creds$output_study, page = -1)) + expect_match(error1$message, "Error code: 400") + + error2 <- expect_error(castor_api$getParticipantsPages(creds$output_study, page = 100000000)) + expect_match(error2$message, "Error code: 409") + + error3 <- expect_error(castor_api$getParticipantsPages(creds$output_study, page = pi)) + expect_match(error3$message, "page must be an integer") }) test_that("getParticipants returns an appropriate object.", { - participant_data <- castor_api$getParticipants(creds$example_study) + participant_data <- castor_api$getParticipants(creds$output_study) + + expect_s3_class(participant_data, "data.frame") + expect_equal(nrow(participant_data), 2) + expect_equal(ncol(participant_data), 34) +}) + +test_that("getParticipants returns an appropriate object when allowing archived.", { + participant_data <- castor_api$getParticipants(creds$output_study, filter_archived = FALSE) + + expect_s3_class(participant_data, "data.frame") + expect_equal(nrow(participant_data), 3) + expect_equal(ncol(participant_data), 34) +}) - expect_is(participant_data, "data.frame") - expect_gt(nrow(participant_data), 0) - expect_gt(ncol(participant_data), 0) - expect_error(castor_api$getParticipants("this is not a stuy id")) +test_that("getParticipants fails appropriately", { + error <- expect_error(castor_api$getParticipants("THISISNOTASTUDYID")) + expect_match(error$message, "Error code: 404") }) diff --git a/tests/testthat/test_repeating_data.R b/tests/testthat/test_repeating_data.R index 2950880..02c4826 100644 --- a/tests/testthat/test_repeating_data.R +++ b/tests/testthat/test_repeating_data.R @@ -1,10 +1,11 @@ +# TODO: Needs updates to tests context("Test RepeatingData related methods.") creds <- readRDS("testing_credentials.Rds") castor_api <- CastorData$new(key=creds$client_id, secret=creds$client_secret, base_url=creds$base_url) test_that("getRepeatingData returns an appropriate object.", { - repeating_data <- castor_api$getRepeatingData(creds$example_study, creds$example_repeating_data) + repeating_data <- castor_api$getRepeatingData(creds$output_study, creds$example_repeating_data) expect_is(repeating_data, "list") expect_equal(repeating_data$repeating_data_id, creds$example_repeating_data) @@ -12,20 +13,20 @@ test_that("getRepeatingData returns an appropriate object.", { }) test_that("getRepeatingDatasPages returns an appropriate object.", { - repeating_datas <- castor_api$getRepeatingDatasPages(creds$example_study) - one_repeating_data <- castor_api$getRepeatingDatasPages(creds$example_study, page = 1) + repeating_datas <- castor_api$getRepeatingDatasPages(creds$output_study) + one_repeating_data <- castor_api$getRepeatingDatasPages(creds$output_study, page = 1) expect_is(repeating_datas, "list") expect_is(one_repeating_data, "list") expect_true(length(one_repeating_data) == 1) - expect_error(castor_api$getRepeatingDatasPages(creds$example_study, page = -1)) - expect_error(castor_api$getRepeatingDatasPages(creds$example_study, + expect_error(castor_api$getRepeatingDatasPages(creds$output_study, page = -1)) + expect_error(castor_api$getRepeatingDatasPages(creds$output_study, page = 100000000)) - expect_error(castor_api$getRepeatingDatasPages(creds$example_study, page = pi)) + expect_error(castor_api$getRepeatingDatasPages(creds$output_study, page = pi)) }) test_that("getRepeatingDatas returns an appropriate object.", { - repeating_data_data <- castor_api$getRepeatingDatas(creds$example_study) + repeating_data_data <- castor_api$getRepeatingDatas(creds$output_study) expect_is(repeating_data_data, "data.frame") expect_gt(nrow(repeating_data_data), 0) @@ -35,7 +36,7 @@ test_that("getRepeatingDatas returns an appropriate object.", { test_that("getRepeatingDataForm returns an appropriate object.", { - repeating_data_form <- castor_api$getRepeatingDataForm(creds$example_study, + repeating_data_form <- castor_api$getRepeatingDataForm(creds$output_study, creds$example_repeating_data, creds$example_repeating_data_form) @@ -45,28 +46,28 @@ test_that("getRepeatingDataForm returns an appropriate object.", { }) test_that("getRepeatingDataFormsPages returns an appropriate object.", { - repeating_data_forms <- castor_api$getRepeatingDataFormsPages(creds$example_study, + repeating_data_forms <- castor_api$getRepeatingDataFormsPages(creds$output_study, creds$example_repeating_data) - one_repeating_data_form <- castor_api$getRepeatingDataFormsPages(creds$example_study, + one_repeating_data_form <- castor_api$getRepeatingDataFormsPages(creds$output_study, creds$example_repeating_data, page = 1) expect_is(repeating_data_forms, "list") expect_is(one_repeating_data_form, "list") expect_true(length(one_repeating_data_form) == 1) - expect_error(castor_api$getRepeatingDataFormsPages(creds$example_study, + expect_error(castor_api$getRepeatingDataFormsPages(creds$output_study, creds$example_repeating_data, page = -1)) - expect_error(castor_api$getRepeatingDataFormsPages(creds$example_study, + expect_error(castor_api$getRepeatingDataFormsPages(creds$output_study, creds$example_repeating_data, page = 100000000)) - expect_error(castor_api$getRepeatingDataFormsPages(creds$example_study, + expect_error(castor_api$getRepeatingDataFormsPages(creds$output_study, creds$example_repeating_data, page = pi)) }) test_that("getRepeatingDataForms returns an appropriate object.", { - repeating_data_form_data <- castor_api$getRepeatingDataForms(creds$example_study) + repeating_data_form_data <- castor_api$getRepeatingDataForms(creds$output_study) expect_is(repeating_data_form_data, "data.frame") expect_gt(nrow(repeating_data_form_data), 0) diff --git a/tests/testthat/test_studies.R b/tests/testthat/test_studies.R index 83fe633..26ded13 100644 --- a/tests/testthat/test_studies.R +++ b/tests/testthat/test_studies.R @@ -1,13 +1,14 @@ +# TODO: Needs updates to tests context("Test Study related methods.") creds <- readRDS("testing_credentials.Rds") castor_api <- CastorData$new(key=creds$client_id, secret=creds$client_secret, base_url=creds$base_url) test_that("getStudy returns an appropriate object.", { - study <- castor_api$getStudy(creds$example_study) + study <- castor_api$getStudy(creds$output_study) expect_is(study, "list") - expect_equal(study$study_id, creds$example_study) + expect_equal(study$study_id, creds$output_study) expect_gt(length(study), 0) }) diff --git a/tests/testthat/test_studydatapoints.R b/tests/testthat/test_studydatapoints.R index ef6bd2b..f595434 100644 --- a/tests/testthat/test_studydatapoints.R +++ b/tests/testthat/test_studydatapoints.R @@ -1,10 +1,11 @@ +# TODO: Needs updates to tests context("Test StudyDataPoint related methods.") creds <- readRDS("testing_credentials.Rds") castor_api <- CastorData$new(key=creds$client_id, secret=creds$client_secret, base_url=creds$base_url) test_that("getStudyDataPoint returns an appropriate object.", { - sdp <- castor_api$getStudyDataPoint(creds$example_study, + sdp <- castor_api$getStudyDataPoint(creds$output_study, creds$example_participant, creds$example_field) @@ -15,28 +16,28 @@ test_that("getStudyDataPoint returns an appropriate object.", { }) test_that("getStudyDataPointsPages returns an appropriate object.", { - sdps <- castor_api$getStudyDataPointsPages(creds$example_study, + sdps <- castor_api$getStudyDataPointsPages(creds$output_study, creds$example_participant) - one_sdp <- castor_api$getStudyDataPointsPages(creds$example_study, + one_sdp <- castor_api$getStudyDataPointsPages(creds$output_study, creds$example_participant, page = 1) expect_is(sdps, "list") expect_is(one_sdp, "list") expect_true(length(one_sdp) == 1) - expect_error(castor_api$getStudyDataPointsPages(creds$example_study, + expect_error(castor_api$getStudyDataPointsPages(creds$output_study, creds$example_participant, page = -1)) - expect_error(castor_api$getStudyDataPointsPages(creds$example_study, + expect_error(castor_api$getStudyDataPointsPages(creds$output_study, creds$example_participant, page = 100000000)) - expect_error(castor_api$getStudyDataPointsPages(creds$example_study, + expect_error(castor_api$getStudyDataPointsPages(creds$output_study, creds$example_participant, page = pi)) }) test_that("getStudyDataPoints returns an appropriate object.", { - sdp_data <- castor_api$getStudyDataPoints(creds$example_study, + sdp_data <- castor_api$getStudyDataPoints(creds$output_study, creds$example_participant, filter_types = creds$filter_vals) diff --git a/tests/testthat/test_surveys.R b/tests/testthat/test_surveys.R index 97c2fdc..83384b4 100644 --- a/tests/testthat/test_surveys.R +++ b/tests/testthat/test_surveys.R @@ -1,10 +1,11 @@ +# TODO: Needs updates to tests context("Test Survey related methods.") creds <- readRDS("testing_credentials.Rds") castor_api <- CastorData$new(key=creds$client_id, secret=creds$client_secret, base_url=creds$base_url) test_that("getSurvey returns an appropriate object.", { - survey <- castor_api$getSurvey(creds$example_study, creds$example_survey) + survey <- castor_api$getSurvey(creds$output_study, creds$example_survey) expect_is(survey, "list") expect_equal(survey$survey_id, creds$example_survey) @@ -12,19 +13,19 @@ test_that("getSurvey returns an appropriate object.", { }) test_that("getSurveysPages returns an appropriate object.", { - surveys <- castor_api$getSurveysPages(creds$example_study) - one_survey <- castor_api$getSurveysPages(creds$example_study, page = 1) + surveys <- castor_api$getSurveysPages(creds$output_study) + one_survey <- castor_api$getSurveysPages(creds$output_study, page = 1) expect_is(surveys, "list") expect_is(one_survey, "list") expect_true(length(one_survey) == 1) - expect_error(castor_api$getSurveysPages(creds$example_study, page = -1)) - expect_error(castor_api$getSurveysPages(creds$example_study, page = 100000000)) - expect_error(castor_api$getSurveysPages(creds$example_study, page = pi)) + expect_error(castor_api$getSurveysPages(creds$output_study, page = -1)) + expect_error(castor_api$getSurveysPages(creds$output_study, page = 100000000)) + expect_error(castor_api$getSurveysPages(creds$output_study, page = pi)) }) test_that("getSurveys returns an appropriate object.", { - survey_data <- castor_api$getSurveys(creds$example_study) + survey_data <- castor_api$getSurveys(creds$output_study) expect_is(survey_data, "data.frame") expect_gt(nrow(survey_data), 0) diff --git a/tests/testthat/test_visits.R b/tests/testthat/test_visits.R index 0aaec24..f0f7959 100644 --- a/tests/testthat/test_visits.R +++ b/tests/testthat/test_visits.R @@ -1,10 +1,11 @@ +# TODO: Needs updates to tests context("Test Visit related methods.") creds <- readRDS("testing_credentials.Rds") castor_api <- CastorData$new(key=creds$client_id, secret=creds$client_secret, base_url=creds$base_url) test_that("getVisit returns an appropriate object.", { - visit <- castor_api$getVisit(creds$example_study, creds$example_visit) + visit <- castor_api$getVisit(creds$output_study, creds$example_visit) expect_is(visit, "list") expect_equal(visit$visit_id, creds$example_visit) @@ -12,19 +13,19 @@ test_that("getVisit returns an appropriate object.", { }) test_that("getVisitsPages returns an appropriate object.", { - visits <- castor_api$getVisitsPages(creds$example_study) - one_visit <- castor_api$getVisitsPages(creds$example_study, page = 1) + visits <- castor_api$getVisitsPages(creds$output_study) + one_visit <- castor_api$getVisitsPages(creds$output_study, page = 1) expect_is(visits, "list") expect_is(one_visit, "list") expect_true(length(one_visit) == 1) - expect_error(castor_api$getVisitsPages(creds$example_study, page = -1)) - expect_error(castor_api$getVisitsPages(creds$example_study, page = 100000000)) - expect_error(castor_api$getVisitsPages(creds$example_study, page = pi)) + expect_error(castor_api$getVisitsPages(creds$output_study, page = -1)) + expect_error(castor_api$getVisitsPages(creds$output_study, page = 100000000)) + expect_error(castor_api$getVisitsPages(creds$output_study, page = pi)) }) test_that("getVisits returns an appropriate object.", { - visit_data <- castor_api$getVisits(creds$example_study) + visit_data <- castor_api$getVisits(creds$output_study) expect_is(visit_data, "data.frame") expect_gt(nrow(visit_data), 0)