Skip to content

Commit ff76b0b

Browse files
Dtphelan1jafeltra
authored andcommitted
Fix all tests here
1 parent 40a8646 commit ff76b0b

11 files changed

+107
-59
lines changed

src/extractors/CSVTreatmentPlanChangeExtractor.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const { BaseCSVExtractor } = require('./BaseCSVExtractor');
33
const { formatDate } = require('../helpers/dateUtils');
44
const { generateMcodeResources } = require('../templates');
55
const { getEmptyBundle } = require('../helpers/fhirUtils');
6+
const { getPatientFromContext } = require('../helpers/contextUtils');
67
const logger = require('../helpers/logger');
78
const { CSVTreatmentPlanChangeSchema } = require('../helpers/schemas/csv');
89

@@ -15,7 +16,7 @@ function formatData(tpcData, patientId) {
1516
return [];
1617
}
1718

18-
// Newly combined data has mrn and list of reviews to map to an extension
19+
// Newly combined data has subjectId and list of reviews to map to an extension
1920
const combinedFormat = { subjectId: patientId, reviews: [] };
2021

2122
// If there are multiple entries, combine them into one object with multiple reviews
@@ -75,15 +76,16 @@ class CSVTreatmentPlanChangeExtractor extends BaseCSVExtractor {
7576
return this.csvModule.get('mrn', mrn, fromDate, toDate);
7677
}
7778

78-
async get({ mrn, fromDate, toDate }) {
79+
async get({ mrn, context, fromDate, toDate }) {
7980
const tpcData = await this.getTPCData(mrn, fromDate, toDate);
8081
if (tpcData.length === 0) {
8182
logger.warn('No treatment plan change data found for patient');
8283
return getEmptyBundle();
8384
}
85+
const patientId = getPatientFromContext(context).id;
8486

8587
// Reformat data
86-
const formattedData = formatData(tpcData);
88+
const formattedData = formatData(tpcData, patientId);
8789

8890
// Fill templates
8991
return generateMcodeResources('CarePlanWithReview', formattedData);

test/cli/fixtures/example-patient.csv

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
mrn,familyName,givenName,gender,birthsex,dateOfBirth,race,ethnicity,language,addressLine,city,state,zip
2+
123,Doe,Jane,female,F,1980-01-01,2028-9,2186-5,en,2 West Side Rd,Malden,MA,02148
3+
456,Doe,John,male,M,1970-01-01,2106-3,2186-5,en-US,3 East Side Rd,Brooklyn,NY,11201
4+
789,Doe,Jimmy,other,UNK,1980-03-01,ASKU,2186-5,ar,,,,90001

test/cli/mcodeExtraction.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ describe('mcodeExtraction', () => {
4646
it('should succeed in extraction when CSV files do not have data for all patients', async () => {
4747
const testConfig = {
4848
extractors: [
49+
{
50+
label: 'patients',
51+
type: 'CSVPatientExtractor',
52+
constructorArgs: {
53+
filePath: path.join(__dirname, './fixtures/example-patient.csv'),
54+
},
55+
},
4956
{
5057
label: 'condition',
5158
type: 'CSVConditionExtractor',

test/extractors/CSVStagingExtractor.test.js

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

810
// Constants for tests
9-
const MOCK_PATIENT_MRN = 'pat-mrn-1'; // linked to values in example-module-response above
11+
const MOCK_PATIENT_MRN = 'mrn-1'; // linked to values in example-module-response above
1012
const MOCK_CSV_PATH = path.join(__dirname, 'fixtures/example.csv'); // need a valid path/csv here to avoid parse error
1113

1214
// Instantiate module with parameters
@@ -17,16 +19,17 @@ const { csvModule } = csvStagingExtractor;
1719

1820
// Spy on csvModule
1921
const csvModuleSpy = jest.spyOn(csvModule, 'get');
20-
2122
const formatTNMCategoryData = rewire('../../src/extractors/CSVStagingExtractor.js').__get__('formatTNMCategoryData');
2223

2324
describe('CSVStagingExtractor', () => {
2425
describe('formatTNMCategoryData', () => {
2526
test('should join data appropriately and throw errors when missing required properties', () => {
26-
const expectedErrorString = 'Staging data is missing an expected property: mrn, conditionId, effectiveDate are required.';
27+
const expectedErrorString = 'Staging data is missing an expected property: conditionId, effectiveDate are required.';
2728
const localData = _.cloneDeep(exampleStagingModuleResponse[0]);
29+
const patientId = getPatientFromContext(MOCK_CONTEXT).id;
30+
2831
// Test that valid data works fine
29-
expect(formatTNMCategoryData(localData)).toEqual(expect.anything());
32+
expect(formatTNMCategoryData(localData, patientId)).toEqual(expect.anything());
3033

3134
// Test all optional properties can be empty without issue
3235
localData.t = '';
@@ -41,7 +44,7 @@ describe('CSVStagingExtractor', () => {
4144
expect(formatTNMCategoryData(localData)).toEqual(expect.anything());
4245

4346
// Removing each required property should throw an error
44-
const requiredKeys = ['mrn', 'conditionId', 'effectiveDate'];
47+
const requiredKeys = ['conditionId', 'effectiveDate'];
4548
requiredKeys.forEach((key) => {
4649
const clonedData = _.cloneDeep(localData);
4750
clonedData[key] = '';
@@ -53,7 +56,7 @@ describe('CSVStagingExtractor', () => {
5356
describe('get', () => {
5457
test('should return bundle with Observation', async () => {
5558
csvModuleSpy.mockReturnValue(exampleStagingModuleResponse);
56-
const data = await csvStagingExtractor.get({ mrn: MOCK_PATIENT_MRN });
59+
const data = await csvStagingExtractor.get({ mrn: MOCK_PATIENT_MRN, context: MOCK_CONTEXT });
5760
expect(data.resourceType).toEqual('Bundle');
5861
expect(data.type).toEqual('collection');
5962
expect(data.entry).toBeDefined();
@@ -63,7 +66,7 @@ describe('CSVStagingExtractor', () => {
6366

6467
test('should return empty bundle when no data available from module', async () => {
6568
csvModuleSpy.mockReturnValue([]);
66-
const data = await csvStagingExtractor.get({ mrn: MOCK_PATIENT_MRN });
69+
const data = await csvStagingExtractor.get({ mrn: MOCK_PATIENT_MRN, context: MOCK_CONTEXT });
6770
expect(data.resourceType).toEqual('Bundle');
6871
expect(data.type).toEqual('collection');
6972
expect(data.entry).toBeDefined();

test/extractors/CSVTreatmentPlanChangeExtractor.test.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,23 @@ const _ = require('lodash');
44
const { CSVTreatmentPlanChangeExtractor } = require('../../src/extractors');
55
const exampleCSVTPCModuleResponse = require('./fixtures/csv-treatment-plan-change-module-response.json');
66
const exampleCSVTPCBundle = require('./fixtures/csv-treatment-plan-change-bundle.json');
7+
const { getPatientFromContext } = require('../../src/helpers/contextUtils');
8+
const MOCK_CONTEXT = require('./fixtures/context-with-patient.json');
79

8-
const MOCK_MRN = 'mrn-1';
10+
// Constants for tests
11+
const MOCK_PATIENT_MRN = 'mrn-1'; // linked to values in example-module-response above
912
const MOCK_CSV_PATH = path.join(__dirname, 'fixtures/example.csv');
13+
14+
// Instantiate module with parameters
1015
const csvTPCExtractor = new CSVTreatmentPlanChangeExtractor({
1116
filePath: MOCK_CSV_PATH,
1217
});
1318

19+
// Destructure all modules
1420
const { csvModule } = csvTPCExtractor;
1521

1622
// Spy on csvModule
1723
const csvModuleSpy = jest.spyOn(csvModule, 'get');
18-
1924
const formatData = rewire('../../src/extractors/CSVTreatmentPlanChangeExtractor.js').__get__('formatData');
2025

2126
describe('CSVTreatmentPlanChangeExtractor', () => {
@@ -33,19 +38,21 @@ describe('CSVTreatmentPlanChangeExtractor', () => {
3338
mrn: 'id',
3439
},
3540
];
41+
const patientId = getPatientFromContext(MOCK_CONTEXT).id;
3642

3743
test('should join data appropriately and throw errors when missing required properties', () => {
38-
const expectedErrorString = 'Treatment Plan Change Data missing an expected property: mrn, dateOfCarePlan, changed are required';
44+
const expectedErrorString = 'Treatment Plan Change Data missing an expected property: dateOfCarePlan, changed are required';
3945

4046
// formatData on example data should not throw error when changed is false
41-
expect(() => formatData(exampleData)).not.toThrowError();
47+
expect(() => formatData(exampleData, patientId)).not.toThrowError();
4248

4349
// Test required properties throw error
44-
Object.keys(exampleData[0]).forEach((key) => {
50+
const requiredKeys = ['dateOfCarePlan', 'changed'];
51+
requiredKeys.forEach((key) => {
4552
const clonedData = _.cloneDeep(exampleData);
4653

4754
delete clonedData[0][key];
48-
expect(() => formatData(clonedData)).toThrow(new Error(expectedErrorString));
55+
expect(() => formatData(clonedData, patientId)).toThrow(new Error(expectedErrorString));
4956
});
5057
});
5158

@@ -54,17 +61,17 @@ describe('CSVTreatmentPlanChangeExtractor', () => {
5461

5562
// error should get throw when changed flag is true and there is no reasonCode provided
5663
exampleData[0].changed = 'true';
57-
expect(() => formatData(exampleData)).toThrow(new Error(expectedErrorString));
64+
expect(() => formatData(exampleData, patientId)).toThrow(new Error(expectedErrorString));
5865

5966
// No error should be throw when reasonCode is provided
6067
exampleData[0].reasonCode = 'example code';
61-
expect(() => formatData(exampleData)).not.toThrowError();
68+
expect(() => formatData(exampleData, patientId)).not.toThrowError();
6269
});
6370

6471
test('should join multiple entries into one', () => {
6572
const expectedFormattedData = [
6673
{
67-
mrn: 'mrn-1',
74+
subjectId: 'mrn-1',
6875
reviews: [
6976
{
7077
effectiveDate: '2020-04-15',
@@ -81,14 +88,14 @@ describe('CSVTreatmentPlanChangeExtractor', () => {
8188
},
8289
];
8390

84-
expect(formatData(exampleCSVTPCModuleResponse)).toEqual(expectedFormattedData);
91+
expect(formatData(exampleCSVTPCModuleResponse, patientId)).toEqual(expectedFormattedData);
8592
});
8693
});
8794

8895
describe('get', () => {
8996
test('should return bundle with CarePlan', async () => {
9097
csvModuleSpy.mockReturnValue(exampleCSVTPCModuleResponse);
91-
const data = await csvTPCExtractor.get({ mrn: MOCK_MRN });
98+
const data = await csvTPCExtractor.get({ mrn: MOCK_PATIENT_MRN, context: MOCK_CONTEXT });
9299

93100
expect(data.resourceType).toEqual('Bundle');
94101
expect(data.type).toEqual('collection');
@@ -98,7 +105,7 @@ describe('CSVTreatmentPlanChangeExtractor', () => {
98105

99106
test('should return empty bundle with no data available from module', async () => {
100107
csvModuleSpy.mockReturnValue([]);
101-
const data = await csvTPCExtractor.get({ mrn: MOCK_MRN });
108+
const data = await csvTPCExtractor.get({ mrn: MOCK_PATIENT_MRN, context: MOCK_CONTEXT });
102109

103110
expect(data.resourceType).toEqual('Bundle');
104111
expect(data.type).toEqual('collection');

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
"type": "collection",
44
"entry": [
55
{
6-
"fullUrl": "urn:uuid:ed5faf7f2a1cef061d7584afd463e60eb7202104700647e92fbb7c9419eb7897",
6+
"fullUrl": "urn:uuid:626b61fd700d8ddc5a6a576a2e47944191b5f608e03083d00c49614f0158bb65",
77
"resource": {
88
"resourceType": "Observation",
9-
"id": "ed5faf7f2a1cef061d7584afd463e60eb7202104700647e92fbb7c9419eb7897",
9+
"id": "626b61fd700d8ddc5a6a576a2e47944191b5f608e03083d00c49614f0158bb65",
1010
"meta": {
1111
"profile": [
1212
"http://hl7.org/fhir/us/mcode/StructureDefinition/mcode-tnm-clinical-primary-tumor-category"
@@ -32,7 +32,7 @@
3232
]
3333
},
3434
"subject": {
35-
"reference": "urn:uuid:pat-mrn-1",
35+
"reference": "urn:uuid:mrn-1",
3636
"type": "Patient"
3737
},
3838
"method": {
@@ -61,10 +61,10 @@
6161
}
6262
},
6363
{
64-
"fullUrl": "urn:uuid:88992af10e3a822f2a946628de91012d5afae49a25d1641db09e9d6ed4ca24c3",
64+
"fullUrl": "urn:uuid:66e0e5f216bebeba287c3a3b0e220170bab88da95030e0c4bdba32f66628d00c",
6565
"resource": {
6666
"resourceType": "Observation",
67-
"id": "88992af10e3a822f2a946628de91012d5afae49a25d1641db09e9d6ed4ca24c3",
67+
"id": "66e0e5f216bebeba287c3a3b0e220170bab88da95030e0c4bdba32f66628d00c",
6868
"meta": {
6969
"profile": [
7070
"http://hl7.org/fhir/us/mcode/StructureDefinition/mcode-tnm-clinical-distant-metastases-category"
@@ -90,7 +90,7 @@
9090
]
9191
},
9292
"subject": {
93-
"reference": "urn:uuid:pat-mrn-1",
93+
"reference": "urn:uuid:mrn-1",
9494
"type": "Patient"
9595
},
9696
"method": {
@@ -119,10 +119,10 @@
119119
}
120120
},
121121
{
122-
"fullUrl": "urn:uuid:1373d3fb234cad0b03912cfbba16bdc4eabbd6217d83b838f6d9c1343bc9b394",
122+
"fullUrl": "urn:uuid:4469acab85a889d722f5b8b1cb786df8adbfc5f0b50ac23393ec42b8ecfd49e9",
123123
"resource": {
124124
"resourceType": "Observation",
125-
"id": "1373d3fb234cad0b03912cfbba16bdc4eabbd6217d83b838f6d9c1343bc9b394",
125+
"id": "4469acab85a889d722f5b8b1cb786df8adbfc5f0b50ac23393ec42b8ecfd49e9",
126126
"meta": {
127127
"profile": [
128128
"http://hl7.org/fhir/us/mcode/StructureDefinition/mcode-tnm-clinical-regional-nodes-category"
@@ -148,7 +148,7 @@
148148
]
149149
},
150150
"subject": {
151-
"reference": "urn:uuid:pat-mrn-1",
151+
"reference": "urn:uuid:mrn-1",
152152
"type": "Patient"
153153
},
154154
"method": {
@@ -177,10 +177,10 @@
177177
}
178178
},
179179
{
180-
"fullUrl": "urn:uuid:23564150098c6afeb2abc712086a21ead2e9bd308929f9d290988c6921ac841b",
180+
"fullUrl": "urn:uuid:8fca0c2922335ea3c92022b4b2d4de17ba0645ce72d884b1e1c71a757c300a10",
181181
"resource": {
182182
"resourceType": "Observation",
183-
"id": "23564150098c6afeb2abc712086a21ead2e9bd308929f9d290988c6921ac841b",
183+
"id": "8fca0c2922335ea3c92022b4b2d4de17ba0645ce72d884b1e1c71a757c300a10",
184184
"meta": {
185185
"profile": [
186186
"http://hl7.org/fhir/us/mcode/StructureDefinition/mcode-tnm-clinical-stage-group"
@@ -214,7 +214,7 @@
214214
]
215215
},
216216
"subject": {
217-
"reference": "urn:uuid:pat-mrn-1",
217+
"reference": "urn:uuid:mrn-1",
218218
"type": "Patient"
219219
},
220220
"effectiveDateTime": "2020-01-01",
@@ -234,15 +234,15 @@
234234
],
235235
"hasMember": [
236236
{
237-
"reference": "urn:uuid:ed5faf7f2a1cef061d7584afd463e60eb7202104700647e92fbb7c9419eb7897",
237+
"reference": "urn:uuid:626b61fd700d8ddc5a6a576a2e47944191b5f608e03083d00c49614f0158bb65",
238238
"type": "Observation"
239239
},
240240
{
241-
"reference": "urn:uuid:88992af10e3a822f2a946628de91012d5afae49a25d1641db09e9d6ed4ca24c3",
241+
"reference": "urn:uuid:66e0e5f216bebeba287c3a3b0e220170bab88da95030e0c4bdba32f66628d00c",
242242
"type": "Observation"
243243
},
244244
{
245-
"reference": "urn:uuid:1373d3fb234cad0b03912cfbba16bdc4eabbd6217d83b838f6d9c1343bc9b394",
245+
"reference": "urn:uuid:4469acab85a889d722f5b8b1cb786df8adbfc5f0b50ac23393ec42b8ecfd49e9",
246246
"type": "Observation"
247247
}
248248
]

test/extractors/fixtures/csv-staging-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
"stageGroup": "3C",
66
"t": "cT3",

0 commit comments

Comments
 (0)