Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datapackr Release Zero #860

Merged
merged 17 commits into from
Aug 8, 2024
2 changes: 2 additions & 0 deletions R/getHTSModality.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
getHTSModality <- function(cop_year = getCurrentCOPYear(),
d2_session = dynGet("d2_default_session",
inherits = TRUE)) {
#Found here https://www.datim.org/dhis-web-maintenance/index.html#/list/dataElementSection/dataElementGroupSet
groupSet <- switch(
as.character(cop_year),
"2025" = "Bm4JmNS8ciD", #Need new one created in Datim touch base with Christian
"2024" = "Bm4JmNS8ciD",
"2023" = "fmxSIyzexmb",
)
Expand Down
2 changes: 1 addition & 1 deletion R/packTool.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ packTool <- function(model_data = NULL,

# Save & Export Workbook ####
interactive_print("Saving...")
if (d$info$cop_year %in% c(2023, 2024) && d$info$tool == "Data Pack") {
if (d$info$cop_year %in% c(2023, 2024, 2025) && d$info$tool == "Data Pack") {
tool_name <- "Target Setting Tool"
} else {
tool_name <- d$info$tool
Expand Down
2 changes: 1 addition & 1 deletion R/unPackTool.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ unPackTool <- function(submission_path = NULL,
d <- unPackDataPack(d,
d2_session = d2_session)

if (d$info$cop_year %in% c("2023", "2024")) {
if (d$info$cop_year %in% c("2023", "2024", "2025")) {
d <- unpackYear2Sheet(d)
}

Expand Down
3 changes: 2 additions & 1 deletion R/unPackingChecks.R
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,8 @@ checkInvalidOrgUnits <- function(sheets, d, quiet = TRUE) {
#There may be some variation in the columns between cop years
cols_to_filter <- switch(as.character(d$info$cop_year),
"2023" = c("PSNU", "Age", "Sex"),
"2024" = c("PSNU", "Age", "Sex"))
"2024" = c("PSNU", "Age", "Sex"),
"2025" = c("PSNU", "Age", "Sex"))

invalid_orgunits <- d$sheets[sheets] %>%
dplyr::bind_rows(.id = "sheet_name") %>%
Expand Down
5 changes: 5 additions & 0 deletions R/update_de_coc_co_map.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,20 @@ update_de_coc_co_map <- function(cop_year = NULL,
"dA9C5bL44NX", "FY24 MER Targets", 2024, "targets", "mer", "psnu",
"lHUEzkjkij1", "FY25 MER Targets", 2025, "targets", "mer", "psnu",
"lHUEzkjkij1", "FY26 MER Targets", 2026, "targets", "mer", "psnu",
"lHUEzkjkij1", "FY27 MER Targets", 2027, "targets", "mer", "psnu", #Needs Christian's sign off
"vpDd67HlZcT", "FY24 DREAMS Targets", 2024, "targets", "dreams", "dsnu",
"tNbhYbrKbnk", "FY25 DREAMS Targets", 2025, "targets", "dreams", "dsnu",
"tNbhYbrKbnk", "FY26 DREAMS Targets", 2026, "targets", "dreams", "dsnu",
"tNbhYbrKbnk", "FY27 DREAMS Targets", 2027, "targets", "dreams", "dsnu", #Needs Christian's sign off
# For all FY25 SUBNAT/IMPATT, mimic FY24
"jgp20ElKCMD", "FY27 IMPATT", 2027, "targets", "impatt", "psnu", #Needs Christian's sign off
"jgp20ElKCMD", "FY26 IMPATT", 2026, "targets", "impatt", "psnu",
"jgp20ElKCMD", "FY25 IMPATT", 2025, "targets", "impatt", "psnu",
"kWKJQYP1uT7", "FY24 IMPATT", 2024, "targets", "impatt", "psnu",
"CMJtVW4ecLn", "FY27 SUBNAT Targets", 2027, "targets", "subnat", "psnu", #Needs Christian's sign off
"CMJtVW4ecLn", "FY26 SUBNAT Targets", 2026, "targets", "subnat", "psnu",
"CMJtVW4ecLn", "FY25 SUBNAT Targets", 2025, "targets", "subnat", "psnu",
# Fri Jul 26 15:42:02 2024 -- Touch base with Christian, but believe the belwo is COP23 specific
# For all FY23 SUBNAT/IMPATT, remap to FY24 disaggs, as these won't go to
# DATIM, but must go to PAW alongside FY24.
"kWKJQYP1uT7", "FY23 IMPATT", 2023, "targets", "impatt", "psnu",
Expand Down
12 changes: 12 additions & 0 deletions R/utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,18 @@ getCOPDatasetUids <- function(cop_year, datastreams) {
}

#List of COP Datasets by year
#Found here https://www.datim.org/dhis-web-maintenance/index.html#/list/dataSetSection/dataSet
cop_datasets <-
list(
"2025" = list(# NOT the COP25 versions NEED To update when released
"mer_targets" = c("HUEzkjkij1", # MER Target Setting: PSNU (Facility
# and Community Combined) (TARGETS) updated 6/28/24
"tNbhYbrKbnk"), # Host Country Targets: DREAMS (USG) updated 4/9/24
"mer_results" = NA,
"subnat_targets" = "bKSmkDP5YTc",
"subnat_results" = "fZVvcMSA9mZ",
"impatt" = "kWKJQYP1uT7"
),
"2024" = list(
"mer_targets" = c("lHUEzkjkij1", # MER Target Setting: PSNU (Facility and Community Combined) (TARGETS)
"tNbhYbrKbnk"), # Host Country Targets: DREAMS (USG)
Expand Down Expand Up @@ -434,13 +444,15 @@ getMapDataPack_DATIM_DEs_COCs <- function(cop_year, datasource = NULL, year = 1)
de_coc_map <- switch(as.character(cop_year),
"2023" = cop23_map_DataPack_DATIM_DEs_COCs,
"2024" = cop24_map_DataPack_DATIM_DEs_COCs,
"2025" = cop25_map_DataPack_DATIM_DEs_COCs,
stop("Invalid COP Year"))
}

if (datasource %in% c("OPU Data Pack", "OPU Data Pack Template", "DATIM", "PSNUxIM", "PSNUxIM Template")) {
de_coc_map <- switch(as.character(cop_year),
"2023" = cop23_map_DataPack_DATIM_DEs_COCs,
"2024" = cop24_map_DataPack_DATIM_DEs_COCs,
"2025" = cop25_map_DataPack_DATIM_DEs_COCs,
stop("Invalid COP Year"))
}

Expand Down
4 changes: 2 additions & 2 deletions R/writeHomeTab.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ writeHomeTab <- function(wb = NULL,
rows = 2, cols = 2)

# Title ####
if (cop_year %in% c(2023, 2024) && tool == "Data Pack") {
if (cop_year %in% c(2023, 2024, 2025) && tool == "Data Pack") {
tool_title <- "Target Setting Tool"
} else {
tool_title <- tool
}

pd <- "COP"
yr <- cop_year - 2000
if (cop_year %in% c(2024)) {
if (cop_year %in% c(2024)) { #Does this need updated to included 2025?
pd <- "FY"
yr <- yr + 1
}
Expand Down
60 changes: 60 additions & 0 deletions data-raw/COP25/COP25_Data_Pack_generation_script.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
library(datapackr)

# Point to DATIM login secrets ####
secrets <- Sys.getenv("SECRETS_FOLDER") %>% paste0(., "datim.json")
datimutils::loginToDATIM(secrets)

output_folder <- Sys.getenv("OUTPUT_FOLDER") %>% paste0(., "Beta Packs/")
model_data_path <- Sys.getenv("MODEL_DATA_PATH")

# For Generating Individual Data Packs ####
generation_list <- c("Malawi",
"Zambia",
"Rwanda",
"Mozambique",
"Zimbabwe",
"Tajikistan",
"India",
"Thailand",
"Vietnam",
"South Africa",
"Central America and Brazil",
"Caribbean Region",
"Cameroon",
"Cote d'Ivoire",
"Ghana",
"Benin")

pick <- datapackr::cop25_datapack_countries %>%
dplyr::filter(datapack_name %in% generation_list)

# test valid org units against cached ####
valid_OrgUnits <- getDataPackOrgUnits(use_cache = FALSE)

compare_diffs <- datapackr::valid_OrgUnits_2025 %>%
dplyr::full_join(valid_OrgUnits, by = "uid") %>%
dplyr::filter(is.na(name.x) | is.na(name.y))

if (NROW(compare_diffs) > 0) {
stop("Valid org units are not up to date! Please update valid org units.")
} else {
rm(valid_OrgUnits, compare_diffs)
}

# # For Production run ####
pick <- datapackr::cop25_datapack_countries %>%
dplyr::filter(!datapack_name %in% c("Asia Region", "Western Hemisphere Region", "Turkmenistan"))

# Execution ####
for (i in seq_along(pick$datapack_name)) {
print(paste0(i, " of ", NROW(pick), ": ", pick[[i, 1]]))

d <- packTool(model_data_path = model_data_path,
tool = "Data Pack",
datapack_name = pick$datapack_name[i],
country_uids = unlist(pick$country_uids[i]),
template_path = NULL,
cop_year = 2025,
output_folder = output_folder,
results_archive = FALSE)
}
18 changes: 18 additions & 0 deletions data-raw/COP25/COP25_Data_Pack_processing_script.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
library(datapackr)
library(magrittr)

# Point to DATIM login secrets ####
secrets <- Sys.getenv("SECRETS_FOLDER") %>% paste0(., "datim.json")

datimutils::loginToDATIM(secrets)

output_folder <- Sys.getenv("OUTPUT_FOLDER") %>% paste0(., "COP24 Data Packs/")
model_data_path <- Sys.getenv("MODEL_DATA_PATH")
snuxim_model_data_path <- Sys.getenv("SNUXIM_MODEL_DATA_PATH")

# Unpack Submitted Data Pack ####
d <- unPackTool(cop_year = 2025, season = "COP")

d <- checkAnalytics(d, model_data_path)

d <- writePSNUxIM(d, snuxim_model_data_path, output_folder)
65 changes: 65 additions & 0 deletions data-raw/COP25/update_cop25_de_coc_co_map.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Point to DATIM login secrets ----
secrets <- Sys.getenv("SECRETS_FOLDER") %>% paste0(., "datim.json")
datimutils::loginToDATIM(secrets)
cop_year <- 2025

# Patch until MER 3.0 deployed
# dp_map <- datapackr::cop23_map_DataPack_DATIM_DEs_COCs %>%
# dplyr::mutate(
# FY = FY + 1,
# period = dplyr::case_when(
# period == "2022Oct" ~ "2023Oct",
# period == "2023Oct" ~ "2024Oct",
# period == "2024Oct" ~ "2025Oct",
# TRUE ~ period),
# period_dataset = stringr::str_replace(period_dataset, "FY25", "FY26"),
# period_dataset = stringr::str_replace(period_dataset, "FY24", "FY25"),
# period_dataset = stringr::str_replace(period_dataset, "FY23", "FY24"),
# )

dp_map <- datapackr::update_de_coc_co_map(cop_year,
d2_session = dynGet("d2_default_session",
inherits = TRUE))

# Compare old and new maps for accuracy ####
new <- dp_map %>%
dplyr::select(-categoryoption_specified)

compare_diffs <- datapackr::cop25_map_DataPack_DATIM_DEs_COCs %>%
dplyr::select(-categoryoption_specified) %>%
dplyr::full_join(new, by = c("indicator_code",
"dataelementuid",
"categoryoptioncombouid",
"FY",
"valid_ages.name", "valid_ages.id", "valid_sexes.name",
"valid_sexes.id", "valid_kps.name", "valid_kps.id",
"categoryOptions.ids", "support_type", "resultstatus", "resultstatus_inclusive")) %>%
dplyr::filter(is.na(indicator_code) | is.na(dataelementname.x) | is.na(dataelementname.y))

waldo::compare(datapackr::cop25_map_DataPack_DATIM_DEs_COCs,
dp_map,
max_diffs = Inf)


cop25_map_DataPack_DATIM_DEs_COCs <- dp_map
usethis::use_data(cop25_map_DataPack_DATIM_DEs_COCs, overwrite = TRUE, compress = "xz")

## Rebuild package again. (Cmd+Shift+B)

## Save metadata in API for easy access by Data Management Team

shareable <- datapackr::cop25_map_DataPack_DATIM_DEs_COCs %>%
dplyr::select(dataElement = dataelementuid,
period,
categoryOptionCombo = categoryoptioncombouid)

output_folder <- paste0(rprojroot::find_package_root_file(),
"/data-raw/")

filename <- "cop25_metadata_DEsCOCs"

filepath <- paste0(output_folder, filename, ".csv")

utils::write.csv(shareable, filepath, row.names = FALSE)

## Rebuild package again. (Cmd+Shift+B)
2 changes: 1 addition & 1 deletion data-raw/COP25/update_cop25_psnuxim_schema.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ checkSchema(schema = cop25_psnuxim_schema,
cop_year = 2025,
tool = "PSNUxIM")

usethis::use_data(cop24_psnuxim_schema, overwrite = TRUE, compress = "xz")
usethis::use_data(cop25_psnuxim_schema, overwrite = TRUE, compress = "xz")

## Rebuild package again. (Cmd+Shift+B)
Binary file added data/cop25_map_DataPack_DATIM_DEs_COCs.rda
Binary file not shown.
Binary file added data/cop25_psnuxim_schema.rda
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading