FHIR Chat · querying Coverage class · cql

Stream: cql

Topic: querying Coverage class


view this post on Zulip Vasyl Herman (Jul 05 2021 at 12:15):

Hello! Could you please help me?
Is there a way to filter a list of Coverage by class type?

define "Plan":
    [Coverage] C
      where C.class.type ~ Code {code:'plan', system:'http://terminology.hl7.org/CodeSystem/coverage-class'}

view this post on Zulip Vasyl Herman (Jul 05 2021 at 14:59):

My goal is accessing Coverage.class[type ~ plan].value which is 'MOS':

    {
      "resource": {
        "resourceType": "Coverage",
        "id": "4bfdaffa-d11a-4e07-bbe1-521a9b44cc41",
        "beneficiary": {
          "reference": "Patient/95007"
        },

        "payor": [
          {
            "reference": "Organization/vf-soft"
          }
        ],
        "type": {
          "coding": [
            {
              "system": "http://terminology.hl7.org/ValueSet/v3-ActCoverageTypeCode",
              "code": "RETIRE"
            }
          ]
        },
        "period": {
          "start": "1954-01-13T00:00:00.000+00:00",
          "end": "2019-01-20T23:59:59.999+00:00"
        },
        "class": [
          {
            "type": {
              "coding": [
                {
                  "system": "http://terminology.hl7.org/CodeSystem/coverage-class",
                  "code": "plan"
                }
              ]
            },
            "value": "MOS"
          }
        ]
      }
    }

I am using the following cql code.

Screenshot-2021-07-05-at-18.03.39.png

define "Plan":
    Last ([Coverage] C
      where C.class.type ~ Code {code:'plan', system:'http://terminology.hl7.org/CodeSystem/coverage-class'}
      and FHIRBase."Normalize Interval"( C.period ) starts before end of "Measurement Period"
        return Tuple {id: C, plan: C.class[0].value.value}
        sort by end of id.period).plan

It looks like an error but it's working Could not resolve call to operator Equivalent with signature (list<FHIR.CodeableConcept>,System.Code).
Could you please correct a beginner if is wrong?
Thank you in advance.

view this post on Zulip JP (Jul 08 2021 at 00:04):

The class element of Coverage is itself a list so you need to do the comparion on the list elements. A sub-query something like this should do the trick:

  define "Plan":
      Last ([Coverage] C
        where exists (C.class Class where Class.type ~ Code {code:'plan', system:'http://terminology.hl7.org/CodeSystem/coverage-class'})
        and FHIRBase."Normalize Interval"( C.period ) starts before end of "Measurement Period"
          return Tuple {id: C, plan: C.class[0].value.value}
          sort by end of id.period).plan

view this post on Zulip Vasyl Herman (Jul 08 2021 at 08:55):

You are Amazing!

What about return Tuple {id: C, plan: C.class[0].value.value}, more specificaly C.class.[0] always returns first element, right?
What if we had a list of multiple items in C.class? I mean there is no guarantee that plan is going to be always the first one. I'd like to reach out its value which is MOS.
Thanks!

view this post on Zulip Vasyl Herman (Jul 08 2021 at 08:59):

for instance:

"class": [
          {
            "type": {
              "coding": [
                {
                  "system": "http://terminology.hl7.org/CodeSystem/coverage-class",
                  "code": "something-else"
                }
              ]
            },
            "value": "TEST"
          },
          {
            "type": {
              "coding": [
                {
                  "system": "http://terminology.hl7.org/CodeSystem/coverage-class",
                  "code": "plan"
                }
              ]
            },
            "value": "MOS"
          }
        ]

view this post on Zulip JP (Jul 08 2021 at 16:01):

How about this (I removed the normalize logic and replaced it with true to make the structure of the query more obvious):

      [Coverage] C
        let plan : First(C.class Class where Class.type ~ Code {code:'plan', system:'http://terminology.hl7.org/CodeSystem/coverage-class'})
        where true and plan is not null
        return Tuple {id: C, plan: plan.value.value}
        sort by end of id.period

Last updated: Apr 12 2022 at 19:14 UTC