QA Multiple Diagnoses and Multiple Value Sets - cqframework/CQL-Formatting-and-Usage-Wiki GitHub Wiki

Questions and Answers


Q&A - Multiple Diagnoses and Multiple Value Sets

Question

I made Encounter changes from .diagnosis to .diagnoses in the measure logic but I am having a problem. There are two values sets in the same definition which is probably causing the problem. I tried different codes but noting seem to resolve the MAT error.

Here is the definition that needs to be re-worked:

  distinct(
    (
      "Inpatient-Encounter" Encounter
        where Encounter.diagnoses in "Single Live Birth"
          or Encounter.diagnoses in "Single Live Born Newborn Born in Hospital"
    )
    union
    (
      "Inpatient-Encounter" Encounter
        with "Single-Live-Birth-Diagnosis" D
          such that D.prevalencePeriod starts during Encounter.relevantPeriod
    )
  )

Answer

Because there may be multiple diagnoses on a single Encounter, we need to use an "exists" to test whether any diagnosis is in the value set. For example:

  define "Current Diagnosis Atrial FibrillationFlutter": 
    "Encounter with Principle Diagnosis of Ischemic Stroke" NonElectiveEncounter
      where exists (NonElectiveEncounter.diagnoses D where D in "Atrial Fibrillation/Flutter")

Here's a rewritten "Single-Live-Birth-Encounter":

  define "Single-Live-Birth-Encounter":
    (
      "Inpatient-Encounter" Encounter
        where exists (
            Encounter.diagnoses Diagnosis 
              where Diagnosis in "Single Live Birth"
                or Diagnosis in "Single Live Born Newborn Born in Hospital"
          )
    )
    union
    (
      "Inpatient-Encounter" Encounter
        with "Single-Live-Birth-Diagnosis" D
          such that D.prevalencePeriod starts during Encounter.relevantPeriod
    )

Note that in CQL 1.2, you no longer need to use "distinct" on the result of a union, the union operator now eliminates duplicates.