Skip to content

Commit b8a6bc9

Browse files
committed
Avoid adding same mappings and segments twice
1 parent 6e29629 commit b8a6bc9

File tree

5 files changed

+50
-23
lines changed

5 files changed

+50
-23
lines changed

package-lock.json

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
"dicomweb-client": "^0.8",
8787
"image-type": "^4.1",
8888
"mathjs": "^10.1",
89-
"ol": "^6.15"
89+
"ol": "^6.15",
90+
"uuid": "^8.3.2"
9091
}
9192
}

src/mapping.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ class ParameterMapping {
7575
/**
7676
* @param {Object} options
7777
* @param {string} options.uid - Unique tracking identifier
78-
* @param {number} options.number - Mapping Number (one-based index value)
79-
* @param {string} options.label - Mapping Label
78+
* @param {number} options.number - Parameter Number (one-based index value)
79+
* @param {string} options.label - Parameter Label
80+
* @param {string} options.description - Parameter Description
8081
* @param {string} options.studyInstanceUID - Study Instance UID of DICOM
8182
* Parametric Map instances
8283
* @param {string} options.seriesInstanceUID - Series Instance UID of DICOM
@@ -90,6 +91,7 @@ class ParameterMapping {
9091
uid,
9192
number,
9293
label,
94+
description,
9395
studyInstanceUID,
9496
seriesInstanceUID,
9597
sopInstanceUIDs,
@@ -103,15 +105,20 @@ class ParameterMapping {
103105
}
104106

105107
if (number === undefined) {
106-
throw new Error('Mapping Number is required.')
108+
throw new Error('Parameter Number is required.')
107109
}
108110
this[_attrs].number = number
109111

110112
if (label === undefined) {
111-
throw new Error('Mapping Label is required.')
113+
throw new Error('Parameter Label is required.')
112114
}
113115
this[_attrs].label = label
114116

117+
if (description === undefined) {
118+
throw new Error('Parameter Description is required.')
119+
}
120+
this[_attrs].description = description
121+
115122
if (studyInstanceUID === undefined) {
116123
throw new Error('Study Instance UID is required.')
117124
}
@@ -142,7 +149,7 @@ class ParameterMapping {
142149
}
143150

144151
/**
145-
* Mapping Number.
152+
* Parameter Number
146153
*
147154
* @type number
148155
*/
@@ -151,14 +158,23 @@ class ParameterMapping {
151158
}
152159

153160
/**
154-
* Mapping Label
161+
* Parameter Label
155162
*
156163
* @type string
157164
*/
158165
get label () {
159166
return this[_attrs].label
160167
}
161168

169+
/**
170+
* Parameter Description
171+
*
172+
* @type string
173+
*/
174+
get description () {
175+
return this[_attrs].description
176+
}
177+
162178
/**
163179
* Study Instance UID of DICOM Parametric Map instances.
164180
*

src/utils.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { inv, multiply } from 'mathjs'
22
import { getPointResolution } from 'ol/proj'
3+
import { v4 as createUUIDv4, v5 as createUUIDv5 } from 'uuid'
4+
5+
const _UUID_NAMESPACE = 'c4f09b11-bac0-4f3a-8dc1-9f0046637383'
36

47
/**
58
* Generates a UUID-derived DICOM UID with root `2.25`.
@@ -8,7 +11,7 @@ import { getPointResolution } from 'ol/proj'
811
*
912
* @private
1013
*/
11-
function _generateUID () {
14+
function _generateUID ({ value } = {}) {
1215
/**
1316
* A UUID can be represented as a single integer value.
1417
* http://dicom.nema.org/medical/dicom/current/output/chtml/part05/sect_B.2.html
@@ -20,12 +23,15 @@ function _generateUID () {
2023
* the least significant bit as the least significant bit (bit 0) of the last
2124
* of the sixteen octets (octet 0).
2225
*/
23-
let uid = '2.25.' + Math.floor(1 + Math.random() * 9)
24-
// FIXME: This is not a valid UUID!
25-
while (uid.length < 44) {
26-
uid += Math.floor(1 + Math.random() * 10)
26+
let uuid
27+
if (value != null) {
28+
uuid = createUUIDv5(value, _UUID_NAMESPACE)
29+
} else {
30+
uuid = createUUIDv4()
2731
}
28-
return uid
32+
const hex = '0x' + uuid.replace(/-/g, '')
33+
const decimal = BigInt(hex)
34+
return '2.25.' + decimal.toString()
2935
}
3036

3137
/**

src/viewer.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3246,8 +3246,10 @@ class VolumeImageViewer {
32463246
refSegmentation.SegmentSequence.forEach((item, index) => {
32473247
const segmentNumber = Number(item.SegmentNumber)
32483248
console.info(`add segment # ${segmentNumber}`)
3249-
let segmentUID = _generateUID()
3250-
if (item.TrackingUID) {
3249+
let segmentUID = _generateUID({
3250+
value: refSegmentation.SOPInstanceUID + segmentNumber.toString()
3251+
})
3252+
if (item.TrackingUID != null) {
32513253
segmentUID = item.TrackingUID
32523254
}
32533255

@@ -3671,10 +3673,13 @@ class VolumeImageViewer {
36713673

36723674
let index = 0
36733675
for (const mappingNumber in mappingNumberToDescriptions) {
3674-
const mappingLabel = `${mappingNumber}`
36753676
const mappingDescriptions = mappingNumberToDescriptions[mappingNumber]
36763677
const refItem = mappingDescriptions[0]
3677-
let mappingUID = _generateUID()
3678+
const mappingLabel = refItem.LUTLabel
3679+
const mappingExplanation = refItem.LUTExplanation
3680+
let mappingUID = _generateUID({
3681+
value: refInstance.SOPInstanceUID + mappingLabel
3682+
})
36783683
if (refItem.TrackingUID != null) {
36793684
mappingUID = refItem.TrackingUID
36803685
}
@@ -3724,7 +3729,7 @@ class VolumeImageViewer {
37243729
}
37253730
if (refInstance.PixelPresentation === 'MONOCHROME') {
37263731
colormap = createColormap({
3727-
name: ColormapNames.GRAY,
3732+
name: ColormapNames.MAGMA,
37283733
bins: Math.pow(2, 8)
37293734
})
37303735
} else {
@@ -3770,6 +3775,7 @@ class VolumeImageViewer {
37703775
uid: mappingUID,
37713776
number: mappingNumber,
37723777
label: mappingLabel,
3778+
description: mappingExplanation,
37733779
studyInstanceUID: refInstance.StudyInstanceUID,
37743780
seriesInstanceUID: refInstance.SeriesInstanceUID,
37753781
sopInstanceUIDs: pyramid.metadata.map(element => {
@@ -3971,7 +3977,6 @@ class VolumeImageViewer {
39713977
}
39723978

39733979
let title = mapping.mapping.label
3974-
// FIXME
39753980
const padding = Math.round((16 - title.length) / 2)
39763981
title = title.padStart(title.length + padding)
39773982
title = title.padEnd(title.length + 2 * padding)

0 commit comments

Comments
 (0)