DHIS2-Data Retrival

Hello community,

https://lg.risa.gov.rw/production/api/dataValueSets?dataSet=yA9raHXXk1w&dataSet=oEHNrvGwTTt&period=2024Q1&orgUnit=QvFN6czJQuE&children=true am using this endpoint to retrive raw data for the datasets but in the response the data elements have there id and I want also to have the data elements name in the same response so how can I do that is there any query I can add in the parameter

Hi @mugisha_alain

Is there a chance you send two API requests (one to get the details about the data set you are request and the other to get the values)? I tried using the fields= option in the dataValueSets endpoint and it doesn’t seem to be an option.

If the above is not possible, would you explain more about the use case? Normally, if you’re requesting dataValueSets, you’d already know specifically all the details of the dataset you are requesting the values from.

Thanks!

HI @mugisha_alain try this … i am not if i was able to understand your request :slight_smile: import requests

data_values_url = “https://lg.risa.gov.rw/production/api/dataValueSets?dataSet=yA9raHXXk1w&dataSet=oEHNrvGwTTt&period=2024Q1&orgUnit=QvFN6czJQuE&children=true
data_values_response = requests.get(data_values_url)
data_values = data_values_response.json()

metadata_url = “https://lg.risa.gov.rw/production/api/dataElements.json?fields=id,name&paging=false
metadata_response = requests.get(metadata_url)
metadata = metadata_response.json()[‘dataElements’]

data_element_dict = {element[‘id’]: element[‘name’] for element in metadata}

Merge data values with metadata

for data_value in data_values[‘dataValues’]:
data_element_id = data_value[‘dataElement’]
data_value[‘dataElementName’] = data_element_dict.get(data_element_id, ‘Unknown’)

print(data_values)

1 Like