FHIR Chat · Counting Specimen using Patient Criteria · cql

Stream: cql

Topic: Counting Specimen using Patient Criteria


view this post on Zulip Alexander Kiel (Sep 16 2019 at 15:27):

I need to count the number of Specimen were there subjects have a BMI > 30 km/m2. The query I came up with is the following:

library Retrieve
using FHIR version '4.0.0'
include FHIRHelpers version '4.0.0'

codesystem loinc: 'http://loinc.org'

context Specimen

define Patient:
  singleton from ([Patient])

define InInitialPopulation:
  exists(
    from [Patient -> Observation: Code '39156-5' from loinc] O
    where (O.value as Quantity) > 30 'kg/m2')

I know that there is currently no official Specimen context but I have a ModelInfo in place which allows be to specify one. Both expressions, Patient and InInitialPopulation are in the Specimen context and I use $evaluate-measure with subject Specimen to count all Specimen which qualify through InInitialPopulation. The Observation retrieve expression however is in the context of the single Patient defined above. I took the idea from the Mother example in Related Context Retrieves.

cql-to-elm translates the CQL without a problem. @Bryn Rhodes I would just ask if that is supposed to work the way I think, before implementing it in my CQL evaluation engine?

view this post on Zulip Bryn Rhodes (Sep 26 2019 at 16:19):

Apologies for the delay here. I don't think you need to use a Related Context Retrieve, since you are not reaching in to another "specimen's" data, you are only saying "Give me all specimens where the patient has had a BMi observation > 30 kg/m2". So I think you can just do this:

view this post on Zulip Bryn Rhodes (Sep 26 2019 at 16:19):

library Retrieve
using FHIR version '4.0.0'
include FHIRHelpers version '4.0.0'

codesystem loinc: 'http://loinc.org'

code bmi: '39165-5' from loinc

context Specimen

define InitialPopulation:
  exists (
        [Patient] P
          with [Observation: code in bmi] O such that EndsWith(O.subject.reference, P.id)
                and O.value > 30 'kg/m2'
    )

view this post on Zulip Bryn Rhodes (Sep 26 2019 at 16:19):

I can't translate that because I don't have a Specimen context defined, but if you do in your model info, that ought to work.

view this post on Zulip Alexander Kiel (Sep 26 2019 at 16:32):

Thanks for your answer. I‘ll try to translate later. I have one question: is the Observation retrieve expression supposed to run in the unspecified context? Because in the Specimen context, I have no link to Observations and if I had, that wouldn’t be the Observations of the Patient.

view this post on Zulip Bryn Rhodes (Sep 27 2019 at 13:20):

In the specimen context, it would be observations for the specimen.

view this post on Zulip Bryn Rhodes (Sep 27 2019 at 13:33):

Using the related context retrieve in the way that you have above is an interesting use case, and I can see other potential uses for that approach. So yes, the original use of related context retrieve should work as well, just using a different reference from the Observation to do the search.

view this post on Zulip Alexander Kiel (Sep 30 2019 at 08:50):

In the specimen context, it would be observations for the specimen.

Ok that's the same I was expecting. I need the observations of the patient. So as you said already, it might be necessary to use related context here.


Last updated: Apr 12 2022 at 19:14 UTC