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

Tsnuxim #886

Open
wants to merge 21 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions R/checkColStructure.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
#' @return d
#'
checkColStructure <- function(d, sheet) {
if (sheet %in% c("SNU x IM", "PSNUxIM")) {

if (sheet %in% c("SNU x IM", "PSNUxIM", "TSNUxIM")) {
data <- d$data$SNUxIM
} else {
data <- d$data$extract
Expand All @@ -24,20 +25,24 @@ checkColStructure <- function(d, sheet) {
dplyr::mutate(
sheet = sheet,
submission_order = as.integer(seq_len(dplyr::n()))) %>%
{ if (sheet == "PSNUxIM")
{ if (sheet == "PSNUxIM" || sheet == "TSNUxIM")
dplyr::filter(.,
!stringr::str_detect(indicator_code, to_keep_regex)) else .
}

# purrr::when(sheet == "PSNUxIM" ~ dplyr::filter(.,
# !stringr::str_detect(indicator_code, to_keep_regex)),
# ~ .)

if (as.character(d$info$cop_year) %in% c("2025") && sheet %in% c("PSNUxIM", "TSNUxIM")) {
submission_cols$indicator_code[submission_cols$indicator_code == "PSNU"] <- "TSNU"
submission_cols$indicator_code[submission_cols$indicator_code == "DataPackTarget"] <- "TST Target"
}

col_check <- d$info$schema %>%
dplyr::filter(sheet_name == sheet) %>%
dplyr::select(indicator_code, template_order = col) %>%
{
if (sheet == "PSNUxIM")
if (sheet == "PSNUxIM" || sheet == "TSNUxIM")
dplyr::filter(.,
!stringr::str_detect(indicator_code, to_keep_regex)) else .
} %>%
Expand Down
5 changes: 5 additions & 0 deletions R/check_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,11 @@ checkSheets <- function(sheets,
sheets_schema <- sheets_schema[!sheets_schema %in% c("PSNUxIM")]
}

if (psnuxim && as.character(cop_year) %in% c("2025")) {
# Perform the replacement
sheets_schema <- stringr::str_replace(sheets_schema, "PSNUxIM", "TSNUxIM")
}

if (!sheets_provided) {
sheets <- sheets_schema
} else {
Expand Down
3 changes: 2 additions & 1 deletion R/createAnalytics.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ createAnalytics <- function(d,


# Append the distributed MER data and subnat data together
if (d$info$tool %in% c("OPU Data Pack", "PSNUxIM", "PSNUxIM Template")) {
print(d$info$tool)
if (d$info$tool %in% c("OPU Data Pack", "PSNUxIM", "TSNUxIM", "PSNUxIM Template")) {

map_des_cocs <- getMapDataPack_DATIM_DEs_COCs(cop_year = d$info$cop_year,
datasource = d$info$tool)
Expand Down
48 changes: 37 additions & 11 deletions R/createKeychainInfo.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ unPackHomeTabMetadata <- function(submission_path) {
cop_year = dplyr::case_when(
stringr::str_detect(home_cell, "^FY\\d{2}") ~ cop_year + 2000 - 1,
TRUE ~ cop_year + 2000),
tool = stringr::str_extract(home_cell, "OPU Data Pack|Data Pack|Target Setting Tool|PSNUxIM"),
tool = stringr::str_extract(home_cell, "OPU Data Pack|Data Pack|Target Setting Tool|PSNUxIM|TSNUxIM"),
tool = stringr::str_replace(tool, "Target Setting Tool", "Data Pack"))
}

Expand Down Expand Up @@ -113,16 +113,42 @@ createKeychainInfo <- function(submission_path = NULL,
header_row <- headerRow(tool = d$info$tool,
cop_year = d$info$cop_year)

check_if_template <-
readxl::read_excel(
path = d$keychain$submission_path,
sheet =
dplyr::if_else(
d$info$tool %in% c("OPU Data Pack", "PSNUxIM"), "PSNUxIM", "Prioritization"),
range = readxl::cell_limits(c(header_row, 1), c(NA, 10)),
col_types = "text",
.name_repair = "minimal") %>%
dplyr::select(PSNU)
if (as.character(d$info$cop_year) %in% c("2023", "2024")) {
check_if_template <-
readxl::read_excel(
path = d$keychain$submission_path,
sheet =
dplyr::if_else(
d$info$tool %in% c("OPU Data Pack", "PSNUxIM"), "PSNUxIM", "Prioritization"),
range = readxl::cell_limits(c(header_row, 1), c(NA, 10)),
col_types = "text",
.name_repair = "minimal") %>%
dplyr::select(PSNU)
} else if (as.character(d$info$cop_year) %in% c("2025") && d$info$tool %in% c("OPU Data Pack", "TSNUxIM")) {
check_if_template <-
readxl::read_excel(
path = d$keychain$submission_path,
sheet = "TSNUxIM",
range = readxl::cell_limits(c(header_row, 1), c(NA, 10)),
col_types = "text",
.name_repair = "minimal") %>%
dplyr::select(TSNU)
} else if (as.character(d$info$cop_year) %in% c("2025") && d$info$tool %in% c("Data Pack", "Data Pack Template")) {
check_if_template <-
readxl::read_excel(
path = d$keychain$submission_path,
sheet = "Prioritization",
range = readxl::cell_limits(c(header_row, 1), c(NA, 10)),
col_types = "text",
.name_repair = "minimal") %>%
dplyr::select(PSNU)
}

if (as.character(d$info$cop_year) %in% c("2025") && d$info$tool %in% c("OPU Data Pack", "TSNUxIM")) {
check_if_template %<>% dplyr::rename(PSNU = TSNU)
} else {
check_if_template
}

is_template <- NROW(check_if_template$PSNU) == 0 | all(is.na(check_if_template$PSNU))

Expand Down
2 changes: 1 addition & 1 deletion R/exportPackr.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ packName <- function(output_folder, tool, datapack_name, extension) {
exportPackr <- function(data, output_folder, tool, datapack_name) {


if (tool %in% c("Data Pack", "OPU Data Pack", "PSNUxIM", "Target Setting Tool")) {
if (tool %in% c("Data Pack", "OPU Data Pack", "PSNUxIM", "TSNUxIM", "Target Setting Tool")) {
if (!inherits(data, "Workbook")) {
stop("Output type and data do not match!")
}
Expand Down
2 changes: 1 addition & 1 deletion R/getHTSModality.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ getHTSModality <- function(cop_year = getCurrentCOPYear(),
#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
"2025" = "UfocMKi1Ph7",
"2024" = "Bm4JmNS8ciD",
"2023" = "fmxSIyzexmb",
)
Expand Down
2 changes: 1 addition & 1 deletion R/loadDataPack.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ readSheet <- function(d,
.name_repair = .name_repair)

# for cop25 we changed names programatically to TSNU for all except below
if (d$info$cop_year %in% c("2025")) {
if (d$info$cop_year %in% c("2025") && !d$info$tool %in% c("TSNUxIM")) {
if (!sheet %in% c("Prioritization", "AGYW")) {
data <- data %>% dplyr::rename(PSNU = TSNU)
} else if (sheet == "AGYW") {
Expand Down
Loading