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

Initial must supports added to data requirement #294

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
Draft
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
2,618 changes: 2,618 additions & 0 deletions src/code-attributes/propertyPaths.ts

Large diffs are not rendered by default.

394 changes: 389 additions & 5 deletions src/helpers/DataRequirementHelpers.ts

Large diffs are not rendered by default.

21 changes: 20 additions & 1 deletion src/helpers/elm/ELMHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,28 @@
}
}
return null;
} else if (expression.localId == localId) {
} else if (expression.localId === localId) {
return expression as ELMExpression;
} else {
return findClauseInExpression(Object.values(expression), localId);
}
}

/**
* Recursively search an ELM tree for all expression (clause) with a given name
*
* @param expression The expression tree to search for the clause in.
* @param name The name to look for.
* @returns The expression if found or null.
*/
export function findNamedClausesInExpression(expression: any, name: string): ELMExpression[] {

Check warning on line 53 in src/helpers/elm/ELMHelpers.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
if (typeof expression === 'string' || typeof expression === 'number' || typeof expression === 'boolean') {

Check warning on line 54 in src/helpers/elm/ELMHelpers.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 54 in src/helpers/elm/ELMHelpers.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 54 in src/helpers/elm/ELMHelpers.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
return [];

Check warning on line 55 in src/helpers/elm/ELMHelpers.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
} else if (Array.isArray(expression)) {
return expression.flatMap(elem => findNamedClausesInExpression(elem, name));

Check warning on line 57 in src/helpers/elm/ELMHelpers.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 57 in src/helpers/elm/ELMHelpers.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 57 in src/helpers/elm/ELMHelpers.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
} else if (expression.name === name) {
return [expression as ELMExpression];

Check warning on line 59 in src/helpers/elm/ELMHelpers.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
} else {
return findNamedClausesInExpression(Object.values(expression), name);

Check warning on line 61 in src/helpers/elm/ELMHelpers.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 62 in src/helpers/elm/ELMHelpers.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 62 in src/helpers/elm/ELMHelpers.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 62 in src/helpers/elm/ELMHelpers.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 62 in src/helpers/elm/ELMHelpers.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 62 in src/helpers/elm/ELMHelpers.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 62 in src/helpers/elm/ELMHelpers.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 62 in src/helpers/elm/ELMHelpers.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 62 in src/helpers/elm/ELMHelpers.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 62 in src/helpers/elm/ELMHelpers.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
}
2 changes: 1 addition & 1 deletion src/helpers/elm/QueryFilterParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@
*/
function parseSources(query: ELMQuery): SourceInfo[] {
const sources: SourceInfo[] = [];
const querySources = [...query.source, ...query.relationship];
const querySources = [...query.source, ...(query.relationship || [])];

Check warning on line 236 in src/helpers/elm/QueryFilterParser.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

querySources.forEach(source => {
if (source.expression.type == 'Retrieve') {
Expand Down
7 changes: 7 additions & 0 deletions src/helpers/elm/RetrievesHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,13 @@ export function findRetrieves(
}

query.relationship?.forEach(relationshipClause => {
if (relationshipClause.localId) {
recursiveOpts.expressionStack.push({
libraryName: elm.library.identifier.id,
localId: relationshipClause.localId,
type: relationshipClause.type
});
}
recurse(results, relationshipClause.expression, recursiveOpts);
recurse(results, relationshipClause.suchThat, recursiveOpts);
});
Expand Down
2 changes: 2 additions & 0 deletions src/types/Calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ export interface DataTypeQuery {
queryInfo?: QueryInfo;
/** specifies an optional template/profile for the objects that the retrieve returns to conform to */
templateId?: string;
/** array of fields that must be supported in association with this retrieve */
mustSupport?: string[];
}

export interface GapsDataTypeQuery extends DataTypeQuery {
Expand Down
3 changes: 2 additions & 1 deletion src/types/ELMTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export interface ELMQuery extends ELMExpression {
type: 'Query';
source: ELMAliasedQuerySource[];
let?: ELMLetClause[];
relationship: ELMRelationshipClause[];
relationship?: ELMRelationshipClause[];
where?: AnyELMExpression;
return?: ELMReturnClause;
sort?: any;
Expand All @@ -253,6 +253,7 @@ export interface ELMAliasedQuerySource {

export interface ELMRelationshipClause extends ELMAliasedQuerySource {
suchThat: AnyELMExpression;
type: string;
}

export interface ELMLetClause {
Expand Down
236 changes: 236 additions & 0 deletions test/unit/DataRequirementHelpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { CalculationOptions, DataTypeQuery } from '../../src/types/Calculator';
import { DataRequirement } from 'fhir/r4';
import { DateTime, Interval } from 'cql-execution';
import moment from 'moment';
import { ELM, ELMAliasedQuerySource, ELMQuery } from '../../src';

describe('DataRequirementHelpers', () => {
describe('generateDataRequirement', () => {
Expand Down Expand Up @@ -308,4 +309,239 @@ describe('DataRequirementHelpers', () => {
);
});
});
describe('findPropertyExpressions', () => {
test('find properties in array', () => {
const expression = {
type: 'anyType',
localId: '0',
anyField: [
{
localId: '1',
type: 'Property'
},
{
localId: '2',
type: 'Other'
},
{
localId: '3',
type: 'Property'
}
]
};
const elm: ELM = {
library: {
identifier: {
id: 'libraryId',
version: 'libraryVersion'
},
schemaIdentifier: {
id: 'schemaId',
version: 'schemaVersion'
},
usings: {},
statements: {
def: [
{
name: 'testStatement',
context: 'Patient',
expression: expression
}
]
}
}
};
const propertyExpressions = DataRequirementHelpers.findPropertyExpressions(expression, [], elm, [elm]);
const expectedPropertyExpressions = [
{
property: {
localId: '1',
type: 'Property'
},
stack: [
{
type: 'anyType',
localId: '0',
libraryName: 'libraryId'
}
]
},
{
property: {
localId: '3',
type: 'Property'
},
stack: [
{
type: 'anyType',
localId: '0',
libraryName: 'libraryId'
}
]
}
];

expect(propertyExpressions).toEqual(expectedPropertyExpressions);
});

test('find properties in object', () => {
const expression = {
type: 'anyType',
localId: '0',
anyField1: {
localId: '1',
type: 'Property'
},
anyField2: {
localId: '2',
type: 'Other'
},
anyField3: {
localId: '3',
type: 'Property'
}
};
const elm: ELM = {
library: {
identifier: {
id: 'libraryId',
version: 'libraryVersion'
},
schemaIdentifier: {
id: 'schemaId',
version: 'schemaVersion'
},
usings: {},
statements: {
def: [
{
name: 'testStatement',
context: 'Patient',
expression: expression
}
]
}
}
};
const propertyExpressions = DataRequirementHelpers.findPropertyExpressions(expression, [], elm, [elm]);
const expectedPropertyExpressions = [
{
property: {
localId: '1',
type: 'Property'
},
stack: [
{
type: 'anyType',
localId: '0',
libraryName: 'libraryId'
}
]
},
{
property: {
localId: '3',
type: 'Property'
},
stack: [
{
type: 'anyType',
localId: '0',
libraryName: 'libraryId'
}
]
}
];

expect(propertyExpressions).toEqual(expectedPropertyExpressions);
});
});

describe('findRetrieveMatches', () => {
test('simple retrieve match', () => {
const stack = [
{
type: 'Query',
localId: '0',
libraryName: 'libraryId'
}
];
const retrieve: DataTypeQuery = {
dataType: 'fhir_type',
path: 'status',
templateId: 'http://hl7.org/fhir/StructureDefinition/fhir_type',
expressionStack: stack,
retrieveLocalId: '1'
};
const property: DataRequirementHelpers.PropertyTracker = {
property: {
localId: '2',
type: 'Property',
path: 'status',
scope: 'TestScope'
},
stack: stack
};
const expression: ELMQuery = {
type: 'Query',
localId: '0',
source: [
{
alias: 'TestScope',
expression: {
type: 'Retrieve',
localId: '1'
}
}
],
relationship: [],
where: property.property
};
const elm: ELM = {
library: {
identifier: {
id: 'libraryId',
version: 'libraryVersion'
},
schemaIdentifier: {
id: 'schemaId',
version: 'schemaVersion'
},
usings: {},
statements: {
def: [
{
name: 'testStatement',
context: 'Patient',
expression: expression
}
]
}
}
};
const expectedRetrieveMatches = [retrieve];
const retrieveMatches = DataRequirementHelpers.findRetrieveMatches(property, [retrieve], [elm]);
expect(retrieveMatches).toEqual(expectedRetrieveMatches);
});
});

describe('findSourceWithScope', () => {
test('simple source', () => {
const source: ELMAliasedQuerySource = {
expression: {
type: 'AnyType',
localId: '1'
},
alias: 'testScope'
};
const expression: ELMQuery = {
type: 'Query',
localId: '0',
relationship: [],
source: [source]
};

expect(DataRequirementHelpers.findSourcewithScope(expression, 'testScope')).toEqual(source);
});
});
});
Loading