From 5ac19d015300bd042fbe105d23dc47c95aa04435 Mon Sep 17 00:00:00 2001 From: Will Beasley Date: Thu, 5 Dec 2024 09:38:57 -0600 Subject: [PATCH] test script to be called by cron tab ref #556 --- utility/cron-example.R | 21 ++ utility/cron-example.log | 414 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 435 insertions(+) create mode 100644 utility/cron-example.R create mode 100644 utility/cron-example.log diff --git a/utility/cron-example.R b/utility/cron-example.R new file mode 100644 index 00000000..cc7bc931 --- /dev/null +++ b/utility/cron-example.R @@ -0,0 +1,21 @@ +# Simplified script incorporating a cron job & REDCapR +# Adapated from https://heds.nz/posts/automate-r-reporting-linux-cron/ +cat(paste0(Sys.time(), " Starting cron job...\n")) + +uri <- "https://bbmc.ouhsc.edu/redcap/api/" + +# A simple project (pid 153) +token <- "9A81268476645C4E5F03428B8AC3AA7B" +REDCapR::redcap_metadata_read(redcap_uri=uri, token=token) + +# A longitudinal project (pid 212) +token <- "0434F0E9CF53ED0587847AB6E51DE762" +REDCapR::redcap_metadata_read(redcap_uri=uri, token=token) + +# A repeating measures (pid 3181) +token <- "22C3FF1C8B08899FB6F86D91D874A159" +REDCapR::redcap_metadata_read(redcap_uri=uri, token=token) + +cat(paste0(Sys.time(), " Finished running scripts/new_iris.R.\n")) + +# * * * * * Rscript ~/redcap/REDCapR/utility/cron-example.R >> ~/redcap/REDCapR/utility/cron-example.log 2>&1 diff --git a/utility/cron-example.log b/utility/cron-example.log new file mode 100644 index 00000000..b7fa1bdb --- /dev/null +++ b/utility/cron-example.log @@ -0,0 +1,414 @@ +2024-12-05 09:33:02.079769 Starting cron job... +The data dictionary describing 17 fields was read from REDCap in 0.3 seconds. The http status code was 200. +$data +# A tibble: 17 × 18 + field_name form_name section_header field_type field_label + + 1 record_id demographics text Study ID + 2 name_first demographics Contact Informa… text First Name + 3 name_last demographics text Last Name + 4 address demographics notes Street, Ci… + 5 telephone demographics text Phone numb… + 6 email demographics text E-mail + 7 dob demographics text Date of bi… + 8 age demographics text Age (years) + 9 sex demographics radio Gender +10 height health text Height (cm) +11 weight health text Weight (ki… +12 bmi health calc BMI +13 comments health General Comments notes Comments +14 mugshot health file Mugshot +15 race race_and_ethnicity checkbox Race (Sele… +16 ethnicity race_and_ethnicity radio Ethnicity +17 interpreter_needed race_and_ethnicity truefalse Are interp… +# ℹ 13 more variables: select_choices_or_calculations , field_note , +# text_validation_type_or_show_slider_number , +# text_validation_min , text_validation_max , identifier , +# branching_logic , required_field , custom_alignment , +# question_number , matrix_group_name , matrix_ranking , +# field_annotation + +$success +[1] TRUE + +$status_code +[1] 200 + +$outcome_message +[1] "The data dictionary describing 17 fields was read from REDCap in 0.3 seconds. The http status code was 200." + +$forms_collapsed +[1] "" + +$fields_collapsed +[1] "" + +$elapsed_seconds +[1] 0.3130496 + +$raw_text +[1] "" + +The data dictionary describing 95 fields was read from REDCap in 0.2 seconds. The http status code was 200. +$data +# A tibble: 95 × 18 + field_name form_name section_header field_type field_label + + 1 study_id demographics text Study ID + 2 date_enrolled demographics Consent Information text Date subject si… + 3 patient_document demographics file Upload the pati… + 4 first_name demographics Contact Information text First Name + 5 last_name demographics text Last Name + 6 telephone_1 demographics text Phone number + 7 email demographics text E-mail + 8 dob demographics text Date of birth + 9 age demographics text Age (years) +10 ethnicity demographics radio Ethnicity +# ℹ 85 more rows +# ℹ 13 more variables: select_choices_or_calculations , field_note , +# text_validation_type_or_show_slider_number , +# text_validation_min , text_validation_max , identifier , +# branching_logic , required_field , custom_alignment , +# question_number , matrix_group_name , matrix_ranking , +# field_annotation + +$success +[1] TRUE + +$status_code +[1] 200 + +$outcome_message +[1] "The data dictionary describing 95 fields was read from REDCap in 0.2 seconds. The http status code was 200." + +$forms_collapsed +[1] "" + +$fields_collapsed +[1] "" + +$elapsed_seconds +[1] 0.1591053 + +$raw_text +[1] "" + +The data dictionary describing 9 fields was read from REDCap in 0.1 seconds. The http status code was 200. +$data +# A tibble: 9 × 18 + field_name form_name section_header field_type field_label + +1 record_id intake text Record ID +2 height intake text patient height +3 weight intake text patient weight +4 bmi intake text patient bmi +5 sbp blood_pressure text systolic blood pressure +6 dbp blood_pressure text diastolic blood pressu… +7 lab laboratory text lab value +8 conc laboratory text concentration +9 image_profile image file Picture of Patient +# ℹ 13 more variables: select_choices_or_calculations , field_note , +# text_validation_type_or_show_slider_number , +# text_validation_min , text_validation_max , identifier , +# branching_logic , required_field , custom_alignment , +# question_number , matrix_group_name , matrix_ranking , +# field_annotation + +$success +[1] TRUE + +$status_code +[1] 200 + +$outcome_message +[1] "The data dictionary describing 9 fields was read from REDCap in 0.1 seconds. The http status code was 200." + +$forms_collapsed +[1] "" + +$fields_collapsed +[1] "" + +$elapsed_seconds +[1] 0.1083767 + +$raw_text +[1] "" + +2024-12-05 09:33:03.784631 Finished running scripts/new_iris.R. +2024-12-05 09:34:02.08569 Starting cron job... +The data dictionary describing 17 fields was read from REDCap in 0.3 seconds. The http status code was 200. +$data +# A tibble: 17 × 18 + field_name form_name section_header field_type field_label + + 1 record_id demographics text Study ID + 2 name_first demographics Contact Informa… text First Name + 3 name_last demographics text Last Name + 4 address demographics notes Street, Ci… + 5 telephone demographics text Phone numb… + 6 email demographics text E-mail + 7 dob demographics text Date of bi… + 8 age demographics text Age (years) + 9 sex demographics radio Gender +10 height health text Height (cm) +11 weight health text Weight (ki… +12 bmi health calc BMI +13 comments health General Comments notes Comments +14 mugshot health file Mugshot +15 race race_and_ethnicity checkbox Race (Sele… +16 ethnicity race_and_ethnicity radio Ethnicity +17 interpreter_needed race_and_ethnicity truefalse Are interp… +# ℹ 13 more variables: select_choices_or_calculations , field_note , +# text_validation_type_or_show_slider_number , +# text_validation_min , text_validation_max , identifier , +# branching_logic , required_field , custom_alignment , +# question_number , matrix_group_name , matrix_ranking , +# field_annotation + +$success +[1] TRUE + +$status_code +[1] 200 + +$outcome_message +[1] "The data dictionary describing 17 fields was read from REDCap in 0.3 seconds. The http status code was 200." + +$forms_collapsed +[1] "" + +$fields_collapsed +[1] "" + +$elapsed_seconds +[1] 0.3179343 + +$raw_text +[1] "" + +The data dictionary describing 95 fields was read from REDCap in 0.4 seconds. The http status code was 200. +$data +# A tibble: 95 × 18 + field_name form_name section_header field_type field_label + + 1 study_id demographics text Study ID + 2 date_enrolled demographics Consent Information text Date subject si… + 3 patient_document demographics file Upload the pati… + 4 first_name demographics Contact Information text First Name + 5 last_name demographics text Last Name + 6 telephone_1 demographics text Phone number + 7 email demographics text E-mail + 8 dob demographics text Date of birth + 9 age demographics text Age (years) +10 ethnicity demographics radio Ethnicity +# ℹ 85 more rows +# ℹ 13 more variables: select_choices_or_calculations , field_note , +# text_validation_type_or_show_slider_number , +# text_validation_min , text_validation_max , identifier , +# branching_logic , required_field , custom_alignment , +# question_number , matrix_group_name , matrix_ranking , +# field_annotation + +$success +[1] TRUE + +$status_code +[1] 200 + +$outcome_message +[1] "The data dictionary describing 95 fields was read from REDCap in 0.4 seconds. The http status code was 200." + +$forms_collapsed +[1] "" + +$fields_collapsed +[1] "" + +$elapsed_seconds +[1] 0.3935587 + +$raw_text +[1] "" + +The data dictionary describing 9 fields was read from REDCap in 0.1 seconds. The http status code was 200. +$data +# A tibble: 9 × 18 + field_name form_name section_header field_type field_label + +1 record_id intake text Record ID +2 height intake text patient height +3 weight intake text patient weight +4 bmi intake text patient bmi +5 sbp blood_pressure text systolic blood pressure +6 dbp blood_pressure text diastolic blood pressu… +7 lab laboratory text lab value +8 conc laboratory text concentration +9 image_profile image file Picture of Patient +# ℹ 13 more variables: select_choices_or_calculations , field_note , +# text_validation_type_or_show_slider_number , +# text_validation_min , text_validation_max , identifier , +# branching_logic , required_field , custom_alignment , +# question_number , matrix_group_name , matrix_ranking , +# field_annotation + +$success +[1] TRUE + +$status_code +[1] 200 + +$outcome_message +[1] "The data dictionary describing 9 fields was read from REDCap in 0.1 seconds. The http status code was 200." + +$forms_collapsed +[1] "" + +$fields_collapsed +[1] "" + +$elapsed_seconds +[1] 0.1074209 + +$raw_text +[1] "" + +2024-12-05 09:34:04.015385 Finished running scripts/new_iris.R. +2024-12-05 09:35:01.322777 Starting cron job... +The data dictionary describing 17 fields was read from REDCap in 0.3 seconds. The http status code was 200. +$data +# A tibble: 17 × 18 + field_name form_name section_header field_type field_label + + 1 record_id demographics text Study ID + 2 name_first demographics Contact Informa… text First Name + 3 name_last demographics text Last Name + 4 address demographics notes Street, Ci… + 5 telephone demographics text Phone numb… + 6 email demographics text E-mail + 7 dob demographics text Date of bi… + 8 age demographics text Age (years) + 9 sex demographics radio Gender +10 height health text Height (cm) +11 weight health text Weight (ki… +12 bmi health calc BMI +13 comments health General Comments notes Comments +14 mugshot health file Mugshot +15 race race_and_ethnicity checkbox Race (Sele… +16 ethnicity race_and_ethnicity radio Ethnicity +17 interpreter_needed race_and_ethnicity truefalse Are interp… +# ℹ 13 more variables: select_choices_or_calculations , field_note , +# text_validation_type_or_show_slider_number , +# text_validation_min , text_validation_max , identifier , +# branching_logic , required_field , custom_alignment , +# question_number , matrix_group_name , matrix_ranking , +# field_annotation + +$success +[1] TRUE + +$status_code +[1] 200 + +$outcome_message +[1] "The data dictionary describing 17 fields was read from REDCap in 0.3 seconds. The http status code was 200." + +$forms_collapsed +[1] "" + +$fields_collapsed +[1] "" + +$elapsed_seconds +[1] 0.3099558 + +$raw_text +[1] "" + +The data dictionary describing 95 fields was read from REDCap in 0.1 seconds. The http status code was 200. +$data +# A tibble: 95 × 18 + field_name form_name section_header field_type field_label + + 1 study_id demographics text Study ID + 2 date_enrolled demographics Consent Information text Date subject si… + 3 patient_document demographics file Upload the pati… + 4 first_name demographics Contact Information text First Name + 5 last_name demographics text Last Name + 6 telephone_1 demographics text Phone number + 7 email demographics text E-mail + 8 dob demographics text Date of birth + 9 age demographics text Age (years) +10 ethnicity demographics radio Ethnicity +# ℹ 85 more rows +# ℹ 13 more variables: select_choices_or_calculations , field_note , +# text_validation_type_or_show_slider_number , +# text_validation_min , text_validation_max , identifier , +# branching_logic , required_field , custom_alignment , +# question_number , matrix_group_name , matrix_ranking , +# field_annotation + +$success +[1] TRUE + +$status_code +[1] 200 + +$outcome_message +[1] "The data dictionary describing 95 fields was read from REDCap in 0.1 seconds. The http status code was 200." + +$forms_collapsed +[1] "" + +$fields_collapsed +[1] "" + +$elapsed_seconds +[1] 0.1435215 + +$raw_text +[1] "" + +The data dictionary describing 9 fields was read from REDCap in 0.1 seconds. The http status code was 200. +$data +# A tibble: 9 × 18 + field_name form_name section_header field_type field_label + +1 record_id intake text Record ID +2 height intake text patient height +3 weight intake text patient weight +4 bmi intake text patient bmi +5 sbp blood_pressure text systolic blood pressure +6 dbp blood_pressure text diastolic blood pressu… +7 lab laboratory text lab value +8 conc laboratory text concentration +9 image_profile image file Picture of Patient +# ℹ 13 more variables: select_choices_or_calculations , field_note , +# text_validation_type_or_show_slider_number , +# text_validation_min , text_validation_max , identifier , +# branching_logic , required_field , custom_alignment , +# question_number , matrix_group_name , matrix_ranking , +# field_annotation + +$success +[1] TRUE + +$status_code +[1] 200 + +$outcome_message +[1] "The data dictionary describing 9 fields was read from REDCap in 0.1 seconds. The http status code was 200." + +$forms_collapsed +[1] "" + +$fields_collapsed +[1] "" + +$elapsed_seconds +[1] 0.1098793 + +$raw_text +[1] "" + +2024-12-05 09:35:03.12585 Finished running scripts/new_iris.R.