FHIR Chat · Generate a FHIR bundle · cql

Stream: cql

Topic: Generate a FHIR bundle


view this post on Zulip Matt Pfeffer (Mar 14 2020 at 00:23):

Has anyone written a CQL pattern for generating a FHIR bundle that you can share?

view this post on Zulip Bryn Rhodes (Mar 16 2020 at 23:26):

So, since the FHIR 4.0.0 model info was generated from the XSD FHIR schema, it actually uses the "ResourceContainer" type whereever a "Resource" appears inline in the spec. So that means you need to process each type independently, and it ends up being a bit... verbose:

define function Bundle(Resources List<Resource>):
  Bundle {
    entry:
      Resources R
        return FHIR.Bundle.Entry {
          resource: ResourceContainer(R)
        }
  }

define function ResourceContainer(Resource Resource):
  ResourceContainer {
    AdverseEvent: Resource as AdverseEvent,
    AllergyIntolerance: Resource as AllergyIntolerance,
    Appointment: Resource as Appointment,
    ...
  }

In the soon to be published 4.0.1 modelinfo, you can actually just say:

define function Bundle(Resources List<Resource>):
  Bundle {
    entry:
      Resources R
        return FHIR.Bundle.Entry {
          resource: R
        }
  }

@Chris Moesel, this turns out to be at least one concrete difference between the 4.0.0 and 4.0.1 model infos, directly resulting from the different toolchains used to create them.

view this post on Zulip Chris Moesel (Mar 17 2020 at 12:23):

Thanks for the heads up, @Bryn Rhodes. Now we know that the CQL FHIR 4.0.0 model is not compatible w/ the CQL FHIR 4.0.1 model -- so runtimes will need to support them independently (i.e., you can't use a FHIR 4.0.0 model provider w/ a FHIR 4.0.1 CQL library). That's definitely a good thing to know! And... it looks like the difference is an improvement, so that's good to see!

view this post on Zulip Matt Pfeffer (Mar 18 2020 at 18:39):

@Bryn Rhodes Thank you!

view this post on Zulip Mohammad Afaq Khan (Mar 19 2020 at 02:12):

@Bryn Rhodes Thanks for explaining!

view this post on Zulip Matt Pfeffer (Mar 20 2020 at 05:33):

@Bryn Rhodes Is there any way to do this in FHIR 3, as well?

view this post on Zulip Bryn Rhodes (Mar 20 2020 at 20:21):

Yes, the same pattern should work, FHIR '3.0.0' has a ResourceContainer, but FHIR '3.0.1' does not.

view this post on Zulip Alex Goel (Jul 09 2021 at 13:18):

We've been using the CQF-Tooling to generate FHIR bundles from CQL files (PlanDefinition, Library, ValueSets), but we were wondering where in the CQF-Tooling code we could find the function that generates the PlanDefinition. It seems like one is generated when we run the refresh script in an IG, but we want to try to do this outside of an IG. Can someone point us at the right file or set of files in the CQF-Tooling? https://github.com/cqframework/cqf-tooling @Paul Puscas

view this post on Zulip Rob Reynolds (Jul 11 2021 at 14:48):

@Alex Goel

Each resource type that gets refreshed has a FHIR specific Refresh Operation that defaults to the location of the respective resources in an IG, like this: https://github.com/cqframework/cqf-tooling/blob/a45090374b140e01cbf96143a92279da48b7cc72/src/main/java/org/opencds/cqf/tooling/measure/r4/RefreshR4MeasureOperation.java#L26.

But I believe for each Resource you can override the default path with a command line argument, like this: https://github.com/cqframework/cqf-tooling/blob/a45090374b140e01cbf96143a92279da48b7cc72/src/main/java/org/opencds/cqf/tooling/operation/RefreshGeneratedContentOperation.java#L48.

So I think you just need to use the arguments for your respective Resources.

view this post on Zulip Alex Goel (Jul 12 2021 at 14:07):

@Rob Reynolds Thanks Rob! I see the Measure and Library functions, but not the PlanDefinition functions, but the refresh does both Measures and PlanDefinitions? We think it's this: https://github.com/cqframework/cqf-tooling/blob/a45090374b140e01cbf96143a92279da48b7cc72/src/main/java/org/opencds/cqf/tooling/operation/RefreshIGOperation.java

view this post on Zulip Alex Goel (Jul 12 2021 at 14:09):

And this: https://github.com/cqframework/cqf-tooling/blob/a45090374b140e01cbf96143a92279da48b7cc72/src/main/java/org/opencds/cqf/tooling/processor/PlanDefinitionProcessor.java

view this post on Zulip Alex Goel (Jul 13 2021 at 14:54):

@Rob Reynolds I spoke too soon! These seem to refresh the PlanDefinitions, but is there a way to automatically build them from the CQL, like the Measures? We were expecting to find a file structure similar to Measures in the CQF-Tooling

view this post on Zulip JP (Jul 13 2021 at 19:14):

@Alex Goel - PlanDefinition is a bit more open-ended than Measure in that it can represent a wider variety of clinical logic such as arbitrary treatment workflows, cds services, etc. So whereas it's relatively straightforward to generate some types of Measure resources from CQL it's not possible to do that for PlanDefinition in a general way. When the cqf-tooling "refreshes" a PlanDefinition resource it merely fills out some meta-data based on whatever Library or CQL is referenced.

view this post on Zulip JP (Jul 13 2021 at 19:16):

IOW, it's expected that the PlanDefinition skeleton and logic would be authored "some other way" and then the tooling takes it from there to ease manual maintenance of things like relatedArtifacts.

view this post on Zulip Alex Goel (Jul 13 2021 at 19:24):

Got it! Thanks @JP

view this post on Zulip Rob Reynolds (Jul 14 2021 at 16:58):

@Alex Goel What @JP said. :laughing:


Last updated: Apr 12 2022 at 19:14 UTC