dcm_dict 0.1.0
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 +7 -0
- data/COPYING +674 -0
- data/LICENSE +22 -0
- data/README.md +296 -0
- data/Rakefile +36 -0
- data/bin/dcm_dict_converter.rb +194 -0
- data/lib/dcm_dict.rb +46 -0
- data/lib/dcm_dict/dictionary/base_dictionary.rb +47 -0
- data/lib/dcm_dict/dictionary/base_record.rb +62 -0
- data/lib/dcm_dict/dictionary/data_element_dictionary.rb +117 -0
- data/lib/dcm_dict/dictionary/data_element_record.rb +93 -0
- data/lib/dcm_dict/dictionary/uid_dictionary.rb +82 -0
- data/lib/dcm_dict/dictionary/uid_record.rb +48 -0
- data/lib/dcm_dict/encoder/data_to_code.rb +79 -0
- data/lib/dcm_dict/error/dictionary_error.rb +30 -0
- data/lib/dcm_dict/ext/object_extension.rb +38 -0
- data/lib/dcm_dict/refine/array_refine.rb +34 -0
- data/lib/dcm_dict/refine/data_element_refine.rb +37 -0
- data/lib/dcm_dict/refine/internal/array_refine_internal.rb +97 -0
- data/lib/dcm_dict/refine/internal/hash_refine_internal.rb +71 -0
- data/lib/dcm_dict/refine/internal/string_refine_internal.rb +119 -0
- data/lib/dcm_dict/refine/string_refine.rb +35 -0
- data/lib/dcm_dict/refine/symbol_refine.rb +34 -0
- data/lib/dcm_dict/refine/uid_refine.rb +36 -0
- data/lib/dcm_dict/rubies/rb_ext.rb +32 -0
- data/lib/dcm_dict/source_data/data_elements_data.rb +3937 -0
- data/lib/dcm_dict/source_data/detached_data.rb +67 -0
- data/lib/dcm_dict/source_data/uid_values_data.rb +382 -0
- data/lib/dcm_dict/version.rb +27 -0
- data/lib/dcm_dict/xml/constant.rb +38 -0
- data/lib/dcm_dict/xml/field_data.rb +47 -0
- data/lib/dcm_dict/xml/nokogiri_tool.rb +108 -0
- data/lib/dcm_dict/xml/rexml_tool.rb +105 -0
- data/lib/dcm_dict/xml/tag_field_data.rb +96 -0
- data/lib/dcm_dict/xml/uid_field_data.rb +49 -0
- data/lib/dcm_dict/xml/xml_tool.rb +47 -0
- data/spec/data_element_sample_spec_helper.rb +110 -0
- data/spec/data_element_shared_example_spec_helper.rb +57 -0
- data/spec/dcm_dict/dictionary/data_element_dictionary_spec.rb +75 -0
- data/spec/dcm_dict/dictionary/data_element_record_spec.rb +117 -0
- data/spec/dcm_dict/dictionary/uid_dictionary_spec.rb +60 -0
- data/spec/dcm_dict/dictionary/uid_record_spec.rb +53 -0
- data/spec/dcm_dict/encoder/data_to_code_spec.rb +109 -0
- data/spec/dcm_dict/ext/object_extension_spec.rb +53 -0
- data/spec/dcm_dict/refine/array_refine_spec.rb +61 -0
- data/spec/dcm_dict/refine/internal/array_refine_internal_spec.rb +98 -0
- data/spec/dcm_dict/refine/internal/hash_refine_internal_spec.rb +64 -0
- data/spec/dcm_dict/refine/internal/string_refine_internal_spec.rb +214 -0
- data/spec/dcm_dict/refine/string_refine_spec.rb +87 -0
- data/spec/dcm_dict/refine/symbol_refine_spec.rb +41 -0
- data/spec/dcm_dict/rubies/rb_ext_spec.rb +46 -0
- data/spec/dcm_dict/source_data/data_elements_data_spec.rb +40 -0
- data/spec/dcm_dict/source_data/detached_data_spec.rb +55 -0
- data/spec/dcm_dict/source_data/uid_values_data_spec.rb +37 -0
- data/spec/dcm_dict/version_spec.rb +30 -0
- data/spec/dcm_dict/xml/tag_field_data_spec.rb +62 -0
- data/spec/dcm_dict/xml/uid_field_data_spec.rb +60 -0
- data/spec/dictionary_shared_example_spec_helper.rb +118 -0
- data/spec/refine_shared_example_spec_helper.rb +54 -0
- data/spec/spec_helper.rb +42 -0
- data/spec/xml_sample_spec_helper.rb +533 -0
- metadata +212 -0
@@ -0,0 +1,53 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2014 Enrico Rivarola
|
3
|
+
#
|
4
|
+
# This file is part of DcmDict gem (dcm_dict).
|
5
|
+
#
|
6
|
+
# DcmDict is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# DcmDict is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with DcmDict. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
#
|
19
|
+
# This software has neither been tested nor approved for clinical use
|
20
|
+
# or for incorporation in a medical device.
|
21
|
+
# It is the redistributor's or user's responsibility to comply with any
|
22
|
+
# applicable local, state, national or international regulations.
|
23
|
+
#
|
24
|
+
require 'spec_helper'
|
25
|
+
|
26
|
+
describe DcmDict::Dictionary::UidRecord do
|
27
|
+
[
|
28
|
+
{ uid_value: '1.2.840.10008.1.2',
|
29
|
+
uid_name: "Implicit VR Little Endian: Default Transfer Syntax for DICOM",
|
30
|
+
uid_type: :transfer_syntax }
|
31
|
+
].each do |data|
|
32
|
+
it "Handle Data Element Data correctly" do
|
33
|
+
ur = DcmDict::Dictionary::UidRecord.new(data.dup)
|
34
|
+
expect(ur.uid_value).to eq(data[:uid_value])
|
35
|
+
expect(ur.uid).to eq(data[:uid_value])
|
36
|
+
expect(ur.uid_name).to eq(data[:uid_name])
|
37
|
+
expect(ur.uid_type).to eq(data[:uid_type])
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
include_examples "Record handle methods correctly",
|
42
|
+
DcmDict::Dictionary::UidRecord.new(data),
|
43
|
+
data
|
44
|
+
|
45
|
+
it "data should be not modifiable" do
|
46
|
+
uid = DcmDict::Dictionary::UidRecord.new(data.dup)
|
47
|
+
old_value = uid.uid_value.dup
|
48
|
+
expect{uid.uid_value << 'aaa'}.to raise_error
|
49
|
+
expect(uid.uid_value).to eq(old_value)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2014 Enrico Rivarola
|
3
|
+
#
|
4
|
+
# This file is part of DcmDict gem (dcm_dict).
|
5
|
+
#
|
6
|
+
# DcmDict is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# DcmDict is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with DcmDict. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
#
|
19
|
+
# This software has neither been tested nor approved for clinical use
|
20
|
+
# or for incorporation in a medical device.
|
21
|
+
# It is the redistributor's or user's responsibility to comply with any
|
22
|
+
# applicable local, state, national or international regulations.
|
23
|
+
#
|
24
|
+
require 'spec_helper'
|
25
|
+
require 'xml_sample_spec_helper'
|
26
|
+
|
27
|
+
describe DcmDict::Encoder::DataToCode do
|
28
|
+
describe "should print out data element with" do
|
29
|
+
it "data elements header code" do
|
30
|
+
header = DcmDict::Encoder::DataToCode.data_element_header
|
31
|
+
expected_header = <<END
|
32
|
+
module DcmDict
|
33
|
+
module SourceData
|
34
|
+
DataElementsData = [
|
35
|
+
END
|
36
|
+
expect(header).to eq(expected_header)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "data elements footer code" do
|
40
|
+
footer = DcmDict::Encoder::DataToCode.data_element_footer
|
41
|
+
expected_footer=<<END
|
42
|
+
]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
END
|
46
|
+
expect(footer).to eq(expected_footer)
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "data element data field" do
|
50
|
+
using DcmDict::Refine::Internal::ArrayRefineInternal
|
51
|
+
|
52
|
+
XmlSampleSpecHelper.xml_tag_single_set.each do |xml_string, data|
|
53
|
+
it "for data element sample as #{data[:tag_ps].inspect}" do
|
54
|
+
indent = 4
|
55
|
+
tag_ary_str = "[0x#{data[:tag_ary].tag_group_str},0x#{data[:tag_ary].tag_element_str}]"
|
56
|
+
src_text = "#{' '*indent}{ tag_ps: '#{data[:tag_ps]}', tag_name: \"#{data[:tag_name]}\", tag_key: '#{data[:tag_key]}', tag_vr: #{data[:tag_vr]}, tag_vm: #{data[:tag_vm]}, tag_str: '#{data[:tag_str]}', tag_sym: #{data[:tag_sym].inspect}, tag_ndm: '#{data[:tag_ndm]}', tag_ary: #{tag_ary_str}, tag_multiple: #{data[:tag_multiple].inspect}, tag_note: '#{data[:tag_note]}'},"
|
57
|
+
src_line = DcmDict::Encoder::DataToCode.data_element_data_to_code(data)
|
58
|
+
expect(src_line).to eq(src_text)
|
59
|
+
src_line = DcmDict::Encoder::DataToCode.data_element_data_to_code(data, indent)
|
60
|
+
expect(src_line).to eq(src_text)
|
61
|
+
indent = 6
|
62
|
+
src_line = DcmDict::Encoder::DataToCode.data_element_data_to_code(data, indent)
|
63
|
+
expect(src_line.start_with?("#{' '*indent}{")).to be true
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "should print out uid with" do
|
71
|
+
it "uid header code" do
|
72
|
+
header = DcmDict::Encoder::DataToCode.uid_header
|
73
|
+
expected_header = <<END
|
74
|
+
module DcmDict
|
75
|
+
module SourceData
|
76
|
+
UidValuesData = [
|
77
|
+
END
|
78
|
+
expect(header).to eq(expected_header)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "uid footer code" do
|
82
|
+
footer = DcmDict::Encoder::DataToCode.uid_footer
|
83
|
+
expected_footer=<<END
|
84
|
+
]
|
85
|
+
end
|
86
|
+
end
|
87
|
+
END
|
88
|
+
expect(footer).to eq(expected_footer)
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "uid data field" do
|
92
|
+
XmlSampleSpecHelper.xml_uid_set.each do |xml_string, data|
|
93
|
+
it "for uid sample as #{data[:uid_value].inspect}" do
|
94
|
+
indent = 4
|
95
|
+
src_text = "#{' '*indent}{ uid_value: '#{data[:uid_value]}', uid_name: \"#{data[:uid_name]}\", uid_type: #{data[:uid_type].inspect}},"
|
96
|
+
src_line = DcmDict::Encoder::DataToCode.uid_data_to_code(data)
|
97
|
+
expect(src_line).to eq(src_text)
|
98
|
+
src_line = DcmDict::Encoder::DataToCode.uid_data_to_code(data, indent)
|
99
|
+
expect(src_line).to eq(src_text)
|
100
|
+
indent = 6
|
101
|
+
src_line = DcmDict::Encoder::DataToCode.uid_data_to_code(data, indent)
|
102
|
+
expect(src_line.start_with?("#{' '*indent}{")).to be true
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2014 Enrico Rivarola
|
3
|
+
#
|
4
|
+
# This file is part of DcmDict gem (dcm_dict).
|
5
|
+
#
|
6
|
+
# DcmDict is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# DcmDict is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with DcmDict. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
#
|
19
|
+
# This software has neither been tested nor approved for clinical use
|
20
|
+
# or for incorporation in a medical device.
|
21
|
+
# It is the redistributor's or user's responsibility to comply with any
|
22
|
+
# applicable local, state, national or international regulations.
|
23
|
+
#
|
24
|
+
require 'spec_helper'
|
25
|
+
|
26
|
+
describe "Object extension" do
|
27
|
+
|
28
|
+
describe "should check object for nil or empty status" do
|
29
|
+
describe "for class with empty? method" do
|
30
|
+
it "as string object" do
|
31
|
+
expect("bla bla".nil_or_empty?).to be_falsy
|
32
|
+
expect("".nil_or_empty?).to be_truthy
|
33
|
+
end
|
34
|
+
|
35
|
+
it "as array object" do
|
36
|
+
expect([1, 2].nil_or_empty?).to be_falsy
|
37
|
+
expect([].nil_or_empty?).to be_truthy
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "for class without empty? method" do
|
43
|
+
it "as fixnum object" do
|
44
|
+
expect(5.nil_or_empty?).to be_falsy
|
45
|
+
end
|
46
|
+
|
47
|
+
it "as nil object" do
|
48
|
+
expect(nil.nil_or_empty?).to be_truthy
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2014 Enrico Rivarola
|
3
|
+
#
|
4
|
+
# This file is part of DcmDict gem (dcm_dict).
|
5
|
+
#
|
6
|
+
# DcmDict is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# DcmDict is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with DcmDict. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
#
|
19
|
+
# This software has neither been tested nor approved for clinical use
|
20
|
+
# or for incorporation in a medical device.
|
21
|
+
# It is the redistributor's or user's responsibility to comply with any
|
22
|
+
# applicable local, state, national or international regulations.
|
23
|
+
#
|
24
|
+
require 'spec_helper'
|
25
|
+
|
26
|
+
describe "Array refinement" do
|
27
|
+
using DcmDict::Refine::ArrayRefine
|
28
|
+
|
29
|
+
describe "should permit access to single data element dictionary information" do
|
30
|
+
|
31
|
+
include_examples "refinement for standard tag",
|
32
|
+
[[0x0010,0x1005], [0x0028,0x1200], [0x0014,0x3050]],
|
33
|
+
Proc.new{|tag| tag}
|
34
|
+
|
35
|
+
|
36
|
+
multi_data = { [0x6046,0x0040] => {
|
37
|
+
tag_name: "Overlay Type",
|
38
|
+
tag_multiple: true,
|
39
|
+
tag_name: "Overlay Type",
|
40
|
+
tag_keyword: "OverlayType",
|
41
|
+
tag_key: "OverlayType",
|
42
|
+
tag_vr: [:CS], tag_vm: ["1"],
|
43
|
+
tag: [0x6046, 0x0040], tag_ary: [0x6046, 0x0040],
|
44
|
+
tag_ps: "(60XX,0040)",
|
45
|
+
tag_sym: :overlay_type,
|
46
|
+
tag_ndm: "60460040",
|
47
|
+
tag_str: "(6046,0040)",
|
48
|
+
tag_group: 0x6046,
|
49
|
+
tag_element: 0x0040 } }
|
50
|
+
|
51
|
+
include_examples "refinement for multiple tag",
|
52
|
+
multi_data,
|
53
|
+
Proc.new {|tag| tag}
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
include_examples "Raise exception for wrong input",
|
58
|
+
[ [0,1,2,3], [-0x0010,-0x0010], [0x1ffff,0x0010], [0x1ffff,0x10010], [0x0010, 0x1ffff]],
|
59
|
+
[],
|
60
|
+
Proc.new {|tag| tag}
|
61
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2014 Enrico Rivarola
|
3
|
+
#
|
4
|
+
# This file is part of DcmDict gem (dcm_dict).
|
5
|
+
#
|
6
|
+
# DcmDict is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# DcmDict is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with DcmDict. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
#
|
19
|
+
# This software has neither been tested nor approved for clinical use
|
20
|
+
# or for incorporation in a medical device.
|
21
|
+
# It is the redistributor's or user's responsibility to comply with any
|
22
|
+
# applicable local, state, national or international regulations.
|
23
|
+
#
|
24
|
+
require 'spec_helper'
|
25
|
+
|
26
|
+
describe "Array Refinement" do
|
27
|
+
|
28
|
+
using DcmDict::Refine::Internal::ArrayRefineInternal
|
29
|
+
it "should implement tag_ary metod" do
|
30
|
+
expect([0x0010,0x0020].to_tag_ary).to eq([0x0010,0x0020])
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "should extract group and element from 'array tag'" do
|
34
|
+
it "for correct object" do
|
35
|
+
expect([0x0010,0x0020].tag_group_num).to eq(0x0010)
|
36
|
+
expect([0x0010,0x0020].tag_element_num).to eq(0x0020)
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "and for wrong array must be raise error" do
|
40
|
+
[
|
41
|
+
[0x0010],
|
42
|
+
[0x0010,0x0020,0x0030],
|
43
|
+
['0010', '0020'],
|
44
|
+
[16.0, 0x0020],
|
45
|
+
[0x1ffff,0x10000],
|
46
|
+
[-1,-2]
|
47
|
+
].each do |tag|
|
48
|
+
it "as #{tag.inspect}" do
|
49
|
+
expect{ tag.tag_group_num }.to raise_error
|
50
|
+
expect{ tag.tag_element_num }.to raise_error
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "should convert group and element to hex string" do
|
59
|
+
{
|
60
|
+
[0xfffe,0xe0dd] => {group: 'FFFE', element: 'E0DD', tag_str: '(FFFE,E0DD)', tag_ndm: 'FFFEE0DD'},
|
61
|
+
[0x0010,0x0020] => {group: '0010', element: '0020', tag_str: '(0010,0020)', tag_ndm: '00100020'}
|
62
|
+
}.each do |tag, value|
|
63
|
+
it "for #{tag.inspect}" do
|
64
|
+
expect(tag.tag_group_str).to eq(value[:group])
|
65
|
+
expect(tag.tag_element_str).to eq(value[:element])
|
66
|
+
expect(tag.to_tag_str).to eq(value[:tag_str])
|
67
|
+
expect(tag.to_tag_ndm).to eq(value[:tag_ndm])
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "should check for group-length tag" do
|
73
|
+
{
|
74
|
+
[0x0010, 0x0020] => false,
|
75
|
+
[0x0010, 0x0000] => true,
|
76
|
+
[0x0000, 0x0002] => false,
|
77
|
+
[0x0000, 0x0000] => true
|
78
|
+
}.each do |tag, value|
|
79
|
+
it "for #{tag.inspect}" do
|
80
|
+
expect(tag.group_length_tag?).to eq(value)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "should check for private-creator tag" do
|
86
|
+
{
|
87
|
+
[0x0010, 0x0010] => false,
|
88
|
+
[0x0011, 0x0010] => true,
|
89
|
+
[0x0011, 0x0110] => false,
|
90
|
+
[0x0028, 0x2468] => false
|
91
|
+
}.each do |tag, value|
|
92
|
+
it "for #{tag.inspect}" do
|
93
|
+
expect(tag.private_creator_tag?).to eq(value)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2014 Enrico Rivarola
|
3
|
+
#
|
4
|
+
# This file is part of DcmDict gem (dcm_dict).
|
5
|
+
#
|
6
|
+
# DcmDict is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# DcmDict is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with DcmDict. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
#
|
19
|
+
# This software has neither been tested nor approved for clinical use
|
20
|
+
# or for incorporation in a medical device.
|
21
|
+
# It is the redistributor's or user's responsibility to comply with any
|
22
|
+
# applicable local, state, national or international regulations.
|
23
|
+
#
|
24
|
+
require 'spec_helper'
|
25
|
+
|
26
|
+
describe "Hash internal refinement" do
|
27
|
+
using DcmDict::Refine::Internal::HashRefineInternal
|
28
|
+
|
29
|
+
it "should check for lowercase tag_ps field" do
|
30
|
+
h = {tag_ps: '(fffe,E000)'}
|
31
|
+
h.check_tag_ps!
|
32
|
+
expect(h).to eq({tag_ps: '(FFFE,E000)'})
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should check for missing tag_ps field" do
|
36
|
+
expect{ {tag_ps: ''}.check_tag_ps! }.to raise_error("Missing tag_ps field")
|
37
|
+
expect{ {}.check_tag_ps! }.to raise_error("Missing tag_ps field")
|
38
|
+
end
|
39
|
+
|
40
|
+
context "Placeholders data: no Name or Keyword or VR or VM is specified" do
|
41
|
+
{
|
42
|
+
{ tag_ps: '(0018,9445)', tag_name: '', tag_key: '', tag_vr: [], tag_vm: [], tag_note: 'RET - See Note' } => { tag_ps: '(0018,9445)', tag_name: "Placeholder (0018,9445)", tag_key: 'Placeholder_0018_9445', tag_vr: [:UN], tag_vm: ["1"], tag_note: 'RET - See Note'},
|
43
|
+
{ tag_ps: '(0018,9445)', tag_name: '', tag_key: '', tag_vm: [], tag_note: 'RET - See Note' } => { tag_ps: '(0018,9445)', tag_name: "Placeholder (0018,9445)", tag_key: 'Placeholder_0018_9445', tag_vr: [:UN], tag_vm: ["1"], tag_note: 'RET - See Note'},
|
44
|
+
{ tag_ps: '(0018,9445)', tag_name: '', tag_key: '', tag_vr: [], tag_note: 'RET - See Note' } => { tag_ps: '(0018,9445)', tag_name: "Placeholder (0018,9445)", tag_key: 'Placeholder_0018_9445', tag_vr: [:UN], tag_vm: ["1"], tag_note: 'RET - See Note'},
|
45
|
+
{ tag_ps: '(0018,9445)', tag_key: '', tag_vr: [], tag_vm: [], tag_note: 'RET - See Note' } => { tag_ps: '(0018,9445)', tag_name: "Placeholder (0018,9445)", tag_key: 'Placeholder_0018_9445', tag_vr: [:UN], tag_vm: ["1"], tag_note: 'RET - See Note'},
|
46
|
+
{ tag_ps: '(0018,9445)', tag_name: '', tag_vr: [], tag_vm: [], tag_note: 'RET - See Note' } => { tag_ps: '(0018,9445)', tag_name: "Placeholder (0018,9445)", tag_key: 'Placeholder_0018_9445', tag_vr: [:UN], tag_vm: ["1"], tag_note: 'RET - See Note'},
|
47
|
+
}.each do |src_data, expected_data|
|
48
|
+
it "should check for placeholder data (#{src_data[:tag_ps].inspect} with keys #{src_data.keys.inspect})" do
|
49
|
+
src_data.check_placeholder_data!
|
50
|
+
expect(src_data).to eq(expected_data)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
[
|
55
|
+
{ tag_ps: '', tag_name: '', tag_key: '', tag_vr: [], tag_vm: [], tag_note: 'RET - See Note' },
|
56
|
+
{ tag_name: '', tag_key: '', tag_vr: [], tag_vm: [], tag_note: 'RET - See Note' }
|
57
|
+
].each do |data|
|
58
|
+
it "should raise error if :tag_ps field is missing (tag_ps=#{data[:tag_ps].inspect})" do
|
59
|
+
expect{data.check_placeholder_data!}.to raise_error("Missing tag_ps field")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,214 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
#
|
3
|
+
# Copyright (C) 2014 Enrico Rivarola
|
4
|
+
#
|
5
|
+
# This file is part of DcmDict gem (dcm_dict).
|
6
|
+
#
|
7
|
+
# DcmDict is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU General Public License as published by
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# DcmDict is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with DcmDict. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
# This software has neither been tested nor approved for clinical use
|
21
|
+
# or for incorporation in a medical device.
|
22
|
+
# It is the redistributor's or user's responsibility to comply with any
|
23
|
+
# applicable local, state, national or international regulations.
|
24
|
+
#
|
25
|
+
require 'spec_helper'
|
26
|
+
|
27
|
+
describe "String refinement (internal)" do
|
28
|
+
|
29
|
+
using DcmDict::Refine::Internal::StringRefineInternal
|
30
|
+
describe "should remove unwanted space characters" do
|
31
|
+
|
32
|
+
[
|
33
|
+
["FileSetDescriptorFileID ", "trailing spaces"],
|
34
|
+
[" FileSetDescriptorFileID", "leading spaces"],
|
35
|
+
[" FileSetDescriptorFileID ", "leading and trailing spaces"],
|
36
|
+
["FileSetDescriptorFileID", "zero width spaces"],
|
37
|
+
[" FileSetDescriptorFileID ", "leading, trailing and zero width spaces"]
|
38
|
+
].each do |wrong_string, comment|
|
39
|
+
it "for string containing #{comment}" do
|
40
|
+
expect(wrong_string.dcm_unspace).to eq('FileSetDescriptorFileID')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "should convert keyword tag string to symbol object" do
|
46
|
+
[
|
47
|
+
['DarkCurrentCounts', :dark_current_counts],
|
48
|
+
['InstanceCreationDate', :instance_creation_date],
|
49
|
+
['RecognitionCode', :recognition_code],
|
50
|
+
['CoefficientsSDVN', :coefficients_sdvn],
|
51
|
+
['OffsetOfReferencedLowerLevelDirectoryEntity', :offset_of_referenced_lower_level_directory_entity],
|
52
|
+
['FileSetDescriptorFileID', :file_set_descriptor_file_id],
|
53
|
+
['SOPClassUID', :sop_class_uid],
|
54
|
+
['RelatedGeneralSOPClassUID', :related_general_sop_class_uid],
|
55
|
+
['ReferencedSOPClassUIDInFile', :referenced_sop_class_uid_in_file],
|
56
|
+
['MAUsedInGainCalibration', :ma_used_in_gain_calibration],
|
57
|
+
['OtherPatientIDsSequence', :other_patient_ids_sequence],
|
58
|
+
['RelativeXRayExposure', :relative_x_ray_exposure],
|
59
|
+
['DisplayedZValue', :displayed_z_value],
|
60
|
+
['PhysicalUnitsXDirection', :physical_units_x_direction],
|
61
|
+
['XRay3DFrameTypeSequence', :x_ray_3d_frame_type_sequence],
|
62
|
+
['SOPInstanceUIDOfConcatenationSource', :sop_instance_uid_of_concatenation_source],
|
63
|
+
['RowsForNthOrderCoefficients', :rows_for_nth_order_coefficients],
|
64
|
+
['EquivalentCDADocumentSequence', :equivalent_cda_document_sequence],
|
65
|
+
['ALineRate', :a_line_rate],
|
66
|
+
['ThreeDPointCoordinates', :three_d_point_coordinates],
|
67
|
+
['SourceImageIDs', :source_image_ids],
|
68
|
+
['ModifyingDeviceID', :modifying_device_id],
|
69
|
+
['TIDOffset', :tid_offset]
|
70
|
+
].each do |str, value|
|
71
|
+
it "from #{str.inspect} to #{value.inspect}" do
|
72
|
+
expect(str.tag_key_to_sym).to eq(value)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "should convert standard string tag" do
|
78
|
+
[
|
79
|
+
['(0014,3050)', '00143050', [0x0014,0x3050]],
|
80
|
+
['(0008,0012)', '00080012', [0x0008,0x0012]],
|
81
|
+
['(FFFE,E00D)', 'FFFEE00D', [0xfffe,0xe00d]]
|
82
|
+
].each do |str, value_str, value_ary|
|
83
|
+
it "from #{str.inspect} to a numeric string tag as #{value_str.inspect}" do
|
84
|
+
expect(str.to_tag_ndm).to eq(value_str)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "from #{str.inspect} to an array object as #{value_ary.inspect}" do
|
88
|
+
expect(str.to_tag_ary).to eq(value_ary)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
{
|
94
|
+
'(0010,0020)'=> [0x0010,0x0020],
|
95
|
+
'00100020' => [0x0010,0x0020]
|
96
|
+
|
97
|
+
}.each do |src, expected_val|
|
98
|
+
it "should implement to_tag_ary metod" do
|
99
|
+
expect(src.to_tag_ary).to eq(expected_val)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
{
|
104
|
+
'(0010,0020)'=> '(0010,0020)',
|
105
|
+
'00100020' => '(0010,0020)'
|
106
|
+
|
107
|
+
}.each do |src, expected_val|
|
108
|
+
it "should implement to_tag_str method" do
|
109
|
+
expect(src.to_tag_str).to eq(expected_val)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
{
|
114
|
+
'(0010,0020)'=> [0x0010,0x0020],
|
115
|
+
'00100020' => [0x0010,0x0020]
|
116
|
+
|
117
|
+
}.each do |src, expected_val|
|
118
|
+
it "should implement tag_group_num and tag_element_num method" do
|
119
|
+
expect(src.tag_group_num).to eq(expected_val[0])
|
120
|
+
expect(src.tag_element_num).to eq(expected_val[1])
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
{
|
125
|
+
'(0010,0020)'=> ['0010','0020'],
|
126
|
+
'00100020' => ['0010','0020'],
|
127
|
+
'(FFFE,E000)'=> ['FFFE','E000'],
|
128
|
+
|
129
|
+
}.each do |src, expected_val|
|
130
|
+
it "should implement tag_group_str and tag_element_str method" do
|
131
|
+
expect(src.tag_group_str).to eq(expected_val[0])
|
132
|
+
expect(src.tag_element_str).to eq(expected_val[1])
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
[
|
137
|
+
'(0010,00208)',
|
138
|
+
'abracadabra',
|
139
|
+
Time.now.to_s,
|
140
|
+
'(1ffff,123)',
|
141
|
+
'(123,1fff0)'
|
142
|
+
].each do |src|
|
143
|
+
it "should manage wrong value #{src.inspect}" do
|
144
|
+
expect{src.to_tag_str}.to raise_error
|
145
|
+
expect{src.to_tag_ndm}.to raise_error
|
146
|
+
expect{src.to_tag_ary}.to raise_error
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
{
|
151
|
+
'SOP Class' => :sop_class,
|
152
|
+
'Transfer Syntax' => :transfer_syntax,
|
153
|
+
'Well-known frame of reference' => :well_known_frame_of_reference,
|
154
|
+
'Well-known SOP Instance' => :well_known_sop_instance,
|
155
|
+
'DICOM UIDs as a Coding Scheme' => :dicom_uids_as_a_coding_scheme,
|
156
|
+
'Coding Scheme' => :coding_scheme,
|
157
|
+
'Query/Retrieve' => :query_retrieve,
|
158
|
+
'LDAP OID' => :ldap_oid
|
159
|
+
|
160
|
+
|
161
|
+
}.each do |src, expected_val|
|
162
|
+
it "should implement uid_type_to_sym method #{src.inspect} > #{expected_val.inspect}" do
|
163
|
+
expect(src.uid_type_to_sym).to eq(expected_val)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
{
|
168
|
+
'1.2.3.4.5.6' => true,
|
169
|
+
'not uid string' => false,
|
170
|
+
'0.1.2.3.4' => true,
|
171
|
+
'1.2.3456.789.0.1.2.3' => true,
|
172
|
+
'1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2.3.4.5.6.7.8.9.0.1.2.3' => false,
|
173
|
+
'1,2.3' => false,
|
174
|
+
'1.2.3.04.5' => false
|
175
|
+
}.each do |string, expected_as_uid|
|
176
|
+
it "should check for UID string #{string.inspect} -> #{expected_as_uid}" do
|
177
|
+
expect(string.uid_value?).to eq(expected_as_uid)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
describe "should check for group-length tag" do
|
182
|
+
{
|
183
|
+
"00100020" => false,
|
184
|
+
"(0010,0020)" => false,
|
185
|
+
"00100000" => true,
|
186
|
+
"(0010,0000)" => true,
|
187
|
+
"00000002" => false,
|
188
|
+
"(0000,0002)" => false,
|
189
|
+
"00000000" => true,
|
190
|
+
"(0000,0000)" => true
|
191
|
+
}.each do |tag, value|
|
192
|
+
it "for #{tag.inspect}" do
|
193
|
+
expect(tag.group_length_tag?).to eq(value)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
describe "should check for private-creator tag" do
|
199
|
+
{
|
200
|
+
'00100010' => false,
|
201
|
+
'(0010,0010)' => false,
|
202
|
+
'00110010' => true,
|
203
|
+
'(0011,0010)' => true,
|
204
|
+
'00110110' => false,
|
205
|
+
'(0011,0110)' => false,
|
206
|
+
'00282468' => false,
|
207
|
+
'(0028,2468)' => false
|
208
|
+
}.each do |tag, value|
|
209
|
+
it "for #{tag.inspect}" do
|
210
|
+
expect(tag.private_creator_tag?).to eq(value)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|