Skip to content

Commit

Permalink
Update to v0.1.4
Browse files Browse the repository at this point in the history
- Refactors adorn_pvls_emr function to put all EMR data into a single column mapped to both indicator and facility instead of just facility.
-
  • Loading branch information
cnemarich committed Sep 25, 2021
1 parent 3918130 commit a320e94
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: daa.analytics
Title: Utilities for Compiling and Analyzing PEPFAR Data Alignment Activity Data
Version: 0.1.3
Version: 0.1.4
Date: 2021-06-17
Authors@R:
person(given = "Chris",
Expand Down
2 changes: 1 addition & 1 deletion R/combine-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ combine_data <- function(daa_indicator_data,

df <- daa_indicator_data %>%
dplyr::left_join(ou_hierarchy, by = c("facilityuid")) %>%
dplyr::left_join(pvls_emr, by = c("facilityuid", "period")) %>%
dplyr::left_join(pvls_emr, by = c("facilityuid", "period", "indicator")) %>%
dplyr::left_join(attribute_data %>%
dplyr::filter(!is.na(.data$moh_id)),
by = c("facilityuid")) %>%
Expand Down
37 changes: 25 additions & 12 deletions R/get-pvls-emr-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,6 @@ adorn_pvls_emr <- function(pvls_emr, coc_metadata, de_metadata, pe_metadata) {
.data$dataelementname == "EMR_SITE (N, NoApp, Serv Del Area)" &
.data$categoryoptioncomboname ==
"Service Delivery Area - ANC and/or Maternity" ~ "emr_anc",
.data$dataelementname == "EMR_SITE (N, NoApp, Serv Del Area)" &
.data$categoryoptioncomboname ==
"Service Delivery Area - Early Infant Diagnosis (not Ped ART)" ~
"emr_eid",
.data$dataelementname == "EMR_SITE (N, NoApp, Serv Del Area)" &
.data$categoryoptioncomboname ==
"Service Delivery Area - HIV/TB" ~ "emr_tb",
Expand All @@ -319,20 +315,37 @@ adorn_pvls_emr <- function(pvls_emr, coc_metadata, de_metadata, pe_metadata) {
values_fn = list(value = list)) %>%
dplyr::rowwise() %>%
dplyr::mutate(
emr_tx = any(as.logical(unlist(.data$emr_tx))),
emr_hts = any(as.logical(unlist(.data$emr_hts))),
emr_anc = any(as.logical(unlist(.data$emr_anc))),
emr_eid = any(as.logical(unlist(.data$emr_eid))),
emr_tb = any(as.logical(unlist(.data$emr_tb))),
emr_TX_CURR = any(as.logical(unlist(.data$emr_tx))),
emr_TX_NEW = any(as.logical(unlist(.data$emr_tx))),
emr_HTS_TST = any(as.logical(unlist(.data$emr_hts))),
emr_PMTCT_STAT = any(as.logical(unlist(.data$emr_anc))),
emr_PMTCT_ART = any(as.logical(unlist(.data$emr_anc))),
emr_TB_PREV = any(as.logical(unlist(.data$emr_tb))),
tx_pvls_n = sum(as.numeric(unlist(.data$tx_pvls_n))),
tx_pvls_d = sum(as.numeric(unlist(.data$tx_pvls_d)))
) %>%
dplyr::select(-.data$emr_tx, -.data$emr_hts,
-.data$emr_anc, -.data$emr_tb) %>%
dplyr::mutate(across(.cols = dplyr::starts_with("emr_"),
.fns = ~ tidyr::replace_na(.x, FALSE))) %>%

# Pivots EMR data back to long data format and replaces NAs with FALSE
tidyr::pivot_longer(cols = tidyr::starts_with("emr_"),
names_to = "indicator",
names_prefix = "emr_",
values_to = "emr_at_site_for_indicator") %>%
dplyr::mutate(
indicator = dplyr::case_when(
indicator == "TB_PREV" & period < 2020 ~ "TB_PREV_LEGACY",
indicator == "TB_PREV" & period >= 2020 ~ "TB_PREV",
TRUE ~ indicator
)
) %>%

# Organizes columns for export
dplyr::select(
organisationunitid = .data$sourceid, .data$period,
.data$emr_hts, .data$emr_tx, .data$emr_anc, .data$emr_eid, .data$emr_tb,
.data$tx_pvls_n, .data$tx_pvls_d
organisationunitid = .data$sourceid, .data$period, .data$indicator,
.data$emr_at_site_for_indicator, .data$tx_pvls_n, .data$tx_pvls_d
)

return(pvls_emr)
Expand Down

0 comments on commit a320e94

Please sign in to comment.