Skip to content

Commit 1ac6fa2

Browse files
committed
updated readme; exporting baseCSVExtractor; added tests
1 parent e840e30 commit 1ac6fa2

File tree

4 files changed

+70
-3
lines changed

4 files changed

+70
-3
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ Examples files for these extractor can be found in the [`test/sample-client-data
9292

9393
After exporting your CSV files to the `data` directory, kickstart the creation of a configuration file by renaming the provided `csv.config.example.json` to `csv.config.json`. Then, ensure the following configuration parameters are properly set:
9494

95-
1. `patientIdCsvPath` should provide a file path to a CSV file containing MRN's for relevant patients;
96-
2. For each extractor, `filePath:` should provide a file path to a CSV file containing that corresponding extractor's data;
95+
1. `patientIdCsvPath` should correspond to an absolute file path to a CSV file containing MRN's for relevant patients;
96+
2. `commonExtractorArgs.dataDirectory` should correspond to an absolute path to the dataDirectory containing all your exported CSV files;
97+
3. For each extractor, `fileName` should correspond to the file name this extractor should be reading from. Note: combining the `dataDirectory` above and `fileName` should resolve to a file on disk containing this corresponding extractor's data;
9798

9899
For instructions on setting up an email notification trigger whenever an error is encountered in extraction, see the [Email Notification](#Email-Notification) section below.
99100

src/extractors/BaseCSVExtractor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class BaseCSVExtractor extends Extractor {
2929
logger.debug(
3030
'Could not instantiate a CSVExtractor with the provided constructor args',
3131
);
32-
throw new Error('Trying to instantiate a CSVExtractor without a filePath, url, or fileName+dataDirectory combination');
32+
throw new Error('Trying to instantiate a CSVExtractor without a valid filePath, url, or fileName+dataDirectory combination');
3333
}
3434
}
3535

src/extractors/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const { BaseCSVExtractor } = require('./BaseCSVExtractor');
12
const { BaseFHIRExtractor } = require('./BaseFHIRExtractor');
23
const { CSVAdverseEventExtractor } = require('./CSVAdverseEventExtractor');
34
const { CSVCancerDiseaseStatusExtractor } = require('./CSVCancerDiseaseStatusExtractor');
@@ -26,6 +27,7 @@ const { FHIRProcedureExtractor } = require('./FHIRProcedureExtractor');
2627
const { MCODESurgicalProcedureExtractor } = require('./MCODESurgicalProcedureExtractor');
2728

2829
module.exports = {
30+
BaseCSVExtractor,
2931
BaseFHIRExtractor,
3032
CSVAdverseEventExtractor,
3133
CSVCancerDiseaseStatusExtractor,
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
const { BaseCSVExtractor } = require('../../src/extractors');
2+
3+
// Tests
4+
describe('BaseCSVExtractor', () => {
5+
describe('constructor', () => {
6+
test('Should create a CSVURLModule when provided a filePath', () => {
7+
const filePathExtractor = new BaseCSVExtractor({ filePath: '/Users/dphelan/Development/mcode-extraction-framework/test/extractors/fixtures/example.csv' });
8+
expect(filePathExtractor.csvModule).not.toBeUndefined();
9+
expect(filePathExtractor.csvModule.constructor.name).toEqual('CSVFileModule');
10+
});
11+
test('Should create a CSVFileModule when provided a URL', () => {
12+
const urlExtractor = new BaseCSVExtractor({ url: 'http://example.com' });
13+
expect(urlExtractor.csvModule).not.toBeUndefined();
14+
expect(urlExtractor.csvModule.constructor.name).toEqual('CSVURLModule');
15+
});
16+
test('Should create a CSVFileModule when provided a fileName and a dataDirectory', () => {
17+
const fileNameDataDirectoryExtractor = new BaseCSVExtractor({ fileName: 'example.csv', dataDirectory: '/Users/dphelan/Development/mcode-extraction-framework/test/extractors/fixtures/' });
18+
expect(fileNameDataDirectoryExtractor.csvModule).not.toBeUndefined();
19+
expect(fileNameDataDirectoryExtractor.csvModule.constructor.name).toEqual('CSVFileModule');
20+
});
21+
test('Should fail when provided only provided a fileName and no dataDirectory', () => {
22+
expect(() => new BaseCSVExtractor({ fileName: 'example.csv' })
23+
.toThrowError('Trying to instantiate a CSVExtractor without a valid filePath, url, or fileName+dataDirectory combination'));
24+
});
25+
test('Should fail when provided only provided a dataDirectory and no fileName', () => {
26+
expect(() => new BaseCSVExtractor({ dataDirectory: '/Users/dphelan/Development/mcode-extraction-framework/test/extractors/fixtures/' })
27+
.toThrowError('Trying to instantiate a CSVExtractor without a valid filePath, url, or fileName+dataDirectory combination'));
28+
});
29+
test('Should fail when provided none of the three options above', () => {
30+
expect(() => new BaseCSVExtractor({})
31+
.toThrowError('Trying to instantiate a CSVExtractor without a valid filePath, url, or fileName+dataDirectory combination'));
32+
});
33+
});
34+
// test('updateRequestHeaders calls its modules updateRequestHeaders function', () => {
35+
// moduleRequestHeadersSpy.mockClear();
36+
// baseFHIRExtractor.updateRequestHeaders(MOCK_REQUEST_HEADERS);
37+
// expect(moduleRequestHeadersSpy).toHaveBeenCalledWith(MOCK_REQUEST_HEADERS);
38+
// });
39+
40+
// test('parametrizeArgsForFHIRModule parses data off of context if available', async () => {
41+
// baseFHIRModuleSearchSpy.mockClear();
42+
// const paramsBasedOnContext = await baseFHIRExtractor.parametrizeArgsForFHIRModule({ context: MOCK_CONTEXT });
43+
// expect(baseFHIRModuleSearchSpy).not.toHaveBeenCalled();
44+
// expect(paramsBasedOnContext).toHaveProperty('patient');
45+
// expect(paramsBasedOnContext.patient).toEqual(MOCK_CONTEXT.entry[0].resource.id);
46+
// });
47+
48+
// test('parametrizeArgsForFHIRModule throws an error if context has no relevant ID', async () => {
49+
// baseFHIRModuleSearchSpy.mockClear();
50+
// await expect(baseFHIRExtractor.parametrizeArgsForFHIRModule({ context: {} })).rejects.toThrow();
51+
// expect(baseFHIRModuleSearchSpy).not.toHaveBeenCalled();
52+
// });
53+
54+
// test('get should return a condition resource', async () => {
55+
// const data = await baseFHIRExtractor.get({ context: MOCK_CONTEXT });
56+
// expect(data.resourceType).toEqual('Bundle');
57+
// expect(data.entry).toBeDefined();
58+
// expect(data.entry.length).toBeGreaterThan(0);
59+
// expect(data.entry[0].resource.resourceType).toEqual('Condition');
60+
61+
// // expect data to contain every element in the example
62+
// expect(data.entry).toEqual(expect.arrayContaining(exampleConditionBundle.entry));
63+
// });
64+
});

0 commit comments

Comments
 (0)