Stream: cql
Topic: cql-exec-fhir issue
Vasyl Herman (Feb 22 2021 at 12:21):
Hello guys, I am trying to build a simple node.js app using cql-exec-fhir library.
The problem is that I am not sure if my ELM file is correct. I did try both cql-to-elm as well as cql-translation-service as a docker container from cqframework
registry.
My goal is to be able to execute a simple .cql
file using cql-execution
, cql-exec-fhir
, cql-exec-vsac
libraries and one of available ways to translate a cql
file to ELM
(JSON).
My simple app
const fs = require("fs");
const path = require("path");
const cql = require("cql-execution");
const cqlfhir = require("cql-exec-fhir");
const cqlvsac = require("cql-exec-vsac");
const elmFile = JSON.parse(fs.readFileSync(
path.join(__dirname, 'r4', 'gender.json'),'utf8'));
const libraries = {
FHIRHelpers: JSON.parse(fs.readFileSync(
path.join(__dirname, 'r4', 'FHIRHelpers.json'), 'utf8'))
};
const fhirBundle = JSON.parse(fs.readFileSync(
path.join(__dirname, 'r4', 'Johnnie679.json'),'utf8'));
const codeService = new cqlvsac.CodeService(path
.join(__dirname, 'r4', 'valueset'),true);
const library = new cql.Library(elmFile, new cql.Repository(libraries));
// const library = new cql.Library(elmFile);
const executor = new cql.Executor(library, codeService);
// const executor = new cql.Executor(library);
patientSource = cqlfhir.PatientSource.FHIRv400();
patientSource.loadBundles([fhirBundle]);
const result = executor.exec(patientSource);
console.log(JSON.stringify(result, undefined, 2));
I am trying to execute gender.cql
:
library EXM74 version '10.2.000'
using FHIR version '4.0.1'
include FHIRHelpers version '4.0.1' called FHIRHelpers
context Patient
define "Initial Population":
Patient.gender = 'female'
define "Denominator":
"Initial Population"
I am getting an error:
D:\git-cql-fhir\cql-exec-fhir-example>node .
Failed to find type info for http://hl7.org/fhir/StructureDefinition/Patient
D:\git-cql-fhir\cql-exec-fhir-example\node_modules\cql-execution\lib\elm\reusable.js:159
functionDefs = functionDefs.filter(function (f) {
^
TypeError: Cannot read property 'filter' of undefined
at FunctionRef.exec (D:\git-cql-fhir\cql-exec-fhir-example\node_modules\cql-execution\lib\elm\reusable.js:159:35)
at FunctionRef.execute (D:\git-cql-fhir\cql-exec-fhir-example\node_modules\cql-execution\lib\elm\expression.js:59:21)
at D:\git-cql-fhir\cql-exec-fhir-example\node_modules\cql-execution\lib\elm\expression.js:73:24
at Array.map (<anonymous>)
at Equal.execArgs (D:\git-cql-fhir\cql-exec-fhir-example\node_modules\cql-execution\lib\elm\expression.js:72:28)
at Equal.exec (D:\git-cql-fhir\cql-exec-fhir-example\node_modules\cql-execution\lib\elm\overloaded.js:81:23)
at Equal.execute (D:\git-cql-fhir\cql-exec-fhir-example\node_modules\cql-execution\lib\elm\expression.js:59:21)
at ExpressionDef.exec (D:\git-cql-fhir\cql-exec-fhir-example\node_modules\cql-execution\lib\elm\reusable.js:57:61)
at ExpressionDef.execute (D:\git-cql-fhir\cql-exec-fhir-example\node_modules\cql-execution\lib\elm\expression.js:59:21)
at Executor.exec_patient_context (D:\git-cql-fhir\cql-exec-fhir-example\node_modules\cql-execution\lib\runtime\executor.js:87:58)
to reproduce it:
- clone my repo https://github.com/PrettySolution/cql-exec-fhir-example
npm i
node .
Node v14.15.4
npm 6.14.10
I would appreciate any help on this :)
Chris Moesel (Feb 22 2021 at 13:59):
Hi @Vasyl Herman -- I don't see anything obviously wrong there. I'll try to reproduce over here and see what happens!
Vasyl Herman (Feb 22 2021 at 14:10):
@Chris Moesel Thanks!
I have just noticed that I am using patientSource = cqlfhir.PatientSource.FHIRv400();
in index.js and using FHIR version '4.0.1'
in gender.cql. Kind of mismatching of FHIR versions. does it make difference?
Chris Moesel (Feb 22 2021 at 14:11):
Good catch. I have seen that make a difference before, but not usually resulting in an error like this. So I would recommend fixing it, but I don't expect it to resolve this particular issue.
Chris Moesel (Feb 22 2021 at 14:29):
I think the issue was that your CQL was using FHIR 4.0.1, but you included the FHIRHelpers for FHIR 4.0.0. I pushed up a PR that fixes this and also adds a gradle script for running CQL-to-ELM (which I find helpful in my own projects). See: https://github.com/PrettySolution/cql-exec-fhir-example/pull/1
Vasyl Herman (Feb 22 2021 at 14:32):
I have found that this line in gender.cql causes an error:
define "Initial Population":
Patient.gender = 'female'
I feel a lack of cql
knowledge.
for instance this definition works fine:
define Is18OrOlder:
AgeInYears() >= 18
The full .cql
file:
library PatientFinderExample version '1.0.0'
using FHIR version '4.0.1'
include FHIRHelpers version '4.0.1' called FHIRHelpers
context Patient
define Is18OrOlder:
AgeInYears() >= 18
... and gives me expected result
Chris Moesel (Feb 22 2021 at 14:34):
@Vasyl Herman -- is this still happening after taking in my pull request? Or was this from before that?
Vasyl Herman (Feb 22 2021 at 14:35):
@Chris Moesel before the PR. Let me take a look.
Vasyl Herman (Feb 22 2021 at 14:42):
@Chris Moesel Amazing!!!! It works now! Thank you!!!
Chris Moesel (Feb 22 2021 at 14:54):
You're welcome! As I said, I think it was the FHIRHelpers mismatch that was the issue. Ideally we'd detect that in the framework and provide a more helpful error -- but for now I think you should be all set.
Vasyl Herman (Feb 22 2021 at 15:06):
Yes. the issue caused the FHIRHelpers
! And I see here a FHIRHelpers.cql
representation of the FHIRHelpers.json
. Well yes, It becomes much more clear to me now, how things work... thanks again.
BTW, Is it a good idea to use cql-translation-service ? I feel like it has some constrains, like not fully supported or something right?
I am trying to send it include MATGlobalCommonFunctions version '5.0.000' called Global
like so:
library EXM74 version '10.2.000'
using FHIR version '4.0.1'
include FHIRHelpers version '4.0.1' called FHIRHelpers
include MATGlobalCommonFunctions version '5.0.000' called Global
and It says me back Could not load source for library MATGlobalCommonFunctions, version 5.0.000.
Chris Moesel (Feb 22 2021 at 15:12):
The translation service is pretty capable, but one downside is that it always lags behind the translator versions a bit, because it needs to be manually updated whenever a new translator is released (and we usually forget until someone asks for it).
As for MATGlobalCommonFunctions, that is not a library built into the translator -- so if you want to translate a library that depends on it, you need to send the MATGlobalCommonFunctions CQL in the same request using multi-part attachments. I think JP provided some links for this in the other thread.
Vasyl Herman (Feb 22 2021 at 15:15):
Yes, I didn't understand what JP meant. Now I fell much better, thanks!
Last updated: Apr 12 2022 at 19:14 UTC