From a320e946f0d54a1df54d80f0af4f20f7f5b04386 Mon Sep 17 00:00:00 2001 From: Christopher Nemarich <55459914+cnemarich@users.noreply.github.com> Date: Sat, 25 Sep 2021 18:07:27 -0400 Subject: [PATCH] Update to v0.1.4 - Refactors adorn_pvls_emr function to put all EMR data into a single column mapped to both indicator and facility instead of just facility. - --- DESCRIPTION | 2 +- R/combine-data.R | 2 +- R/get-pvls-emr-data.R | 37 +++++++++++++++++++++++++------------ 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index c66c273..8c69894 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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", diff --git a/R/combine-data.R b/R/combine-data.R index 69e09a6..91f6619 100644 --- a/R/combine-data.R +++ b/R/combine-data.R @@ -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")) %>% diff --git a/R/get-pvls-emr-data.R b/R/get-pvls-emr-data.R index 1c19e32..b6af822 100644 --- a/R/get-pvls-emr-data.R +++ b/R/get-pvls-emr-data.R @@ -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", @@ -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)