Uploaded image for project: 'Reporting Module'
  1. Reporting Module
  2. REPORT-846

CompositionCohortDefinition should be able to support unions/OR

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Should
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Cohort Definitions
    • Labels:
      None
    • Complexity:
      Low

      Description

      We have a use case where we need to create a CodedObsCohortDefinition for multiple questions. So what we did was Create each CodedObsCohortDefinition for each question and combined them using the composition cohort definition. See sample code below

      Concept question1 = Context.getConceptService().getConceptByUuid("95312123-e0c2-466d-b6b1-cb6e990d0d65");
      Concept question2 = Context.getConceptService().getConceptByUuid("f5a541ae-28bc-4471-826f-7e089644cd11");
      
      Concept malariaDiagnosisConcept = Context.getConceptService().getConceptByUuid("f7a7df79-8ecf-4e20-a13d-020adc6d4944");
      
      CodedObsCohortDefinition diag1 = new CodedObsCohortDefinition();
      diag1.addParameter(new Parameter("onOrAfter", "On Or After", Date.class));
      diag1.addParameter(new Parameter("onOrBefore", "On Or Before", Date.class));
      diag1.addParameter(new Parameter("locationList", "Visit Location", Location.class, List.class, null));
      diag1.setOperator(SetComparator.IN);
      diag1.setQuestion(question1);
      diag1.setValueList(Arrays.asList(malariaDiagnosisConcept));
      
      CodedObsCohortDefinition diag2 = new CodedObsCohortDefinition();
      diag2.addParameter(new Parameter("onOrAfter", "On Or After", Date.class));
      diag2.addParameter(new Parameter("onOrBefore", "On Or Before", Date.class));
      diag2.addParameter(new Parameter("locationList", "Visit Location", Location.class, List.class, null));
      diag2.setOperator(SetComparator.IN);
      diag2.setQuestion(question2);
      diag2.setValueList(Arrays.asList(malariaDiagnosisConcept));
      
      CompositionCohortDefinition compD = new CompositionCohortDefinition();
      compD.initializeFromElements(diag1, diag2);
      

      When we evaluate the CodedObsCohortDefinitions evaluations separately they produce cohorts of sizes 3 and 1 respectively. These cohorts contain different patients. But when the coded obs cohort definitions are  put together using CompositionCohortDefinition and evaluated, the result is an empty cohort. What we want is a cohort of 4 patients.

      I tracked down this bug to https://github.com/openmrs/openmrs-module-reporting/blob/46bd752150b0d23decaa9c2afe24733a7fe6df17/api/src/main/java/org/openmrs/module/reporting/query/evaluator/CompositionQueryEvaluator.java#L164

      The operator is always set to AND which even makes the else block redundant

      if (operator == BooleanOperator.AND) {
           ret = QueryUtil.intersect(ret, c);
           log.debug("AND this in to get: " + ret.getSize());
      }
       else if (operator == BooleanOperator.OR) {
           ret = QueryUtil.union(ret, c);
           log.debug("OR this in to get: " + ret.getSize());
      }
      

      Since the if will always be true.

      A proposed solution will be to add a BooleanOperator configuration property CompositionCohortDefinition. Then instead of assigning the operator to an AND like how it's currently done, we could get the operator from the passed configuration. To ensure existing implementations that already depend on the current behavior of the evaluator(that is the fact that it always performs an AND), we could have a default property for the configuration which will default to BooleanOperator.AND so that implementations that didn't provide an operator will still work as expected.

        Gliffy Diagrams

          Attachments

            Activity

              People

              Assignee:
              Unassigned
              Reporter:
              ivange94 Ivange Larry Ndumbe
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: