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

MAT-7246 get valueset version #171

Merged
merged 1 commit into from
Jun 12, 2024
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
28 changes: 14 additions & 14 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions src/CqlAntlrListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ export default class CqlAntlrListener implements cqlListener {
}

enterValuesetDefinition(ctx: ValuesetDefinitionContext): void {
const cqlCode: CqlValueSet | undefined = new CqlValueSetSystemCreator(ctx).buildDao();
const cqlValueSet: CqlValueSet | undefined = new CqlValueSetSystemCreator(ctx, this.cqlResult.using?.name).buildDao();

if (cqlCode) {
this.cqlResult.valueSets.push(cqlCode);
if (cqlValueSet) {
this.cqlResult.valueSets.push(cqlValueSet);
}
}

Expand Down
13 changes: 12 additions & 1 deletion src/CqlCodeValueSystemCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,25 @@ import CreatorBase from "./CreatorBase";
import CqlValueSet from "./dto/CqlValueSet";
import {cqlLexer} from "../generated";

type StringOrUndefined = undefined | string;

export default class CqlValueSetSystemCreator extends CreatorBase<CqlValueSet> {
constructor(ctx: ParserRuleContext) {
model: StringOrUndefined

constructor(ctx: ParserRuleContext, model: StringOrUndefined) {
super(ctx, {} as CqlValueSet);
this.model = model;
}

protected build(): CqlValueSet {
this.cqlDao.name = this.findChildText(cqlLexer.QUOTEDIDENTIFIER);
this.cqlDao.url = this.findChildText(cqlLexer.STRING);
if (this.model === "QDM") {
this.cqlDao.version = this.findChildText(cqlLexer.STRING, 2);
} else {
const tokens = this.cqlDao.url?.split("|");
this.cqlDao.version = tokens?.length === 2 ? tokens[1] : undefined
}
this.cqlDao.hits = 0;
return this.cqlDao;
}
Expand Down
4 changes: 2 additions & 2 deletions src/dto/CqlValueSet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import CqlText from "./CqlText";
import CqlVersion from "./CqlVersion";

export default interface CqlValueSet extends CqlText {
export default interface CqlValueSet extends CqlVersion {
url?: string;
hits: number;
}
19 changes: 16 additions & 3 deletions test/CqlAntlr.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
testCql,
fhirTestCql,
qdmTestCql,
cqlWithSyntaxErrors,
cqlWithUsedParam,
cqlWithUsedDefines,
Expand All @@ -13,8 +14,8 @@
import CqlResult from "../src/dto/CqlResult";

describe("test antlr", () => {
it("parse", () => {
const cqlAntlr = new CqlAntlr(testCql);
it("parse fhir cql", () => {

Check failure on line 17 in test/CqlAntlr.test.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

test/CqlAntlr.test.ts#L17

Unsafe call of an `any` typed value.
const cqlAntlr = new CqlAntlr(fhirTestCql);

const cqlResult: CqlResult = cqlAntlr.parse();

Expand All @@ -29,6 +30,18 @@
expect(cqlResult.expressionDefinitions.length).toEqual(7);
expect(cqlResult.retrieves.length).toEqual(1);
});

it("parse qdm cql", () => {
const cqlAntlr = new CqlAntlr(qdmTestCql);
const cqlResult: CqlResult = cqlAntlr.parse();

expect(cqlResult.using?.name).toBe("QDM");
expect(cqlResult.valueSets.length).toBe(2);
expect(cqlResult.valueSets[0].name).toBe("\"Adolescent depression screening assessment\"");
expect(cqlResult.valueSets[0].version).toBeUndefined();
expect(cqlResult.valueSets[1].name).toBe("\"Adolescent depression screening assessment with version\"");
expect(cqlResult.valueSets[1].version).toBe("'urn:hl7:version:20240307'");
});

it("reports syntactical errors", () => {
const cqlAntlr = new CqlAntlr(cqlWithSyntaxErrors);
Expand Down
11 changes: 9 additions & 2 deletions test/testCql.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const testCql = `library TJCOverall_FHIR4 version '4.0.000'
const fhirTestCql = `library TJCOverall_FHIR4 version '4.0.000'

using FHIR version '4.0.0'
// NOTE: BTR 2019-07-30: Updated version dependencies
Expand Down Expand Up @@ -52,6 +52,12 @@ define "Antithrombotic Not Given at Discharge":
and NoAntithromboticDischarge.status = 'completed'
and NoAntithromboticDischarge.intent = 'order'
`;
const qdmTestCql = `
library PreventiveCareScreeningFollowUpPlan version '0.0.000'
using QDM version '5.6'
valueset "Adolescent depression screening assessment": 'urn:oid:2.16.840.1.113762.1.4.1260.162'
valueset "Adolescent depression screening assessment with version": 'urn:oid:2.16.840.1.113762.1.4.1260.162' version 'urn:hl7:version:20240307'
`

const cqlWithSyntaxErrors = `library TJCOverall_FHIR4 version '4.0.000'

Expand Down Expand Up @@ -170,7 +176,8 @@ define FactorialOfFive:
`

export {
testCql,
fhirTestCql,
qdmTestCql,
cqlWithSyntaxErrors,
cqlWithUsedParam,
cqlWithUsedDefines,
Expand Down
Loading