Skip to content

Commit

Permalink
Merge pull request #849 from pepfar-datim/Release-7.6.0
Browse files Browse the repository at this point in the history
Release 7.6.0
  • Loading branch information
JordanBalesBAO authored Jul 1, 2024
2 parents 65ebf58 + 01917cf commit beac698
Show file tree
Hide file tree
Showing 91 changed files with 1,168 additions and 1,327 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Type: Package
Package: datapackr
Title: A Package that Packs and Unpacks all Data Packs and Target Setting
Tools
Version: 7.5.0
Date: 2024-05-28
Version: 7.6.0
Date: 2024-06-28
Authors@R: c(
person("Scott", "Jackson", , "sjackson@baosystems.com", role = c("aut", "cre")),
person("Jason", "Pickering", , "jason.p.pickering@gmail.com", role = c("aut", "rev")),
Expand Down
3 changes: 0 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export(check_cop_year)
export(check_country_uids)
export(check_params)
export(check_schema)
export(check_season)
export(check_tool)
export(compareData_DatapackVsDatim)
export(compareData_OpuDatapackVsDatim)
Expand Down Expand Up @@ -97,7 +96,6 @@ export(getMemoIndicators)
export(getOPUDataFromDATIM)
export(getOUFromCountryUIDs)
export(getPSNUInfo)
export(getPresignedURL)
export(getSaneName)
export(getValidOrgUnits)
export(handshakeFile)
Expand Down Expand Up @@ -149,7 +147,6 @@ export(separateDataSets)
export(skip_tabs)
export(strip_wb_NAs)
export(supportedCOPYears)
export(supportedSeasons)
export(supportedTools)
export(swapColumns)
export(toolName_homeCell)
Expand Down
15 changes: 14 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
# datapackr 7.6.0
## New features
* Sunset COP21 and COP22
* Added original versions of the COP25 templates

## Bug fixes
* reenabled droping invalid disaggs from the year 2 sheet
* Updated Valid Org Units for 2024 to account for regionalization.
* Removed COP Season parameter

## Minor improvements and fixes
* Updated strip_wb_nas

# datapackr 7.5.0
## New features
* Add utility functions for interacting with PDAP Jobs

## Bug fixes
*
*

## Minor improvements and fixes
* Updated dependencies
Expand Down
143 changes: 12 additions & 131 deletions R/check_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#' * `check_PSNUs`: Dataframe of valid `PSNUs` (uid and names).
#' * `check_cop_year`: Valid `cop_year` as numeric value.
#' * `check_tool`: Valid `tool` type as string.
#' * `check_season`: Valid `season` as string.
#' * `check_schema`: Valid `schema` as dataframe.
#' * `checkDataPackName`: Valid `datapack_name` as string.
#' * `checkTemplatePath`: Valid `template_path` as string.
Expand Down Expand Up @@ -243,49 +242,30 @@ check_cop_year <- function(cop_year, tool) {

#' @export
#' @rdname parameter-checks
check_tool <- function(tool, season, cop_year) {
# If tool not provided — even if season or cop_year are — return default.
check_tool <- function(tool, cop_year) {
# If tool not provided — even if cop_year is — return default.
# If only tool provided, validate it's a valid choice.
# If tool & season provided, validate against each other.
# If tool & cop_year provided, validate against each other.

# Collect parameters.
tool <- tool %missing% NULL
tool_provided <- !is.null(tool)

season <- season %missing% NULL
season_provided <- !is.null(season)

cop_year <- cop_year %missing% NULL
cop_year_provided <- !is.null(cop_year)

# Validate clue parameters
if (cop_year_provided) {
cop_year %<>% check_cop_year()
}
if (season_provided) {
season %<>% check_season()
}

# If tool not provided, return default.
default_cop_tool <- "Data Pack"
default_opu_tool <- "PSNUxIM"
if (cop_year_provided) {
if (cop_year >= 2022) {
default_opu_tool <- "PSNUxIM"
}
}

#Default to a datapack if the tool is not specified.
if (!tool_provided) {
tool_to_return <- default_cop_tool
if (season_provided) {
if (season == "OPU") {
tool_to_return <- default_opu_tool
}
}
interactive_message(
paste0("In check_tool, deduced you meant a ", tool_to_return))
return(tool_to_return)
return(default_cop_tool)
}

# Rule out invalid tools.
Expand All @@ -296,13 +276,6 @@ check_tool <- function(tool, season, cop_year) {
}
}

# If tool & season provided, validate against each other
if (tool_provided && season_provided) {
if (!season %in% supportedSeasons(tool = tool) ||
!tool %in% supportedTools(season = season)) {
stop("In check_tool, provided tool & provided season don't match.")
}
}

if (tool_provided && cop_year_provided) {
if (!cop_year %in% supportedCOPYears(tool = tool) ||
Expand All @@ -311,87 +284,12 @@ check_tool <- function(tool, season, cop_year) {
}
}

if (tool_provided && cop_year_provided && season_provided) {
if (!tool %in% supportedTools(cop_year = cop_year, season = season))
stop("In check_tool, the tool type provided is not valid for that specific COP Year & Season.")
}

tool
}


#' @export
#' @rdname parameter-checks
check_season <- function(season, tool) {
# If neither season nor tool is provided, default to "COP".
# If season alone is provided, check it's a valid choice.
# If season & tool are both provided, validate season against tool.
# If only tool is provided, deduce season from tool.

supported_seasons <- c("COP", "OPU")
default_season <- "COP"

# Collect parameters
season <- season %missing% NULL
season_provided <- !is.null(season)

tool <- tool %missing% NULL
tool_provided <- !is.null(tool)

# If neither is provided, default to "COP"
if (!season_provided && !tool_provided) {
interactive_message("Since neither season nor tool was provided, we assumed you meant 'COP'.")
return(default_season)
}

# Validate what's been provided.
if (season_provided) {
if (!season %in% supported_seasons) {
stop("Cannot support any seasons other than 'COP' or 'OPU'.")
}
}

if (tool_provided) {
tool %<>% check_tool()
deduced_season <- switch(tool,
"Data Pack" = c("OPU", "COP"),
"Data Pack Template" = c("OPU", "COP"),
"PSNUxIM" = c("OPU", "COP"),
"PSNUxIM Template" = c("OPU", "COP"),
"OPU Data Pack" = "OPU",
"OPU Data Pack Template" = "OPU")
}

# If both season & tool provided, validate against each other.
if (season_provided && tool_provided) {
if (!season %in% deduced_season) {
interactive_warning("In check_season, provided tool & season aren't compatible.")
}
}

# If only tool provided, use it to guess the season.
if (!season_provided && tool_provided) {
if (tool %in% c("OPU Data Pack", "OPU Data Pack Template")) {
interactive_message(
paste0("Deduced season based on tool."))
return(deduced_season)
} else {
interactive_message(
paste0("Since Data Packs & PSNUxIM tools are now valid for both COP & ",
"OPU seasons, we couldn't deduce season based on just tool. ",
"Please provide season as a parameter. In the meantime, we'll ",
"use 'COP' as a placeholder for season."))
return(default_season)
}
}

return(season)
}


#' @export
#' @rdname parameter-checks
check_schema <- function(schema, cop_year, tool, season) {
check_schema <- function(schema, cop_year, tool) {

# Collect parameters
schema <- schema %missing% NULL
Expand All @@ -403,21 +301,17 @@ check_schema <- function(schema, cop_year, tool, season) {
tool <- tool %missing% NULL
tool_provided <- !is.null(tool)

season <- season %missing% NULL
season_provided <- !is.null(season)

# Validate parameters
cop_year %<>% check_cop_year()
season <- suppressMessages(check_season(season = season, tool = tool))
tool %<>% check_tool(tool = ., season = season, cop_year = cop_year)
tool %<>% check_tool(tool = ., cop_year = cop_year)

# For NULL schemas, attempt to deduce from other parameters, if provided.
# Default here is the COP schema for the most recent/current COP Year
expected_schema <- suppressMessages(pick_schema(tool = tool, cop_year = cop_year))

schema <- schema %||% expected_schema

if (!schema_provided && !tool_provided && (!cop_year_provided || !season_provided)) {
if (!schema_provided && !tool_provided && !cop_year_provided) {
interactive_message(
paste0(
"Because of ommitted parameters, we assumed you meant the schema for ",
Expand Down Expand Up @@ -509,8 +403,7 @@ checkDataPackName <- function(datapack_name, country_uids, cop_year) {
#' @importFrom utils capture.output
checkTemplatePath <- function(template_path,
cop_year,
tool,
season) {
tool) {

# Collect parameters
template_path <- template_path %missing% NULL
Expand All @@ -522,13 +415,9 @@ checkTemplatePath <- function(template_path,
tool <- tool %missing% NULL
tool_provided <- !is.null(tool)

season <- season %missing% NULL
season_provided <- !is.null(season)

# Validate parameters
cop_year %<>% check_cop_year()
season %<>% check_season(season = ., tool = tool)
tool %<>% check_tool(tool = ., season = season, cop_year = cop_year)
tool %<>% check_tool(tool = ., cop_year = cop_year)

# For NULL template_paths, attempt to deduce from other parameters, if
# provided. Default here is the template_path for the most recent/current COP
Expand Down Expand Up @@ -713,7 +602,6 @@ check_params <- function(country_uids,
PSNUs,
cop_year,
tool,
season,
schema,
datapack_name,
template_path,
Expand Down Expand Up @@ -747,20 +635,14 @@ check_params <- function(country_uids,

# Check tool ####
if (!missing(tool)) {
params$tool <- check_tool(tool, season, cop_year)
}

# Check season ####
if (!missing(season)) {
params$season <- check_season(season, tool = tool)
params$tool <- check_tool(tool, cop_year)
}

# Check schema ####
if (!missing(schema)) {
params$schema <- check_schema(schema = schema,
cop_year = cop_year,
tool = tool,
season = season)
tool = tool)
}

# Check datapack_name ####
Expand All @@ -773,8 +655,7 @@ check_params <- function(country_uids,
if (!missing(template_path)) {
params$template_path <- checkTemplatePath(template_path = template_path,
cop_year = cop_year,
tool = tool,
season = season)
tool = tool)
}

# Check wb ####
Expand Down
3 changes: 0 additions & 3 deletions R/createDataPack.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#'
createDataPack <- function(datapack_name = NULL,
country_uids,
season,
template_path = NULL,
cop_year = NULL,
tool = NULL,
Expand All @@ -24,7 +23,6 @@ createDataPack <- function(datapack_name = NULL,
params <- check_params(
country_uids = country_uids,
cop_year = cop_year,
season = season,
tool = tool,
template_path = template_path,
schema = NULL,
Expand Down Expand Up @@ -54,7 +52,6 @@ createDataPack <- function(datapack_name = NULL,
d <- createKeychainInfo(submission_path = wb_copy,
tool = tool,
country_uids = country_uids,
season = season,
cop_year = cop_year,
d2_session = d2_session)

Expand Down
7 changes: 1 addition & 6 deletions R/createKeychainInfo.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ unPackHomeTabMetadata <- function(submission_path) {
#'
createKeychainInfo <- function(submission_path = NULL,
tool = NULL,
season = NULL,
country_uids = NULL,
cop_year = NULL,
d2_session = NULL) {
Expand All @@ -43,8 +42,7 @@ createKeychainInfo <- function(submission_path = NULL,
info = list(
tool = tool,
country_uids = country_uids,
cop_year = cop_year,
season = season)
cop_year = cop_year)
)

# Pulls username if `d2_session` object provided
Expand Down Expand Up @@ -108,9 +106,6 @@ createKeychainInfo <- function(submission_path = NULL,

d$info$tool %<>% check_tool()

# season ####
d$info$season <- check_season(season = d$info$season, tool = d$info$tool)

# schema ####
d$info$schema <- check_schema(cop_year = d$info$cop_year, tool = d$info$tool)

Expand Down
10 changes: 6 additions & 4 deletions R/getCOPDataFromDATIM.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ getCOPDataFromDATIM <- function(country_uids,
inherits = TRUE)) {


if (!cop_year %in% c(2020:2024)) {
if (!cop_year %in% c(2023:2024)) {

stop("The COP year provided is not supported by the internal function getCOPDataFromDATIM")
### NOTE for COP23 some special handling of SUBNAT data for FY23 like the code below may be
Expand All @@ -30,9 +30,11 @@ getCOPDataFromDATIM <- function(country_uids,
# hack to allow forward compatibility between FY21 subnat dataset in DATIM and
# COP21/FY22 datapack
# need to be able to grab dataelements from FY22 subnat targets dataset for FY21 period
if (cop_year == 2020 && "subnat_targets" %in% datastreams) {
dataset_uids <- c(dataset_uids, getCOPDatasetUids(2021, "subnat_targets"))
}

# Mon May 13 19:44:45 2024 ----- Will delete after this proves not to break anything
# if (cop_year == 2020 && "subnat_targets" %in% datastreams) {
# dataset_uids <- c(dataset_uids, getCOPDatasetUids(2021, "subnat_targets"))
# }


# package parameters for getDataValueSets function call
Expand Down
2 changes: 0 additions & 2 deletions R/getHTSModality.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ getHTSModality <- function(cop_year = getCurrentCOPYear(),
as.character(cop_year),
"2024" = "Bm4JmNS8ciD",
"2023" = "fmxSIyzexmb",
"2022" = "bEktFhmEKn6",
"2021" = "ra9ZqrTtSQn"
)

stopifnot("Requested COP year is not supported." = !is.null(groupSet))
Expand Down
Loading

0 comments on commit beac698

Please sign in to comment.