Skip to content

Commit 8ea6be3

Browse files
author
Alexis Girault
committed
Check tags validity when imoprting parseDicomFiles
Not when instantiating a DICOMEntity class
1 parent 0b39e7d commit 8ea6be3

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

examples/Dicom/src/parseDicomFiles.js

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,6 @@ const DICOM_DICTIONARY = {
2525
}
2626

2727
class DICOMEntity {
28-
constructor() {
29-
this.checkTagsValidity() // could it be a static assertion instead?
30-
}
31-
32-
checkTagsValidity() {
33-
const name = this.constructor.name
34-
const tags = this.constructor.tags
35-
const primaryTag = this.constructor.primaryTag
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-
}
39-
tags.forEach((tag) => {
40-
if (!(tag in DICOM_DICTIONARY)) {
41-
throw Error(`The tag "${tag}" associated with the ${name} class is not defined in DICOM_DICTIONARY.`)
42-
}
43-
})
44-
}
45-
4628
extractTags(dicomMetaData) {
4729
const name = this.constructor.name
4830
const tags = this.constructor.tags
@@ -156,6 +138,23 @@ class DICOMSerie extends DICOMEntity {
156138
}
157139
}
158140

141+
function checkTagsValidity(klass) {
142+
const name = klass.name
143+
const tags = klass.tags
144+
const primaryTag = klass.primaryTag
145+
if (!tags.includes(primaryTag)) {
146+
throw Error(`The primary tag of the ${name} class ("${primaryTag}") is not included in its list of tags ([${tags}]).`)
147+
}
148+
tags.forEach((tag) => {
149+
if (!(tag in DICOM_DICTIONARY)) {
150+
throw Error(`The tag "${tag}" associated with the ${name} class is not defined in DICOM_DICTIONARY.`)
151+
}
152+
})
153+
}
154+
checkTagsValidity(DICOMPatient)
155+
checkTagsValidity(DICOMStudy)
156+
checkTagsValidity(DICOMSerie)
157+
159158
class ParseDicomError extends Error {
160159
constructor(failures) {
161160
const message =

0 commit comments

Comments
 (0)