Skip to content

Commit 73048fe

Browse files
committed
Fixes real JA1 - now unknown codes will result in a code-only method
1 parent c3493c9 commit 73048fe

File tree

2 files changed

+28
-23
lines changed

2 files changed

+28
-23
lines changed

src/templates/snippets/cancerStaging.js

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
11
const logger = require('../../helpers/logger');
2+
const { ifSomeArgsObj } = require('../../helpers/templateUtils');
23
const { isCancerStagingSystem } = require('../../helpers/cancerStagingUtils');
34
const { coding } = require('./coding');
45

5-
function stagingMethodTemplate({ code }) {
6-
if (isCancerStagingSystem(code)) {
7-
// NOTE: our general value set lookup should probably return the associate system, since it's available at the VS level
8-
return {
6+
function methodTemplate({ code, system }) {
7+
return ifSomeArgsObj(
8+
({ code: code_, system: system_ }) => ({
99
method: {
1010
coding: [
1111
coding({
12-
code,
13-
system: 'http://snomed.info/sct',
12+
...(code_ && { code: code_ }),
13+
...(system_ && { system: system_ }),
1414
}),
1515
],
1616
},
17-
};
17+
}),
18+
)({ code, system });
19+
}
20+
21+
function stagingMethodTemplate({ code }) {
22+
if (isCancerStagingSystem(code)) {
23+
// NOTE: our general value set lookup should probably return the associate system, since it's available at the VS level
24+
return methodTemplate({ code, system: 'http://snomed.info/sct' });
1825
} if (code === 'C146985') {
1926
// TODO: fix this HARDCODED special case as delineated by this VS's description http://hl7.org/fhir/us/mcode/ValueSet-mcode-cancer-staging-system-vs.html
2027
// System based on http://hl7.org/fhir/us/mcode/Observation-mCODETNMClinicalPrimaryTumorCategoryExample01.json.html
21-
return {
22-
method: {
23-
coding: [
24-
coding({
25-
code,
26-
system: 'http://ncimeta.nci.nih.gov',
27-
}),
28-
],
29-
},
30-
};
28+
return methodTemplate({ code, system: 'http://ncimeta.nci.nih.gov' });
3129
}
32-
logger.warn(`stagingMethodTemplate received a code ${code} that is not recognized; code will not be added to the resulting FHIR resource`);
33-
return null;
30+
logger.debug(`stagingMethodTemplate received a code ${code} that is not recognized; code will not be added to the resulting FHIR resource`);
31+
return methodTemplate({ code });
3432
}
3533

3634
module.exports = {

test/templates/snippets/cancerStaging.test.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ describe('cancerStaging snippets', () => {
2525
const stagingMethod = stagingMethodTemplate({ code: stagingCode });
2626
expect(stagingMethod).toEqual(expectedStagingMethod);
2727
});
28-
// Test that it returns a method when the one hardcoded case is in the VS
2928
test('Special case: it returns an object with a well defined method property when code is C146985', () => {
3029
const specialStagingCode = 'C146985';
3130
const specialStagingCodeSystem = 'http://ncimeta.nci.nih.gov';
@@ -43,10 +42,18 @@ describe('cancerStaging snippets', () => {
4342
const stagingMethod = stagingMethodTemplate({ code: specialStagingCode });
4443
expect(stagingMethod).toEqual(expectedSpecialStagingMethod);
4544
});
46-
// Test that it returns null when the one hardcoded case is
47-
test('it returns null when provided an unknown code', () => {
45+
test('it returns a method with a code and no system when provided an unknown code', () => {
4846
const unknownStagingCode = 'anything-goes';
49-
expect(stagingMethodTemplate({ code: unknownStagingCode })).toBeNull();
47+
const unknownStagingMethod = {
48+
method: {
49+
coding: [
50+
{
51+
code: unknownStagingCode,
52+
},
53+
],
54+
},
55+
};
56+
expect(stagingMethodTemplate({ code: unknownStagingCode })).toEqual(unknownStagingMethod);
5057
});
5158
});
5259
});

0 commit comments

Comments
 (0)