Skip to content

Commit 9468349

Browse files
committed
Update comment for clarity
1 parent 5d28fb7 commit 9468349

2 files changed

Lines changed: 22 additions & 20 deletions

File tree

examples/browser/cql4browsers.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4961,19 +4961,20 @@ class Retrieve extends expression_1.Expression {
49614961
throw new Error("Operator '~' is not defined for Code ~ CodeSystem");
49624962
}
49634963
else if (rhs instanceof clinical_1.ValueSet) {
4964-
// It's not obvious that this combination should even be allowed.
4965-
// If in the CQL representation of the Retrieve, the terminology is a ValueSet,
4966-
// eg [Condition: code ~ "SomeValueSet"],
4967-
// the CQL-to-ELM translation may turn that into either:
4968-
// - a `ValueSetRef` expression (appears here as a `ValueSet`)
4969-
// - or an `ExpandValueSet` expression wrapping the `ValueSetRef` (appears here as a `Code[]`).
4970-
// Because we can't tell the original intent here, we treat the ValueSet as if it were a Code[].
4964+
// It's not obvious that code ~ ValueSet and code ~ Code[] should be allowed,
4965+
// when code ~ CodeSystem is disallowed. Same for operator = below.
4966+
// In short, due to various translator behaviors, when `rhs` here is Code[],
4967+
// it's possible it was originally written in the CQL as a Code, a List<Code>, or a ValueSet.
4968+
// We can't distinguish, so we have to allow all of them.
4969+
// Then, again because of translator behaviors, x ~ ValueSet could reach this point
4970+
// with `rhs` either being a Code[] or a ValueSet object.
4971+
// Because we can't filter it out in the Code[] path, we should allow it in the ValueSet path as well
4972+
// to reduce unexpected inconsistencies.
4973+
// See full description and discussion at https://github.com/cqframework/cql-execution/pull/370
49714974
return rhs.hasMatch(lhs);
49724975
}
49734976
else if (Array.isArray(rhs)) {
4974-
// It's also not obvious that this should be allowed.
4975-
// But because the RHS is always list-promoted, there's no way to tell
4976-
// if the original CQL referred to a single code or to a list.
4977+
// As noted above, there's no way to tell if the original CQL referred to a single code or to a list.
49774978
// So, we treat the operators ~ and = to mean
49784979
// "some match exists between the LHS and RHS, with the appropriate operator"
49794980
// instead of the usual meaning

src/elm/external.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,19 @@ export class Retrieve extends Expression {
125125
if (rhs instanceof CodeSystem) {
126126
throw new Error("Operator '~' is not defined for Code ~ CodeSystem");
127127
} else if (rhs instanceof ValueSet) {
128-
// It's not obvious that this combination should even be allowed.
129-
// If in the CQL representation of the Retrieve, the terminology is a ValueSet,
130-
// eg [Condition: code ~ "SomeValueSet"],
131-
// the CQL-to-ELM translation may turn that into either:
132-
// - a `ValueSetRef` expression (appears here as a `ValueSet`)
133-
// - or an `ExpandValueSet` expression wrapping the `ValueSetRef` (appears here as a `Code[]`).
134-
// Because we can't tell the original intent here, we treat the ValueSet as if it were a Code[].
128+
// It's not obvious that code ~ ValueSet and code ~ Code[] should be allowed,
129+
// when code ~ CodeSystem is disallowed. Same for operator = below.
130+
// In short, due to various translator behaviors, when `rhs` here is Code[],
131+
// it's possible it was originally written in the CQL as a Code, a List<Code>, or a ValueSet.
132+
// We can't distinguish, so we have to allow all of them.
133+
// Then, again because of translator behaviors, x ~ ValueSet could reach this point
134+
// with `rhs` either being a Code[] or a ValueSet object.
135+
// Because we can't filter it out in the Code[] path, we should allow it in the ValueSet path as well
136+
// to reduce unexpected inconsistencies.
137+
// See full description and discussion at https://github.com/cqframework/cql-execution/pull/370
135138
return rhs.hasMatch(lhs);
136139
} else if (Array.isArray(rhs)) {
137-
// It's also not obvious that this should be allowed.
138-
// But because the RHS is always list-promoted, there's no way to tell
139-
// if the original CQL referred to a single code or to a list.
140+
// As noted above, there's no way to tell if the original CQL referred to a single code or to a list.
140141
// So, we treat the operators ~ and = to mean
141142
// "some match exists between the LHS and RHS, with the appropriate operator"
142143
// instead of the usual meaning

0 commit comments

Comments
 (0)