Skip to content

Instantly share code, notes, and snippets.

@joebrew
Last active September 22, 2017 09:37
Show Gist options
  • Save joebrew/83d1efa5abf233c84cb31a483b626d0c to your computer and use it in GitHub Desktop.
Save joebrew/83d1efa5abf233c84cb31a483b626d0c to your computer and use it in GitHub Desktop.
Decoding API
# Query the raw data
# https://dbs.manhica.net:4843/dhis/api/27/dataValueSets.json?orgUnit=gA8TPImqcD3&period=2017W30&dataSet=KrDJDTu8M7j&children=true
rd <- jsonlite::fromJSON(txt = 'data/rrs/rd.json')$dataValues
# Query the organization units
# https://dbs.manhica.net:4843/dhis/api/27/dataValueSets.json?orgUnit=gA8TPImqcD3&period=2017W30&dataSet=KrDJDTu8M7j&children=true
ou <- jsonlite::fromJSON(txt = 'data/rrs/ou.json')$dataValues
# Then get data elements
# https://dbs.manhica.net:4843/dhis/api/dataElements.json
de <- jsonlite::fromJSON(txt = 'data/rrs/de.json')$dataElements
# Get category combinations
# https://dbs.manhica.net:4843/dhis/api/categoryOptionCombos.json
cc <- jsonlite::fromJSON(txt = 'data/rrs/cc.json')$categoryOptionCombos
# Join all together
x <-
# Get data elements
left_join(rd %>%
dplyr::select(-attributeOptionCombo, -storedBy, -created, -lastUpdated),
de,
by = c('dataElement' = 'id')) %>%
dplyr::select(-dataElement) %>%
rename(data_element = displayName) %>%
# Get category combinations
left_join(cc,
by = c('categoryOptionCombo' = 'id')) %>%
dplyr::select(-categoryOptionCombo) %>%
# Get organization units
left_join(ou %>% dplyr::select(dataElement, period, orgUnit))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment