FHIR Chat · FHIR CQL Operation · cql

Stream: cql

Topic: FHIR CQL Operation


view this post on Zulip Alexander Kiel (Jun 17 2019 at 16:27):

I currently try to model a OperationDefinition for CQL like the existing $graphql one (https://www.hl7.org/fhir/graphql.html).

The operation should allow arbitrary CQL queries either system wide [base]/$cql or at instance level of a single Patient [base]/Patient/[id]/$cql. The system wide queries would require to use the Unspecified context, while the Patient instance level queries would use the Patient context.

I struggle a bit with the output parameter(s). I could use Binary like $graphql is doing. But then CQL is lacking specification how to represent results (or I miss this). On the other hand, I don't see how I can use Bundle like in searches, because CQL can return non-resources as results and it returns more like a dictionary of ExpressionDef names to results rather than a single list of results.

So how could a generic $cql operation look like?

view this post on Zulip Chris Moesel (Jun 17 2019 at 18:30):

This would be a very cool capability to have, but as you've pointed out, not without its own challenges. For one, as you noted, CQL doesn't define a "result format" of any kind, although I think one could make some assumptions to arrive at a reasonable JSON format:

  • top-level keys are expression names
  • lists are arrays, tuples are objects
  • datetime / date / time use CQL-defined toString representation
  • interval, code, concept are objects w/ keys matching terms used in spec to define their components

One open question would be if the responses contain FHIR resource instances, should the JSON format be valid FHIR JSON? I think so, but that means it is not a strict tuple representation of the FHIR modelinfo used by CQL (which represents primitives as complex types).

view this post on Zulip Chris Moesel (Jun 17 2019 at 18:32):

The other challenge is, of course, what FHIR resource type to actually use to return this data. I think maybe the most flexible approach is to simply represent the JSON-formatted result object as a FHIR Attachment w/ application/json mimetype. If you don't want to return an Attachment directly, but prefer an actual Resource, then DocumentReference might fit the bill.

view this post on Zulip Grahame Grieve (Jun 17 2019 at 18:34):

just use Binary and say it's application/json and where it contains actual resources, make this clear in the format of the json

view this post on Zulip Grahame Grieve (Jun 17 2019 at 18:34):

.. so like graphql

view this post on Zulip Chris Moesel (Jun 17 2019 at 18:38):

I was also thinking Parameters might be an interesting choice. It would allow each expression result to be its own parameter with a name -- and you could use value[x]or resource to hold the value (depending on the value type), and falling back to valueAttachmentfor non-typed tuples.

view this post on Zulip Chris Moesel (Jun 17 2019 at 18:38):

Or you could just do what Grahame said, which sounds much easier. ;-)

view this post on Zulip Bryn Rhodes (Jun 17 2019 at 19:34):

We have a $cql operation implemented in the CQF Ruler, we took a sort of hybrid approach that returns the results as a Parameters resource, but with the value of each result as a JSON string.

view this post on Zulip Alexander Kiel (Jun 18 2019 at 16:01):

Thanks for all your answers. I thought a bit more about our use case for which we like to use CQL. I found Quality Reporting and it seems to fit your use case very well.

What are we trying to do?

We like to count the number of Patients which qualify for a particular research project a researcher has in mind. So it's like finding Patients for a study. In the first iteration, we only need the counts and not the list of Patients. Both counts and the actual list seems to be possible with Quality Reporting.

With Quality Reporting, there is already the Measure resource, the $evaluate-measure operation and the MeasureReport.

In my opinion using such a domain specific way of doing things should be more suitable than providing a generic CQL operation. Especially because for a generic CQL operation, the response format is not specified.

view this post on Zulip Alexander Kiel (Jun 18 2019 at 17:12):

One additional consideration: Our Measures will be created ad-hoc by researchers and the results (MeasureReport) should be available in minutes. So I would create one Measure resource per ad-hoc query. It is also common that a Measure will be evaluated only once. You can see a first prototype of the search interface here: https://search.germanbiobanknode.de

view this post on Zulip Bryn Rhodes (Jun 18 2019 at 17:56):

Hi @Alexander Kiel , yes, a cohort measure is a good fit for this. I just tried the prototype, that looks great!

view this post on Zulip Michael Riley (Jun 19 2019 at 19:44):

GTRI chiming in. We're consdering MeasureReport as well as a possible workflow for using CQL with FHIR. It's matches to the workflow we want, which is "run this measure and tell me it's output".

This is all too confusing though when you consider we have the FHIR data provider library, where FHIR just acts as the retrieval source. https://github.com/DBCG/cql_engine/tree/master/cql-engine-fhir

It doesn't make a ton of sense to use a FHIR REST call to call a FHIR independent process and return FHIR-adjacent outputs. At that point, why even use FHIR? We should consider making a different domain if that's the case, or we should ensure that we're using FHIR as a data provider when using CQL in this manner.

view this post on Zulip Alexander Kiel (Jun 20 2019 at 14:54):

@Michael Riley We currently work on a FHIR Server with integrated CQL engine. It'll support the $evaluate-measure operation for simple use-cases soon. https://github.com/life-research/blaze Please tell me if it's an option to use our server and what do you need exactly from Measure.

view this post on Zulip Bryn Rhodes (Jun 20 2019 at 19:29):

@Michael Riley and @Alexander Kiel , we've added a Community Projects page to the translator wiki. If you're willing, please feel free to add your project there, or let me know and I'm happy to add it.

view this post on Zulip Alexander Kiel (Jun 21 2019 at 09:00):

@Bryn Rhodes Thanks for pointing me at that page. I added Blaze. Please feel free to move it into another category.

view this post on Zulip Michael Riley (Jun 24 2019 at 15:49):

@Alexander Kiel Re: using measure, $evaluate-measure, and MeasureReport, we've been a little stuck as the CQL results don't really fit up with what a MeasureReport is giving back.

Right now, we're just using the library resource to hold CQL as an attachment hosted on a seperate service. So we can code the existence of the CQL into our system as a measure referencing that library.

I've been thinking about doing a little bit of CQL result-key hacking: MeasureReport primarily reports back populations, and stratum. I could match up result key names like "Stratum.at-risk.score" or "Population.numerator.count" to the various featuers in the MeasureReport.

Also, it would be helpful if (during a patient context run) all resources retreived during the CQL run were attached as a bundle in the MeasureReport in the "evaluatedResources" field. It might be too much to ask for a population context, that bundle might have 1000s of resources and you'd have to hold them in the server somewhere for reference.

At the very least, having the library exist within the fhir server means that we can maintain the CQL with fhir, even if we don't evaluate against it.

view this post on Zulip Alexander Kiel (Jun 24 2019 at 15:56):

@Michael Riley Do you currently use a server which supports $evaluate-measure? If yes, which one?

view this post on Zulip Michael Riley (Jun 24 2019 at 15:58):

@Alexander Kiel no sorry, this is all just design we're doing right now.

The server we use is our GT-FHIR implementation you can find here. Uses core java JPA persistence and we use a postgresql OMOP db backend. https://github.com/gt-health/GT-FHIR

view this post on Zulip Alexander Kiel (Jun 24 2019 at 16:03):

What di you mean with?

[...] the CQL results don't really fit up with what a MeasureReport is giving back.

view this post on Zulip Michael Riley (Jun 24 2019 at 21:08):

When you run $evaluate-measure, the FHIR spec say that you must respond back with an out parameter of MeasureReport https://www.hl7.org/fhir/stu3/measurereport.html This measure report has a lot of limitations. It's expecting a list of populations, and a list of stratum as being the major data elements a measure is creating. A fine assumption for measures, but CQL can just create results from anything, and they don't all have to be population based.

view this post on Zulip Bryn Rhodes (Jun 25 2019 at 04:21):

Also, it would be helpful if (during a patient context run) all resources retreived during the CQL run were attached as a bundle in the MeasureReport in the "evaluatedResources" field. It might be too much to ask for a population context, that bundle might have 1000s of resources and you'd have to hold them in the server somewhere for reference.

This is the intent of the evaluatedResources element, it should be a reference to a Bundle containing any resources that were used in evaluating the CQL, but only for subject-level reports. The CQF Ruler implementation does this now by keeping a hashtable in the engine of resources that come back from the data access layer and surfacing that to the measure evaluation, which builds the bundle out of it.

view this post on Zulip Alexander Kiel (Jun 25 2019 at 06:32):

This measure report has a lot of limitations. It's expecting a list of populations, and a list of stratum as being the major data elements a measure is creating. A fine assumption for measures, but CQL can just create results from anything, and they don't all have to be population based.

That is right, $evaluate-measure isn't a generic CQL evaluation operation. But also, Measure is already opinionated what to query. So MeasureReport is a perfect fit for that you can ask with Measure. In this thread, I started thinking about a generic $cql operation (like $graphql). Do you have use case for this?

view this post on Zulip Surya (Jul 12 2019 at 13:26):

hello,
I have gone through the AHRQ project(https://cds.ahrq.gov/authoring/build) . I got some doubt , can we generate cql file for MeasureReport by using this tool or this tool has only generated cql for cds-hooks i.e. for PlanDefinition ??If yes then can we have any open-source tools that can generates measure-report related cql file.
Thank you in Advance.

view this post on Zulip Saoji Adhe (Oct 24 2019 at 11:30):

Hi @Alexander Kiel ,
i want to test cqf-ruler-0.1.13-SNAPSHOT.jar with hapi-fhir-3.8 , to test $evaluate-measure
but it's not working with example given by hspc in there documentation
anybody know about where i will get example related to $evaluate-measure, $apply, cds-hooks etc...
Thank you in advance.

view this post on Zulip Alexander Kiel (Oct 24 2019 at 14:06):

@Saoji Adhe Please see my other post.


Last updated: Apr 12 2022 at 19:14 UTC