Skip to content

Commit 859d1d3

Browse files
committed
System matching now required on VS checks
1 parent 864993e commit 859d1d3

File tree

4 files changed

+29
-19
lines changed

4 files changed

+29
-19
lines changed

src/helpers/valueSetUtils.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,14 @@ const checkCodeInVs = (code, codeSystem, valueSetFilePath, typeOfVS = vsTypes.js
5050
if (valueSet.expansion) {
5151
// If valueSet has expansion, we only need to check these codes
5252
inVSExpansion = valueSet.expansion.contains.some((containsItem) => {
53-
if (!code || !containsItem) return false;
54-
if (containsItem.system) {
55-
return code === containsItem.code && codeSystem === containsItem.codeSystem;
56-
}
57-
return code === containsItem.code;
53+
if (!code || !codeSystem || !containsItem || !containsItem.system) return false;
54+
return code === containsItem.code && codeSystem === containsItem.system;
5855
});
5956
} else {
6057
// Checks if code is in any of the valueSet.compose.include arrays
6158
inVSCompose = valueSet.compose.include.some((includeItem) => {
62-
if (!code || !includeItem || !includeItem.concept) return false;
63-
if (includeItem.system) {
64-
return includeItem.system === codeSystem && includeItem.concept.map((concept) => concept.code).includes(code);
65-
}
66-
return includeItem.concept.map((concept) => concept.code).includes(code);
59+
if (!code || !codeSystem || !includeItem || !includeItem.system || !includeItem.concept) return false;
60+
return includeItem.system === codeSystem && includeItem.concept.map((concept) => concept.code).includes(code);
6761
});
6862
}
6963
return inVSCompose || inVSExpansion;

test/helpers/fixtures/valueset-with-expansion.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717
"expansion": {
1818
"timestamp": "2020-04-02T12:54:59-0400",
1919
"contains": [
20-
{
21-
"code": "C00.0",
22-
"display": "Malignant neoplasm of external upper lip"
23-
},
2420
{
2521
"code": "C00.1",
2622
"display": "Malignant neoplasm of external lower lip"

test/helpers/fixtures/valueset-without-expansion.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
"display": "Malignant neoplasm of external upper lip"
1212
}
1313
]
14+
},
15+
{
16+
"concept": [
17+
{
18+
"code": "C00.1",
19+
"display": "Malignant neoplasm of external upper lip"
20+
}
21+
]
1422
}
1523
]
1624
}

test/helpers/valueSetUtils.test.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe('valueSetUtils', () => {
4646

4747
describe('checkCodeInVs', () => {
4848
const includesCode = 'C00.0';
49-
const expansionCode = 'C00.1';
49+
const expansionCodeWithoutSystem = 'C00.1';
5050
const expansionCodeWithSystem = 'C00.2';
5151
const missingCode = 'C12.34';
5252
const icd10System = 'http://hl7.org/fhir/sid/icd-10-cm';
@@ -65,13 +65,25 @@ describe('valueSetUtils', () => {
6565
expect(checkCodeInVs(includesCode, icd10System, vsPath, vsTypes.json)).toBeTruthy();
6666
});
6767
test('Should return false if the code is not in the VS includes', () => {
68-
expect(checkCodeInVs(expansionCode, icd10System, vsPath, vsTypes.json)).toBeFalsy();
68+
expect(checkCodeInVs(expansionCodeWithSystem, icd10System, vsPath, vsTypes.json)).toBeFalsy();
6969
});
7070
test('Should return false if the code is in the VS includes but the systems do not match', () => {
7171
expect(checkCodeInVs(includesCode, snomedSystem, vsPath, vsTypes.json)).toBeFalsy();
7272
});
73-
test('Should return true if the code is in the VS expansion', () => {
74-
expect(checkCodeInVs(expansionCode, icd10System, vsWithExpansionPath, vsTypes.json)).toBeTruthy();
73+
test('Should return false if the code is in the VS includes but the coding lacks a system', () => {
74+
expect(checkCodeInVs(expansionCodeWithoutSystem, snomedSystem, vsPath, vsTypes.json)).toBeFalsy();
75+
});
76+
test('Should return false if the code is in the VS includes but a system was not included as an argument', () => {
77+
expect(checkCodeInVs(expansionCodeWithoutSystem, undefined, vsPath, vsTypes.json)).toBeFalsy();
78+
});
79+
test('Should return true if the code is in the VS expansion and systems match', () => {
80+
expect(checkCodeInVs(expansionCodeWithSystem, icd10System, vsWithExpansionPath, vsTypes.json)).toBeTruthy();
81+
});
82+
test('Should return false if the code is in the VS expansion but the coding lacks a system', () => {
83+
expect(checkCodeInVs(expansionCodeWithoutSystem, icd10System, vsWithExpansionPath, vsTypes.json)).toBeFalsy();
84+
});
85+
test('Should return false if the code is in the VS expansion but a system was not included as an argument', () => {
86+
expect(checkCodeInVs(expansionCodeWithSystem, undefined, vsWithExpansionPath, vsTypes.json)).toBeFalsy();
7587
});
7688
test('Should return false if the code is in the VS expansion but the systems do not match', () => {
7789
expect(checkCodeInVs(expansionCodeWithSystem, snomedSystem, vsWithExpansionPath, vsTypes.json)).toBeFalsy();
@@ -83,7 +95,7 @@ describe('valueSetUtils', () => {
8395
});
8496
test('Should check against a json valueSet when no type is provided', () => {
8597
expect(checkCodeInVs(includesCode, icd10System, vsPath)).toBeTruthy();
86-
expect(checkCodeInVs(expansionCode, icd10System, vsWithExpansionPath)).toBeTruthy();
98+
expect(checkCodeInVs(expansionCodeWithSystem, icd10System, vsWithExpansionPath)).toBeTruthy();
8799
expect(checkCodeInVs(missingCode, icd10System, vsPath)).toBeFalsy();
88100
});
89101
});

0 commit comments

Comments
 (0)