@@ -33,30 +33,26 @@ class DICOMEntity {
33
33
const name = this . constructor . name
34
34
const tags = this . constructor . tags
35
35
const primaryTag = this . constructor . primaryTag
36
- console . assert (
37
- tags . includes ( primaryTag ) ,
38
- `The primary tag of the ${ name } class ("${ primaryTag } ") is not included in its list of tags ([${ tags } ]).`
39
- )
36
+ if ( ! tags . includes ( primaryTag ) ) {
37
+ throw Error ( `The primary tag of the ${ name } class ("${ primaryTag } ") is not included in its list of tags ([${ tags } ]).` )
38
+ }
40
39
tags . forEach ( ( tag ) => {
41
- console . assert (
42
- tag in DICOM_DICTIONARY ,
43
- `The tag "${ tag } " associated with the ${ name } class is not defined in DICOM_DICTIONARY.`
44
- )
40
+ if ( ! ( tag in DICOM_DICTIONARY ) ) {
41
+ throw Error ( `The tag "${ tag } " associated with the ${ name } class is not defined in DICOM_DICTIONARY.` )
42
+ }
45
43
} )
46
44
}
47
45
48
46
extractTags ( dicomMetaData ) {
47
+ const name = this . constructor . name
49
48
const tags = this . constructor . tags
50
49
const primaryTag = this . constructor . primaryTag
51
50
tags . forEach ( ( tag ) => {
52
51
const value = dicomMetaData . string ( DICOM_DICTIONARY [ tag ] )
53
52
if ( this [ tag ] === undefined ) {
54
53
this [ tag ] = value
55
- } else if ( value !== undefined ) {
56
- console . assert (
57
- this [ tag ] === value ,
58
- `Inconsistent value for ${ tag } property of ${ this [ primaryTag ] } `
59
- )
54
+ } else if ( value !== undefined && this [ tag ] !== value ) {
55
+ throw new Error ( `Inconsistent value for the "${ tag } " property of ${ name } "${ this [ primaryTag ] } ": received "${ this [ tag ] } " but already had "${ value } ".` )
60
56
}
61
57
} )
62
58
}
@@ -160,8 +156,9 @@ class DICOMSerie extends DICOMEntity {
160
156
}
161
157
}
162
158
163
- const parseDicomFiles = async ( fileList ) => {
164
- var patientDict = { }
159
+ const parseDicomFiles = async ( fileList , skipOnFailure = false ) => {
160
+ const patientDict = { }
161
+ const failures = [ ]
165
162
166
163
const parseFile = async ( file ) => {
167
164
// Read
@@ -182,13 +179,23 @@ const parseDicomFiles = async (fileList) => {
182
179
patient . parseMetaData ( dicomMetaData , file )
183
180
}
184
181
182
+ // Set up promises
183
+ const parseFiles = [ ...fileList ] . map ( ( file ) => {
184
+ const promise = parseFile ( file )
185
+ if ( skipOnFailure ) {
186
+ promise . catch ( ( error ) => {
187
+ failures . push ( { file, error } )
188
+ } )
189
+ }
190
+ return promise
191
+ } )
192
+
185
193
// Parse all files and populate patientDict
186
- const parseFiles = [ ...fileList ] . map ( parseFile )
187
194
const logName = `Parsed ${ fileList . length } DICOM files in`
188
195
console . time ( logName )
189
196
await Promise . all ( parseFiles )
190
197
console . timeEnd ( logName )
191
- return patientDict
198
+ return { patientDict, failures }
192
199
}
193
200
194
201
export default parseDicomFiles
0 commit comments