What's the correct way to query patient using the "Search By Person Attributes" on the Cohort Builder

Good day,

A bug was reported for Search By Person Attributes on the Patient Attributes tab on the new Cohort Builder. On the Patients Attributes Tab, when a “Search By Person Attributes” is done for any attributes except for “Any”, no result is returned.

I tried the same search on both the old and new Cohort Builder and the result was the same for all attributes except Any. On the New Cohort Builder, 502 results are returned while only 2 results were returned on the old Cohort Builder.

Below is a query request object for the new Cohort Builder:

{
  "type": "org.openmrs.module.reporting.dataset.definition.PatientDataSetDefinition",
  "columns": [
    {
      "name": "firstname",
      "key": "reporting.library.patientDataDefinition.builtIn.preferredName.givenName",
      "type": "org.openmrs.module.reporting.data.patient.definition.PatientDataDefinition"
    },
    {
      "name": "lastname",
      "key": "reporting.library.patientDataDefinition.builtIn.preferredName.familyName",
      "type": "org.openmrs.module.reporting.data.patient.definition.PatientDataDefinition"
    },
    {
      "name": "gender",
      "key": "reporting.library.patientDataDefinition.builtIn.gender",
      "type": "org.openmrs.module.reporting.data.patient.definition.PatientDataDefinition"
    },
    {
      "name": "age",
      "key": "reporting.library.patientDataDefinition.builtIn.ageOnDate.fullYears",
      "type": "org.openmrs.module.reporting.data.patient.definition.PatientDataDefinition"
    },
    {
      "name": "patientId",
      "key": "reporting.library.patientDataDefinition.builtIn.patientId",
      "type": "org.openmrs.module.reporting.data.patient.definition.PatientDataDefinition"
    }
  ],
  "rowFilters": [
    {
      "key": "reporting.library.cohortDefinition.builtIn.personWithAttribute",
      "parameterValues": {
        "attributeType": "8d871f2a-c2cc-11de-8d13-0010c6dffd0f",
        "values": []
      },
      "type": "org.openmrs.module.reporting.dataset.definition.PatientDataSetDefinition"
    }
  ],
  "customRowFilterCombination": "1"
}

And here is the response object for the above query:

    {
    "uuid": "3e76ef11-9508-466b-bec6-cc7f19cf3f61",
    "metadata": {
        "columns": []
    },
    "rows": [],
    "definition": {
        "class": "org.openmrs.module.reporting.dataset.definition.PatientDataSetDefinition",
        "uuid": "3e76ef11-9508-466b-bec6-cc7f19cf3f61",
        "name": null,
        "description": null,
        "parameters": [],
        "links": [
            {
                "rel": "self",
                "uri": "http://modules-refapp.openmrs.org/openmrs/ws/reporting/v1/reportingrest/dataSetDefinition/3e76ef11-9508-466b-bec6-cc7f19cf3f61"
            },
            {
                "rel": "full",
                "uri": "http://modules-refapp.openmrs.org/openmrs/ws/reporting/v1/reportingrest/dataSetDefinition/3e76ef11-9508-466b-bec6-cc7f19cf3f61?v=full"
            }
        ],
        "resourceVersion": "1.8"
    },
    "links": [
        {
            "rel": "self",
            "uri": "http://modules-refapp.openmrs.org/openmrs/ws/rest/v1/reportingrest/dataSet/3e76ef11-9508-466b-bec6-cc7f19cf3f61"
        }
    ],
    "resourceVersion": "1.8"
}

I feel like this isn’t a bug, as I expect all results to be returned when there’s no constraint added to the query; so that’s why on the new Cohort Builder, 502 results are returned for Any attribute but I could be totally wrong about this. Also, there’s no way for me to confirm if these attributes are currently added to the Patients.

What are your thought’s on this?

cc @mseaton

@joelakwes, I’m not 100% sure what you mean by “ANY”, but I assume this means that you are not constraining the query by any particular value (eg. patient simply has a person attribute of the given type, regardless of value).

I don’t have any of these UIs in front of me, but from what I recall, the old Cohort Builder only searches for a single value (and the code is written to constrain against a single value). Looking here, it appears that if this value is non-null, it will constrain against it. So if you pass in an empty string, it will return patients who have an empty string as the value for that person attribute.

In the new Cohort Builder, this uses a PersonAttributeCohortDefinition behind the scenes. This supports taking in an array of possible values, to support an “in clause” behavior. It interprets an empty array to mean - do not constrain against value at all - see this code here and here. To constrain against an empty string like the previous cohort builder, you’d need to add an empty string to the value array.

Anyway, I think I agree with you that the new Cohort Builder gives the results we want. I don’t know what the new Cohort Builder looks like in this respect, but for clarity, we could add support for the following:

  • Support querying for more that 1 attribute value
  • Support querying for an attribute value that equals “”

Mike

Thanks, I’ll look into this