[Knowledge Sharing] How to fetch data values using python & dhis2 api using Analytics

Thanks and yeah however I actually found a much simpler solution rather than doing

f'analytics.csv?dimension=pe:{period}&dimension=dx:{data_element}&filter=ou:{row["id"]};'

I replaced the row["id"] which contains the id for the CHW with LEVEL-6 which grabs all the 6th level data which I believe should be the same and is significantly faster. So the code is now just.

period='LAST_MONTH'
data_element = 'wfaQBIVQxWo'  # Data element for "Fever Case (suspected malaria)"
org='LEVEL-6'

r = api.get(f'analytics.csv?dimension=pe:{period}&dimension=dx:{data_element}&dimension=ou:{org};')
    
# Convert the CSV response to a pandas DataFrame
data = pd.read_csv(StringIO(r.text))
1 Like