FHIR Chat · cql: errors that I do not know how to solve · cql

Stream: cql

Topic: cql: errors that I do not know how to solve


view this post on Zulip Adrien Prost (Jun 07 2021 at 15:26):

Hello, I am posting this here as I am not sure where does this kind of thread belong. I am working on converting some existing medical algorithms (which are currently in a custom format) to CQL libraries. Some of the medical algorithms have scoring systems where, in this example, the value of the respiratory rate and age of the patient yield score values and diagnostic depends on the total score. I am therefore trying to represent this with CQL functions. To do so, I have created a template code using the CDS authoring tool available at https://cds.ahrq.gov/ in which I created the Respiratory rate as a basic value and then downloaded the generated CQL. I then added 2 functions that yield scores depending on the patient age and respiratory rate. Then, I ran the CQL using the java-quickstart from https://github.com/cqframework/clinical_quality_language/blob/master/Src/java-quickstart/README.md and I got a bunch of errors (output from java-quickstart):

line 4:0 extraneous input 'codesystem' expecting {'include', 'parameter', 'valueset', 'let', 'context', 'define'}
line 8:7 no viable alternative at input 'define "Respiratory rate (observable entity)"'
line 27:35 missing ':' at 'List'
line 27:39 mismatched input '<' expecting {',', ')'}
line 36:34 missing ':' at 'Observation'
line 36:46 mismatched input ':' expecting '{'
line 40:29 missing ':' at 'System'
line 40:35 mismatched input '.' expecting {',', ')'}
line 47:27 mismatched input 'returns' expecting '{'
library: score_system
version: 1.0.0

Defined Variables:

Defined ValueSets:

Defined Retrieves:

The weird thing here is that some of these errors are related to the code generated from the CDS authoring tool (which I thought would yield valid code). The second issue is that I do not know how to interpret the errors from the output, as I have followed the specifications from https://cql.hl7.org/03-developersguide.html#conditional-expressions and https://cql.hl7.org/03-developersguide.html#defining-functions .

Therefore any help/advice is welcomed and I have attached the relevant .cql files in this post. Note that I do not intend to use this forum for other users to debug my code and instead would like to learn where to find relevant resources that could help me debug my code in the future.

Thanks a lot !

score_system.cql FHIRHelpers.json FHIRHelpers.cql

view this post on Zulip David Winters (Jun 08 2021 at 10:37):

@Chris Moesel

I've never used the Java Quickstart. Have you tried cql-to-elm? That will translate your CQL to ELM JSON and I will use it to check for syntax errors. There's also a plugin for the Atom editor which can also check syntax. Once you have something that compiles I'd suggest defining some tests using something like the cql-testing-framework.

view this post on Zulip Adrien Prost (Jun 08 2021 at 13:24):

@David Winters Thanks for the answer, indeed I have tried running the code using the web-based IDE at https://cql-runner.dataphoria.org/ (I do not know what engine/cql-execution program is used there) and now it works, it seems like the Java version is out of date (for example it does not recognize the codesystem keyword). For CQL to ELM is there a software that I can run on linux to interpret ELM ?

view this post on Zulip David Winters (Jun 08 2021 at 13:34):

@Adrien Prost I think there are a couple of options. There's the JavaScript CQL Execution library and then the Java CQL Evaluator.

view this post on Zulip Adrien Prost (Jun 08 2021 at 13:39):

This might be a more opinionated question, but may I ask why a testing framework does not directly embed a CQL-to-ELM translator and this must be done manually be implementors? I think the whole concept of designing a standard for health data exchange is great, but making it user friendly would result in people actually implementing it :)

view this post on Zulip JP (Jun 08 2021 at 15:47):

@Adrien Prost - Are you familiar with the Atom cql-language plugin? I run it on Linux to execute ELM regularly:

https://atom.io/packages/language-cql

view this post on Zulip Adrien Prost (Jun 08 2021 at 15:58):

@JP I used the vscode plugin but apparently it only does the syntax highlighting, I will definitely install atom to test my cql syntax then. Thanks !

view this post on Zulip John Silva (Jun 08 2021 at 17:38):

And @Adrien Prost - in order to run the tests you need to have the folder structure setup and populated with the FHIR resources (vocab-related and patient-related) as described in the language-cql page. I also found that I had to run the test within a certain folder in order for all the artifacts to be found. (Usually brought up Atom on the .../build folder, which was parallel to the input folder, which is where I directed the output from the cql-to-elm tool. (the other thing I didn't realize was that the ../input/tests/<cql-library-name> had to be the name identified in the .cql file library statement, e.g.

MyCqlTest.cql:

library MyCqlTest version '0.1.0' ...

.../input/tests/MyCqlTest/<patientId>/...

view this post on Zulip David Winters (Jun 08 2021 at 18:27):

Great suggestion @Adrien Prost
I think the concept is that users would bring them both into their project as dependencies. @Chris Moesel and I have talked about setting up a "starter kit" that would be a skeleton project that would have these setup for people. Wondering if that would be of interest to others out there.

view this post on Zulip David Winters (Jun 08 2021 at 20:28):

@Adrien Prost turns out the testing framework does include the cql-to-elm translator: https://github.com/AHRQ-CDS/CQL-Testing-Framework/blob/master/package.json#L8

view this post on Zulip Adrien Prost (Jun 09 2021 at 08:44):

@John Silva Thanks for the tips, it is indeed not very clear from the language-cql how these directories must be setup. Does the FHIR website provide a bundle of test resources that I could use to test CQL queries ?

view this post on Zulip Adrien Prost (Jun 09 2021 at 08:47):

@David Winters Yep I was thinking something similar like a script that generates a project folder, configurations files etc.. As I am new to this I am having trouble to understand how a FHIR/CQL production environment would look like in practice

view this post on Zulip David Winters (Jun 09 2021 at 11:40):

@Adrien Prost on each FHIR resource page they typically provide some example resources in JSON and XML format. The cql-testing-framework allows you to define FHIR resources in a YAML shorthand and then run them through your CQL.

view this post on Zulip John Silva (Jun 09 2021 at 14:02):

@Adrien Prost - the FHIR resources you need depend upon what your CQL logic is expecting so you probably need to generate them yourself. One option would be to create FSH files for the resources that meet the requirements of your CQL logic, e.g. an Observation with a particular code that you expect, along with (of course) the Patient resource or others used in your CQL.

view this post on Zulip JP (Jun 09 2021 at 15:08):

The directory structure is based on the standard IG layout so currently the best way to figure it out is to take a look at an existing IG. Here's one for reference:

https://github.com/DBCG/connectathon/tree/master/fhir401

view this post on Zulip Bryn Rhodes (Jun 10 2021 at 21:00):

Late to the party here, but the testing structure is documented in the Atom Plugin readme:
https://github.com/cqframework/atom_cql_support/blob/master/README.md#using-the-cql-support-in-atom


Last updated: Apr 12 2022 at 19:14 UTC