@@ -33,30 +33,26 @@ class DICOMEntity {
3333 const name = this . constructor . name
3434 const tags = this . constructor . tags
3535 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+ }
4039 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+ }
4543 } )
4644 }
4745
4846 extractTags ( dicomMetaData ) {
47+ const name = this . constructor . name
4948 const tags = this . constructor . tags
5049 const primaryTag = this . constructor . primaryTag
5150 tags . forEach ( ( tag ) => {
5251 const value = dicomMetaData . string ( DICOM_DICTIONARY [ tag ] )
5352 if ( this [ tag ] === undefined ) {
5453 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 } ".` )
6056 }
6157 } )
6258 }
@@ -160,7 +156,7 @@ class DICOMSerie extends DICOMEntity {
160156 }
161157}
162158
163- const parseDicomFiles = async ( fileList ) => {
159+ const parseDicomFiles = async ( fileList , skipOnFailure = false ) => {
164160 var patientDict = { }
165161
166162 const parseFile = async ( file ) => {
@@ -186,7 +182,17 @@ const parseDicomFiles = async (fileList) => {
186182 const parseFiles = [ ...fileList ] . map ( parseFile )
187183 const logName = `Parsed ${ fileList . length } DICOM files in`
188184 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+ }
190196 console . timeEnd ( logName )
191197 return patientDict
192198}
0 commit comments