File tree Expand file tree Collapse file tree 4 files changed +33
-10
lines changed Expand file tree Collapse file tree 4 files changed +33
-10
lines changed Original file line number Diff line number Diff line change @@ -66,7 +66,7 @@ class MCODEClient extends BaseClient {
66
66
{ type : 'CSVAdverseEventExtractor' , dependencies : [ 'CSVPatientExtractor' ] } ,
67
67
] ;
68
68
// Sort extractors based on order and dependencies
69
- sortExtractors ( this . extractorConfig , dependencyInfo ) ;
69
+ this . extractorConfig = sortExtractors ( this . extractorConfig , dependencyInfo ) ;
70
70
// Store webServiceAuthConfig if provided`
71
71
this . authConfig = webServiceAuthConfig ;
72
72
this . commonExtractorArgs = {
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ const logger = require('./logger');
14
14
*/
15
15
function sortExtractors ( extractors , dependencyInfo ) {
16
16
const missing = { } ;
17
- // Filter dependency info to onlly extractors in the config
17
+ // Filter dependency info to only extractors in the config
18
18
dependencyInfo . filter ( ( e ) => extractors . map ( ( x ) => x . type ) . includes ( e . type ) ) . forEach ( ( extractor ) => {
19
19
// For each extractor, check if its dependencies are present
20
20
extractor . dependencies . forEach ( ( dependency ) => {
@@ -35,8 +35,10 @@ function sortExtractors(extractors, dependencyInfo) {
35
35
throw new Error ( 'Some extractors are missing dependencies, see above for details.' ) ;
36
36
}
37
37
// If no missing dependencies, sort extractors into correct order
38
+ const sortedExtractors = [ ...extractors ] ;
38
39
const order = dependencyInfo . map ( ( x ) => x . type ) ;
39
- extractors . sort ( ( a , b ) => order . indexOf ( a . type ) - order . indexOf ( b . type ) ) ;
40
+ sortedExtractors . sort ( ( a , b ) => order . indexOf ( a . type ) - order . indexOf ( b . type ) ) ;
41
+ return sortedExtractors ;
40
42
}
41
43
42
44
module . exports = {
Original file line number Diff line number Diff line change @@ -92,6 +92,13 @@ describe('mcodeExtraction', () => {
92
92
filePath : path . join ( __dirname , './fixtures/example-clinical-trial-info.csv' ) ,
93
93
} ,
94
94
} ,
95
+ {
96
+ label : 'patient' ,
97
+ type : 'CSVPatientExtractor' ,
98
+ constructorArgs : {
99
+ filePath : path . join ( __dirname , './fixtures/example-patient.csv' ) ,
100
+ } ,
101
+ } ,
95
102
] ,
96
103
} ;
97
104
@@ -105,5 +112,21 @@ describe('mcodeExtraction', () => {
105
112
const flatErrors = flattenErrorValues ( totalExtractionErrors ) ;
106
113
expect ( flatErrors ) . toHaveLength ( 3 ) ;
107
114
} ) ;
115
+ it ( 'should throw error when initialized with missing dependencies' , async ( ) => {
116
+ const testConfig = {
117
+ extractors : [
118
+ // Should fail when this extractor is run without patient data in context
119
+ {
120
+ label : 'CTI' ,
121
+ type : 'CSVClinicalTrialInformationExtractor' ,
122
+ constructorArgs : {
123
+ filePath : path . join ( __dirname , './fixtures/example-clinical-trial-info.csv' ) ,
124
+ } ,
125
+ } ,
126
+ ] ,
127
+ } ;
128
+
129
+ expect ( ( ) => new MCODEClient ( testConfig ) ) . toThrow ( ) ;
130
+ } ) ;
108
131
} ) ;
109
132
} ) ;
Original file line number Diff line number Diff line change 1
- const _ = require ( 'lodash' ) ;
2
1
const { sortExtractors } = require ( '../../src/helpers/dependencyUtils.js' ) ;
3
2
4
3
const WRONG_ORDER = [
@@ -26,15 +25,14 @@ const DEPENDENCY_INFO = [
26
25
27
26
describe ( 'sortExtractors' , ( ) => {
28
27
test ( 'should put extractors in the correct order' , ( ) => {
29
- sortExtractors ( WRONG_ORDER , DEPENDENCY_INFO ) ;
30
- expect ( WRONG_ORDER [ 0 ] . type ) . toEqual ( 'Extractor1' ) ;
31
- expect ( WRONG_ORDER [ 1 ] . type ) . toEqual ( 'Extractor2' ) ;
32
- expect ( WRONG_ORDER [ 2 ] . type ) . toEqual ( 'Extractor3' ) ;
28
+ const sorted = sortExtractors ( WRONG_ORDER , DEPENDENCY_INFO ) ;
29
+ expect ( sorted [ 0 ] . type ) . toEqual ( 'Extractor1' ) ;
30
+ expect ( sorted [ 1 ] . type ) . toEqual ( 'Extractor2' ) ;
31
+ expect ( sorted [ 2 ] . type ) . toEqual ( 'Extractor3' ) ;
33
32
} ) ;
34
33
35
34
test ( 'should change nothing if all extractors are in order with all dependencies' , ( ) => {
36
- const unchanged = _ . cloneDeep ( NO_CHANGE ) ;
37
- sortExtractors ( unchanged , DEPENDENCY_INFO ) ;
35
+ const unchanged = sortExtractors ( NO_CHANGE , DEPENDENCY_INFO ) ;
38
36
expect ( unchanged ) . toEqual ( NO_CHANGE ) ;
39
37
} ) ;
40
38
You can’t perform that action at this time.
0 commit comments