Extending the Cohort Module Data Model

Hi all.

I recently installed and tested the cohort module and it works great. I created a PR here to help solve some of the issues I was facing while trying to load it onto OpenMRS v2.1.2. I have the following questions:

  1. We want to extend the cohort data model by adding some additional data that we need. For example, I would like to add a unique identifier for each cohort and I’d like to be able to search using the rest api with this identifier. What would be the best way to achieve this without modifying the existing data model?

  2. We want to be able to track the leaders of a cohort over time, how long a current leader has been the leader and if the current leader is a patient or not, what would be the way to go about this?

@maimoonak and team looking forward to your response on the above.

Adding Jonathan to this thread @jdick.

To add to what @fali has written, we were thinking we might add functionality to allow for search of cohort attributes via the rest API. In addition, we’d like to modify the rest endpoint for getting cohorts to include any attributes about the cohort. Thanks for your feedback.

Adding @burke to this thread as well.

Thanks @fali. The PR has been merged to branch 2.1.0. We may need to merge this code into master once you are done with further testing and edits.

There would be two types of changes to data model you might want to do.

  • One, which would be helpful for cohort module and may fit almost every usecase. These ideally should be done to cohort data to avoid complexity (POJO, hbm.xml, liquibase, REST).
  • 2nd, which are required by your usecase only. Most of the data can be handled by using CohortAttribute (CohortAttributeType). We can also work further on this class to make dynamic enough as OpenMRS PersonAttribute (PersonAttributeType).

However, if you find no way other than creating your own data model (example SubwayTravelersGroup), then I can think of adding another maven submodule, add your POJO (extend or nest Cohort class), hbm liquibase mappings. Then extend or add REST service as well (the url has to be different)

We would need to add another Table,POJO,hbm, DAO,Service,REST which would keep track of GroupHead/CohortHead with required fields i.e. startDate, endDate, etc. Adding it to cohort module would be great as this could be the usecase for almost everyone.

@jdick Cohort attributes can be searched by Cohort and CohortAttributeType like here. However, to make Cohort REST Resource we may need to modify the search method a little bit (let me get back on this after a while).

Hi @maimoonak,

Thanks for your detailed response. In our case, we want go with option number 2, use the CohortAttribute and CohortAttributeType. What would be the best way to search for a cohort using its cohort attribute? Is it advisable?

@fali I have committed the code for this in branch 2.1.0. The cohort can be searched via attributes in json without curly brackets like ?attributes=“a”:“va”,“b”:“v2”,“e”:“e” . This would initiate a ‘OR’ on attributes list i.e. if any of the pair matches cohort would be fetched.

Hi @maimoonak, great job! Thanks! I made a PR here which adds a cohort leader table and resource. Please have a look and give me feedback on it.