FHIR Chat · CQF Ruler - /$cql · cql

Stream: cql

Topic: CQF Ruler - /$cql


view this post on Zulip Joel Montavon (Mar 28 2022 at 22:34):

I am trying to execute CQL using the CQF Ruler and the Swagger UI. The response that I am getting back is not what I am expecting.

I am successfully posting to /$cql:
curl -X 'POST' \
'http://localhost:8080/fhir/$cql' \
-H 'accept: application/fhir+json' \
-H 'Content-Type: application/fhir+json' \
-d '{"resourceType":"Parameters","parameter":[{"name":"code","valueString":"define \"Inequality Expression\":\n 4 != 5"}]}'

The response status is 200 and the headers look good:
connection: keep-alive
content-encoding: gzip
content-type: application/fhir+json;charset=UTF-8
date: Mon,28 Mar 2022 22:06:21 GMT
keep-alive: timeout=60
transfer-encoding: chunked
x-powered-by: HAPI FHIR 5.5.3 REST Server (FHIR Server; FHIR 4.0.1/R4)
x-request-id: Fw0yTyFbFncZIipZ

But, I am getting a response body that looks like this:
{
"resourceType": "Parameters",
"parameter": [
{
"name": "value",
"valueString": "null"
},
{
"name": "resultType",
"valueString": "Null"
}
]
}

How do I get the result of the executed CQL? Any help would be greatly appreciated!

view this post on Zulip Bryn Rhodes (Mar 28 2022 at 23:54):

Hi @Joel Montavon , the $cql operation lets you evaluate expressions of CQL, but the text you're providing is actually a declaration statement: define InequalityExpression: 4 != 5. The expression is just 4 != 5. Also, the parameter is named expression, but it looks like you have code as the parameter name?

view this post on Zulip Bryn Rhodes (Mar 28 2022 at 23:55):

It's definitely not a very helpful response, you really should be getting an error message about not providing the expected expression parameter.

view this post on Zulip Joel Montavon (Mar 29 2022 at 15:23):

Thanks! I missed that.

I'm not a JAVA programmer and looking for a way to evaluate CQL code on the fly for a node.js program. The cql_execution_service is basically what I am looking for but has not been recently updated. Is the cql_execution_service not being maintained and the cqf-ruler is preferred going forward? I've also tried using the CQL-to-ELM translator to convert the CQL to ELM as JSON and then using cql-execution to evaluate. However, this requires writing the CQL and ELM to disk and is slow. I haven't tried this yet but, instead of using $cql, it looks like I could load the CQL code as a library or measure and $evaluate or $evaluate-measure. What is the best way to execute CQL on the fly?

view this post on Zulip David Winters (Mar 29 2022 at 16:41):

You could take a look at cql-worker, but this requires you to pre-translate your CQL to ELM since it uses the cql-execution-engine. It can work either in the browser or node.

view this post on Zulip Bryn Rhodes (Mar 30 2022 at 22:58):

Yes, the cql_execution_service hasn't been updated in a while, we've been focused on CQF Ruler support, which does have a $cql implementation, so that's been our preferred approach for ad-hoc execution.

view this post on Zulip Joel Montavon (Apr 01 2022 at 04:12):

Thanks for the responses! Are there any examples showing what the request body should look like for creating a library or measure in the cqf-ruler (i.e., POST /library or POST /measure)? For example, if I wanted to create a library with a single definition like define InequalityExpression: 4 != 5. I can't seem to figure it out from the Swagger-UI documentation or from the CQF recommendations.

view this post on Zulip Andy Stevens (Apr 01 2022 at 13:18):

For putting CQL in a Library resource, you would just need to base64 encode your CQL and place it in Library.content.data, as well as include a Library.status (as per FHIR spec), as well as setting Library.content.contentType as text/cql (don't know if this is required to evaluate CQL, but we use it to differentiate Libraries and its what example Libraries have looked like). For example, here's the FHIR Helpers Library in JSON: https://www.hl7.org/fhir/library-fhir-helpers.json.html

view this post on Zulip Corey Sanders (Apr 01 2022 at 13:36):

To be clear, you don't need to put your CQL into a library resource to be able to execute it via the $cql operation in cqf-ruler. You certainly can and should if you have CQL that you are going to be executing repeatedly, but you also just pass in ad-hoc CQL and execute it without storing the code in a Library.

curl --silent -k -X 'POST' \
'https://cloud.alphora.com/sandbox/r4/cqm/fhir/$cql' \
-H 'accept: application/fhir+json' \
-H 'Content-Type: application/fhir+json' \
-d '{"resourceType":"Parameters","parameter":[{"name":"expression","valueString":"4 != 5"}]}'
{
  "resourceType": "Parameters",
  "parameter": [ {
    "name": "value",
    "valueString": "true"
  }, {
    "name": "resultType",
    "valueString": "Boolean"
  } ]
}

Last updated: Apr 12 2022 at 19:14 UTC