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

Coverage 3.14.0 #314

Merged
merged 4 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Library for calculating Electronic Clinical Quality Measures (eCQMs) written in
- [Recipes](#recipes)
- [Displaying Highlighted HTML in a React App](#displaying-highlighted-html-in-a-react-app)
- [Usage Within a FHIR Server](#usage-within-a-fhir-server)
- [Special Testing](#special-testing)
- [Contributing](#contributing)
- [License](#license)

Expand Down
34 changes: 32 additions & 2 deletions src/helpers/ClauseResultsHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ELMFunctionRef } from '../types/ELMTypes';
import { ELM, ELMBinaryExpression, ELMStatement } from '../types/ELMTypes';

/**
* Finds all localIds in a statement by it's library and statement name.
* Finds all localIds in a statement by its library and statement name.
lmd59 marked this conversation as resolved.
Show resolved Hide resolved
* @public
* @param {ELM} libraryElm - The library the statement belongs to.
* @param {string} statementName - The statement name to search for.
Expand Down Expand Up @@ -49,7 +49,37 @@ export function findAllLocalIdsInStatementByName(libraryElm: ELM, statementName:
clause.isUnsupported = true;
}
}
return localIds;

// find all localids in the annotation
const allAnnotatedIds = findAnnotationLocalIds(statement?.annotation);
// filter out local ids that aren't in the annotation
const annotatedLocalIds: { [key: string]: any } = {};
lmd59 marked this conversation as resolved.
Show resolved Hide resolved
for (const [key, value] of Object.entries(localIds)) {
if (allAnnotatedIds.includes(key)) {
annotatedLocalIds[key] = value;
}
}
return annotatedLocalIds;
}

/**
* Recursively finds just localIds that are in an annotation structure by pulling out all "r:"-keyed values
lmd59 marked this conversation as resolved.
Show resolved Hide resolved
* @public
* @param {object} annotation - all or a subset of the annotation structure to search
* @return {Array} List of local ids in the annotation.
*/
function findAnnotationLocalIds(annotation: any): string[] {
if (Array.isArray(annotation)) {
return annotation.flatMap(ent => findAnnotationLocalIds(ent));
} else if (typeof annotation === 'object') {
return Object.entries(annotation).flatMap(ent => {
// if key is r, return value, else recurse
if (ent[0] === 'r') return ent[1] as string;
return findAnnotationLocalIds(ent[1]);
});
}
// default empty
return [];
}

/**
Expand Down
30 changes: 22 additions & 8 deletions test/unit/ClauseResultsHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ describe('ClauseResultsHelpers', () => {
const localIds = ClauseResultsHelpers.findAllLocalIdsInStatementByName(libraryElm, statementName);

// For the fixture loaded for this test it is known that the localId for the Equivalent statement
// is 23 and the localId for the Not expression is 24 but we want the Equivalent clause to take
// the result of the Not expression
expect(localIds[23]).toBeDefined();
expect(localIds[23]).toEqual({ localId: '23', sourceLocalId: '24' });
// is 23 and the localId for the Not expression is 24. We want 23 to not be included because 24 is
// the correct id from the annotation.
expect(localIds[23]).not.toBeDefined();
expect(localIds[24]).toBeDefined();
});

test('finds localIds for an Equal comparison operator that is wrapped in a Not expression', () => {
Expand All @@ -28,10 +28,24 @@ describe('ClauseResultsHelpers', () => {
const localIds = ClauseResultsHelpers.findAllLocalIdsInStatementByName(libraryElm, statementName);

// For the fixture loaded for this test it is known that the localId for the Equal statement
// is 100 and the localId for the Not expression is 23 but we want the Equal clause to take
// the result of the Not expression
expect(localIds[100]).toBeDefined();
expect(localIds[100]).toEqual({ localId: '100', sourceLocalId: '23' });
// is 100, and the localId for the Not expression is 23. We want 100 to not be included because 23 is
// the correct id from the annotation.
expect(localIds[23]).toBeDefined();
expect(localIds[100]).not.toBeDefined();
});

test('finds localIds for an not null operator', () => {
lmd59 marked this conversation as resolved.
Show resolved Hide resolved
// ELM from test/unit/fixtures/cql/NotNull.cql, translated with 3.15.0 translator
const libraryElm: ELM = getJSONFixture('elm/3.15.0/NotNull.json');

const statementName = 'Not Null Clause';
const localIds = ClauseResultsHelpers.findAllLocalIdsInStatementByName(libraryElm, statementName);

// For the fixture loaded for this test it is known that the localId for the IsNull statement
// is 237, and the localId for the Not expression is 238. We want 237 to not be included because 238 is
// the correct id from the annotation.
expect(localIds[238]).toBeDefined();
expect(localIds[237]).not.toBeDefined();
});

test('finds localIds for an ELM Binary Expression with a comparison operator with a literal', () => {
Expand Down
24 changes: 24 additions & 0 deletions test/unit/fixtures/cql/NotNull.cql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
library Test

using FHIR version '4.0.1'

include FHIRHelpers version '4.0.1'
include MATGlobalCommonFunctions version '5.0.000' called Global

codesystem "EXAMPLE": 'http://example.com'
codesystem "EXAMPLE-2": 'http://example.com/2'
codesystem "ConditionClinicalStatusCodes": 'http://terminology.hl7.org/CodeSystem/condition-clinical'

valueset "test-vs": 'http://example.com/test-vs'

code "Active": 'active' from "ConditionClinicalStatusCodes"
code "Recurrence": 'recurrence' from "ConditionClinicalStatusCodes"
code "Relapse": 'relapse' from "ConditionClinicalStatusCodes"

concept "Condition Active": { "Active", "Recurrence", "Relapse" } display 'Active'

context Patient

define "Not Null Clause":
[Condition: "test-vs"] C
where C.id is not null
Loading
Loading