Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
173 changes: 169 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"license": "Apache-2.0",
"dependencies": {
"cql-exec-fhir": "^2.0.2",
"cql-exec-vsac": "git@github.com:PuraJuniper/cql-exec-vsac.git#2307581c2577a5321beba2ea7a6d7f7f03f80826",
"cql-execution": "^2.4.0"
}
}
12 changes: 10 additions & 2 deletions src/CqlProcessor.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import cql from 'cql-execution';
import fhir from 'cql-exec-fhir';
import fhirHelpersJson from './FHIRHelpers-4.0.1.json.js';
import { CodeService } from 'cql-exec-vsac';

/**
* Executes logical expression written in the Clinical Quality Language (CQL) against
Expand All @@ -21,10 +22,16 @@ export default class CqlProcessor {
...elmJsonDependencies
});
this.library = new cql.Library(elmJson, this.repository);
this.codeService = new cql.CodeService(valueSetJson);
this.codeService = new CodeService(undefined, false);
this.executor = new cql.Executor(this.library, this.codeService, parameters);
}

async initValueSets() {
if (this.library.source.library.valueSets !== undefined) {
await this.codeService.ensureValueSetsInLibraryWithAPIKey(this.library, true, undefined, false);
}
}

/**
* Load a patient bundle into the CQL Processor
* @param {object} patientBundle - A bundle of FHIR resources for the patient
Expand All @@ -43,9 +50,10 @@ export default class CqlProcessor {
* @param {string} expr - The name of an expression from elmJson
* @returns {object} results - The results from executing the expression
*/
evaluateExpression(expr) {
async evaluateExpression(expr) {
// Only try to evaluate an expression if we have a patient bundle loaded.
if (this.patientSource._bundles && this.patientSource._bundles.length > 0) {
await this.initValueSets();
let results = this.executor.exec_expression(expr, this.patientSource);
this.patientSource._index = 0; // HACK: rewind the patient source
return results.patientResults[this.patientID][expr];
Expand Down
15 changes: 8 additions & 7 deletions src/cql.worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,24 @@ onmessage = function(rx) {
if ((expression = rx.data.expression) != null) {
let tx;
if (processor.patientSource._bundles.length > 0) {
let result = processor.evaluateExpression(expression);
tx = {
expression: expression,
result: result
};
processor.evaluateExpression(expression).then(v => {
this.postMessage({
expression: expression,
result: v
}); // send the result back
});
} else {
// If we don't have a bundle just send the expression back.
tx = {
expression: expression,
result: 'WAITING_FOR_PATIENT_BUNDLE'
}
this.postMessage(tx); // send the result back
}
this.postMessage(tx); // send the result back
} else if ((patientBundle = rx.data.patientBundle) != null) {
// If the message contains a patient bundle, load it.
processor.loadBundle(patientBundle);
} else if ((elmJson = rx.data.elmJson) != null && (valueSetJson = rx.data.valueSetJson) != null) { // TODO: Allow empty value sets and check elm dependencies
} else if ((elmJson = rx.data.elmJson) != null) { // TODO: Allow empty value sets and check elm dependencies
// If the message contains translated CQL (ELM JSON), use it to create a new
// CQL Processor object.
parameters = rx.data.parameters;
Expand Down