Registry / workflow / cql-execution

cql-execution

JSON →
library3.3.0jsnpmunverified

cql-execution is a TypeScript/JavaScript library providing an execution framework for Clinical Quality Language (CQL) artifacts expressed as JSON ELM. Currently at stable version 3.3.0, the library focuses on the logical constructs of CQL, allowing for integration with external data model providers (`PatientSource` implementations) and terminology services (`CodeService` implementations), rather than implementing these directly. A significant architectural shift occurred in version 3.0.0, introducing an asynchronous execution flow that enables `PatientSource` and `CodeService` calls to leverage web services and databases more effectively. Subsequent releases have primarily focused on improving alignment with CQL 1.5 specifications, enhancing support for CodeSystems and ValueSets, and refining operator behaviors. The project maintains an active release cadence with regular minor updates addressing bug fixes and specification alignment. Its key differentiator is a lean, extensible core for CQL execution, delegating data and terminology specifics to companion libraries like `cqm-execution`, `cql-exec-fhir`, and `cql-exec-vsac`.

npm install cql-execution
INSTALL
IMPORT
SIG · CQL-EXECUTION
C
cql-execution
workflowjavascriptv3.3.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Executor
✓ import { Executor } from 'cql-execution';
✗ const Executor = require('cql-execution').Executor;
The primary class for executing ELM against data and terminology services. ESM import is standard, CJS is often problematic since v3.
PatientSource
✓ import { PatientSource } from 'cql-execution';
✗ import { DataProvider } from 'cql-execution';
An interface for providing patient data to the Executor. While referred to as `DataProvider` in some docs, the exported interface is `PatientSource`. Implementations must be asynchronous since v3.0.0.
CodeService
✓ import { CodeService } from 'cql-execution';
✗ import { TerminologyProvider } from 'cql-execution';
An interface for providing terminology services (e.g., ValueSet resolution) to the Executor. Referred to as `TerminologyProvider` in some docs, the exported interface is `CodeService`. Implementations must be asynchronous since v3.0.0.

Demonstrates how to load a simple ELM library, create mock `PatientSource` and `CodeService` implementations, and execute basic CQL logic for a single patient using the asynchronous execution engine.

import { Executor, PatientSource, CodeService } from 'cql-execution'; // 1. Define a simple ELM library (JSON representation of CQL) const elm = { library: { identifier: { id: 'MyLibrary', version: '1.0.0' }, statements: { def: [ { name: 'TrueExpression', context: 'Patient', expression: { type: 'Literal', valueType: '{http://www.w3.org/2001/XMLSchema}boolean', value: 'true' } }, { name: 'PatientAge', context: 'Patient', expression: { type: 'AgeInYears', operand: { type: 'SingletonFrom', operand: { type: 'Retrieve', dataType: '{http://hl7.org/fhir/R4}Patient' } } } } ] } } }; // 2. Implement a mock PatientSource (DataProvider) class MockPatientSource implements PatientSource { private patients: any[]; constructor(patients: any[]) { this.patients = patients; } async currentPatient(): Promise<any> { return this.patients[0]; } async nextPatient(): Promise<any | undefined> { this.patients.shift(); return this.patients[0]; } async retrieve(patientId: string, dataType: string, template: string, codes: any[], dateRange: any): Promise<any[]> { if (dataType === '{http://hl7.org/fhir/R4}Patient') { // Mock patient data for AgeInYears calculation. Real impl would query a data source. return [{ birthDate: '1990-01-01' }]; } return []; } async loadPatients(): Promise<void> { /* no-op for mock */ } getPatientSourceIterator(): AsyncIterator<any> { let index = 0; const patients = this.patients; return { next: async () => { if (index < patients.length) { const value = patients[index++]; return { value, done: false }; } else { return { value: undefined, done: true }; } } }; } count(): number { return this.patients.length; } } // 3. Implement a mock CodeService (TerminologyProvider) class MockCodeService implements CodeService { async findValueSet(valueSetUrl: string, version?: string): Promise<any> { return { codes: [] }; } async findCodes(code: any): Promise<any> { return []; } async resolveValueSet(valueSet: any): Promise<any> { return { codes: [] }; } } async function executeCql() { const patientSource = new MockPatientSource([{ id: 'patient1', birthDate: '1990-01-01' }]); const codeService = new MockCodeService(); const executor = new Executor(elm); const results = await executor.execute(patientSource, codeService, { // `executionDateTime` is crucial for date-related CQL operations. executionDateTime: '2025-01-01T12:00:00Z', verbose: true }); console.log('Results for Patient 1:'); for (const patientId in results.patientResults) { const patientResults = results.patientResults[patientId]; console.log(` Patient ID: ${patientId}`); console.log(` TrueExpression: ${patientResults.TrueExpression}`); console.log(` PatientAge: ${patientResults.PatientAge}`); } } executeCql().catch(console.error);
Debug
Known issues
breakingVersion 3.0.0 introduced a significant breaking change by shifting the execution flow to be entirely asynchronous. All methods in custom `PatientSource` (formerly `DataProvider`) and `CodeService` (formerly `TerminologyProvider`) implementations must now return Promises. Code relying on synchronous data or terminology access will fail.
fix
Update all `PatientSource` and `CodeService` methods to be `async` and return `Promise` objects. Ensure `await` is used when calling these methods within the `Executor`.
affects: >=3.0.0
breakingIn version 3.0.1, the core execution method was renamed from `exec` to `execute` for improved consistency. Direct calls to `executor.exec(...)` will no longer work.
fix
Replace `executor.exec(...)` with `executor.execute(...)` in your application code.
affects: >=3.0.1
gotchaDue to JavaScript's `Number` class being used for both CQL `Integer` and `Decimal` types, `cql-execution` may exhibit reduced precision and floating-point arithmetic issues, potentially treating decimals without a fractional part (e.g., `2.0`) as CQL `Integer`s.
fix
Be aware of these inherent JavaScript numerical limitations when writing CQL involving precise decimal calculations or large integers. Consider external validation for critical numerical results.
affects: >=1.0.0
gotchaThe `PatientSource`, `CodeService`, and `Results` APIs are explicitly noted as evolving and subject to change. This means that minor or major version updates may introduce breaking changes to these interfaces or their expected behavior.
fix
Carefully review the changelogs and documentation for each new version, especially when upgrading minor or major releases, and adapt your custom implementations accordingly.
affects: >=1.0.0
gotchaThe library does not fully implement all features of CQL 1.4 and 1.5. Key unsupported features include the `Long` datatype, fluent functions, retrieve search paths/includes, related context retrieves, unfiltered context retrieves, unfiltered context references to other libraries, and external functions.
fix
Consult the `CQL_Execution_Features.xlsx` spreadsheet (available in the GitHub repository) for a detailed list of supported features and avoid using unsupported CQL constructs in your ELM.
affects: >=1.0.0
gotchaDespite being written in TypeScript, the library does not yet have full-fledged type definitions across all modules. This may lead to situations where type `any` is inferred or specific type definitions are missing, potentially reducing TypeScript's compile-time safety.
fix
Be prepared to use type assertions (`as any`) or augment types where necessary. Refer to the library's JavaScript source code for the definitive API structure in cases of ambiguous typing.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: executor.exec is not a function
Attempting to use the deprecated `exec` method for execution, which was renamed to `execute` in v3.0.1.
fix
Update the execution call from `executor.exec(...)` to `executor.execute(...)`.
TypeError: patientSource.currentPatient is not a function
Your custom `PatientSource` (or `CodeService`) implementation is not an `async` function and/or not returning a `Promise` for its methods, a requirement since v3.0.0.
fix
Ensure all methods within your `PatientSource` and `CodeService` implementations are declared `async` and explicitly return `Promise` objects, even if the internal operation is synchronous (e.g., `return Promise.resolve(data);`).
AnnotatedError: Encountered unexpected error at Library.MyLibrary.1.0.0.TrueExpression: Cannot read properties of undefined (reading 'value')
A runtime error occurred during CQL expression evaluation, often due to unexpected `null` or `undefined` data, an unsupported operation, or malformed ELM. The error message indicates the exact ELM path.
fix
Examine the `AnnotatedError` message for the specific CQL expression and location. Debug your CQL logic and verify the patient data or terminology provided to the `Executor`.
ReferenceError: require is not defined
Attempting to use CommonJS `require()` syntax to import `cql-execution` in an ECMAScript Module (ESM) environment (e.g., a modern Node.js project with `"type": "module"` or browser bundlers).
fix
Switch to ESM `import` statements: `import { Executor } from 'cql-execution';`. Ensure your project's build configuration or Node.js environment is set up for ESM.
Upgrade
Version history
3.3.0latest on npm
Audit
Dependencies
cql-exec-fhiroptionalProvides a FHIR-based data source for the execution engine. Often used together for FHIR-based CQL logic.
cql-exec-vsacoptionalProvides a VSAC-enabled terminology service for looking up value sets. Often used together for terminology resolution.
cqm-executionoptionalA project built on cql-execution for executing electronic Clinical Quality Measures (eCQMs) using the QDM data model.
Agent activity
13 hits · last 30 days
node
12
OpenAI (training)
1
Resources
cql-execution — npm install cql-execution · libregistry