Skip to content

Commit fe873b5

Browse files
committed
Updated value set to use proper ICD codes; added tests for the valueSetUtils
1 parent 1a059b5 commit fe873b5

18 files changed

+1655
-1302
lines changed

src/helpers/conditionUtils.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
const { checkCodeInVS } = require('./valueSetUtils');
1+
const path = require('path');
2+
const { checkCodeInVs } = require('./valueSetUtils');
23

34

45
/**
@@ -23,8 +24,8 @@ function getICD10Code(condition) {
2324
* @return {boolean} if primary cancer condition
2425
*/
2526
function isConditionCodePrimary(code) {
26-
const primaryCancerConditionVSFilepath = './valueSets/ValueSet-onco-core-PrimaryOrUncertainBehaviorCancerDisorderVS.json';
27-
return checkCodeInVS(code, primaryCancerConditionVSFilepath);
27+
const primaryCancerConditionVSFilepath = path.resolve(__dirname, './valueSets/ValueSet-mcode-primary-or-uncertain-behavior-cancer-disorder-vs.json');
28+
return checkCodeInVs(code, primaryCancerConditionVSFilepath);
2829
}
2930

3031
/**
@@ -33,8 +34,8 @@ function isConditionCodePrimary(code) {
3334
* @return {boolean} if secondary cancer condition
3435
*/
3536
function isConditionCodeSecondary(code) {
36-
const secondaryCancerConditionVSFilepath = './valueSets/ValueSet-onco-core-SecondaryCancerDisorderVS.json';
37-
return checkCodeInVS(code, secondaryCancerConditionVSFilepath);
37+
const secondaryCancerConditionVSFilepath = path.resolve(__dirname, './valueSets/ValueSet-mcode-secondary-cancer-disorder-vs.json');
38+
return checkCodeInVs(code, secondaryCancerConditionVSFilepath);
3839
}
3940

4041
/**

src/helpers/observationUtils.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
const { checkCodeInVS } = require('./valueSetUtils');
1+
const path = require('path');
2+
const { checkCodeInVs } = require('./valueSetUtils');
23

34
// Codes and display values for Vital Signs resources
45
// Code mapping is based on http://hl7.org/fhir/R4/observation-vitalsigns.html
@@ -19,8 +20,8 @@ const vitalSignsCodeToTextLookup = {
1920

2021

2122
function isTumorMarker(code) {
22-
const tumorMarkerTestVSPath = './valueSets/ValueSet-mcode-tumor-marker-test-vs.json';
23-
return checkCodeInVS(code, tumorMarkerTestVSPath);
23+
const tumorMarkerTestVSPath = path.resolve(__dirname, './valueSets/ValueSet-mcode-tumor-marker-test-vs.json');
24+
return checkCodeInVs(code, tumorMarkerTestVSPath);
2425
}
2526

2627
function isVitalSign(code) {

src/helpers/valueSetUtils.js

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const fs = require('fs');
2-
const path = require('path');
2+
const _ = require('lodash');
33
const logger = require('./logger');
44

55
const vsTypes = {
@@ -8,45 +8,43 @@ const vsTypes = {
88
turtle: 3,
99
};
1010

11-
function loadJsonVS(filepath) {
11+
function loadJsonVs(absoluteFilepath) {
1212
try {
13-
const vsData = fs.readFileSync(path.resolve(__dirname, filepath));
13+
const vsData = fs.readFileSync(absoluteFilepath);
1414
const vsJson = JSON.parse(vsData);
1515
return vsJson;
1616
} catch (error) {
17-
logger.error(`Could not load valueSet from path ${filepath}`);
17+
logger.error(`Could not load valueSet from path ${absoluteFilepath}`);
1818
throw error;
1919
}
2020
}
2121

22-
function loadVS(filepath, typeOfVS = vsTypes.json) {
22+
function loadVs(absoluteFilepath, typeOfVS) {
2323
switch (typeOfVS) {
2424
case vsTypes.json:
25-
logger.info(`loading JSON valueset from ${filepath}`);
26-
return loadJsonVS(filepath);
25+
logger.debug(`loading JSON valueset from ${absoluteFilepath}`);
26+
return loadJsonVs(absoluteFilepath);
2727

2828
case vsTypes.xml:
29-
logger.error('No defined valueset loader for `xml` type valuesets');
30-
return null;
29+
throw Error('No defined valueset loader for `xml` type valuesets');
3130

3231
case vsTypes.turtle:
33-
logger.error('No defined valueset loader for `turtle` type valuesets');
34-
return null;
32+
throw Error('No defined valueset loader for `turtle` type valuesets');
3533

3634
default:
37-
logger.error(`'${typeOfVS}' is not a recognized valueset type`);
38-
return null;
35+
throw Error(`${typeOfVS}' is not a recognized valueset type`);
3936
}
4037
}
4138

4239
/**
4340
* Check if code is in value set
44-
* @param {object} code value to look for in a valueset
41+
* @param {string} code value to look for in a valueset
4542
* @param {object} valueSet contains list of codes included in value set
4643
* @return {boolean} true if condition is in valueSet's compose block or expansion block
4744
*/
48-
const checkCodeInVS = (code, valueSetFilePath, typeOfVS = vsTypes.json) => {
49-
const valueSet = loadVS(valueSetFilePath, typeOfVS);
45+
const checkCodeInVs = (code, valueSetFilePath, typeOfVS = vsTypes.json) => {
46+
if (_.isUndefined(code)) throw Error('checkCodeInVs received a code of undefined');
47+
const valueSet = loadVs(valueSetFilePath, typeOfVS);
5048
let inVSExpansion = false;
5149
let inVSCompose = false;
5250
if (valueSet.expansion) {
@@ -69,7 +67,7 @@ const checkCodeInVS = (code, valueSetFilePath, typeOfVS = vsTypes.json) => {
6967

7068
module.exports = {
7169
vsTypes,
72-
loadJsonVS,
73-
loadVS,
74-
checkCodeInVS,
70+
loadJsonVs,
71+
loadVs,
72+
checkCodeInVs,
7573
};

0 commit comments

Comments
 (0)