USAID-OHA-SI / grabr

OHA/SI APIs package
https://usaid-oha-si.github.io/grabr/
Other
1 stars 2 forks source link

Broken Hierarchy mapping #55

Closed achafetz closed 4 months ago

achafetz commented 8 months ago

Not sure what happened, but when I run an API, the orgunit uid should be mapped to their names, but they aren't any more. I can't figure out why this changed...

library(grabr)
url <- "final.datim.org/api/analytics.json?dimension=ou:l1KFEXKI4Dg;LEVEL-6&dimension=HWPJnUTMjEq:pxz2gGSIQhG&dimension=LxhLO68FcXm:MvszPTQrUhy&dimension=pe:2023Q4&displayProperty=SHORTNAME&skipMeta=false&hierarchyMeta=true"

datim_process_query(url) %>% View()
baboyma commented 8 months ago

Looks like a version change. The current "version":"2.40.2.2"

The temp solution will be to set hierarchyMeta to false, grab the ou/country orgunits (datim_orgunits()) as a reference data set, and then join it to the results. See below:

url <- "final.datim.org/api/analytics.json?dimension=ou:l1KFEXKI4Dg;LEVEL-6&dimension=HWPJnUTMjEq:pxz2gGSIQhG&dimension=LxhLO68FcXm:MvszPTQrUhy&dimension=pe:2023Q4&displayProperty=SHORTNAME&skipMeta=false&hierarchyMeta=false"

df_results <- datim_process_query(url) 

df_results <- df_results %>% 
  janitor::clean_names() %>% 
  rename(orgunit = organisation_unit,
         indicator = technical_area,
         standarddizeddisaggregate = disaggregation_type) %>% 
  relocate(indicator, .before = standarddizeddisaggregate)

df_orgs <- datim_orgunits(cntry = cntry, reshape=T)

df_results <- df_results %>% 
  left_join(df_orgs, by = c("orgunituid", "orgunit"))

Note: you can also get the same query datim_query() and not have to remember the uids

datim_query(
  ou = cntry, 
  username = datim_user(),
  password = datim_pwd(),
  level = "facility",
  pe = "2023Q4",
  ta = "TX_CURR",
  value = "MER Results",
  disaggs = "Age/Sex/HIVStatus",
  property = "SHORTNAME",
  metadata = TRUE,
  hierarchy = FALSE,
  verbose = FALSE
)
baboyma commented 4 months ago

Solution was provided - moving this to archive.