Creating cohort with cohort members

Hello guys, As you know by now I’m working on 3.0 Cohort Builder project. It contains a feature called “Save Cohort” which will give the user the ability to save search results as a cohort. This search result contains the patient list that matches the criteria.

But the issue is /ws/rest/v1/cohort/ API’s memberIds field is deprecated. @ibacher has already provided some solutions but those are not ideal solutions. The below section is from the slack discussion.

overview of how the OMRS 2.1+ Cohort REST API seems to be intended to use:

  1. Cohorts in OMRS 2.0 and below (and the reporting module) are just sets of patientIds, which are, in fact, just the database primary key, so even if we exposed the memberIds property, you still wouldn’t be able to get from those to patients (the memberIds property is marked as deprecated and only there to not break things; it will likely be removed in the future).
  2. Instead in OMRS 2.1+ the Cohort domain is model as a Cohort which has a list of CohortMemberships. These CohortMemberships are link records between a Cohort and it members, with some additional properties (and even more in the Cohort Module—actually, if you can build your app to work with that API, that’d be great…
  3. The base API works with the CohortMemberships exposed as a REST sub-resource, so a request to /ws/rest/v1/cohort/<uuid> gets you the cohort, but a request to /ws/rest/v1/cohort/<uuid>/membership/ should get you a list of all the cohort memberships. (The reason for this is that cohorts can potentially be very large and this allows us to provide paging for the list of cohort members if it’s very long).
  4. It looks like it should be possible to create a membership by first creating a Cohort via a POST request and then creating CohortMemberships by POSTing to the /ws/rest/v1/cohort/<uuid>/membership/ with something like:

{ “patientId”: , “startDate”: <today’s date in OMRS format> }

/ws/rest/v1/cohort/<uuid>/membership/ API doesn’t allow editing patientId and even if it did it’s not a good solution. Let’s say I have 100 patients I will have to send 100 API calls to save them.

As @ibacher suggested updating the Cohort create request to also handle the memberships property would be the solution. Should I move forward with this?

CC: @jayasanka @dkayiwa @zacbutko @ibacher

1 Like

Yes, move forward with the proposed solution.

1 Like