cqframework / cql-execution

A JavaScript framework for executing CQL
Apache License 2.0
63 stars 31 forks source link

Getting error while evaluating valuesets #274

Open nehaghub opened 2 years ago

nehaghub commented 2 years ago

C:\Users\neha.f.goel\tt\cql-execution\lib\elm\clinical.js:35 const valueset = ctx.codeService.findValueSet(this.id, this.version) || new dt.ValueSet(this.id, this.version); ^

TypeError: Cannot read properties of undefined (reading 'findValueSet') at ValueSetDef.exec (C:\Users\neha.f.goel\tt\cql-execution\lib\elm\clinical.js:35:42) at ValueSetDef.execute (C:\Users\neha.f.goel\tt\cql-execution\lib\elm\expression.js:29:25) at ValueSetRef.exec (C:\Users\neha.f.goel\tt\cql-execution\lib\elm\clinical.js:51:33) at ValueSetRef.execute (C:\Users\neha.f.goel\tt\cql-execution\lib\elm\expression.js:29:25) at Retrieve.exec (C:\Users\neha.f.goel\tt\cql-execution\lib\elm\external.js:22:46) at Retrieve.execute (C:\Users\neha.f.goel\tt\cql-execution\lib\elm\expression.js:29:25) at C:\Users\neha.f.goel\tt\cql-execution\lib\elm\expression.js:37:45 at Array.map () at Union.execArgs (C:\Users\neha.f.goel\tt\cql-execution\lib\elm\expression.js:37:30) at Union.exec (C:\Users\neha.f.goel\tt\cql-execution\lib\elm\overloaded.js:83:29)

Please help me for the same. Thanks Neha

cmoesel commented 2 years ago

Hi @nehaghub. If I had to guess, it seems like you are not passing in a CodeService when you construct the cql-execution Executor. The CodeService instance is the 2nd argument in the Executor constructor. See the Overview.

If you aren't passing one in to the constructor, then you need to do so. If you're using value sets from VSAC, then you can use the cql-exec-vsac code service.

If you are passing in a code service and still getting this error, then we'll need more information:

nehaghub commented 2 years ago

Hi,

  1. I am using "version": "2.4.1".
  2. Yes, I am using this way.
  3. Below is my code const fs = require('fs'); const path = require('path');

const cqlfhir = require('../lib'); const vsac = require('../../cql-exec-vsac'); const cql = require('../../cql-execution/lib/cql');

parameters = { "Measurement Period" : new cql.Interval ( new cql.DateTime(1952,1,1,0,0,0,0), new cql.DateTime(2021,1,1,0,0,0,0) ) }

const elmFile = JSON.parse(fs.readFileSync('C:/Users/neha.f.goel/tt/bcs.json', 'utf8')); const libraries = { FHIRBase:JSON.parse(fs.readFileSync('C:/Users/neha.f.goel/tt/CCS_HEDIS_MY2022-1.1.0/CCS_HEDIS_MY2022-1.1.0/libraryElm/NCQA_FHIRBase-1.1.0.json', 'utf8')),
FHIRHelpers: JSON.parse(fs.readFileSync('C:/Users/neha.f.goel/tt/CCS_HEDIS_MY2022-1.1.0/CCS_HEDIS_MY2022-1.1.0/libraryElm/FHIRHelpers-4.0.1.json', 'utf8')) }; ) const library = new cql.Library(elmFile, new cql.Repository(libraries));

const bundles = [];

const patientsPath = 'mcode1_0_longitudinal/longitudinal/female'; for (const fileName of fs.readdirSync(patientsPath)) { const file = path.join(patientsPath, fileName); if (!file.endsWith('.json')) { continue; } const json = JSON.parse(fs.readFileSync(file)); bundles.push(json); }

const patientSource = cqlfhir.PatientSource.FHIRv401(); // or .FHIRv300() or .FHIRv400()

patientSource.loadBundles(bundles);

// let valueSets = [];

// if (elmFile.library && elmFile.library.valueSets && elmFile.library.valueSets.def) { // valueSets = elmFile.library.valueSets.def; // }

// const codeService = new vsac.CodeService('C:/Users/neha.f.goel/tt/jim_cql/valuesets/vsac_cache/', true);

console.log("b4 execution") ; const executor = new cql.Executor(library);

// const executor = new cql.Executor(library, codeService,parameters); const results = executor.exec(patientSource);

console.log(JSON.stringify(results, undefined, 2));

cmoesel commented 1 year ago

I apologize for the long delay in getting back to you. In your code above, you have commented out the lines that initialize a code service and pass it into the Executor. As I noted in my previous response, you need to pass in a CodeService as the 2nd argument to the executor.