FHIR Chat · Retrieve list of codes from valueset? · cql

Stream: cql

Topic: Retrieve list of codes from valueset?


view this post on Zulip Frank Adrian (Jan 20 2022 at 20:10):

In CQL 1.5 is there any way to retrieve a list of codes that make up a valueset?

In 1.4, you could pass a valueset as a parameter to a function like this:

define function "VS Cast Function"(VSet List<System.Code>):
( ( cast { "VSet", 1 }[0]as Tuple {
codes List<System.Code>,
oid System.String,
version System.String
}
).codes ) VSetCodes
return System.Code { code: VSetCodes.code, system: VSetCodes.system }

and get back a list of the codes from the valueset.

In 1.5, attempting to pass in a valueset to this function results in a compilation error that complains about a parameter mismatch. If you change the function parameter to a System.ValueSet instead of a List<System.Code>, the code compiles, but generates a run-time error.

Is there a way to retrieve the list of codes that make up a value set in CQL 1.5? Is there some reason that the code from CQL 1.4 shouldn't still work? Maybe a transparent coercion from System.ValueSet to a List<System.Code> in expressions would still be useful.

view this post on Zulip JP (Jan 23 2022 at 02:05):

Runtime error in VS Code or cqf-ruler? If so possibly a cql-engine bug.

view this post on Zulip Frank Adrian (Jan 24 2022 at 17:30):

It's a runtime error in the CQL engine: "Could not resolve data provider for package 'org.cqframework.cql.elm.execution'." It seems to happen any time you attempt to use a System.ValueSet object in the 1.5 engine.

Here is some code I've been trying in 1.5 ("ED", "Observation", and "Outpatients" are define in the header using the valueset declaration):

define function "VS Cast Function"(VSet System.ValueSet):
( ( cast { "VSet", 1 }[0]as Tuple {
codes List<System.Code>,
oid System.String,
version System.String
}
).codes ) VSetCodes
return System.Code { code: VSetCodes.code, system: VSetCodes.system }

define function "Combine Valuesets"(vss List<System.ValueSet>)
returns List<System.Code>:
flatten(vss VSet return "VS Cast Function"(VSet))

define Test: "Combine Valuesets"({"ED", "Observation", "Outpatient"})

define function Test1 (vset System.ValueSet):
[Procedure: vset] P

define Test2: Test1("Outpatient")

Both "Test" and "Test2" die with the error message listed above.

view this post on Zulip Bryn Rhodes (Jan 24 2022 at 17:32):

Hi Frank, we had some discussion about this during the connectathon. The VSCast function is actually taking advantage of the internal representation of valuesets in the JavaScript engine, and isn't "compatible" with the Java engine. To make it run in the Java engine, just replace the body of the VSCast function so that it returns the VSet argument (which is what the function is ultimately doing).

view this post on Zulip Bryn Rhodes (Jan 24 2022 at 17:33):

There are several trackers related to addressing this behavior in the Java and JavaScript engines to address the inconsistency.

view this post on Zulip Bryn Rhodes (Jan 24 2022 at 17:33):

The changes have been applied to the 1.5.6 translator and the current release of the engine/evaluator and IDE plugins in the Java stack.

view this post on Zulip Bryn Rhodes (Jan 24 2022 at 17:35):

Basically, retrieving the list of codes from a ValueSet is just referencing the ValueSet declaration in 1.4, but in 1.5, since the specification introduced a ValueSet runtime type, you can now pass value sets around as references and there is newly proposed explicit ExpandValueSet operation (or you can just treat it like a list of codes to force an implicit expand).

view this post on Zulip Frank Adrian (Jan 24 2022 at 22:30):

We've tried using 1.5.6 translator and the 1.5.4 version of the engine and received a run-time error when ExpandValueSet was run: Unexpected exception caught during execution: org.apache.commons.lang3.NotImplementedException: evaluate not implemented for class ExpandValueSet. Which version of the engine has this operator?

view this post on Zulip Bryn Rhodes (Jan 24 2022 at 23:40):

The fix was actually included in the 1.5.3 engine, so it should definitely be there. Are you using the cql-evaluator? And if so, what version? 1.4.2 is the latest and targets the 1.5.4 engine.


Last updated: Apr 12 2022 at 19:14 UTC