Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Union operator on valuesets does not work #331

Closed
sorliog opened this issue Feb 10, 2025 · 2 comments
Closed

Union operator on valuesets does not work #331

sorliog opened this issue Feb 10, 2025 · 2 comments

Comments

@sorliog
Copy link
Contributor

sorliog commented Feb 10, 2025

Good afternoon.

I am developing rule that use external valuesets. In my expression, I need to union valuesets together, ideally into a list of codes. However, I discoved that the union operator on valuesets throws a Null error. I am using cql-execution version 3.1.0 with the vsac.CodeService() to resolve valuesets from NLM. All valuesets in the CQL do resolve successfully and are not null.

This is the CQL rule that I am using:

library "Union issue" version '1.0.0'
using FHIR version '4.0.1'

codesystem "Snomed": 'http://snomed.info/sct'
codesystem "CVX": 'http://hl7.org/fhir/sid/cvx'

code "Single Pregnancy": '237244005' from "Snomed" display 'Single Pregnancy'
code "Pregnant woman": '255409004' from "Snomed" display 'Pregnant woman'
valueset "Pregnant State VS": 'https://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.3157.4055'
valueset "Pregnancy VS": 'https://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1078.264'

// Does not work
define "Union on valuesets":
    "Pregnant State VS" union "Pregnancy VS" // Here is the issue

// Does work
define "Union on codes":
    "Single Pregnancy" union "Pregnant woman"

// Does work
define "Union on numbers":
     1 union 3

// Does work
define "Union on strings":
     'hello' union 'world'

This is the error message:

Error Message:	Cannot read properties of null (reading 'execute')
	CQL Library:	Union issue|1.0.0
	Expression:	Union


    at Union.execute (projectPath\node_modules\cql-execution\src\elm\expression.ts:49:13)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at ExpressionDef.exec (projectPath\node_modules\cql-execution\src\elm\reusable.ts:18:45)
    at ExpressionDef.execute (projectPath\node_modules\cql-execution\src\elm\expression.ts:41:27)
    at Executor.exec_patient_context (projectPath\node_modules\cql-execution\src\runtime\executor.ts:99:28)
    at Executor.exec (projectPath\node_modules\cql-execution\src\runtime\executor.ts:60:15)
    at executeCql (projectPath\src\cdss-module.js:253:20)
    at Object.<anonymous> (projectPath\src\test\debug.test.js:34:22)

Does the union operator have an implementation to deal with valuesets? I seem to recall that it did work in the near past.

@cmoesel
Copy link
Member

cmoesel commented Feb 10, 2025

If you look at the ELM that CQL-to-ELM produces for the example above, you'll notice that performing a union on two value sets results in calls to ExpandValueSet for each value set. Unfortunately, cql-execution does not currently support the ExpandValueSet operator (which is marked as trial-use in CQL 1.5). I apologize that the error it produces doesn't convey what's really happening.

In practice, I've avoided this issue by doing unions of retrieve statements instead. In other words, instead of:

define "Union of Pregnancy VS":
    "Pregnant State VS" union "Pregnancy VS"

define PregnancyOperations: [Observation: "Union of Pregnancy VS"]

you can do:

define PregnancyOperations: [Observation: "Pregnant State VS"] union [Observation: "Pregnancy VS"]

We'd also be glad to accept a PR for this if you'd like to consider taking a crack at implementing it yourself.

@sorliog
Copy link
Contributor Author

sorliog commented Feb 13, 2025

Thank you @cmoesel. The workarounds did not work in my use case. Instead I implemented the ExpandValueset function in this PR

@sorliog sorliog closed this as completed Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants