library(qrcode) knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
output_dir <- params$output_dir # Create `odk_external_files` folder if it does not exist dir.create(file.path(output_dir, "odk_external_files"), showWarnings = FALSE) crf_hospit_fid <- Sys.getenv("TIMCI_CRF_HOSPIT_FID") if (!is.null(params$raw_day7fu_data)) { pii <- params$pii day0_data <- params$day0_data rctls_pid <- params$rctls_pid rct_ls_form_list <- params$rct_ls_form_list raw_day7fu_data <- params$raw_day7fu_data raw_hospit_data <- params$raw_hospit_data raw_withdrawal_data <- params$raw_withdrawal_data } else { print("Please load data first") }
hospit_fu <- timci::generate_hospital_log(pii = pii, fu7df = raw_day7fu_data, day0df = day0_data, hospitdf = raw_hospit_data, deidentify = FALSE)
dir.create(file.path(output_dir, "odk_external_files"), showWarnings = FALSE) csvh_fname <- file.path(output_dir, "odk_external_files", "higher_level_visits.csv") write.csv(hospit_fu, csvh_fname, row.names = FALSE, quote = FALSE, fileEncoding = "UTF-8") if (!is.null(hospit_fu)) { if (nrow(hospit_fu) > 0) { tmp <- timci::export_df2xlsx(hospit_fu, output_dir, "timci_hospit_fu_log_all") } }
if (!is.null(hospit_fu)) { if (nrow(hospit_fu) > 0) { for (i in 1:nrow(hospit_fu)) { pid <- toString(hospit_fu[i,'name']) png_file <- file.path(tempdir(), paste0(pid,".png")) png(png_file) qrcode::qr_code(pid) dev.off() } df <- hospit_fu %>% dplyr::mutate( code = paste0(', paste0(hospit_fu$name,".png")), ')', '{width=0.75in}') ) %>% dplyr::select('code', dplyr::everything()) %>% dplyr::rename('id' = 'name', 'child' = 'label', 'enrolment date' = 'enroldate', 'day 7 call date' = 'day7fudate') drops <- c("sex", "device_id", "rhf_loc_id") df <- df[ , !(names(df) %in% drops)] df %>% knitr::kable() } }
current_version <- "N/A" if (crf_hospit_fid %in% rct_ls_form_list) { # Get form details cform <- ruODK::form_detail( pid = rctls_pid, fid = crf_hospit_fid, url = ruODK::get_default_url(), un = ruODK::get_default_un(), pw = ruODK::get_default_pw(), ) version_no_bracket <- strsplit(cform$version, "[[]")[[1]][1] encryption_version <- strsplit(cform$version, "[[]")[[1]][2] current_version <- as.numeric(version_no_bracket) }
form_url <- "N/A" draft_response <- NULL csv_upload_response <- NULL new_version <- "N/A" publication_response <- NULL if (crf_hospit_fid %in% rct_ls_form_list) { form_url <- paste0(ruODK::get_default_url(), "/v1/projects/", rctls_pid, "/forms/", crf_hospit_fid) # Create a draft form draft_response <- timci::create_odkc_draft_form(ruODK::get_default_un(), ruODK::get_default_pw(), form_url) # Upload the new CSV created as a form attachment csv_upload_response <- timci::upload_odkc_csv_attachment(ruODK::get_default_un(), ruODK::get_default_pw(), form_url, csvh_fname) # Publish a draft form new_version <- as.character(current_version + 0.000000001) publication_response <- timci::publish_odkc_draft_form(ruODK::get_default_un(), ruODK::get_default_pw(), form_url, new_version) }
r form_url
Initial version of the form: r current_version
Create a new draft of the form: r draft_response$success
Upload the CSV containing the current follow-up log as an attachment to the draft: r csv_upload_response$success
Publish the updated form with version number r new_version
: r publication_response$success
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.