# Programme Enrollment search (cohort builder)

**URL:** <https://talk.openmrs.org/t/programme-enrollment-search-cohort-builder/11417>\
**Category:** Development\
**Tags:** cohort-builder, restws, reporting\
**Created:** [May 10, 2017, 12:50pm UTC](https://talk.openmrs.org/t/programme-enrollment-search-cohort-builder/11417 "2017-05-10T12:50:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![femi](https://talk.openmrs.org/user_avatar/talk.openmrs.org/femi/32/4171_2.png) [@femi](https://talk.openmrs.org/u/femi)\
**Post date:** [May 10, 2017, 12:50pm UTC](https://talk.openmrs.org/t/programme-enrollment-search-cohort-builder/11417/1 "2017-05-10T12:50:45Z")

</div>

Hi everyone, the cohort builder is being given a new look and an improved user experience. You can check it out [here.](https://modules-refapp.openmrs.org/openmrs/owa/cohortbuilder/index.html#/) We’ve been able to fix the programme enrollment search tab that allows a user to be able to search for patients enrolled in programs. The image below is how the form looks like now

 ![](https://talk.openmrs.org/uploads/default/original/2X/0/055ede6c4438eb0c021e0971e152b4a65f38bc19.png)Programme enrollment search

At the moment, you can search for patients enrolled in a particular programme by selecting the program but the form also allows user to be able to select program workflow & state. However after taking a look at the patient\_program table. I don’t know how that can be achieved. The image below shows the schema of the patient\_program table. It has a foreign key for program\_id but nothing for program\_workflow or state ![](https://talk.openmrs.org/uploads/default/original/2X/4/4ea2fbfbe9e3ac964a72e8c564b20db2e610c014.png)patient\_program schema

Thanks

---

<div class="post-metadata">

**Author:** ![dkayiwa](https://talk.openmrs.org/user_avatar/talk.openmrs.org/dkayiwa/32/179_2.png) [@dkayiwa](https://talk.openmrs.org/u/dkayiwa)\
**Post date:** [May 10, 2017, 1:02pm UTC](https://talk.openmrs.org/t/programme-enrollment-search-cohort-builder/11417/2 "2017-05-10T13:02:29Z")

</div>

I thought you are making REST calls to the reporting module api which should take care of that, without requiring you to know the database tables. Not so?

---

<div class="post-metadata">

**Author:** ![femi](https://talk.openmrs.org/user_avatar/talk.openmrs.org/femi/32/4171_2.png) [@femi](https://talk.openmrs.org/u/femi)\
**Post date:** [May 10, 2017, 1:50pm UTC](https://talk.openmrs.org/t/programme-enrollment-search-cohort-builder/11417/3 "2017-05-10T13:50:57Z")

</div>

Yes, that’s correct, I’m making an AJAX post request to `ws/rest/v1/reportingrest/adhocquery?v=preview` and this is a sample of the post body

```
{
  "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"]
    	}
    }
  ]
}

```

But the [ProgrammeEnrollmentCohortDefinition](https://github.com/openmrs/openmrs-module-reporting/blob/master/api/src/main/java/org/openmrs/module/reporting/cohort/definition/ProgramEnrollmentCohortDefinition.java) does not have configuration property to handle workflow and state. However, those fields are in the old cohort definition that was why I had to take a look at the database table. Also, I made use of the old cohort builder and I’m not so sure if the workflow was actually made use of because I got the same result set when I specified one and when I did not

---

<div class="post-metadata">

**Author:** ![mseaton](https://talk.openmrs.org/user_avatar/talk.openmrs.org/mseaton/32/8088_2.png) [@mseaton](https://talk.openmrs.org/u/mseaton)\
**Post date:** [May 10, 2017, 2:05pm UTC](https://talk.openmrs.org/t/programme-enrollment-search-cohort-builder/11417/4 "2017-05-10T14:05:14Z")

</div>

@femi, see PatientStateCohortDefinition and InStateCohortDefinition.

---

<div class="post-metadata">

**Author:** ![femi](https://talk.openmrs.org/user_avatar/talk.openmrs.org/femi/32/4171_2.png) [@femi](https://talk.openmrs.org/u/femi)\
**Post date:** [May 12, 2017, 2:11pm UTC](https://talk.openmrs.org/t/programme-enrollment-search-cohort-builder/11417/5 "2017-05-12T14:11:49Z")

</div>

Thanks, @mseaton, I’ve taken a look at the `PatientStateCohortDefinition` and `InStateCohortDefinition` and it has what I need. But I don’t know if any exist for program workflow

---

<div class="post-metadata">

**Author:** ![darius](https://talk.openmrs.org/user_avatar/talk.openmrs.org/darius/32/8082_2.png) [@darius](https://talk.openmrs.org/u/darius)\
**Post date:** [May 12, 2017, 3:43pm UTC](https://talk.openmrs.org/t/programme-enrollment-search-cohort-builder/11417/6 "2017-05-12T15:43:43Z")

</div>

@femi the idea is that (1) may be enrolled in a program, (2) you may have a current state within a workflow.

But it would not make any sense in real life to be “in a workflow”, so the user cannot actually search for that.

-Darius (by phone)
