FHIR Chat · CQL Exercise questions · cql

Stream: cql

Topic: CQL Exercise questions


view this post on Zulip Alex Goel (Apr 13 2021 at 20:38):

@Bryn Rhodes We have a few questions about the CQL Exercises: https://github.com/cqframework/cqf-exercises

When would we use expand? Can you give an example?
Exercise 8, how does it create the tuples from 2 lists that seem like they would be the same?
○ Would this not return 0s?
Exercise 10: What does context do? Why is the context Patient? The context for Patient does not seem to matter for this group of Observations. Is this how the CQL kind of views the data e.g. from a Patient-centric perspective?

view this post on Zulip Joel Francis (Apr 16 2021 at 14:04):

@Bryn Rhodes kind of struggling with the same questions from the exercise. Any help or guidance is appreciated please and thanks

view this post on Zulip Bryn Rhodes (Apr 16 2021 at 15:28):

One of the most useful examples for expand (the use case it was introduced to support specifically) is as part of determining average daily dose. Part of that calculation involves calculating the days in an interval:

expand { Interval[@2010-01-01, @2010-01-31] } per day

This returns a list of intervals, one for each day in the input period, which we then use to aggregate the daily dose for medications with an active prescription on that day.

view this post on Zulip Bryn Rhodes (Apr 16 2021 at 15:33):

In Exercise 8, looking at the result of just the multi-source query with no restrictions might help:

define "Quantitative Laboratory Result Pairs":
  from
    "Quantitative Laboratory Results" O1,
    "Quantitative Laboratory Results" O2

view this post on Zulip Bryn Rhodes (Apr 16 2021 at 15:34):

This returns all pairs of Quantitative Laboratory Results:

Quantitative Laboratory Result Pairs=[Tuple {
    "O1": org.hl7.fhir.r4.model.Observation@e4871af7
    "O2": org.hl7.fhir.r4.model.Observation@e4871af7
}, Tuple {
    "O1": org.hl7.fhir.r4.model.Observation@e4871af7
    "O2": org.hl7.fhir.r4.model.Observation@251765e9
}, Tuple {
    "O1": org.hl7.fhir.r4.model.Observation@e4871af7
    "O2": org.hl7.fhir.r4.model.Observation@de86d67e
}, Tuple {
    "O1": org.hl7.fhir.r4.model.Observation@e4871af7
    "O2": org.hl7.fhir.r4.model.Observation@66ce16b1
}, Tuple {
... <snipped for brevity>

view this post on Zulip Bryn Rhodes (Apr 16 2021 at 15:35):

Perhaps a clearer example:

define "Input List": { 'A', 'B', 'C' }
define "Input List Pairs":
  from "Input List" X, "Input List" Y

view this post on Zulip Bryn Rhodes (Apr 16 2021 at 15:35):

Input List=[A, B, C]
Input List Pairs=[Tuple {
    "X": A
    "Y": A
}, Tuple {
    "X": A
    "Y": B
}, Tuple {
    "X": A
    "Y": C
}, Tuple {
    "X": B
    "Y": A
}, Tuple {
    "X": B
    "Y": B
}, Tuple {
    "X": B
    "Y": C
}, Tuple {
    "X": C
    "Y": A
}, Tuple {
    "X": C
    "Y": B
}, Tuple {
    "X": C
    "Y": C
}]

view this post on Zulip Bryn Rhodes (Apr 16 2021 at 15:40):

On the question of context, CQL allows the model to specify a context, which you can think of as a "default filter" with respect to a particular context. Patient is the most common context, but models can define any number of them. In FHIR specifically, this corresponds roughly to the notion of a "compartment", and the FHIR model info includes context definitions for each compartment definition in the FHIR specification.

view this post on Zulip Bryn Rhodes (Apr 16 2021 at 15:45):

There's an explanation of the impact of context in the Retrieve Context topic of the Author's Guide.

view this post on Zulip Bryn Rhodes (Apr 16 2021 at 15:46):

Does that help?

view this post on Zulip Bryn Rhodes (Apr 16 2021 at 15:46):

(And apologies for the delays in getting back to this) @Joel Francis @Alex Goel

view this post on Zulip Alex Goel (Apr 16 2021 at 16:02):

define "Quantitative Laboratory Result Pairs":
  from
    "Quantitative Laboratory Results" O1,
    "Quantitative Laboratory Results" O2

@Bryn Rhodes No worries on the delay! I'm not clear on why this returns what the lists. In reading these functions it seems like these would be the same list and you're subtracting 1 from 1. How does the CQL know that it should iterate through these lists to produce the pairs?

view this post on Zulip Bryn Rhodes (Apr 16 2021 at 16:14):

The "from" clause is setting up the sources for a query. The Quantitative Laboratory Results expression returns a list of lab results, so this is saying, "from Quantitative Laboratory Results with the name O1 and Quantitative Laboratory Results as the name O2, perform the following query". The definition of a multi-source query starts with the set of all possible combinations of the input sources (also known as cartesian product of sets).

view this post on Zulip Bryn Rhodes (Apr 16 2021 at 16:16):

If you're familiar with SQL, it's the same as saying:

select *
  from "Quantitative Laboratory Results" O1, "Quantitative Laboratory Results" O2

Or in join syntax:

select *
  from "Quantitative Laboratory Results" O1 cross join "Quantitative Laboratory Results" O2

view this post on Zulip Bryn Rhodes (Apr 16 2021 at 16:18):

The Multi-source queries topic has more discussion as well.


Last updated: Apr 12 2022 at 19:14 UTC