O3: New Endpoint: Searching for Cohorts by Name

Hi Team,

Thanks everyone for your help resolving O3: Cohort Endpoint Support . Now it is possible to post a cohort with multiple members. The next step is to implement a cohort search. The idea is we want to be able to search by name for a cohort we previously created so we can find it easily and perform actions for the cohort members. Currently reading the readme of the cohort-module it doesn’t look like this is a supported action? Does anyone know if the endpoint actually exists but isn’t documented yet? Or if it doesn’t exist would it be possible to create this endpoint?

Ideally the response would have a format like

{
    "results": [
        {
            "name": "Rodeo Group 2",
            "description": null,
            "startDate": null,
            "endDate": null,
            "groupCohort": false,
            "uuid": "49caa1ab-82dc-4285-a753-2b521971d81c",
            "location": null,
            "cohortType": null,
            "attributes": [],
            "voided": false,
            "voidReason": null,
            "display": "Rodeo Group 2",
            "links": [
                {
                    "rel": "self",
                    "uri": "http://backend:8080/openmrs/ws/rest/v1/cohortm/cohort/49caa1ab-82dc-4285-a753-2b521971d81c",
                    "resourceAlias": "cohort"
                },
                {
                    "rel": "full",
                    "uri": "http://backend:8080/openmrs/ws/rest/v1/cohortm/cohort/49caa1ab-82dc-4285-a753-2b521971d81c?v=full",
                    "resourceAlias": "cohort"
                }
            ],
            "resourceVersion": "1.8",
            "cohortMembers": [
                  {
                      "uuid": "49caa1ab-82dc-4285-a753-2b521971d81c",
                      "uuid": "51caa1ab-82dc-4285-a753-2b521971f819",
                      ...
                  }
            ]
        },
       ...
    ]
}

Additionally, it would be very useful to have the GET /ws/rest/v1/cohortm/cohort/<cohort_uuid> endpoint return cohortMembers and their uuids. Right now this is returning just the cohort object, and I’m not sure how to get the cohortMembers from that object? Is that a different endpoint? For the endpoint which returns the cohort members, is it possible to include (for patients) their patientUuids ?

Thanks in advance.

/openmrs/ws/rest/v1/cohortm/cohort?q=name

1 Like

/ws/rest/v1/cohortm/cohort/<cohort_uuid>?v=full

If you want to refine it to only the properties you need, you can use this below:

/ws/rest/v1/cohortm/cohort/<cohort_uuid>?v=custom:(cohortMembers:(uuid,patient:(uuid)))

1 Like

@dkayiwa Both of these are working like you say! Thank you so much!

I’m really not familiar with this v=custom:... syntax, but I’ve seen it a few times now throughout the site. Is this an OpenMRS rest - wide convention? Should I just assume that syntax like this is working for all rest endpoints? What options are available here and what should the syntax look like? Also what all query parameters are available? So far it looks like v means “view” here? And q for “query” above? Are there more? Obv if this is already well documented somewhere just the link would be great :slight_smile:

Yes

All end points served from the REST Webservices Module or the framework it provides… which is not equivalent to all endpoints that may or may not be REST (appointments is an example of a backend module which uses a different set of conventions).

The conventions are on the Wiki here.

1 Like