dicom 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +20 -1
- data/README.rdoc +26 -17
- data/lib/dicom.rb +32 -28
- data/lib/dicom/anonymizer.rb +187 -49
- data/lib/dicom/audit_trail.rb +117 -0
- data/lib/dicom/constants.rb +1 -2
- data/lib/dicom/d_client.rb +13 -13
- data/lib/dicom/d_object.rb +50 -22
- data/lib/dicom/d_read.rb +9 -9
- data/lib/dicom/d_server.rb +14 -10
- data/lib/dicom/d_write.rb +6 -6
- data/lib/dicom/deprecated.rb +73 -0
- data/lib/dicom/element.rb +37 -5
- data/lib/dicom/elemental.rb +4 -4
- data/lib/dicom/file_handler.rb +10 -10
- data/lib/dicom/image_item.rb +28 -12
- data/lib/dicom/item.rb +36 -4
- data/lib/dicom/link.rb +1 -1
- data/lib/dicom/logging.rb +0 -0
- data/lib/dicom/parent.rb +41 -41
- data/lib/dicom/ruby_extensions.rb +6 -4
- data/lib/dicom/sequence.rb +34 -2
- data/lib/dicom/stream.rb +9 -2
- data/lib/dicom/variables.rb +19 -0
- data/lib/dicom/version.rb +1 -1
- metadata +30 -17
@@ -96,8 +96,7 @@ class String
|
|
96
96
|
# Returns true if it is, false if not.
|
97
97
|
#
|
98
98
|
def private?
|
99
|
-
|
100
|
-
return ((self.upcase =~ /\A[a-fA-F\d]{3}[1,3,5,7,9,B,D,F],[a-fA-F\d]{4}\z/) == nil ? false : true)
|
99
|
+
return ((self.upcase =~ /\A\h{3}[1,3,5,7,9,B,D,F],\h{4}\z/) == nil ? false : true)
|
101
100
|
end
|
102
101
|
|
103
102
|
# Checks if the string is a valid tag (as defined by Ruby DICOM: "GGGG,EEEE").
|
@@ -105,8 +104,7 @@ class String
|
|
105
104
|
#
|
106
105
|
def tag?
|
107
106
|
# Test that the string is composed of exactly 4 HEX characters, followed by a comma, then 4 more HEX characters:
|
108
|
-
|
109
|
-
return ((self.upcase =~ /\A[a-fA-F\d]{4},[a-fA-F\d]{4}\z/) == nil ? false : true)
|
107
|
+
return ((self.upcase =~ /\A\h{4},\h{4}\z/) == nil ? false : true)
|
110
108
|
end
|
111
109
|
|
112
110
|
# Redefines the old unpack method, adding the ability to decode signed integers in big endian.
|
@@ -154,6 +152,10 @@ class Array
|
|
154
152
|
# * <tt>string</tt> -- A template string which decides the encoding scheme to use.
|
155
153
|
#
|
156
154
|
def pack(string)
|
155
|
+
# FIXME: At some time in the future, when Ruby 1.9.3 can be set as required ruby version,
|
156
|
+
# this custom pack (as well as unpack) method can be discarded, and the desired endian
|
157
|
+
# encodings can probably be achieved with the new template strings introduced in 1.9.3.
|
158
|
+
#
|
157
159
|
# Check for some custom pack strings that we've invented:
|
158
160
|
case string
|
159
161
|
when "k*" # SS
|
data/lib/dicom/sequence.rb
CHANGED
@@ -29,9 +29,9 @@ module DICOM
|
|
29
29
|
# === Examples
|
30
30
|
#
|
31
31
|
# # Create a new Sequence and connect it to a DObject instance:
|
32
|
-
# structure_set_roi = Sequence.new("3006,0020", :parent =>
|
32
|
+
# structure_set_roi = Sequence.new("3006,0020", :parent => dcm)
|
33
33
|
# # Create an "Encapsulated Pixel Data" Sequence:
|
34
|
-
# encapsulated_pixel_data = Sequence.new("7FE0,0010", :name => "Encapsulated Pixel Data", :parent =>
|
34
|
+
# encapsulated_pixel_data = Sequence.new("7FE0,0010", :name => "Encapsulated Pixel Data", :parent => dcm, :vr => "OW")
|
35
35
|
#
|
36
36
|
def initialize(tag, options={})
|
37
37
|
raise ArgumentError, "The supplied tag (#{tag}) is not valid. The tag must be a string of the form 'GGGG,EEEE'." unless tag.is_a?(String) && tag.tag?
|
@@ -57,5 +57,37 @@ module DICOM
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
+
# Returns true if the argument is an instance with attributes equal to self.
|
61
|
+
#
|
62
|
+
def ==(other)
|
63
|
+
if other.respond_to?(:to_sequence)
|
64
|
+
other.send(:state) == state
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
alias_method :eql?, :==
|
69
|
+
|
70
|
+
# Generates a Fixnum hash value for this instance.
|
71
|
+
#
|
72
|
+
def hash
|
73
|
+
state.hash
|
74
|
+
end
|
75
|
+
|
76
|
+
# Returns self.
|
77
|
+
#
|
78
|
+
def to_sequence
|
79
|
+
self
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
|
86
|
+
# Returns the attributes of this instance in an array (for comparison purposes).
|
87
|
+
#
|
88
|
+
def state
|
89
|
+
[@tag, @vr, @tags]
|
90
|
+
end
|
91
|
+
|
60
92
|
end
|
61
93
|
end
|
data/lib/dicom/stream.rb
CHANGED
@@ -80,7 +80,14 @@ module DICOM
|
|
80
80
|
value = nil
|
81
81
|
else
|
82
82
|
if type == "AT"
|
83
|
-
|
83
|
+
# We need to guard ourselves against the case where a string contains an invalid 'AT' value:
|
84
|
+
if length == 4
|
85
|
+
value = decode_tag
|
86
|
+
else
|
87
|
+
# Invalid. Just return nil.
|
88
|
+
skip(length)
|
89
|
+
value = nil
|
90
|
+
end
|
84
91
|
else
|
85
92
|
# Decode the binary string and return value:
|
86
93
|
value = @string.slice(@index, length).unpack(vr_to_str(type))
|
@@ -233,7 +240,7 @@ module DICOM
|
|
233
240
|
# Encode:
|
234
241
|
bin = value.pack(type)
|
235
242
|
# Add an empty byte if the resulting binary has an odd length:
|
236
|
-
bin = bin + @pad_byte[vr] if bin.length
|
243
|
+
bin = bin + @pad_byte[vr] if bin.length.odd?
|
237
244
|
end
|
238
245
|
return bin
|
239
246
|
end
|
data/lib/dicom/variables.rb
CHANGED
@@ -17,6 +17,25 @@ module DICOM
|
|
17
17
|
# Module methods:
|
18
18
|
#++
|
19
19
|
|
20
|
+
# Generates a random (unique) UID string.
|
21
|
+
# The UID is composed of a DICOM root UID, a type prefix,
|
22
|
+
# a datetime part and a random number part.
|
23
|
+
# Returns the UID string.
|
24
|
+
#
|
25
|
+
# === Parameters
|
26
|
+
#
|
27
|
+
# * <tt>root</tt> -- String. The DICOM root UID to be used for generating the UID string, e.g. '1.2.840.999'.
|
28
|
+
# * <tt>prefix</tt> -- String. An integer string which is placed between the dicom root and the time/random part of the UID.
|
29
|
+
#
|
30
|
+
def generate_uid(root=UID, prefix=1)
|
31
|
+
# NB! For UIDs, leading zeroes immediately after a dot is not allowed.
|
32
|
+
date = Time.now.strftime("%Y%m%d").to_i.to_s
|
33
|
+
time = Time.now.strftime("%H%M%S").to_i.to_s
|
34
|
+
random = rand(99999) + 1 # (Minimum 1, max. 99999)
|
35
|
+
uid = [root, prefix, date, time, random].join('.')
|
36
|
+
return uid
|
37
|
+
end
|
38
|
+
|
20
39
|
# Use tags as key. Example: "0010,0010"
|
21
40
|
#
|
22
41
|
def key_use_tags
|
data/lib/dicom/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: dicom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.9.
|
5
|
+
version: 0.9.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Christoffer Lervag
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date:
|
13
|
+
date: 2012-05-06 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -24,60 +24,71 @@ dependencies:
|
|
24
24
|
type: :development
|
25
25
|
version_requirements: *id001
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
|
-
name:
|
27
|
+
name: rake
|
28
28
|
prerelease: false
|
29
29
|
requirement: &id002 !ruby/object:Gem::Requirement
|
30
30
|
none: false
|
31
31
|
requirements:
|
32
32
|
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: 2.
|
34
|
+
version: 0.9.2.2
|
35
35
|
type: :development
|
36
36
|
version_requirements: *id002
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
|
-
name:
|
38
|
+
name: rspec
|
39
39
|
prerelease: false
|
40
40
|
requirement: &id003 !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
43
|
- - ">="
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
45
|
+
version: 2.9.0
|
46
46
|
type: :development
|
47
47
|
version_requirements: *id003
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
|
-
name:
|
49
|
+
name: mocha
|
50
50
|
prerelease: false
|
51
51
|
requirement: &id004 !ruby/object:Gem::Requirement
|
52
52
|
none: false
|
53
53
|
requirements:
|
54
54
|
- - ">="
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
version: 0.
|
56
|
+
version: 0.10.5
|
57
57
|
type: :development
|
58
58
|
version_requirements: *id004
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
|
-
name:
|
60
|
+
name: narray
|
61
61
|
prerelease: false
|
62
62
|
requirement: &id005 !ruby/object:Gem::Requirement
|
63
63
|
none: false
|
64
64
|
requirements:
|
65
65
|
- - ">="
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version:
|
67
|
+
version: 0.6.0.0
|
68
68
|
type: :development
|
69
69
|
version_requirements: *id005
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
|
-
name:
|
71
|
+
name: rmagick
|
72
72
|
prerelease: false
|
73
73
|
requirement: &id006 !ruby/object:Gem::Requirement
|
74
74
|
none: false
|
75
75
|
requirements:
|
76
76
|
- - ">="
|
77
77
|
- !ruby/object:Gem::Version
|
78
|
-
version:
|
78
|
+
version: 2.12.0
|
79
79
|
type: :development
|
80
80
|
version_requirements: *id006
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: mini_magick
|
83
|
+
prerelease: false
|
84
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 3.2.1
|
90
|
+
type: :development
|
91
|
+
version_requirements: *id007
|
81
92
|
description: DICOM is a standard widely used throughout the world to store and transfer medical image data. This library enables efficient and powerful handling of DICOM in Ruby, to the benefit of any student or professional who would like to use their favorite language to process DICOM files and communicate across the network.
|
82
93
|
email: chris.lervag@gmail.com
|
83
94
|
executables: []
|
@@ -88,6 +99,7 @@ extra_rdoc_files: []
|
|
88
99
|
|
89
100
|
files:
|
90
101
|
- lib/dicom/anonymizer.rb
|
102
|
+
- lib/dicom/audit_trail.rb
|
91
103
|
- lib/dicom/constants.rb
|
92
104
|
- lib/dicom/d_client.rb
|
93
105
|
- lib/dicom/d_library.rb
|
@@ -95,6 +107,7 @@ files:
|
|
95
107
|
- lib/dicom/d_read.rb
|
96
108
|
- lib/dicom/d_server.rb
|
97
109
|
- lib/dicom/d_write.rb
|
110
|
+
- lib/dicom/deprecated.rb
|
98
111
|
- lib/dicom/dictionary.rb
|
99
112
|
- lib/dicom/element.rb
|
100
113
|
- lib/dicom/elemental.rb
|
@@ -117,8 +130,8 @@ files:
|
|
117
130
|
- COPYING
|
118
131
|
- README.rdoc
|
119
132
|
homepage: http://dicom.rubyforge.org/
|
120
|
-
licenses:
|
121
|
-
|
133
|
+
licenses:
|
134
|
+
- GPLv3
|
122
135
|
post_install_message:
|
123
136
|
rdoc_options: []
|
124
137
|
|
@@ -129,17 +142,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
129
142
|
requirements:
|
130
143
|
- - ">="
|
131
144
|
- !ruby/object:Gem::Version
|
132
|
-
version: 1.
|
145
|
+
version: 1.9.2
|
133
146
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
147
|
none: false
|
135
148
|
requirements:
|
136
149
|
- - ">="
|
137
150
|
- !ruby/object:Gem::Version
|
138
|
-
version: 1.
|
151
|
+
version: 1.8.6
|
139
152
|
requirements: []
|
140
153
|
|
141
154
|
rubyforge_project: dicom
|
142
|
-
rubygems_version: 1.8.
|
155
|
+
rubygems_version: 1.8.13
|
143
156
|
signing_key:
|
144
157
|
specification_version: 3
|
145
158
|
summary: Library for handling DICOM files and DICOM network communication.
|