@@ -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,7 +156,7 @@ class DICOMSerie extends DICOMEntity {
160
156
}
161
157
}
162
158
163
- const parseDicomFiles = async ( fileList ) => {
159
+ const parseDicomFiles = async ( fileList , skipOnFailure = false ) => {
164
160
var patientDict = { }
165
161
166
162
const parseFile = async ( file ) => {
@@ -186,7 +182,17 @@ const parseDicomFiles = async (fileList) => {
186
182
const parseFiles = [ ...fileList ] . map ( parseFile )
187
183
const logName = `Parsed ${ fileList . length } DICOM files in`
188
184
console . time ( logName )
189
- await Promise . all ( parseFiles )
185
+ if ( skipOnFailure ) {
186
+ parseFiles . forEach ( async ( promise ) => {
187
+ try {
188
+ await promise
189
+ } catch ( error ) {
190
+ console . error ( error )
191
+ }
192
+ } )
193
+ } else {
194
+ await Promise . all ( parseFiles )
195
+ }
190
196
console . timeEnd ( logName )
191
197
return patientDict
192
198
}
0 commit comments