Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Context.childContext(null) to default to empty context_values object #282

Merged
merged 7 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions examples/browser/cql4browsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7868,9 +7868,9 @@ class Context {
findRecords(profile, retrieveDetails) {
return this.parent && this.parent.findRecords(profile, retrieveDetails);
}
childContext(context_values = {}) {
childContext(context_values) {
const ctx = new Context(this);
ctx.context_values = context_values;
ctx.context_values = context_values !== null && context_values !== void 0 ? context_values : {};
return ctx;
}
getLibraryContext(library) {
Expand Down Expand Up @@ -7998,7 +7998,7 @@ class Context {
for (const localId in libraryResults) {
const localIdResult = libraryResults[localId];
const existingResult = localIdResults[libraryId][localId];
// overwite this localid result if the existing result is "falsey". future work could track all results for each localid
// overwrite this localid result if the existing result is "falsey". future work could track all results for each localid
if (existingResult === false ||
existingResult === null ||
existingResult === undefined ||
Expand Down Expand Up @@ -8210,7 +8210,7 @@ class UnfilteredContext extends Context {
return this;
}
findRecords(_template) {
throw new exception_1.Exception('Retreives are not currently supported in Unfiltered Context');
throw new exception_1.Exception('Retrieves are not currently supported in Unfiltered Context');
}
getLibraryContext(_library) {
throw new exception_1.Exception('Library expressions are not currently supported in Unfiltered Context');
Expand All @@ -8221,10 +8221,11 @@ class UnfilteredContext extends Context {
return this.context_values[identifier];
}
//if not look to see if the library has a unfiltered expression of that identifier
if (this.library[identifier] && this.library[identifier].context === 'Unfiltered') {
if (this.library.expressions[identifier] &&
this.library.expressions[identifier].context === 'Unfiltered') {
return this.library.expressions[identifier];
}
//lastley attempt to gather all patient level results that have that identifier
//lastly attempt to gather all patient level results that have that identifier
// should this compact null values before return ?
return Object.values(this.results.patientResults).map((pr) => pr[identifier]);
}
Expand Down
84 changes: 52 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"coveralls": "^3.1.0",
"eslint": "^8.0.1",
"eslint-config-prettier": "^6.11.0",
"mocha": "^9.1.3",
"mocha": "^10.1.0",
"nyc": "^15.1.0",
"prettier": "^2.1.1",
"should": "^13.2.3",
Expand Down
26 changes: 15 additions & 11 deletions src/runtime/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import * as dt from '../datatypes/datatypes';
import { MessageListener, NullMessageListener } from './messageListeners';
import { Parameter } from '../types/runtime.types';
import { PatientObject, RetrieveDetails, TerminologyProvider } from '../types';
import { Library } from '../elm/library';

export class Context {
// Public Construcor args
// Public Constructor args
parent: any;
executionDateTime?: dt.DateTime;
messageListener?: MessageListener;

// Private Construcor args
// Private Constructor args
private _codeService?: TerminologyProvider | null;
private _parameters?: Parameter;

Expand All @@ -22,7 +23,7 @@ export class Context {
evaluatedRecords: any[];

constructor(
parent: Context,
parent: Context | Library,
mgramigna marked this conversation as resolved.
Show resolved Hide resolved
_codeService?: TerminologyProvider | null,
_parameters?: Parameter,
executionDateTime?: dt.DateTime,
Expand Down Expand Up @@ -80,9 +81,9 @@ export class Context {
return this.parent && this.parent.findRecords(profile, retrieveDetails);
}

childContext(context_values = {}) {
childContext(context_values?: any) {
const ctx = new Context(this);
ctx.context_values = context_values;
ctx.context_values = context_values ?? {};
return ctx;
}

Expand Down Expand Up @@ -223,7 +224,7 @@ export class Context {
for (const localId in libraryResults) {
const localIdResult = libraryResults[localId];
const existingResult = localIdResults[libraryId][localId];
// overwite this localid result if the existing result is "falsey". future work could track all results for each localid
// overwrite this localid result if the existing result is "falsey". future work could track all results for each localid
if (
existingResult === false ||
existingResult === null ||
Expand Down Expand Up @@ -420,7 +421,7 @@ export class Context {

export class PatientContext extends Context {
constructor(
public library: any,
public library: Library,
public patient?: PatientObject | null,
codeService?: TerminologyProvider | null,
parameters?: Parameter,
Expand Down Expand Up @@ -467,7 +468,7 @@ export class PatientContext extends Context {

export class UnfilteredContext extends Context {
constructor(
public library: any,
public library: Library,
public results: any,
codeService?: TerminologyProvider | null,
parameters?: Parameter,
Expand All @@ -482,7 +483,7 @@ export class UnfilteredContext extends Context {
}

findRecords(_template: any) {
throw new Exception('Retreives are not currently supported in Unfiltered Context');
throw new Exception('Retrieves are not currently supported in Unfiltered Context');
}

getLibraryContext(_library: any) {
Expand All @@ -495,10 +496,13 @@ export class UnfilteredContext extends Context {
return this.context_values[identifier];
}
//if not look to see if the library has a unfiltered expression of that identifier
if (this.library[identifier] && this.library[identifier].context === 'Unfiltered') {
if (
this.library.expressions[identifier] &&
this.library.expressions[identifier].context === 'Unfiltered'
) {
return this.library.expressions[identifier];
}
//lastley attempt to gather all patient level results that have that identifier
//lastly attempt to gather all patient level results that have that identifier
mgramigna marked this conversation as resolved.
Show resolved Hide resolved
// should this compact null values before return ?
return Object.values(this.results.patientResults).map((pr: any) => pr[identifier]);
}
Expand Down
4 changes: 2 additions & 2 deletions test/elm/library/library-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ describe('Using CommonLib and CommonLib2', () => {
should.exist(this.common2LocalIdObject[twoPlusOneLocalId]);
});

it('should contian TwoTimesThree localId in the localIdMap', function () {
it('should contain TwoTimesThree localId in the localIdMap', function () {
const twoTimesThreeLocalId = this.lib.includes.common2.expressions.TwoTimesThree.localId;
should.exist(this.common2LocalIdObject[twoTimesThreeLocalId]);
});
Expand Down Expand Up @@ -181,7 +181,7 @@ describe('Using CommonLib and CommonLib2 with namespace support', () => {
should.exist(this.common2LocalIdObject[twoPlusOneLocalId]);
});

it('should contian TwoTimesThree localId in the localIdMap with namespace support', function () {
it('should contain TwoTimesThree localId in the localIdMap with namespace support', function () {
const twoTimesThreeLocalId = this.lib.includes.common2.expressions.TwoTimesThree.localId;
should.exist(this.common2LocalIdObject[twoTimesThreeLocalId]);
});
Expand Down
Binary file modified test/generator/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion test/generator/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading