Skip to content

Commit 0ec159b

Browse files
committed
fix TODO comment, explain why ~ VS is the same as in VA
1 parent 75fde9e commit 0ec159b

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

src/elm/external.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,22 @@ 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-
// TODO: explain
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[].
129135
return rhs.hasMatch(lhs);
130-
} else {
136+
} 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+
// So, we treat the operators ~ and = to mean
141+
// "some match exists between the LHS and RHS, with the appropriate operator"
142+
// instead of the usual meaning
143+
// "the LHS and RHS themselves are a match, with the appropriate operator"
131144
return (rhs as Code[]).some(c => c.hasMatch(lhs));
132145
} else {
133146
// Unexpected, but just in case a single code came through

0 commit comments

Comments
 (0)