A library for executing Clinical Quality Language (CQL) expressions asynchronously via web workers or node worker threads.
cql-worker includes version 4.0.1 of FHIRHelpers, which is available under an Apache 2.0 License, Copyright 2014 The MITRE Corporation. Other versions of FHIRHelpers can be found here.cql-exec-fhir is used to provide a FHIR-based data source for use with the CQL Execution Engine.isNodeJs flag to true.CQL Worker is published on npm and can be installed via: npm install cql-worker.
``javascript
// See: https://github.com/webpack-contrib/worker-loader
import Worker from "
import { initialzieCqlWorker } from 'cql-worker';
// Define a web worker for evaluating CQL expressions
const cqlWorker = new Worker();
// Initialize the cql-worker
let [setupExecution, sendPatientBundle, evaluateExpression] = initialzieCqlWorker(cqlWorker);
// Define elmJson, valueSetJson, cqlParameters, and elmJsonDependencies
// Send the cqlWorker an initial message containing the ELM JSON representation of the CQL expressions
setupExecution(elmJson, valueSetJson, cqlParameters, elmJsonDependencies);
// Create patientBundle to hold the patient's FHIR resources
// Send the patient bundle to the CQL web worker
sendPatientBundle(patientBundle);
// Define namedExpression, a string containing the name of a CQL expression
let result = await evaluateExpression(namedExpression);
`
See the ASBI CDS Screening and Intervention apps for additional information for how to configure Webpack to properly package cql-worker.
flag.`javascript
import { Worker } from 'worker_threads';
import { initialzieCqlWorker } from 'cql-worker';
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
let cqlWorker = new Worker(require.resolve('cql-worker/src/cql-worker-thread.js'));
let [setupExecution, sendPatientBundle, evaluateExpression] = initialzieCqlWorker(cqlWorker, true);
// Define elmJson, valueSetJson, and cqlParameters
setupExecution(elmJson, valueSetJson, cqlParameters, elmJsonDependencies);
// Create patientBundle to hold the patient's FHIR resources
sendPatientBundle(patientBundle);
// Define namedExpression, a string containing the name of a CQL expression
let result = await evaluateExpression(namedExpression);
``
Unless otherwise noted, this work is available under an Apache 2.0 license. It was produced by the MITRE Corporation for the National Center on Birth Defects and Developmental Disabilities, Centers for Disease Control and Prevention in accordance with the Statement of Work, contract number 75FCMC18D0047, task order number 75D30119F05691.