Skip to content

Commit

Permalink
add wrapper function
Browse files Browse the repository at this point in the history
  • Loading branch information
rtesra committed Oct 29, 2024
1 parent 5fdb573 commit 47b9e69
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
37 changes: 36 additions & 1 deletion R/input-time-series.R
Original file line number Diff line number Diff line change
Expand Up @@ -689,10 +689,45 @@ prepare_anc_spectrum_comparison <- function(anc, shape, pjnz) {
dat |>
dplyr::mutate(
sex = "female", age_group = "Y015_049",
group = indicator,
group = "anc_adult_female",
difference = value_spectrum - value_naomi) |>
dplyr::select(indicator, area_name, year, group,
value_spectrum, value_naomi, difference)

}

##' Compare aggregated subnational Naomi + spectrum totals for comparison table
##'
##' @param art Path to file containing ART data or ART data object
##' @param anc Path to file containing ART data or ART data object
##' @param shape Path to file containing geojson areas data or areas data object
##' @param pjnz Path to zip file containing spectrum pjnz file/s
##' @keywords internal

prepare_spectrum_naomi_comparison <- function(art, anc, shape, pjnz){


## Check if shape is object or file path
if(!inherits(shape, "sf")) {
shape <- read_area_merged(shape) }

## Check if anc is object or file path
if(!inherits(anc, c("spec_tbl_df","tbl_df","tbl","data.frame" ))) {
anc <- read_anc_testing(anc)
}

## Check if art is object or file path
if(!inherits(art, c("spec_tbl_df","tbl_df","tbl","data.frame" ))) {
art <- read_art_number(art, all_columns = TRUE)}

## PJNZ either object or file path
if (!inherits(pjnz, "spec_program_data")) {
pjnz <- extract_pjnz_program_data(pjnz) }

art_comparison <- prepare_art_spectrum_comparison(art, shape, pjnz)
anc_comparison <- prepare_anc_spectrum_comparison(anc, shape, pjnz)

rbind(art_comparison, anc_comparison)

}

8 changes: 5 additions & 3 deletions tests/testthat/test-input-time-series.R
Original file line number Diff line number Diff line change
Expand Up @@ -813,8 +813,9 @@ test_that("ANC data is properly aggreagted for Spectrum comparison table", {

x <- prepare_anc_spectrum_comparison(anc, shape, pjnz)

expect_equal(unique(x$group), c("anc_already_art", "anc_clients",
"anc_known_pos", "anc_tested" , "anc_tested_pos"))
expect_equal(unique(x$indicator), c("anc_already_art", "anc_clients",
"anc_known_pos", "anc_tested" , "anc_tested_pos"))
expect_equal(unique(x$group), c("anc_adult_female"))
expect_equal(unique(x$area_name), c("Northern", "Central", "Southern"))

# Test that aggregation works with national pjnz
Expand All @@ -824,8 +825,9 @@ test_that("ANC data is properly aggreagted for Spectrum comparison table", {
x <- prepare_anc_spectrum_comparison(anc, shape, pjnz)


expect_equal(unique(x$group), c("anc_already_art", "anc_clients",
expect_equal(unique(x$indicator), c("anc_already_art", "anc_clients",
"anc_known_pos", "anc_tested" , "anc_tested_pos"))
expect_equal(unique(x$group), c("anc_adult_female"))
expect_equal(unique(x$area_name), c("Malawi - Demo"))

})

0 comments on commit 47b9e69

Please sign in to comment.