Skip to content

Commit 40a8646

Browse files
Dtphelan1jafeltra
authored andcommitted
Consistency updates and comments; fix procedure, observation, condition tests
1 parent 2a35248 commit 40a8646

10 files changed

+62
-53
lines changed

test/extractors/CSVCancerDiseaseStatusExtractor.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const { getPatientFromContext } = require('../../src/helpers/contextUtils');
77
const MOCK_CONTEXT = require('./fixtures/context-with-patient.json');
88

99
// Constants for tests
10-
const MOCK_PATIENT_MRN = 'pat-mrn-1'; // linked to values in example-module-response above
10+
const MOCK_PATIENT_MRN = 'mrn-1'; // linked to values in example-module-response and context-with-patient above
1111
const MOCK_CSV_PATH = path.join(__dirname, 'fixtures/example.csv'); // need a valid path/csv here to avoid parse error
1212
const IMPLEMENTATION = 'mcode';
1313

test/extractors/CSVCancerRelatedMedicationExtractor.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const MOCK_CONTEXT = require('./fixtures/context-with-patient.json');
1111
const CSVCancerRelatedMedicationExtractorRewired = rewire('../../src/extractors/CSVCancerRelatedMedicationExtractor.js');
1212

1313
// Constants for tests
14-
const MOCK_PATIENT_MRN = 'mrn-1'; // linked to values in example-module-response above
14+
const MOCK_PATIENT_MRN = 'mrn-1'; // linked to values in example-module-response and context-with-patient above
1515
const MOCK_CSV_PATH = path.join(__dirname, 'fixtures/example.csv'); // need a valid path/csv here to avoid parse error
1616

1717
// Instantiate module with parameters

test/extractors/CSVClinicalTrialInformationExtractor.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ const { getPatientFromContext } = require('../../src/helpers/contextUtils');
77
const MOCK_CONTEXT = require('./fixtures/context-with-patient.json');
88

99
// Constants for mock tests
10+
const MOCK_PATIENT_MRN = 'mrn-1'; // linked to values in example-module-response and context-with-patient above
1011
const MOCK_CSV_PATH = path.join(__dirname, 'fixtures/example.csv'); // need a valid path/csv here to avoid parse error
1112
const MOCK_CLINICAL_SITE_ID = 'EXAMPLE-CLINICAL-SITE-ID';
1213
const MOCK_CLINICAL_SITE_SYSTEM = 'EXAMPLE-CLINICAL-SITE-SYSTEM';
13-
const MOCK_PATIENT_MRN = 'EXAMPLE-MRN';
1414

1515
// Instantiate module with mock parameters
1616
const csvClinicalTrialInformationExtractor = new CSVClinicalTrialInformationExtractor({
@@ -38,8 +38,8 @@ describe('CSVClinicalTrialInformationExtractor', () => {
3838
Object.keys(firstClinicalTrialInfoResponse).forEach((key) => {
3939
const clonedData = _.cloneDeep(firstClinicalTrialInfoResponse);
4040
expect(csvClinicalTrialInformationExtractor.joinClinicalTrialData(clonedData, patientId)).toEqual(expect.anything());
41-
if (key === 'mrn') return; // MRN is not required from CSV
42-
if (key === 'trialResearchSystem') return; // trialResearchSystem is an optional field
41+
if (key === 'patientId') return; // MRN is optional
42+
if (key === 'trialResearchSystem') return; // trialResearchSystem is optional
4343
delete clonedData[key];
4444
expect(() => csvClinicalTrialInformationExtractor.joinClinicalTrialData(clonedData, patientId)).toThrow(new Error(expectedErrorString));
4545
});

test/extractors/CSVConditionExtractor.test.js

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ const _ = require('lodash');
33
const { CSVConditionExtractor } = require('../../src/extractors');
44
const exampleConditionResponse = require('./fixtures/csv-condition-module-response.json');
55
const exampleConditionBundle = require('./fixtures/csv-condition-bundle.json');
6+
const MOCK_CONTEXT = require('./fixtures/context-with-patient.json');
67

78
// Constants for mock tests
8-
const MOCK_PATIENT_MRN = 'mrn-1';
9+
const MOCK_PATIENT_MRN = 'mrn-1';// linked to values in example-module-response and context-with-patient above
910
const MOCK_CSV_PATH = path.join(__dirname, 'fixtures/example.csv'); // need a valid path/csv here to avoid parse error
1011
const csvConditionExtractor = new CSVConditionExtractor({
1112
filePath: MOCK_CSV_PATH,
@@ -23,26 +24,28 @@ expandedExampleBundle.entry.push(exampleConditionBundle.entry[0]);
2324

2425

2526
describe('CSV Condition Extractor tests', () => {
26-
test('get should return a fhir bundle when MRN is known', async () => {
27-
csvModuleSpy.mockReturnValue(exampleConditionResponse);
28-
const data = await csvConditionExtractor.get({ mrn: MOCK_PATIENT_MRN });
29-
30-
expect(data.resourceType).toEqual('Bundle');
31-
expect(data.type).toEqual('collection');
32-
expect(data.entry).toBeDefined();
33-
expect(data.entry.length).toEqual(1);
34-
expect(data).toEqual(exampleConditionBundle);
35-
});
36-
37-
test('get() should return an array of 2 when two conditions are tied to a single patient', async () => {
38-
exampleConditionResponse.push(exampleEntry);
39-
csvModuleSpy.mockReturnValue(exampleConditionResponse);
40-
const data = await csvConditionExtractor.get({ mrn: MOCK_PATIENT_MRN });
41-
42-
expect(data.resourceType).toEqual('Bundle');
43-
expect(data.type).toEqual('collection');
44-
expect(data.entry).toBeDefined();
45-
expect(data.entry.length).toEqual(2);
46-
expect(data).toEqual(expandedExampleBundle);
27+
describe('get', () => {
28+
test('get should return a fhir bundle when MRN is known', async () => {
29+
csvModuleSpy.mockReturnValue(exampleConditionResponse);
30+
const data = await csvConditionExtractor.get({ mrn: MOCK_PATIENT_MRN, context: MOCK_CONTEXT });
31+
32+
expect(data.resourceType).toEqual('Bundle');
33+
expect(data.type).toEqual('collection');
34+
expect(data.entry).toBeDefined();
35+
expect(data.entry.length).toEqual(1);
36+
expect(data).toEqual(exampleConditionBundle);
37+
});
38+
39+
test('get() should return an array of 2 when two conditions are tied to a single patient', async () => {
40+
exampleConditionResponse.push(exampleEntry);
41+
csvModuleSpy.mockReturnValue(exampleConditionResponse);
42+
const data = await csvConditionExtractor.get({ mrn: MOCK_PATIENT_MRN, context: MOCK_CONTEXT });
43+
44+
expect(data.resourceType).toEqual('Bundle');
45+
expect(data.type).toEqual('collection');
46+
expect(data.entry).toBeDefined();
47+
expect(data.entry.length).toEqual(2);
48+
expect(data).toEqual(expandedExampleBundle);
49+
});
4750
});
4851
});

test/extractors/CSVObservationExtractor.test.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ const _ = require('lodash');
44
const { CSVObservationExtractor } = require('../../src/extractors');
55
const exampleCSVObservationModuleResponse = require('./fixtures/csv-observation-module-response.json');
66
const exampleCSVObservationBundle = require('./fixtures/csv-observation-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 CSVObservationExtractorRewired = rewire('../../src/extractors/CSVObservationExtractor.js');
1012

1113
// Constants for tests
12-
const MOCK_PATIENT_MRN = 'pat-mrn-1'; // linked to values in example-module-response above
14+
const MOCK_PATIENT_MRN = 'mrn-1'; // linked to values in example-module-response and context-with-patient above
1315
const MOCK_CSV_PATH = path.join(__dirname, 'fixtures/example.csv'); // need a valid path/csv here to avoid parse error
1416

1517
// Instantiate module with parameters
@@ -28,15 +30,16 @@ const formatData = CSVObservationExtractorRewired.__get__('formatData');
2830
describe('CSVObservationExtractor', () => {
2931
describe('formatData', () => {
3032
test('should join data appropriately and throw errors when missing required properties', () => {
31-
const expectedErrorString = 'The observation is missing an expected attribute. Observation id, mrn, status, code, code system, value, and effective date are all required.';
33+
const expectedErrorString = 'The observation is missing an expected attribute. Observation id, status, code, code system, value, and effective date are all required.';
3234
const localData = _.cloneDeep(exampleCSVObservationModuleResponse);
35+
const patientId = getPatientFromContext(MOCK_CONTEXT).id;
3336

3437
// Test that valid maximal data works fine
35-
expect(formatData(exampleCSVObservationModuleResponse)).toEqual(expect.anything());
38+
expect(formatData(exampleCSVObservationModuleResponse, patientId)).toEqual(expect.anything());
3639

3740
// Test that deleting an optional value works fine
3841
delete localData[0].bodySite;
39-
expect(formatData(exampleCSVObservationModuleResponse)).toEqual(expect.anything());
42+
expect(formatData(exampleCSVObservationModuleResponse, patientId)).toEqual(expect.anything());
4043

4144
// Test that deleting a mandatory value throws an error
4245
delete localData[0].status;
@@ -47,7 +50,7 @@ describe('CSVObservationExtractor', () => {
4750
describe('get', () => {
4851
test('should return bundle with Observation', async () => {
4952
csvModuleSpy.mockReturnValue(exampleCSVObservationModuleResponse);
50-
const data = await csvObservationExtractor.get({ mrn: MOCK_PATIENT_MRN });
53+
const data = await csvObservationExtractor.get({ mrn: MOCK_PATIENT_MRN, context: MOCK_CONTEXT });
5154
expect(data.resourceType).toEqual('Bundle');
5255
expect(data.type).toEqual('collection');
5356
expect(data.entry).toBeDefined();
@@ -57,7 +60,7 @@ describe('CSVObservationExtractor', () => {
5760

5861
test('should return empty bundle when no data available from module', async () => {
5962
csvModuleSpy.mockReturnValue([]);
60-
const data = await csvObservationExtractor.get({ mrn: MOCK_PATIENT_MRN });
63+
const data = await csvObservationExtractor.get({ mrn: MOCK_PATIENT_MRN, context: MOCK_CONTEXT });
6164
expect(data.resourceType).toEqual('Bundle');
6265
expect(data.type).toEqual('collection');
6366
expect(data.entry).toBeDefined();

test/extractors/CSVProcedureExtractor.test.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ const _ = require('lodash');
44
const { CSVProcedureExtractor } = require('../../src/extractors');
55
const exampleCSVProcedureModuleResponse = require('./fixtures/csv-procedure-module-response.json');
66
const exampleCSVProcedureBundle = require('./fixtures/csv-procedure-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 CSVProcedureExtractorRewired = rewire('../../src/extractors/CSVProcedureExtractor.js');
1012

1113
// Constants for tests
12-
const MOCK_PATIENT_MRN = 'mrn-1'; // linked to values in example-module-response above
14+
const MOCK_PATIENT_MRN = 'mrn-1'; // linked to values in example-module-response and patient-context above
1315
const MOCK_CSV_PATH = path.join(__dirname, 'fixtures/example.csv'); // need a valid path/csv here to avoid parse error
1416

1517
// Instantiate module with parameters
@@ -27,25 +29,27 @@ const formatData = CSVProcedureExtractorRewired.__get__('formatData');
2729
describe('CSVProcedureExtractor', () => {
2830
describe('formatData', () => {
2931
test('should join data appropriately and throw errors when missing required properties', () => {
30-
const expectedErrorString = 'The procedure is missing an expected attribute. Procedure id, mrn, code system, code, status and effective date are all required.';
32+
const expectedErrorString = 'The procedure is missing an expected attribute. Procedure id, code system, code, status and effective date are all required.';
3133
const localData = _.cloneDeep(exampleCSVProcedureModuleResponse);
34+
const patientId = getPatientFromContext(MOCK_CONTEXT).id;
35+
3236
// Test that valid data works fine
33-
expect(formatData(localData)).toEqual(expect.anything());
37+
expect(formatData(localData, patientId)).toEqual(expect.anything());
3438

3539
// Test that removing an optional value works
3640
delete localData[0].bodySite;
37-
expect(formatData(localData)).toEqual(expect.anything());
41+
expect(formatData(localData, patientId)).toEqual(expect.anything());
3842

3943
// Test that removing a required value throws
4044
delete localData[0].procedureId;
41-
expect(() => formatData(localData)).toThrow(new Error(expectedErrorString));
45+
expect(() => formatData(localData, patientId)).toThrow(new Error(expectedErrorString));
4246
});
4347
});
4448

4549
describe('get', () => {
4650
test('should return bundle with Procedure', async () => {
4751
csvModuleSpy.mockReturnValue(exampleCSVProcedureModuleResponse);
48-
const data = await csvProcedureExtractor.get({ mrn: MOCK_PATIENT_MRN });
52+
const data = await csvProcedureExtractor.get({ mrn: MOCK_PATIENT_MRN, context: MOCK_CONTEXT });
4953
expect(data.resourceType).toEqual('Bundle');
5054
expect(data.type).toEqual('collection');
5155
expect(data.entry).toBeDefined();
@@ -55,7 +59,7 @@ describe('CSVProcedureExtractor', () => {
5559

5660
test('should return empty bundle when no data available from module', async () => {
5761
csvModuleSpy.mockReturnValue([]);
58-
const data = await csvProcedureExtractor.get({ mrn: MOCK_PATIENT_MRN });
62+
const data = await csvProcedureExtractor.get({ mrn: MOCK_PATIENT_MRN, context: MOCK_CONTEXT });
5963
expect(data.resourceType).toEqual('Bundle');
6064
expect(data.type).toEqual('collection');
6165
expect(data.entry).toBeDefined();

test/extractors/fixtures/csv-cancer-disease-status-module-response.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[
22
{
3-
"mrn": "pat-mrn-1",
3+
"mrn": "mrn-1",
44
"conditionId": "cond-1",
55
"diseaseStatusCode": "268910001",
66
"dateOfObservation": "2019-12-02",
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[
22
{
3-
"mrn": "EXAMPLE-MRN",
3+
"patientId": "mrn-1",
44
"trialSubjectID": "example-subjectId",
55
"enrollmentStatus": "example-enrollment-status",
66
"trialResearchID": "example-researchId",
77
"trialStatus": "example-trialStatus",
8-
"trialResearchSystem":"example-system"
8+
"trialResearchSystem": "example-system"
99
}
1010
]

test/extractors/fixtures/csv-observation-bundle.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
}
1818
]
1919
}
20-
],
20+
],
2121
"code": {
2222
"coding": [
2323
{
@@ -26,11 +26,11 @@
2626
}
2727
]
2828
},
29-
"subject" : {
30-
"reference": "urn:uuid:example-patient",
29+
"subject": {
30+
"reference": "urn:uuid:mrn-1",
3131
"type": "Patient"
3232
},
33-
"effectiveDateTime" : "2020-01-02",
33+
"effectiveDateTime": "2020-01-02",
3434
"valueCodeableConcept": {
3535
"coding": [
3636
{
@@ -39,7 +39,7 @@
3939
}
4040
]
4141
},
42-
"bodySite": {
42+
"bodySite": {
4343
"extension": [
4444
{
4545
"url": "http://hl7.org/fhir/us/mcode/StructureDefinition/mcode-laterality",
@@ -52,16 +52,15 @@
5252
]
5353
}
5454
}
55-
],
55+
],
5656
"coding": [
5757
{
5858
"system": "http://snomed.info/sct",
5959
"code": "12345"
6060
}
61-
]
61+
]
6262
}
6363
}
6464
}
6565
]
6666
}
67-

test/extractors/fixtures/csv-observation-module-response.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[
22
{
3-
"mrn": "example-patient",
3+
"mrn": "mrn-1",
44
"observationId": "observation-id",
55
"status": "final",
66
"code": "1695-6",
@@ -12,4 +12,4 @@
1212
"bodySite": "12345",
1313
"laterality": "678910"
1414
}
15-
]
15+
]

0 commit comments

Comments
 (0)