Saving of search history on cohort builder

My team has been working on revamping the cohort builder, we have been able to display search results as you can see in the image below

However, we are having difficulties implementing the save feature. we have gone through the web services module documentation and we couldn’t see an endpoint that we could use. I would like to know if anyone has any idea on how to go about this.

cc @darius @dkayiwa

@enahomurphy how about adding these endpoints to the reportingrest module? Can you share here an example of the search history details format?

@dkayiwa I have synced with @femi and we have been able to conclude on how the data would look like. Below is a sample of what we want to save and how it’s to be formatted.

]
  {
    "description": "Patients that are Alive",
    "parameters": {
      "type": "org.openmrs.module.reporting.dataset.definition.PatientDataSetDefinition",
      "customRowFilterCombination": "1",
	  "rowFilters": [
		{
			"type": "org.openmrs.module.reporting.cohort.definition.PatientDataDefinition",
			"key": "reporting.library.cohortDefinition.builtIn.patientsWithEnrollmentkhkjhjkh",
			"parameterValues": {
				"programs": ["09c52c0c-aafe-11df-a781-001e378eb67e"]
			}
		}
	  ]
    }
  }
]

Excellent! :slight_smile:’ Do you think you can create a reportingrest ticket and start adding an endpoint for this?

Take a look at the existing adhocdataset REST endpoint (assuming you’re using the adhocquery resource to do the evaluations). This won’t be have the ideal REST semantics for you, but I think it should work out of the box without requiring any new server-side code. It’s documented here: https://github.com/openmrs/openmrs-module-reportingrest/wiki/Ad-Hoc-Analysis#adhocdataset

Otherwise, I don’t like the JSON format that you’re proposing… I assume from the screenshot that you want to save a single search, and not the entire search history, right? If so, then you would ideally do this using the cohortDefinition resource (code and docs), but this does not yet support saving a new definition, so you will have to create a ticket for this.

In order for this to be more generically useful (outside just the cohort builder) I would expect that you’d post something like:

{
    "name": "Patients that are Alive",
    "description": "Patients that are Alive",
    "definitionClass": "org.openmrs.module.reporting.cohort.definition.DefinitionLibraryCohortDefinition",
    "properties": {
        "definitionKey": "reporting.library.cohortDefinition.builtIn.patientsWithEnrollmentkhkjhjkh",
        "parameterValues": {
            "programs": ["09c52c0c-aafe-11df-a781-001e378eb67e"]
        }
    }
}

@mseaton, any thoughts?

Thanks, @dkayiwa @darius for your response, I will look into it and start working on it. I’ll reach to both of you if I have any issue.