Analytics query - filter on org unit group

Hello everyone,
I’ve a question on the analytics API. If I want to get a result for a single org unit, I can do something like this:

https://play.dhis2.org/demo/api/analytics.json?dimension=dx:fbfJHSPpUQD&dimension=pe:LAST_MONTH&dimension=ou:ImspTQPwCqd

(in this case, asking for the ANC 1st visit result for the last month for the Sierra Leone country).

This is actually giving me the aggregation of all the org unit in the country, as per the documentation:

“For the organisation unit dimension the dimension items are the organisation units and their sub-hierarchy - data will be aggregated for all organisation units below the given organisation unit in the hierarchy.”

Now in my case, I would like to run the same query (result for the whole country), but limiting the org unit to a given group - let’s say the CHCs. The thing is: I don’t want the results for each CHC, but still a single result at the top level - I just want to include only the CHC in the aggregation.

Can this be expressed using the DHIS2 API? I’ve the feeling I could use a filter there, but could not manage to make it work.

Attempting to add filter=ou:OU_GROUP-CXw2yu5fodb to the above query result to the API returning an error as: “Dimensions cannot be specified as dimension and filter simultaneously” - and I don’t see how I can say “give me the aggregate for all units under Sierra Leone that are part of the CHC group”.

Any help or pointer would be most welcome.

Martin

···

**Martin Van Aken - **Freelance Enthusiast Developer

Mobile : +32 486 899 652

Follow me on Twitter : @martinvanaken

Call me on Skype : vanakenm

Hang out with me : martin@joyouscoding.com

Contact me on LinkedIn : http://www.linkedin.com/in/martinvanaken

Company website : www.joyouscoding.com

Hey Martin,

I suggest that you use (if necessary create) an organisation unit group set-based dimension in your request. The group in question needs to be part of the group set. In this case we can use the org unit group set called “facility type” as an example, where CHC is one of the groups.

Facility type - org unit group set - id: J5jldMd8OHv

CHC - org unit group - id: J5jldMd8OHv:CXw2yu5fodb

Now this group set dimension can be used as a filter. In your example above, the API correctly returns a message explaining that a single dimension cannot be used as both dimension and filter.

We now have this URL which I think gives you what you want:

https://play.dhis2.org/demo/api/analytics.json?dimension=dx:fbfJHSPpUQD&dimension=pe:LAST_12_MONTHS&dimension=ou:ImspTQPwCqd&filter=J5jldMd8OHv:CXw2yu5fodb

best,

Lars

···

On Fri, Jan 20, 2017 at 4:15 PM, Martin Van Aken martin@joyouscoding.com wrote:

Hello everyone,
I’ve a question on the analytics API. If I want to get a result for a single org unit, I can do something like this:

https://play.dhis2.org/demo/api/analytics.json?dimension=dx:fbfJHSPpUQD&dimension=pe:LAST_MONTH&dimension=ou:ImspTQPwCqd

(in this case, asking for the ANC 1st visit result for the last month for the Sierra Leone country).

This is actually giving me the aggregation of all the org unit in the country, as per the documentation:

“For the organisation unit dimension the dimension items are the organisation units and their sub-hierarchy - data will be aggregated for all organisation units below the given organisation unit in the hierarchy.”

Now in my case, I would like to run the same query (result for the whole country), but limiting the org unit to a given group - let’s say the CHCs. The thing is: I don’t want the results for each CHC, but still a single result at the top level - I just want to include only the CHC in the aggregation.

Can this be expressed using the DHIS2 API? I’ve the feeling I could use a filter there, but could not manage to make it work.

Attempting to add filter=ou:OU_GROUP-CXw2yu5fodb to the above query result to the API returning an error as: “Dimensions cannot be specified as dimension and filter simultaneously” - and I don’t see how I can say “give me the aggregate for all units under Sierra Leone that are part of the CHC group”.

Any help or pointer would be most welcome.

Martin


**Martin Van Aken - **Freelance Enthusiast Developer

Mobile : +32 486 899 652

Follow me on Twitter : @martinvanaken

Call me on Skype : vanakenm

Hang out with me : martin@joyouscoding.com

Contact me on LinkedIn : http://www.linkedin.com/in/martinvanaken

Company website : www.joyouscoding.com


Mailing list: https://launchpad.net/~dhis2-users

Post to : dhis2-users@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-users

More help : https://help.launchpad.net/ListHelp

Lars Helge Øverland

Lead developer, DHIS 2

University of Oslo

Skype: larshelgeoverland

lars@dhis2.org

http://www.dhis2.org

Small correction:

Facility type - org unit group set - id: J5jldMd8OHv

CHC - org unit group - id: CXw2yu5fodb

https://play.dhis2.org/demo/api/analytics.json?dimension=dx:fbfJHSPpUQD&dimension=pe:LAST_12_MONTHS&dimension=ou:ImspTQPwCqd&filter=J5jldMd8OHv:CXw2yu5fodb

···

On Fri, Jan 20, 2017 at 5:22 PM, Lars Helge Øverland lars@dhis2.org wrote:

Hey Martin,

I suggest that you use (if necessary create) an organisation unit group set-based dimension in your request. The group in question needs to be part of the group set. In this case we can use the org unit group set called “facility type” as an example, where CHC is one of the groups.

Facility type - org unit group set - id: J5jldMd8OHv

CHC - org unit group - id: J5jldMd8OHv:CXw2yu5fodb

Now this group set dimension can be used as a filter. In your example above, the API correctly returns a message explaining that a single dimension cannot be used as both dimension and filter.

We now have this URL which I think gives you what you want:

https://play.dhis2.org/demo/api/analytics.json?dimension=dx:fbfJHSPpUQD&dimension=pe:LAST_12_MONTHS&dimension=ou:ImspTQPwCqd&filter=J5jldMd8OHv:CXw2yu5fodb

best,

Lars

On Fri, Jan 20, 2017 at 4:15 PM, Martin Van Aken martin@joyouscoding.com wrote:

Hello everyone,
I’ve a question on the analytics API. If I want to get a result for a single org unit, I can do something like this:

https://play.dhis2.org/demo/api/analytics.json?dimension=dx:fbfJHSPpUQD&dimension=pe:LAST_MONTH&dimension=ou:ImspTQPwCqd

(in this case, asking for the ANC 1st visit result for the last month for the Sierra Leone country).

This is actually giving me the aggregation of all the org unit in the country, as per the documentation:

“For the organisation unit dimension the dimension items are the organisation units and their sub-hierarchy - data will be aggregated for all organisation units below the given organisation unit in the hierarchy.”

Now in my case, I would like to run the same query (result for the whole country), but limiting the org unit to a given group - let’s say the CHCs. The thing is: I don’t want the results for each CHC, but still a single result at the top level - I just want to include only the CHC in the aggregation.

Can this be expressed using the DHIS2 API? I’ve the feeling I could use a filter there, but could not manage to make it work.

Attempting to add filter=ou:OU_GROUP-CXw2yu5fodb to the above query result to the API returning an error as: “Dimensions cannot be specified as dimension and filter simultaneously” - and I don’t see how I can say “give me the aggregate for all units under Sierra Leone that are part of the CHC group”.

Any help or pointer would be most welcome.

Martin


**Martin Van Aken - **Freelance Enthusiast Developer

Mobile : +32 486 899 652

Follow me on Twitter : @martinvanaken

Call me on Skype : vanakenm

Hang out with me : martin@joyouscoding.com

Contact me on LinkedIn : http://www.linkedin.com/in/martinvanaken

Company website : www.joyouscoding.com


Mailing list: https://launchpad.net/~dhis2-users

Post to : dhis2-users@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-users

More help : https://help.launchpad.net/ListHelp

Lars Helge Øverland

Lead developer, DHIS 2

University of Oslo

Skype: larshelgeoverland

lars@dhis2.org

http://www.dhis2.org

Lars Helge Øverland

Lead developer, DHIS 2

University of Oslo

Skype: larshelgeoverland

lars@dhis2.org

http://www.dhis2.org

This is exactly what I needed. Just tested it. I did not expect to have to specify the group set (even if I can understand). Great, thanks.

···

On Fri, Jan 20, 2017 at 4:30 PM, Jan Henrik Øverland jan@dhis2.org wrote:

Hi Martin,

Keep Sierra Leone as the “ou” and simply add filter=J5jldMd8OHv:CXw2yu5fodb where J5jldMd8OHv = Facility type (dimension) and CXw2yu5fodb = CHC (dimension item).

https://play.dhis2.org/demo/api/25/analytics.json?dimension=dx:Uvn6LCg7dVU&dimension=ou:ImspTQPwCqd&dimension=pe:LAST_12_MONTHS&filter=J5jldMd8OHv:CXw2yu5fodb

You can easily replicate that in the pivot tables app by finding the Facility type tab to the left, select CHC only, then open the layout window and move Facility type to “filter”.

Like you said, the OU_GROUP keyword will explicitly select the orgunits in the specified group(s) instead.

Jan

On 20 January 2017 at 16:15, Martin Van Aken martin@joyouscoding.com wrote:

Hello everyone,
I’ve a question on the analytics API. If I want to get a result for a single org unit, I can do something like this:

https://play.dhis2.org/demo/api/analytics.json?dimension=dx:fbfJHSPpUQD&dimension=pe:LAST_MONTH&dimension=ou:ImspTQPwCqd

(in this case, asking for the ANC 1st visit result for the last month for the Sierra Leone country).

This is actually giving me the aggregation of all the org unit in the country, as per the documentation:

“For the organisation unit dimension the dimension items are the organisation units and their sub-hierarchy - data will be aggregated for all organisation units below the given organisation unit in the hierarchy.”

Now in my case, I would like to run the same query (result for the whole country), but limiting the org unit to a given group - let’s say the CHCs. The thing is: I don’t want the results for each CHC, but still a single result at the top level - I just want to include only the CHC in the aggregation.

Can this be expressed using the DHIS2 API? I’ve the feeling I could use a filter there, but could not manage to make it work.

Attempting to add filter=ou:OU_GROUP-CXw2yu5fodb to the above query result to the API returning an error as: “Dimensions cannot be specified as dimension and filter simultaneously” - and I don’t see how I can say “give me the aggregate for all units under Sierra Leone that are part of the CHC group”.

Any help or pointer would be most welcome.

Martin


**Martin Van Aken - **Freelance Enthusiast Developer

Mobile : +32 486 899 652

Follow me on Twitter : @martinvanaken

Call me on Skype : vanakenm

Hang out with me : martin@joyouscoding.com

Contact me on LinkedIn : http://www.linkedin.com/in/martinvanaken

Company website : www.joyouscoding.com


Mailing list: https://launchpad.net/~dhis2-users

Post to : dhis2-users@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-users

More help : https://help.launchpad.net/ListHelp

Jan Henrik Øverland

Software developer, DHIS 2

University of Oslo

http://www.dhis2.org

**Martin Van Aken - **Freelance Enthusiast Developer

Mobile : +32 486 899 652

Follow me on Twitter : @martinvanaken

Call me on Skype : vanakenm

Hang out with me : martin@joyouscoding.com

Contact me on LinkedIn : http://www.linkedin.com/in/martinvanaken

Company website : www.joyouscoding.com