-
Notifications
You must be signed in to change notification settings - Fork 24
QA Much Ado About Nothing
What differs between the CQL concepts of "false" and "null" and "{}"?
CQL provides a number of ways to say "no" that may look similar at first but in fact have very different meanings and have different use cases.
Consider this expression:
AgeInYearsAt(start of "Measurement Period") >= 13
When asking a question of the form "Is X true?", such as the above expression, the result of this question is could be one of 3 things in CQL based on what we know about the patient.
If we know that the patient is 13 years or older, the result is the Boolean
value true
, meaning we are expressly asserting that this expression is true.
If we know that the patient is 12 years or younger, the result is the Boolean
value false
, meaning we are expressly denying that this expression is true.
If the patient record doesn't include their date of birth, the result
is null
, meaning we are expressly saying we don't know if this
expression is true or false.
Consider this expression:
["Encounter, Performed": "Inpatient Encounter Codes"] Encounter
where Encounter.relevantPeriod during "Measurement Period"
When asking a question of the form "Please give me a list of all the X.",
such as the above expression, the result of the expression would be a List
where each element of the List is, in this case, an "Encounter, Performed".
But that also leaves open the possibility that there are no X, in this case
that the patient had no relevant encounters. In that case, the resulting
List would be the empty list, which is spelled {}
, meaning we are
expressly saying that we have a list of no items to give you.
If we want to test that an expression X yields "false", we can say either of these:
not X
X = false
Or conversely, to test that an expression X yields "true", we can say either of these:
X
X = true
If we want to test that an expression X yields "null", we can say this:
X is null
Or conversely, to test that an expression X yields anything besides "null", we can say this:
X is not null
Note that you can't test for null using "=" because CQL uses 3-valued logic, so "X = null" will not result in "true" but rather in "null".
If we want to test that an expression X yields an empty List "{}", we can say this:
not exists(X)
Or conversely, to test that an expression X yields a List of at least one element, we can say this:
exists(X)
Note that this last example is also true even if any of the List elements of X are "false" or "null" or a List with no elements "{}".
Authoring Patterns - QICore v4.1.1
Authoring Patterns - QICore v5.0.0
Authoring Patterns - QICore v6.0.0
Cooking with CQL Q&A All Categories
Additional Q&A Examples
Developers Introduction to CQL
Specifying Population Criteria