Skip to content

Commit

Permalink
Changed use of exec to execute for expressions (#314)
Browse files Browse the repository at this point in the history
Changed use of exec to execute for expressions so that local ids are more consistently recorded for coverage-tracking purposes.
  • Loading branch information
elsaperelli authored Aug 30, 2023
1 parent cc3ff79 commit 1d2d4ff
Show file tree
Hide file tree
Showing 10 changed files with 868 additions and 39 deletions.
16 changes: 8 additions & 8 deletions examples/browser/cql4browsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3751,7 +3751,7 @@ class AnyInValueSet extends expression_1.Expression {
if (valueset == null || !valueset.isValueSet) {
throw new Error('ValueSet must be provided to InValueSet function');
}
const codes = await this.codes.exec(ctx);
const codes = await this.codes.execute(ctx);
return codes != null && codes.some((code) => valueset.hasMatch(code));
}
}
Expand Down Expand Up @@ -5659,7 +5659,7 @@ class First extends expression_1.Expression {
this.source = (0, builder_1.build)(json.source);
}
async exec(ctx) {
const src = await this.source.exec(ctx);
const src = await this.source.execute(ctx);
if (src != null && (0, util_1.typeIsArray)(src) && src.length > 0) {
return src[0];
}
Expand All @@ -5675,7 +5675,7 @@ class Last extends expression_1.Expression {
this.source = (0, builder_1.build)(json.source);
}
async exec(ctx) {
const src = await this.source.exec(ctx);
const src = await this.source.execute(ctx);
if (src != null && (0, util_1.typeIsArray)(src) && src.length > 0) {
return src[src.length - 1];
}
Expand All @@ -5693,10 +5693,10 @@ class Slice extends expression_1.Expression {
this.endIndex = (0, builder_1.build)(json.endIndex);
}
async exec(ctx) {
const src = await this.source.exec(ctx);
const src = await this.source.execute(ctx);
if (src != null && (0, util_1.typeIsArray)(src)) {
const startIndex = await this.startIndex.exec(ctx);
const endIndex = await this.endIndex.exec(ctx);
const startIndex = await this.startIndex.execute(ctx);
const endIndex = await this.endIndex.execute(ctx);
const start = startIndex != null ? startIndex : 0;
const end = endIndex != null ? endIndex : src.length;
if (src.length === 0 || start < 0 || end < 0 || end < start) {
Expand Down Expand Up @@ -6559,11 +6559,11 @@ class AggregateClause extends expression_1.Expression {
this.distinct = json.distinct != null ? json.distinct : true;
}
async aggregate(returnedValues, ctx) {
let aggregateValue = this.starting != null ? await this.starting.exec(ctx) : null;
let aggregateValue = this.starting != null ? await this.starting.execute(ctx) : null;
for (const contextValues of returnedValues) {
const childContext = ctx.childContext(contextValues);
childContext.set(this.identifier, aggregateValue);
aggregateValue = await this.expression.exec(childContext);
aggregateValue = await this.expression.execute(childContext);
}
return aggregateValue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/elm/clinical.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class AnyInValueSet extends Expression {
throw new Error('ValueSet must be provided to InValueSet function');
}

const codes = await this.codes.exec(ctx);
const codes = await this.codes.execute(ctx);
return codes != null && codes.some((code: any) => valueset.hasMatch(code));
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/elm/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export class First extends Expression {
}

async exec(ctx: Context) {
const src = await this.source.exec(ctx);
const src = await this.source.execute(ctx);
if (src != null && typeIsArray(src) && src.length > 0) {
return src[0];
} else {
Expand All @@ -251,7 +251,7 @@ export class Last extends Expression {
}

async exec(ctx: Context) {
const src = await this.source.exec(ctx);
const src = await this.source.execute(ctx);
if (src != null && typeIsArray(src) && src.length > 0) {
return src[src.length - 1];
} else {
Expand All @@ -273,10 +273,10 @@ export class Slice extends Expression {
}

async exec(ctx: Context) {
const src = await this.source.exec(ctx);
const src = await this.source.execute(ctx);
if (src != null && typeIsArray(src)) {
const startIndex = await this.startIndex.exec(ctx);
const endIndex = await this.endIndex.exec(ctx);
const startIndex = await this.startIndex.execute(ctx);
const endIndex = await this.endIndex.execute(ctx);
const start = startIndex != null ? startIndex : 0;
const end = endIndex != null ? endIndex : src.length;
if (src.length === 0 || start < 0 || end < 0 || end < start) {
Expand Down
4 changes: 2 additions & 2 deletions src/elm/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ class AggregateClause extends Expression {
}

async aggregate(returnedValues: any, ctx: Context) {
let aggregateValue = this.starting != null ? await this.starting.exec(ctx) : null;
let aggregateValue = this.starting != null ? await this.starting.execute(ctx) : null;
for (const contextValues of returnedValues) {
const childContext = ctx.childContext(contextValues);
childContext.set(this.identifier, aggregateValue);
aggregateValue = await this.expression.exec(childContext);
aggregateValue = await this.expression.execute(childContext);
}
return aggregateValue;
}
Expand Down
21 changes: 21 additions & 0 deletions test/elm/clinical/clinical-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,27 @@ describe('ValueSetRef', () => {
});
});

describe('AnyInValueSet', () => {
beforeEach(function () {
setup(this, data, [], vsets);
});

it('should call execute on codes which is a list of concepts', async function () {
(await this.anyInListOfConcepts.exec(this.ctx)).should.be.true();
should(this.ctx.localId_context[this.anyInListOfConcepts.codes.localId]).not.be.undefined();
});

it('should call execute on codes which is a list of codes', async function () {
(await this.anyInListOfCodes.exec(this.ctx)).should.be.true();
should(this.ctx.localId_context[this.anyInListOfCodes.codes.localId]).not.be.undefined();
});

it('should call execute on codes which is a list of strings', async function () {
(await this.anyInListOfStrings.exec(this.ctx)).should.be.true();
should(this.ctx.localId_context[this.anyInListOfStrings.codes.localId]).not.be.undefined();
});
});

describe('InValueSet', () => {
beforeEach(function () {
setup(this, data, [], vsets);
Expand Down
11 changes: 10 additions & 1 deletion test/elm/clinical/data.cql
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ define Foo: 'Bar'
valueset "Acute Pharyngitis": '2.16.840.1.113883.3.464.1003.101.12.1001'
define Foo: "Acute Pharyngitis"

// @Test: AnyInValueSet
valueset "Major Depressive Disorder Active": '2.16.840.1.113883.3.526.3.1491'
codesystem "SNOMED": 'http://snomed.info/sct'
code "ChronicRecurrentDepression": '2618002' from "SNOMED" display 'Chronic recurrent major depressive disorder (disorder)'
code "ModerateMajorDepression": '832007' from "SNOMED" display 'Moderate major depression (disorder)'
concept "Depression Concept": { "ChronicRecurrentDepression", "ModerateMajorDepression" } display 'Depression Concept'
define AnyInListOfConcepts: { "Depression Concept" } in "Major Depressive Disorder Active"
define AnyInListOfCodes: { "ChronicRecurrentDepression", "ModerateMajorDepression" } in "Major Depressive Disorder Active"
define AnyInListOfStrings: { '2618002', '12345' } in "Major Depressive Disorder Active"

// @Test: InValueSet
valueset "Female": '2.16.840.1.113883.3.560.100.2'
valueset "Versioned Female": '2.16.840.1.113883.3.560.100.2' version '20121025'
Expand Down Expand Up @@ -35,7 +45,6 @@ define InWrongListOfCodes: WrongListOfCodes in "Female"
define ListOfCodesWithNull: { Code { code: 'M' }, (null as Code), Code { code: 'F', system: '2.16.840.1.113883.18.2' } } in "Female"
define ListOfCodesNull: (null as List<Code>) in "Female"


// @Test: Patient Property In ValueSet
valueset "Female": '2.16.840.1.113883.3.560.100.2'
define IsFemale: Patient.gender in "Female"
Expand Down
Loading

0 comments on commit 1d2d4ff

Please sign in to comment.