DHIS 2 API for pulling Period Based on Data Set Name selected

Do we have an API for dynamically pulling the Period based on the Data Set selected?

Currently am using the following API for pulling the DataSets
https://play.dhis2.org/2.34.0/api/dataSets

For pulling the Data Element Names based on the DataSet
https://play.dhis2.org/2.34.0/api/dataElements.json?filter=dataSetElements.dataSet.id:eq:OsPTWNqq26W

Do we have something like below for pulling Periods?
https://play.dhis2.org/2.34.0/api/period.json?filter=period.dataSet.id:eq:OsPTWNqq26W

Hi @mountain, thanks for the question!

I think what you are looking for is either the periodType or dataInputPeriods fields of the dataSet, is that correct? It’s these two fields in the Maintenance app.

Screen Shot 2020-06-26 at 3.16.23 PM

If so, those are stored as fields on the dataSet object, which you can access by adding a fields parameter to the dataSets.json API call:
https://play.dhis2.org/2.34.0/api/dataSets/OsPTWNqq26W.json?fields=periodType,dataInputPeriods

Instead of using multiple network requests and filters, it is more efficient to use the field expansion capabilities of the DHIS2 api within a single request.

This will select the dataSet ID, period type, dataInputPeriods, and the name and id of each affiliated dataElement within a single API call:

https://play.dhis2.org/2.34.0/api/dataSets/OsPTWNqq26W.json?fields=id,periodType,dataInputPeriods,dataSetElements(dataElement(id,name))

You can do the same with the dataSets.json collection endpoint as well, so that you can retrieve this for multiple dataSets, if you want:

https://play.dhis2.org/2.34.0/api/dataSets.json?fields=id,periodType,dataInputPeriods,dataSetElements(dataElement(id,name))

1 Like

Hello @austin, Thank you for that solution.
I’m developing an App using javascript and once I select a data set, I want to be able to dynamically pull the DataSet Period for data entry as below:
DataEntry

Hope this clarifies my problem.
Remember if one selects a Period that is not mapped according to how it was set, the Data Elements will not be pulled.

Hi @mountain - sorry for the delayed response.

I get what you are trying to do here, it’s a good question. The current Data Entry app does not fetch these periods from the API, so I am not sure they are exposed in the API itself. @jan or @Lars might be able to confirm that.

Hello @austin,
Thank you for the feedback. I will wait on @jan and @Lars to confirm on how this can be achieved.