Can I fetch dataset with dataElementGroup

I am trying to fetch dataset with dataElementGroup. And I want to return dataElement inside the dataElementGroup. Currently I sent the api url below

/api/dataSets.json?paging=false&fields=id,name,code,dataSetElements[dataElementGroups[id,name,dataElement[id,name,attributeValues[id,name]]]]

But the query return empty result. Is there other way around this?

Hi @jetisco4u ,

Please use /api/dataSets.json?paging=false&fields=id,name,code,dataSetElements[dataElement[dataElementGroups[id,name,dataElement[id,name,attributeValues[id,name]]]]]

To get the required details.

Thanks,
Rithvik

1 Like

@rithvik thanks a lot. The api you sent return each dataelements and their associated groups which is a bit different from what I want. But that gave me a clue to know that I can place DEGroup inside DE. So I make small change to this one below and it gives me something I can use JS to desctructure.

http://localhost:8080/api/dataSets.json?paging=false&fields=id,name,code,dataSetElements[dataElement[id,name,attributeValues,dataElementGroups[id,name]]]

Once again thanks very much.

Is it possible to send a filter query to this api url to fetch only 1 dataset if I know the ID?

1 Like

Hi @jetisco4u ,

You can use filter query param to filter the individual dataset or you can also do something like this
/api/dataSets/{ID}.json

Thanks,
Rithvik

1 Like

I applied filter like below and it seems to to do the magic

http://localhost:8080/api/dataSets.json?paging=false&fields=id,name,code,dataSetElements[dataElement[id,name,valueType,attributeValues,dataElementGroups[id,name]]]&filter:id:2YYUEZ6I1r9

But your example should be a better approach

1 Like

The closest I got is like the nested query blow. It will be better if we can fetch say

dataSets[dataElementsGroup[dataElement]] rather than the other way round. My query request looks like:

{
    "name": "Report",
    "id": "2YYUEZ6I1r9",
    "dse": [
        {
            "de1": {
                "name": "Number",
                "id": "HjMOngg3kuy",
                "av": [
                    {
                        "value": "FHaQMPv9zc7",
                        "attribute": {
                            "id": "uwVkIP7PZDt"
                        }
                    },
                    {
                        "value": "something",
                        "attribute": {
                            "id": "FHaQMPv9zc7"
                        }
                    }
                ],
                "deg1": [
                    {
                        "name": "TB",
                        "id": "2XJB1JO9qX8"
                    }
                ]
            }
        }
    ]
}

Now I need a way to get all the dataElements inside the dataElementsGroup inside the dataSet.

Hi @jetisco4u ,

Datasets contains dataElements. Also, dataElements are part of different dataElementGroups. If you keenly observe, there is no direct relationship between datasets and dataElementGroups. So, it is not possible to fetch the data you are expecting.

The current result is as follows:
data set [ DEs part of the data set [All DE groups the DE is part of ]]

Hope this clarifies your question.

Thanks,
Rithvik

1 Like

I already noticed. That’s why I suggest that it would be better if dataElementGroup have the higher relationship to dataset so that when we fetch the data it can be nested as dataset>dataElementGroup>dataElement. That way it well be easy to destructure it. I am still trying to work around it.

I am working on an existing solution that I develop with this top to bottom hierarchy for fetching DE before I know about DHIS2.