Skip to content

Commit

Permalink
Merge pull request #723 from MeasureAuthoringTool/MAT-7530
Browse files Browse the repository at this point in the history
MAT-7530 QiCore value set apply
  • Loading branch information
adongare authored Jan 3, 2025
2 parents 19505f0 + 17872d8 commit c678e64
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/components/editMeasure/editor/MeasureEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ const MeasureEditor = () => {
setRefValueSetDetails(vs);
const result = applyValueset(
editorVal,
measure.model,
vs,
prevSelectedValueSetDetails?.current
); // should have updated editorVal but doesn't
Expand Down
92 changes: 81 additions & 11 deletions src/components/editMeasure/editor/valuesetApplier.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import applyValueset from "./valuesetApplier.ts";
import applyValueset from "./valuesetApplier";
import * as fs from "fs";
import { CqlApplyActionResult } from "./CqlApplyActionResult";
import { Model } from "@madie/madie-models";

it("Should add valuset to CQL that does not exist when no valusets present", () => {
const cql = fs.readFileSync(
Expand All @@ -13,7 +14,11 @@ it("Should add valuset to CQL that does not exist when no valusets present", ()
);

const valuset = JSON.parse(valusetJson);
const result: CqlApplyActionResult = applyValueset(cql, valuset);
const result: CqlApplyActionResult = applyValueset(
cql,
Model.QDM_5_6,
valuset
);
expect(result.cql).toContain("Emergency Department Evaluation");
expect(result.status).toBeTruthy();
expect(result.message).toEqual(
Expand All @@ -32,7 +37,11 @@ it("Should add valuset to CQL that does not exist when valususets are present",
);

const valuset = JSON.parse(valusetJson);
const result: CqlApplyActionResult = applyValueset(cql, valuset);
const result: CqlApplyActionResult = applyValueset(
cql,
Model.QDM_5_6,
valuset
);
expect(result.cql).toContain("Emergency Department Evaluation");
expect(result.status).toBeTruthy();
expect(result.message).toEqual(
Expand All @@ -51,8 +60,8 @@ it("Should not add a valuset that already exists", () => {
);

const valuset = JSON.parse(valusetJson);
let result: CqlApplyActionResult = applyValueset(cql, valuset);
result = applyValueset(result.cql, valuset);
let result: CqlApplyActionResult = applyValueset(cql, Model.QDM_5_6, valuset);
result = applyValueset(result.cql, Model.QDM_5_6, valuset);
expect(cql).toContain(
"valueset \"Ethnicity\": 'urn:oid:2.16.840.1.114222.4.11.837'"
);
Expand All @@ -74,7 +83,7 @@ it("Should add valuset, priotiy location usings array", () => {
"valueset \"Ethnicity\": 'urn:oid:2.16.840.1.114222.4.11.837'"
);
const valuset = JSON.parse(valusetJson);
let result: CqlApplyActionResult = applyValueset(cql, valuset);
let result: CqlApplyActionResult = applyValueset(cql, Model.QDM_5_6, valuset);
expect(result.cql).toContain(
"valueset \"Ethnicity\": 'urn:oid:2.16.840.1.114222.4.11.837'"
);
Expand All @@ -95,7 +104,7 @@ it("Should add valuset, priotiy location includes array", () => {
);

const valuset = JSON.parse(valusetJson);
let result: CqlApplyActionResult = applyValueset(cql, valuset);
let result: CqlApplyActionResult = applyValueset(cql, Model.QDM_5_6, valuset);
expect(cql).not.toContain(
"valueset \"Ethnicity\": 'urn:oid:2.16.840.1.114222.4.11.837'"
);
Expand All @@ -122,7 +131,7 @@ it("Should add valuset, priotiy location valuset array", () => {
expect(cql).not.toContain(
"valueset \"Ethnicity\": 'urn:oid:2.16.840.1.114222.4.11.837'"
);
let result: CqlApplyActionResult = applyValueset(cql, valuset);
let result: CqlApplyActionResult = applyValueset(cql, Model.QDM_5_6, valuset);
expect(result.cql).toContain(
"valueset \"Ethnicity\": 'urn:oid:2.16.840.1.114222.4.11.837'"
);
Expand All @@ -143,7 +152,11 @@ it("Should not add valuset to CQL when value set was already added", () => {
);

const valuset = JSON.parse(valusetJson);
const result: CqlApplyActionResult = applyValueset(cql, valuset);
const result: CqlApplyActionResult = applyValueset(
cql,
Model.QDM_5_6,
valuset
);
expect(result.cql).toContain("Emergency Department Evaluation");
expect(result.status).toBe("info");
expect(result.message).toEqual(
Expand All @@ -162,7 +175,11 @@ it("Should remove valuset suffix to already present CQL", () => {
);

const valuset = JSON.parse(valusetJson);
const result: CqlApplyActionResult = applyValueset(cql, valuset);
const result: CqlApplyActionResult = applyValueset(
cql,
Model.QDM_5_6,
valuset
);
expect(result.cql).not.toContain("Emergency Department Evaluation (1)");
expect(result.cql).toContain("Emergency Department Evaluation");
expect(result.status).toBe("success");
Expand All @@ -182,11 +199,64 @@ it("Should add valuset suffix to already present CQL", () => {
);

const valuset = JSON.parse(valusetJson);
const result: CqlApplyActionResult = applyValueset(cql, valuset);
const result: CqlApplyActionResult = applyValueset(
cql,
Model.QDM_5_6,
valuset
);
expect(result.cql).toContain("Emergency Department Evaluation (1)");
expect(result.cql).not.toContain('Emergency Department Evaluation":');
expect(result.status).toBe("success");
expect(result.message).toEqual(
`Value Set Emergency Department Evaluation (1) has been successfully updated in the CQL.`
);
});

it("should add a new value set", () => {
const cql =
"library SimpleEncounterMeasure version '4.0.000'\n" +
"using QICore version '4.1.1'";
const valueSet = {
title: "Sex",
name: "Sex",
url: "http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1240.3",
oid: "urn:oid:2.16.840.1.113762.1.4.1240.3",
};
const result: CqlApplyActionResult = applyValueset(
cql,
Model.QICORE_6_0_0,
valueSet
);
expect(result.cql).toContain(valueSet.name);
expect(result.cql).toContain(valueSet.url);
expect(result.status).toBe("success");
expect(result.message).toEqual(
`Value Set Sex has been successfully added to the CQL.`
);
});

it("should update an existing value set if exists", () => {
const cql =
"library SimpleEncounterMeasure version '4.0.000'\n" +
"using QICore version '4.1.1'\n" +
"valueset \"Sex\": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1240.3'";
const valueSet = {
title: "Sex",
name: "Sex",
url: "http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1240.3",
oid: "urn:oid:2.16.840.1.113762.1.4.1240.3",
suffix: "1",
};
const result: CqlApplyActionResult = applyValueset(
cql,
Model.QICORE_6_0_0,
valueSet,
{ ...valueSet, name: "Sex" }
);
expect(result.cql).toContain("Sex");
expect(result.cql).toContain(valueSet.url);
expect(result.status).toBe("success");
expect(result.message).toEqual(
`Value Set Sex (1) has been successfully updated in the CQL.`
);
});
11 changes: 7 additions & 4 deletions src/components/editMeasure/editor/valuesetApplier.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CqlAntlr, CqlResult } from "@madie/cql-antlr-parser/dist/src";
import { ValueSetForSearch } from "@madie/madie-editor";
import { CqlApplyActionResult } from "./CqlApplyActionResult";
import { Model } from "@madie/madie-models";

// given correct vs line order and the cqlArr, splice in the declarations
const sortCQLValuesetsInPlace = (
Expand Down Expand Up @@ -147,6 +148,7 @@ const getValueSetTitleName = (vs) => {

const applyValueset = (
cql: string,
measureModel: Model,
vs: ValueSetForSearch,
previousVs?: ValueSetForSearch
): CqlApplyActionResult => {
Expand All @@ -157,13 +159,14 @@ const applyValueset = (
let vsExactExists: boolean = false;
let vsSameTitleExist: boolean = false;

// are there valuesets at all?
// are there value sets at all?
if (parseResults?.valueSets?.length > 0) {
parseResults.valueSets.some((valueSet) => {
const oldVsName = valueSet.name.replace(/["']/g, "");
const oldUrl = valueSet.url.replace(/["']/g, "");
vsExactExists =
oldVsName === getValueSetTitleName(vs) && oldUrl === vs.oid;
oldVsName === getValueSetTitleName(vs) &&
(oldUrl === vs.oid || oldUrl === vs.url);
vsSameTitleExist =
(oldVsName &&
extractValueSetNameAndSuffix(oldVsName)
Expand All @@ -177,7 +180,7 @@ const applyValueset = (
// no matching valueset in the cql, add it.
if (!vsExactExists && !vsSameTitleExist) {
const valueSetStatement = `valueset "${getValueSetTitleName(vs)}": '${
vs.oid
measureModel === Model.QDM_5_6 ? vs.oid : vs.url
}'`;
valuesetChangeStatus = "success";
message = `Value Set ${getValueSetTitleName(
Expand Down Expand Up @@ -214,7 +217,7 @@ const applyValueset = (
}
} else if (vsSameTitleExist && !vsExactExists) {
const valueSetStatement = `valueset "${getValueSetTitleName(vs)}": '${
vs.oid
measureModel === Model.QDM_5_6 ? vs.oid : vs.url
}'`;
valuesetChangeStatus = "success";
message = `Value Set ${getValueSetTitleName(
Expand Down

0 comments on commit c678e64

Please sign in to comment.