@femi, looking for documentation on the reportingrest module puts you on the right track. Unfortunately, I don’t think much documentation exists. @darius is the one who knows the most about these resources, but he is not fully available at the moment, so I’ll try to weigh in quickly.
At a high-level, evaluating Cohort Definitions using the reporting module API is the approach you need to take, not querying the main OpenMRS API. The reasons for this are:
- This is one of the primary use cases that it was written for
- It is built for efficiency and speed for finding Cohorts
- it already has built in searches for most of the use cases that you are trying to support.
- it has built in support for creating compositions of searches (eg. 1 AND 2 OR (3 AND NOT 4)
So, before getting into how to access this API over REST, it is important to understand what these resources are accessing behind the scenes in the reporting module API, because you will need to configure your searches to support that.
Taking the Demographic form you show above, I can see this supported by a few different existing Cohort Definitions:
For this UI, you might just intersect (AND) the results of all of these queries together. If and when you want to have more complex composition logic, you would use a CompositionCohortDefinition.
Now, the easiest thing to do if you are trying to write a UI that has a pre-specified selection of Cohort Queries available (and if you have the requisite Java/OpenMRS knowledge to do so) would be to expose your own Web Services that you can hit, and simply use the reporting module classes in your API implementation to produce your Cohorts.
@darius did some initial work demonstrating how to post “serializedXml” to this resource, which represents the configured Cohort Definition that you wish to evaluate. I’m not sure if that is going to be the best approach to use here or not. A lot of this will depend on whether or not we can write any convenience server-side classes for this new cohort builder tool, or if everything needs to live within an OWA.
I know this answer will only get you so far, but hopefully it gets the conversation moving and we can progress from here.