FHIR Chat · Pointing CQL to Structure Definitions for Extensions · cql

Stream: cql

Topic: Pointing CQL to Structure Definitions for Extensions


view this post on Zulip Joe Amlung (Apr 06 2021 at 11:40):

Hi all, I'm new to the chat but just getting started with CQL and could use a little help. I'm working with a basic custom FHIR IG that I generated for this work. I am wondering how I can incorporate the Extension Definitions that I made into the CQL language that I started. How can I point my CQL to pull from a particular Structure Definition (e.g. estimatedAge in the linked CQL above)?

view this post on Zulip Bryn Rhodes (Apr 06 2021 at 13:43):

There is in-progress tooling here to generate ModelInfo from structure definitions. Once the ModelInfo is generated, it can be referenced from your CQL with a using declaration. The ModelInfo will have first-class elements for extensions and slices defined in the profiles.

view this post on Zulip Bryn Rhodes (Apr 06 2021 at 13:48):

In lieu of that, you can access extensions directly in the CQL using functions like this:

/*
@description: Returns any US Core extensions defined on the given resource with the specified id.
@comment: NOTE: Extensions are not the preferred approach, but are used as a way to access
content that is defined by extensions but not yet surfaced in the CQL model info.
*/
define function USExtensions(domainResource DomainResource, id String):
  domainResource.extension E
      where E.url = ('http://hl7.org/fhir/us/core/StructureDefinition/' + id)
        return E

/*
@description: Returns the single US Core extension (if present) on the given resource with the specified id.
@comment: This function uses singleton from to ensure that a run-time exception is thrown if there
is more than one extension on the given resource with the specified url.
*/
define function USExtension(domainResource DomainResource, id String):
  singleton from USExtensions(domainResource, id)

view this post on Zulip Bryn Rhodes (Apr 06 2021 at 13:49):

You could also follow that same pattern and write functions to expose specific extensions.

view this post on Zulip Joe Amlung (Apr 07 2021 at 17:37):

Thanks @Bryn Rhodes ! Are there any CQL examples that use these functions in the code you pasted? I think this method should work, but an example should help me get the syntax right.

view this post on Zulip Joe Amlung (Apr 07 2021 at 18:48):

Actually, @Richard Stanley pointed me to a CQF Exercise that helped me: https://github.com/cqframework/cqf-exercises/blob/master/input/cql/Exercises09Key.cql


Last updated: Apr 12 2022 at 19:14 UTC