cqframework / vscode-cql

VS Code Clinical Quality Language Extension
Apache License 2.0
8 stars 5 forks source link

InValueSet Error #16

Closed drthyl closed 2 years ago

drthyl commented 2 years ago

Hello, the following CQL generates an InValueSet error when tested. The CQL, error message, and FHIR JSON Bundle syntax are included below. Is the CQL expression incorrect here? Thanks for any insights!

library AdvancedIllnessandFrailtyExclusionECQMFHIR4 version '6.0.000'
using QICore version '4.1.1'

include FHIRHelpers version '4.0.012' called FHIRHelpers
// include FHIRCommon version '4.0.012' called FHIRCommon //https://github.com/cqframework/ecqm-content-qicore-2022/issues/5
include QICoreCommon version '1.0.000' called QICoreCommon 

codesystem "LOINC": 'http://loinc.org'

valueset "Frailty Device": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.118.12.1300'

code "Medical equipment used": '98181-1' from "LOINC" display 'Medical equipment used'

parameter "Measurement Period" Interval<DateTime>
default Interval[@2023-01-01T00:00:00.000Z, @2024-01-01T00:00:00.000Z)

context Patient

define "Has Criteria Indicating Frailty":
([Observation: "Medical equipment used"]) FrailtyDeviceApplied
        where FrailtyDeviceApplied.value in "Frailty Device"
The following errors were encountered during evaluation:
org.opencds.cqf.cql.engine.exception.CqlException: Translation of library AdvancedIllnessandFrailtyExclusionECQMFHIR4 failed with the following message: Call to operator InValueSet(choice<System.Quantity,System.Concept,System.String,System.Boolean,System.Integer,interval<System.Quantity>,System.Ratio,QICore.SampledData,System.Time,System.DateTime,interval<System.DateTime>>) is ambiguous with: 
  - InValueSet(System.Concept)
  - InValueSet(System.String)
    at org.opencds.cqf.cql.evaluator.engine.execution.TranslatingLibraryLoader.translate(TranslatingLibraryLoader.java:134)
    at org.opencds.cqf.cql.evaluator.engine.execution.TranslatingLibraryLoader.load(TranslatingLibraryLoader.java:78)
    at org.opencds.cqf.cql.evaluator.engine.execution.CacheAwareLibraryLoaderDecorator.load(CacheAwareLibraryLoaderDecorator.java:49)
    at org.opencds.cqf.cql.engine.execution.CqlEngine.loadAndValidate(CqlEngine.java:254)
    at org.opencds.cqf.cql.engine.execution.CqlEngine.evaluate(CqlEngine.java:154)
    at org.opencds.cqf.cql.evaluator.CqlEvaluator.evaluate(CqlEvaluator.java:89)
    at org.opencds.cqf.cql.evaluator.CqlEvaluator.evaluate(CqlEvaluator.java:76)
    at org.opencds.cqf.cql.evaluator.cli.command.CqlCommand.call(CqlCommand.java:163)
    at org.opencds.cqf.cql.evaluator.cli.command.CqlCommand.call(CqlCommand.java:34)
    at picocli.CommandLine.executeUserObject(CommandLine.java:1953)
    at picocli.CommandLine.access$1300(CommandLine.java:145)
    at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2352)
    at picocli.CommandLine$RunLast.handle(CommandLine.java:2346)
    at picocli.CommandLine$RunLast.handle(CommandLine.java:2311)
    at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179)
    at picocli.CommandLine.execute(CommandLine.java:2078)
    at org.opencds.cqf.cql.evaluator.cli.Main.run(Main.java:19)
    at org.opencds.cqf.cql.ls.DebugCqlCommandContribution.executeCql(DebugCqlCommandContribution.java:37)
    at org.opencds.cqf.cql.ls.DebugCqlCommandContribution.executeCommand(DebugCqlCommandContribution.java:65)
    at org.opencds.cqf.cql.ls.service.CqlWorkspaceService.executeCommandFromContributions(CqlWorkspaceService.java:173)
    at org.opencds.cqf.cql.ls.service.CqlWorkspaceService.executeCommand(CqlWorkspaceService.java:121)
    at jdk.internal.reflect.GeneratedMethodAccessor14.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.lambda$null$0(GenericEndpoint.java:65)
    at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.request(GenericEndpoint.java:120)
    at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.handleRequest(RemoteEndpoint.java:261)
    at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.consume(RemoteEndpoint.java:190)
    at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.handleMessage(StreamMessageProducer.java:194)
    at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.listen(StreamMessageProducer.java:94)
    at org.eclipse.lsp4j.jsonrpc.json.ConcurrentMessageProcessor.run(ConcurrentMessageProcessor.java:113)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
    at java.base/java.lang.Thread.run(Thread.java:832)
elapsed: -0.902 seconds
{
  "resourceType": "Bundle",
  "id": "Patient-1-MedicalEquipmentUsedFrailtyDevice",
  "type": "transaction",
  "entry": [
    {
      "resource": {
        "resourceType": "Patient",
        "id": "Patient-1",
        "meta": {
          "profile": [
            "http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient"
          ]
        },
        "extension": [
          {
            "url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-race",
            "extension": [
              {
                "url": "ombCategory",
                "valueCoding": {
                  "code": "2028-9",
                  "system": "urn:oid:2.16.840.1.113883.6.238",
                  "display": "Asian"
                }
              }
            ]
          },
          {
            "url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-ethnicity",
            "extension": [
              {
                "url": "ombCategory",
                "valueCoding": {
                  "code": "2135-2",
                  "system": "urn:oid:2.16.840.1.113883.6.238",
                  "display": "Hispanic or Latino"
                }
              }
            ]
          }
        ],
        "identifier": [
          {
            "system": "http://hospital.smarthealthit.org",
            "value": "999999995"
          }
        ],
        "name": [
          {
            "family": "Bertha",
            "given": [
              "Betty"
            ]
          }
        ],
        "birthDate": "1999-12-31",
        "gender": "female"
      }
    },
    {
      "resource": {
        "resourceType": "Observation",
        "id": "Observation-1",
        "subject": {
          "reference": "Patient/Patient-1"
        },
        "code": {
          "coding": [
            {
              "code": "98181-1",
              "system": "http://loinc.org",
              "display": "Medical equipment used"
            }
          ]
        },
        "status": "final",
        "category": [
          {
            "coding": [
              {
                "code": "survey",
                "system": "http://terminology.hl7.org/CodeSystem/observation-category"
              }
            ]
          }
        ],
        "effectiveDateTime": "2023-11-01T23:59:00.000Z",
        "valueCodeableConcept": {
          "coding": [
            {
              "code": "183240000",
              "system": "http://snomed.info/sct",
              "display": "Self-propelled wheelchair (physical object)"
            }
          ]
        }
      }
    }
  ]
}
brynrhodes commented 2 years ago

The issue here is that there are two overloads of InValueSet that could be used:

InValueSet(Concept) InValueSet(String)

Since Concept and String are both possible types for the value element of an Observation, the translator is indicating that it doesn't know which one to choose. Using an as Concept will tell the translator which one is appropriate:

([Observation: "Medical equipment used"]) FrailtyDeviceApplied where FrailtyDeviceApplied.value as Concept in "Frailty Device"