FHIR Chat · Finding patients based on observations in time proximity · cql

Stream: cql

Topic: Finding patients based on observations in time proximity


view this post on Zulip Lloyd McKenzie (Jan 08 2020 at 18:08):

I have a client who wanted to know how to query for data like this: "Find me all patients who had observations with glucose > 150 mg/dL(UCUM) and and Hemoblogin < 10 mg/dK (UCUM) on the same day"

"on the same day" could be "has the same data" or could be "within 24 hours" - whichever is easier. I'm pretty sure we can't do that with REST, _query or graphql. So CQL, you're my only hope! :)

Is it possible to write a query that would do that? (@Bryn Rhodes )

view this post on Zulip Chris Moesel (Jan 08 2020 at 18:34):

Hi @Lloyd McKenzie -- I have to run to a meeting, but here is an example I wrote up showing one approach to using CQL to find patients that meet certain criteria. The criteria is defined in the Patient context in terms of a specific patient and then the Population context (now Unfiltered context in CQL 1.4) aggregates it at a population level. It obviously doesn't align with your specific query, but maybe it is still helpful as a start: https://github.com/cqframework/cql-exec-examples/blob/master/patient-finder/r4/cql/PatientFinderExample.cql

view this post on Zulip Lloyd McKenzie (Jan 08 2020 at 18:37):

The question isn't really about how to find patients based on criteria (that I can do). It's more about how to express a criterion that is the presence of two Observations of different types with a maximum time gap between them. That's more advanced than I know how to do. (And could possibly be more advanced than what CQL is capable of doing.) Understand folks are busy today at the connectathon, but wanted to raise it before I forgot to.

view this post on Zulip Chris Moesel (Jan 08 2020 at 20:03):

(deleted)

view this post on Zulip Chris Moesel (Jan 08 2020 at 20:04):

I can't test or compile this right now, but I think you basically want this?

define "HasSameDayTestCriteria":
  exists (
    [Observation: "Glucose Test"] G
    with [Observation: "Hemoglobin Test"] H
    such that
      (G.value as Quantity) > 150 'mg/dL'
      and (H.value as Quantity) < 10 'mg/dK'
      and G.issued.value same day as H.issued.value
  )

view this post on Zulip Chris Moesel (Jan 08 2020 at 20:05):

That assumes you've set up value sets for the observations and that you want it based on issued -- but it would be trivial to do it based on effectiveDateTime instead (although it involves more casts since those are choices).

view this post on Zulip Chris Moesel (Jan 08 2020 at 20:08):

OK, it does compile at least. That one is using same day as, which is looking for them to be on the same calendar day. But if you want them within 24 hours instead, then you can replace same day as with within 24 hours of.

view this post on Zulip Lloyd McKenzie (Jan 08 2020 at 23:53):

effectiveDateTime would be better. But the fact that it's at least theoretically possible is great. Thanks Chris!

view this post on Zulip Chris Moesel (Jan 09 2020 at 01:20):

Didn't compile it, but I think you're basically looking at something like this then:

define "HasSameDayTestCriteria":
  exists (
    [Observation: "Glucose Test"] G
    with [Observation: "Hemoglobin Test"] H
    such that
      (G.value as Quantity) > 150 'mg/dL'
      and (H.value as Quantity) < 10 'mg/dK'
      and (G.effective as DateTime) same day as (H.effective as DateTime)
  )

Last updated: Apr 12 2022 at 19:14 UTC