Cohorts and Cohort Searches

@reddberckley, @femi, and all,

Yesterday I went through and documented all the existing behavior in the Reporting REST module. That documentation is now here: https://github.com/openmrs/openmrs-module-reportingrest/wiki. Please bookmark this and continue to let me know of gaps in the functionality.

Further, I discovered that I had already built an endpoint that has equivalent functionality to the new API features I was going to add, although the syntax might be a bit trickier. Take a look at the adhocquery resource in the documentation.


Instead of this:

POST .../cohort
{
  definitionLibrary: {
  	libraryKey: "reporting.library.cohortDefinition.builtIn.atLeastAgeOnDate",
  	parameterValues: {
		"minAge": 15
    }
  }  
}

…you can do

GET .../cohort/reporting.library.cohortDefinition.builtIn.atLeastAgeOnDate?minAge=15

…and in the snapshot version of the module you can also do:

POST .../cohort/reporting.library.cohortDefinition.builtIn.atLeastAgeOnDate
{
    "minAge": 15
}

Instead of this

POST .../cohort
{
  composition: {
  	compositionString: "1 AND 2",
  	searches: {
  	  "1": {
        libraryKey: "reporting.library.cohortDefinition.builtIn.males"
      },
      "2": {
        libraryKey: "reporting.library.cohortDefinition.builtIn.atLeastAgeOnDate",
        parameters: {
          "minAge": 15
        }
      }
  	}
  }
}

You can do this:

POST .../adhocquery?v=rowFilters
{
    "type": "org.openmrs.module.reporting.dataset.definition.PatientDataSetDefinition",
    "rowFilters": [
        {
            "type": "org.openmrs.module.reporting.cohort.definition.CohortDefinition",
            "key": "reporting.library.cohortDefinition.builtIn.males"
        },
        {
            "type": "org.openmrs.module.reporting.cohort.definition.CohortDefinition",
            "key": "reporting.library.cohortDefinition.builtIn.atLeastAgeOnDate",
            "parameterValues": {
                "minAge": 15
            }
        }
    ],
    "customRowFilterCombination": "1 AND 2" // AND of everything together is the default behavior
}

This syntax is a bit worse, so maybe I will go ahead and implement the shorthand that we talked about anyway. If I do that I’ll post again. (Edit: I created REPORT-796 for this.)

But for now this should be sufficient for doing any of the queries you need in the cohort builder, and it should work in the current module version. Plus, if you add a couple columns and use the ?v=preview flag this will let you build a nice UI that shows details about the first 10 results, without adding a ton of server load.

1 Like