Skip to content

Commit c4ad9c6

Browse files
Dtphelan1jafeltra
authored andcommitted
Done CancerRelatedMeds; minor fixes to CDS and AE
1 parent bf4ef14 commit c4ad9c6

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

test/extractors/CSVAdverseEventExtractor.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ const path = require('path');
22
const rewire = require('rewire');
33
const _ = require('lodash');
44
const { CSVAdverseEventExtractor } = require('../../src/extractors');
5-
const { getPatientFromContext } = require('../../src/helpers/contextUtils');
65
const exampleCSVAdverseEventModuleResponse = require('./fixtures/csv-adverse-event-module-response.json');
76
const exampleCSVAdverseEventBundle = require('./fixtures/csv-adverse-event-bundle.json');
7+
const { getPatientFromContext } = require('../../src/helpers/contextUtils');
88
const MOCK_CONTEXT = require('./fixtures/context-with-patient.json');
99

1010
// Constants for tests

test/extractors/CSVCancerDiseaseStatusExtractor.test.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const path = require('path');
22
const _ = require('lodash');
33
const { CSVCancerDiseaseStatusExtractor } = require('../../src/extractors');
4-
const { getPatientFromContext } = require('../../src/helpers/contextUtils');
54
const exampleCSVDiseaseStatusModuleResponse = require('./fixtures/csv-cancer-disease-status-module-response.json');
65
const exampleCSVDiseaseStatusBundle = require('./fixtures/csv-cancer-disease-status-bundle.json');
6+
const { getPatientFromContext } = require('../../src/helpers/contextUtils');
77
const MOCK_CONTEXT = require('./fixtures/context-with-patient.json');
88

99
// Constants for tests
@@ -29,22 +29,24 @@ describe('CSVCancerDiseaseStatusExtractor', () => {
2929
test('should join data appropriately and throw errors when missing required properties', () => {
3030
const expectedErrorString = 'DiseaseStatusData missing an expected property: conditionId, diseaseStatusCode, and dateOfObservation are required.';
3131
const localData = _.cloneDeep(exampleCSVDiseaseStatusModuleResponse);
32+
const patientId = getPatientFromContext(MOCK_CONTEXT).id;
33+
3234
// Test that valid data works fine
33-
expect(csvCancerDiseaseStatusExtractor.joinAndReformatData(exampleCSVDiseaseStatusModuleResponse)).toEqual(expect.anything());
35+
expect(csvCancerDiseaseStatusExtractor.joinAndReformatData(exampleCSVDiseaseStatusModuleResponse, patientId)).toEqual(expect.anything());
3436

3537
localData[0].evidence = ''; // Evidence is not required and will not throw an error
3638
localData[0].observationStatus = ''; // Observation Status is not required and will not throw an error
3739

3840
// Only including required properties is valid
39-
expect(csvCancerDiseaseStatusExtractor.joinAndReformatData(localData)).toEqual(expect.anything());
41+
expect(csvCancerDiseaseStatusExtractor.joinAndReformatData(localData, patientId)).toEqual(expect.anything());
4042

4143
const requiredProperties = ['conditionId', 'diseaseStatusCode', 'dateOfObservation'];
4244

4345
// Removing each required property should throw an error
4446
requiredProperties.forEach((key) => {
4547
const clonedData = _.cloneDeep(localData);
4648
clonedData[0][key] = '';
47-
expect(() => csvCancerDiseaseStatusExtractor.joinAndReformatData(clonedData)).toThrow(new Error(expectedErrorString));
49+
expect(() => csvCancerDiseaseStatusExtractor.joinAndReformatData(clonedData, patientId)).toThrow(new Error(expectedErrorString));
4850
});
4951
});
5052
});

test/extractors/CSVCancerRelatedMedicationExtractor.test.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const _ = require('lodash');
44
const { CSVCancerRelatedMedicationExtractor } = require('../../src/extractors');
55
const exampleCSVMedicationModuleResponse = require('./fixtures/csv-medication-module-response.json');
66
const exampleCSVMedicationBundle = require('./fixtures/csv-medication-bundle.json');
7+
const { getPatientFromContext } = require('../../src/helpers/contextUtils');
8+
const MOCK_CONTEXT = require('./fixtures/context-with-patient.json');
79

810
// Rewired extractor for helper tests
911
const CSVCancerRelatedMedicationExtractorRewired = rewire('../../src/extractors/CSVCancerRelatedMedicationExtractor.js');
@@ -35,24 +37,25 @@ describe('CSVCancerRelatedMedicationExtractor', () => {
3537
test('should join data appropriately and throw errors when missing required properties', () => {
3638
const expectedErrorString = 'The cancer-related medication is missing an expected element; mrn, code, code system, and status are all required values.';
3739
const localData = _.cloneDeep(exampleCSVMedicationModuleResponse);
40+
const patientId = getPatientFromContext(MOCK_CONTEXT).id;
3841

3942
// Test that valid maximal data works fine
40-
expect(formatData(exampleCSVMedicationModuleResponse)).toEqual(expect.anything());
43+
expect(formatData(localData, patientId)).toEqual(expect.anything());
4144

4245
// Test that deleting an optional value works fine
4346
delete localData[0].treatmentIntent;
44-
expect(formatData(exampleCSVMedicationModuleResponse)).toEqual(expect.anything());
47+
expect(formatData(localData, patientId)).toEqual(expect.anything());
4548

4649
// Test that deleting a mandatory value throws an error
4750
delete localData[0].code;
48-
expect(() => formatData(localData)).toThrow(new Error(expectedErrorString));
51+
expect(() => formatData(localData, patientId)).toThrow(new Error(expectedErrorString));
4952
});
5053
});
5154

5255
describe('get', () => {
5356
test('should return bundle with a CancerRelatedMedication', async () => {
5457
csvModuleSpy.mockReturnValue(exampleCSVMedicationModuleResponse);
55-
const data = await csvCancerRelatedMedicationExtractor.get({ mrn: MOCK_PATIENT_MRN });
58+
const data = await csvCancerRelatedMedicationExtractor.get({ mrn: MOCK_PATIENT_MRN, context: MOCK_CONTEXT });
5659
expect(data.resourceType).toEqual('Bundle');
5760
expect(data.type).toEqual('collection');
5861
expect(data.entry).toBeDefined();
@@ -62,7 +65,7 @@ describe('CSVCancerRelatedMedicationExtractor', () => {
6265

6366
test('should return empty bundle when no data available from module', async () => {
6467
csvModuleSpy.mockReturnValue([]);
65-
const data = await csvCancerRelatedMedicationExtractor.get({ mrn: MOCK_PATIENT_MRN });
68+
const data = await csvCancerRelatedMedicationExtractor.get({ mrn: MOCK_PATIENT_MRN, context: MOCK_CONTEXT });
6669
expect(data.resourceType).toEqual('Bundle');
6770
expect(data.type).toEqual('collection');
6871
expect(data.entry).toBeDefined();
@@ -72,8 +75,7 @@ describe('CSVCancerRelatedMedicationExtractor', () => {
7275
test('get() should return an array of 2 when two medication statements are tied to a single patient', async () => {
7376
exampleCSVMedicationModuleResponse.push(exampleEntry);
7477
csvModuleSpy.mockReturnValue(exampleCSVMedicationModuleResponse);
75-
const data = await csvCancerRelatedMedicationExtractor.get({ mrn: MOCK_PATIENT_MRN });
76-
78+
const data = await csvCancerRelatedMedicationExtractor.get({ mrn: MOCK_PATIENT_MRN, context: MOCK_CONTEXT });
7779
expect(data.resourceType).toEqual('Bundle');
7880
expect(data.type).toEqual('collection');
7981
expect(data.entry).toBeDefined();

0 commit comments

Comments
 (0)