cqframework / cql-execution

A JavaScript framework for executing CQL
Apache License 2.0
65 stars 30 forks source link

Error Interval - interval.start is not a function #312

Closed rainesmoshe closed 1 year ago

rainesmoshe commented 1 year ago

Hi,

I'm getting the following error, it looks like in this code it is not creating an Interval class

      if (interval == null) {
        return null;
      }

      var start = interval.start();

this is what i have as "interval"

JSON.stringify(interval,null,2)
'{
  "localId": "26",
  "name": "Measurement Period",
  "parameterTypeSpecifier": {
    "localId": "25",
    "locator": "29:32-29:49",
    "type": "IntervalTypeSpecifier",
    "resultTypeSpecifier": {
      "type": "IntervalTypeSpecifier",
      "pointType": {
        "name": "{urn:hl7-org:elm-types:r1}DateTime",
        "type": "NamedTypeSpecifier"
      }
    },
    "pointType": {
      "localId": "24",
      "locator": "29:41-29:48",
      "resultTypeName": "{urn:hl7-org:elm-types:r1}DateTime",
      "name": "{urn:hl7-org:elm-types:r1}DateTime",
      "type": "NamedTypeSpecifier"
    }
  }
}'
TypeError: interval.start is not a function
    at Start.exec (**C:\work\cqldemo\node_modules\cql-execution\lib\elm\interval.js:450:28**)
    at Start.execute (C:\work\cqldemo\node_modules\cql-execution\lib\elm\expression.js:55:30)
    at DateTimeComponentFrom.execArgs (C:\work\cqldemo\node_modules\cql-execution\lib\elm\expression.js:77:27)
    at DateTimeComponentFrom.exec (C:\work\cqldemo\node_modules\cql-execution\lib\elm\datetime.js:288:22)
    at DateTimeComponentFrom.execute (C:\work\cqldemo\node_modules\cql-execution\lib\elm\expression.js:55:30)
    at C:\work\cqldemo\node_modules\cql-execution\lib\elm\expression.js:73:24
    at Array.map (<anonymous>)
    at Subtract.execArgs (C:\work\cqldemo\node_modules\cql-execution\lib\elm\expression.js:72:28)
    at Subtract.exec (C:\work\cqldemo\node_modules\cql-execution\lib\elm\arithmetic.js:110:23)
    at Subtract.execute (C:\work\cqldemo\node_modules\cql-execution\lib\elm\expression.js:55:30)
cmoesel commented 1 year ago

The interval you pasted above is a CQL parameter named Measurement Period. When you ran the execution, did you pass in a value for this parameter? If so, how did you construct the parameter value that you passed in?

rainesmoshe commented 1 year ago

This is How I set the Measurement Period:

let loadParameters = () => {
    return {
        'Measurment Period': new Interval(
            new DateTime(2013, 1, 1, 0, 0, 0, 0),
            new DateTime(2014, 1, 1, 0, 0, 0, 0),
            true,
            false
          )
    }
};

And this is how I pass it to the executor

let loadAllData = () => {
    return {
        measure: loadMeasure(),
        patient: loadPatient(),
        libraries: loadLibraries(),
        valuesets: loadValuesets(),
        parameters: loadParameters()
    }
};

let{ measure, patient, libraries, valuesets, parameters} = loadAllData();

let executor = new Executor(library,codeService,parameters);
rainesmoshe commented 1 year ago

BTW, I get the same error if i do not pass the parameter:

let executor = new Executor(library,codeService);

could it be an issue with the Patient FHIR format? where can i find test data? looking to test NCQA measurements AISE, BCSE

cmoesel commented 1 year ago

I see a typo:

'Measurment Period': new Interval(

Note the missing e. Can you try fixing that and see if it clears it up?

'Measurement Period': new Interval(
rainesmoshe commented 1 year ago

Hi, Yes now it is working, however not sure why it didn't work without the parameter Thank you

cmoesel commented 1 year ago

When you don't provide a parameter value at runtime, and the parameter does not specify a default value either, then the parameter should evaluate as null. It seems that for some reason it might have evaluated as some other non-null value though -- so this is probably something we should look at further.

I'm glad your issue is now resolved, but I'll re-open this to reflect that we need to see why the parameter isn't null when it is not supplied. Or perhaps it is null but something else in the CQL is causing interval logic to be called on a non-interval... Is the CQL for this measure publicly available? Or can you possibly send the CQL snippet that caused this error?

rainesmoshe commented 1 year ago

I was using a licensed NCQA measure BCSE, and not sure if I can share it, will need to check with NCQA

birick1 commented 1 year ago

The code used above originally came from this NCQA demo. NCQA measures are not shareable (to my knowledge) and all require a "Measurement Period" parameter.

@cmoesel - I set up some testing and am able to reproduce the behavior.

With "Measurement Period": image

With "Measurment Period": image

birick1 commented 1 year ago

This item was resolved - closing.