Combining multiple queries using the DHIS2 adaptor

I need to fetch data element values and their associated data element definitions using the language-dhis2 adaptor. Is the snippet below correct syntax, and would the resulting state include both result sets?

When I ran this script, state seemed to only include results of the second operation.

getDataValues({
    orgUnit: 'plPz2j9VSIz',
    period: '202105',
    dataSet: 'IBhezUyCB5Q',
    limit: 2,
});

getMetadata(['dataElements'], {
    filters: ['dataSetElements.dataSet.id:eq:IBhezUyCB5Q'],
});

console.log(state);

@dsurrao You are only seeing the results of the second operation because state.data only contains the results of the last run operation for a given job. If you want to inspect how each operation modifies state, you would also want to check what gets stored in state.references(this kinda keeps a list of results of each operation in a given job).

So for this job, try putting the console logs as below and inspect the results:

console.log('state.data',state.data);
console.log('state.references',state.references);
getDataValues({
    orgUnit: 'plPz2j9VSIz',
    period: '202105',
    dataSet: 'IBhezUyCB5Q',
    limit: 2,
});

console.log('state.data',state.data);
console.log('state.references',state.references);

getMetadata(['dataElements'], {
    filters: ['dataSetElements.dataSet.id:eq:IBhezUyCB5Q'],
});

console.log('state.data',state.data);
console.log('state.references',state.references);
3 Likes

Thanks @chaiwa, this is very helpful!