Stream: cql
Topic: 'String' in MyValueSet
Corey Sanders (Nov 12 2021 at 23:02):
The CQL grammar allows for an expression 'String' in MyValueSet
. I'm trying to figure out how that should work in practice.
Section 5.8.3. Terminology Operations says that valueset membership is based strictly on the definition of equivalence. Equivalence for codes means that both system and code must match. If either side has just a code value and the other side has both code and system, the equivalence operation will return null.
1) The Java engine treats 'String' in the above expression as a Code object with a code value and null system. It passes that code object to the TerminologyProvider.in(...)
method and the R4RestFhirTerminologyProvider.in(...)
implementation of the TerminologyProvider will then build a request to the FHIR server ValueSet/$validate-code operation that includes a code
parameter and optionally a system
parameter if the system is specified in the code object. For the 'String' in MyValueSet
expression the system is always null, so the parameter isn't passed to the FHIR server.
The FHIR spec for $validate-code says that if a code parameter is specified, then either a context
or system
parameter MUST also be provided in the validate-code request, so there seems to be a disconnect here. It shouldn't be legal to send only the code
parameter. I confirmed at least on the IBM FHIR server I use for CQL evaluation that the ValueSet/$validate-code operation does require the system parameter when code is specified. The $validate-code throws an error if system isn't specified.
As one last note, the ValueSet specification requires that system be present for any included codes. Strictly from a FHIR R4 perspective, you shouldn't be able to lookup a code that doesn't contain a system in a valueset. The valueset won't contain codes without system.
2) The Javascript engine takes some pretty reasonable liberties when trying to handle this case. It will allow string containership as long as all the codes in the valueset share a common system value. If not, an "In (valueset) is ambiguous" error is thrown.
3) I tried to review samply/blaze to see how it was handled there, but as best as I can tell from the conformance statement the InValueSet operation is still TBD right now.
So, what is the expected behavior here? The design clearly allows for non-FHIR terminology support, so the FHIR rules need not apply, but that is the main use case and the Java implementation doesn't really support FHIR correctly as-is. The Javascript logic seems reasonable, but wouldn't be supported by the FHIR validate-code operation.
Bryn Rhodes (Nov 13 2021 at 19:47):
The string overload of in is a special case that we allowed for simplicity, but that overload has specific evaluation semantics: https://cql.hl7.org/09-b-cqlreference.html#in-valueset
Bryn Rhodes (Nov 13 2021 at 19:51):
Based on those semantics, I don't think the Java implementation is doing the right thing here, because you're right, it couldn't be evaluated as a FHIR ValueSet membership test. It would actually have to be evaluated as:
'String' in (MyValueSet X return X.code)
and even then, there would have to be a check to make sure that (MyValueSet X return X.code) = (MyValueSet X return all X.code)
.
Bryn Rhodes (Nov 13 2021 at 19:52):
In the case that the ValueSet is also the default ValueSet for a given CodeSystem, an implementation could provide that system.
Bryn Rhodes (Nov 13 2021 at 19:54):
https://github.com/DBCG/cql_engine/issues/514
Corey Sanders (Nov 15 2021 at 15:31):
Thanks, Bryn. I was missing the extra detail in the cqlreference section.
Last updated: Apr 12 2022 at 19:14 UTC