Dicom_UID 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/dicom_uid.rb +32 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77add1d490996873947cbb9b63cb9ac6731b9107362da19707bb6c6918d0f65d
|
4
|
+
data.tar.gz: aa93e16d1ea8374321ccdb4b0f3b772d768af63cd80c0ac8a39ac04c7a583d0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d2f8ff395c4867c134176b99a4970a740769a1e802e291366d98a819d28ef59300e3be05947631fc355b016e835c2de08d857402444fa4f8095517eb90a345e
|
7
|
+
data.tar.gz: 23eab413d47fd50ad28a8bc7768f3c1bc8b3163fb69b4a6e93e3c99dffeccab55e3a3ebc3517a7166ab483fb37fe35031ba00a5e7a76e1772f8402f85418bb38
|
data/lib/dicom_uid.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
# DICOM UID Generator according to the DICOM documentation
|
4
4
|
# http://dicom.nema.org/dicom/2013/output/chtml/part05/chapter_9.html
|
5
|
+
# <org>.<suffix>
|
5
6
|
class DicomUID
|
6
7
|
|
7
8
|
|
@@ -40,9 +41,37 @@ class DicomUID
|
|
40
41
|
|
41
42
|
|
42
43
|
# set default values, with org_root if needed
|
43
|
-
|
44
|
-
|
45
|
-
|
44
|
+
# the size of the UID is randomized
|
45
|
+
def self.random_dicom_uid org_root, fixed_size
|
46
|
+
# building the org root
|
47
|
+
org_root ||= random_component# UID needs at least an org root
|
48
|
+
raise LeadingZeroError if org_root[0] == '0' and org_root.length != 1
|
49
|
+
raise OddByteError if org_root[-2].to_i % 2 == 1 and org_root[-1] != 0
|
50
|
+
org_root << '.' if org_root[-1] != '.'
|
51
|
+
srand
|
52
|
+
fixed_size ||= rand 64
|
53
|
+
# building the suffix
|
54
|
+
return self.rand_duid org_root, (fixed_size - org_root.length)
|
46
55
|
end
|
47
56
|
|
48
57
|
end
|
58
|
+
|
59
|
+
# EXCEPTIONS
|
60
|
+
|
61
|
+
class LeadingZeroError < StandardError
|
62
|
+
def initialize msg = "Can't have a leading 0 in a component with multiple digits"
|
63
|
+
super
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class OddByteError < StandardError
|
68
|
+
def initialize msg = "Can't have an odd last byte in a component"
|
69
|
+
super
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
class OversizedUIDError < StandardError
|
74
|
+
def initialize msg = "UID musn't be more than 64 characters"
|
75
|
+
super
|
76
|
+
end
|
77
|
+
end
|