diff --git a/R/downloads.R b/R/downloads.R index 9f125ad8..2f3ee899 100644 --- a/R/downloads.R +++ b/R/downloads.R @@ -136,12 +136,14 @@ hintr_prepare_agyw_download <- function(output, pjnz, #' @param path Path to save output file #' @param vmmc_file Optional file object, with path, filename and hash for #' VMMC input +#' @param ids List of naomi web app queue ids for putting into metadata #' #' @return Path to output file and metadata for file #' @export hintr_prepare_datapack_download <- function(output, path = tempfile(fileext = ".xlsx"), - vmmc_file = NULL) { + vmmc_file = NULL, + ids = NULL) { assert_model_output_version(output) progress <- new_simple_progress() progress$update_progress("PROGRESS_DOWNLOAD_SPECTRUM") @@ -157,7 +159,7 @@ hintr_prepare_datapack_download <- function(output, model_output$output_package, model_output$output_package$fit$model_options$psnu_level, vmmc_datapack) - datapack_metadata <- build_datapack_metadata(model_output$output_package) + datapack_metadata <- build_datapack_metadata(model_output$output_package, ids) writexl::write_xlsx(list(data = datapack_output, metadata = datapack_metadata), path = path) list( diff --git a/R/pepfar-datapack.R b/R/pepfar-datapack.R index 84479c93..c5ddb66b 100644 --- a/R/pepfar-datapack.R +++ b/R/pepfar-datapack.R @@ -201,18 +201,24 @@ build_datapack_output <- function(naomi_output, psnu_level, dmppt2_output) { ) } -build_datapack_metadata <- function(naomi_output) { +build_datapack_metadata <- function(naomi_output, ids) { meta_period <- get_period_metadata( c(naomi_output$fit$model_options$calendar_quarter_t1, naomi_output$fit$model_options$calendar_quarter_t2, naomi_output$fit$model_options$calendar_quarter_t3, naomi_output$fit$model_options$calendar_quarter_t4, naomi_output$fit$model_options$calendar_quarter_t5)) + info <- attr(naomi_output, "info") inputs <- read.csv(text = info$inputs.csv, header = FALSE) version <- data.frame("version", utils::packageVersion("naomi")) - all_data <- list(version, inputs) + + if (!is.null(ids)) { + all_data <- list(version, ids, inputs, meta_period) + } else { + all_data <- list(version, inputs, meta_period) + } max_cols <- max(vapply(all_data, ncol, numeric(1))) col_names <- vapply(seq_len(max_cols), function(i) paste0("V", i), character(1))