@@ -364,6 +364,19 @@ class ValueSet {
364364 get isValueSet() {
365365 return true;
366366 }
367+ /**
368+ * Determines if the provided code matches any code in the current set.
369+ * If the input is a single string, it checks for a direct match with the
370+ * codes in the set, ensuring all code systems are consistent. Throws an
371+ * error if multiple code systems exist and a match is found, indicating
372+ * ambiguity. For other inputs, it checks for any matching codes using
373+ * the `codesInList` function. Used for the `code in valueset` operation.
374+ *
375+ * @param code - The code to be checked for a match, which can be a string
376+ * or an object containing codes.
377+ * @returns {boolean} True if a match is found, otherwise false.
378+ * @throws {Error} If a match is found with multiple code systems present.
379+ */
367380 hasMatch(code) {
368381 const codesList = toCodeList(code);
369382 // InValueSet String Overload
@@ -388,6 +401,31 @@ class ValueSet {
388401 return codesInList(codesList, this.codes);
389402 }
390403 }
404+ /**
405+ * Expands the current set of codes by returning a list of unique `Code` objects.
406+ * This method filters out duplicate codes from the `codes` array, ensuring each
407+ * code appears only once in the returned list. Use for the ExpandValueset operator
408+ *
409+ * @returns {Code[]} An array of unique `Code` objects.
410+ */
411+ expand() {
412+ const expanded = [];
413+ this.codes.forEach(code => {
414+ const foundUniqueCode = expanded.find(uniqueCode => {
415+ if (uniqueCode == null || code == null) {
416+ return true;
417+ }
418+ return (uniqueCode.code === code.code &&
419+ uniqueCode.system == code.system &&
420+ uniqueCode.version == code.version &&
421+ uniqueCode.display == code.display);
422+ });
423+ if (!foundUniqueCode) {
424+ expanded.push(code);
425+ }
426+ });
427+ return expanded;
428+ }
391429}
392430exports.ValueSet = ValueSet;
393431function toCodeList(c) {
@@ -3714,7 +3752,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
37143752 return result;
37153753};
37163754Object.defineProperty(exports, "__esModule", { value: true });
3717- exports.CalculateAgeAt = exports.CalculateAge = exports.Concept = exports.ConceptRef = exports.ConceptDef = exports.Code = exports.CodeRef = exports.CodeDef = exports.CodeSystemDef = exports.InValueSet = exports.AnyInValueSet = exports.ValueSetRef = exports.ValueSetDef = void 0;
3755+ exports.CalculateAgeAt = exports.CalculateAge = exports.Concept = exports.ConceptRef = exports.ConceptDef = exports.Code = exports.CodeRef = exports.CodeDef = exports.CodeSystemDef = exports.ExpandValueSet = exports. InValueSet = exports.AnyInValueSet = exports.ValueSetRef = exports.ValueSetDef = void 0;
37183756const expression_1 = require("./expression");
37193757const dt = __importStar(require("../datatypes/datatypes"));
37203758const builder_1 = require("./builder");
@@ -3795,6 +3833,23 @@ class InValueSet extends expression_1.Expression {
37953833 }
37963834}
37973835exports.InValueSet = InValueSet;
3836+ class ExpandValueSet extends expression_1.Expression {
3837+ constructor(json) {
3838+ super(json);
3839+ this.valueset = new ValueSetRef(json.operand);
3840+ }
3841+ async exec(ctx) {
3842+ const valueset = await this.valueset.execute(ctx);
3843+ if (valueset == null) {
3844+ return null;
3845+ }
3846+ else if (!valueset.isValueSet) {
3847+ throw new Error('ExpandValueSet function invoked on object that is not a ValueSet');
3848+ }
3849+ return valueset.expand();
3850+ }
3851+ }
3852+ exports.ExpandValueSet = ExpandValueSet;
37983853class CodeSystemDef extends expression_1.Expression {
37993854 constructor(json) {
38003855 super(json);
0 commit comments