dcm_dict 0.29.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +156 -0
- data/COPYING +674 -0
- data/LICENSE +22 -0
- data/README.md +327 -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 +135 -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 +4945 -0
- data/lib/dcm_dict/source_data/detached_data.rb +67 -0
- data/lib/dcm_dict/source_data/uid_values_data.rb +467 -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 +60 -0
- data/lib/dcm_dict/xml/xml_tool.rb +47 -0
- data/spec/data_element_sample_spec_helper.rb +203 -0
- data/spec/data_element_shared_example_spec_helper.rb +57 -0
- data/spec/dcm_dict/dictionary/data_element_dictionary_spec.rb +76 -0
- data/spec/dcm_dict/dictionary/data_element_record_spec.rb +138 -0
- data/spec/dcm_dict/dictionary/uid_dictionary_spec.rb +82 -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 +60 -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 +228 -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 +567 -0
- metadata +216 -0
@@ -0,0 +1,40 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2014-2020 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 'set'
|
26
|
+
|
27
|
+
describe "DcmDict::SourceData::DataElementsData" do
|
28
|
+
it "All record must have valid field" do
|
29
|
+
supported_keys = [:tag_ps, :tag_name, :tag_key, :tag_vr, :tag_vm, :tag_str, :tag_sym, :tag_ndm, :tag_ary, :tag_multiple, :tag_note].to_set
|
30
|
+
not_empty_keys = supported_keys-[:tag_multiple, :tag_note]
|
31
|
+
DcmDict::SourceData::DataElementsData.each do |record|
|
32
|
+
supported_keys.each do |key|
|
33
|
+
expect(record).to have_key(key)
|
34
|
+
end
|
35
|
+
not_empty_keys.each do |key|
|
36
|
+
expect(record[key].empty?).to be_falsy, "Error on check #{key} not empty for #{record[:tag_ps]} - '#{record[key].inspect}'"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2014-2020 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 'data_element_sample_spec_helper'
|
26
|
+
|
27
|
+
describe "DcmDict::SourceData::DetachedData" do
|
28
|
+
|
29
|
+
DataElementSampleSpecHelper.unknown_group_length_sample.each do |tag, expected_data|
|
30
|
+
it "create data for 'group length' record for tag=#{tag.inspect}" do
|
31
|
+
data = DcmDict::SourceData::DetachedData.make_group_length_data(tag)
|
32
|
+
expected_data.each do |key, val|
|
33
|
+
expect(data[key]).to eq(val)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
DataElementSampleSpecHelper.private_creator_sample.each do |tag, expected_data|
|
39
|
+
it "create data for 'private creator' record for tag=#{tag.inspect}" do
|
40
|
+
data = DcmDict::SourceData::DetachedData.make_private_creator_data(tag)
|
41
|
+
expected_data.each do |key, val|
|
42
|
+
expect(data[key]).to eq(val)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
DataElementSampleSpecHelper.unknown_sample.each do |tag, expected_data|
|
48
|
+
it "create data for 'unknown tag' record for tag=#{tag.inspect}" do
|
49
|
+
data = DcmDict::SourceData::DetachedData.make_unknown_data(tag)
|
50
|
+
expected_data.each do |key, val|
|
51
|
+
expect(data[key]).to eq(val)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2014-2020 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::SourceData::UidValuesData" do
|
27
|
+
it "All record must have valid field" do
|
28
|
+
supported_keys = [:uid_value, :uid_name, :uid_type]
|
29
|
+
DcmDict::SourceData::UidValuesData.each do |record|
|
30
|
+
supported_keys.each do |key|
|
31
|
+
expect(record).to have_key(key)
|
32
|
+
expect(record.nil_or_empty?).to be_falsy
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2014-2020 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 version" do
|
27
|
+
it "may be defined" do
|
28
|
+
expect(DcmDict::VERSION).not_to be_nil
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2014-2020 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
|
+
|
28
|
+
|
29
|
+
describe "XML management for Data Element" do
|
30
|
+
|
31
|
+
RSpec.shared_examples "XML management for Data Element" do |xml_mod, desc|
|
32
|
+
describe "should extract data from single node set data (#{desc})" do
|
33
|
+
XmlSampleSpecHelper.xml_tag_single_set.each do |xml_string, expected_data|
|
34
|
+
xml_data = xml_mod.extract_data_element_field_from_xml_tr(xml_string)
|
35
|
+
describe "for '#{expected_data[:tag_name]}'" do
|
36
|
+
expected_data.each do |key, expected_value|
|
37
|
+
it "with key #{key.inspect}" do
|
38
|
+
expect(xml_data[key]).to eq(expected_value)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
it "from XML doc" do
|
42
|
+
doc = xml_mod.create_xml_doc(xml_string)
|
43
|
+
data = {}
|
44
|
+
xml_mod.each_tr_set(doc, '//xmlns:tr') do |trset|
|
45
|
+
data = xml_mod.extract_data_element_field_from_tr_set(trset)
|
46
|
+
end
|
47
|
+
expect(data).to eq(expected_data)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
if DcmDict::XML.nokogiri_enable?
|
55
|
+
include_examples "XML management for Data Element", DcmDict::XML::NokogiriTool, "with Nokogiri"
|
56
|
+
end
|
57
|
+
|
58
|
+
include_examples "XML management for Data Element", DcmDict::XML::RexmlTool, "with REXML"
|
59
|
+
|
60
|
+
include_examples "XML management for Data Element", DcmDict::XML::XmlTool, "with general XML module"
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2014-2020 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 "XML management for UID" do
|
28
|
+
|
29
|
+
RSpec.shared_examples "XML management for UID" do |xml_mod, desc|
|
30
|
+
describe "should extract data from single node set data (#{desc})" do
|
31
|
+
XmlSampleSpecHelper.xml_uid_set.each do |xml_string, expected_data|
|
32
|
+
xml_data = xml_mod.extract_uid_field_from_xml_tr(xml_string)
|
33
|
+
describe "for '#{expected_data[:uid_name]}'" do
|
34
|
+
expected_data.each do |key, expected_value|
|
35
|
+
it "with key #{key.inspect}" do
|
36
|
+
expect(xml_data[key]).to eq(expected_value)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
it "from XML doc" do
|
40
|
+
doc = xml_mod.create_xml_doc(xml_string)
|
41
|
+
data = {}
|
42
|
+
xml_mod.each_tr_set(doc, '//xmlns:tr') do |trset|
|
43
|
+
data = xml_mod.extract_uid_field_from_tr_set(trset)
|
44
|
+
end
|
45
|
+
expect(data).to eq(expected_data)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
if DcmDict::XML.nokogiri_enable?
|
53
|
+
include_examples "XML management for UID", DcmDict::XML::NokogiriTool, "with Nokogiri"
|
54
|
+
end
|
55
|
+
|
56
|
+
include_examples "XML management for UID", DcmDict::XML::RexmlTool, "with REXML"
|
57
|
+
|
58
|
+
include_examples "XML management for UID", DcmDict::XML::XmlTool, "with general XML module"
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2014-2020 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
|
+
|
25
|
+
FrozenStringExMessage = (RUBY_ENGINE == 'rbx') ? "can't modify frozen instance of String" : "can't modify frozen String"
|
26
|
+
|
27
|
+
RSpec.shared_examples "Record handle methods correctly" do |obj, data|
|
28
|
+
it "Handle methods correctly" do
|
29
|
+
data.each do |key, expected_val|
|
30
|
+
expect(obj.respond_to?(key.to_sym)).to be true
|
31
|
+
expect(obj.respond_to?(key.to_s)).to be true
|
32
|
+
end
|
33
|
+
|
34
|
+
expect(obj.respond_to?(:undefined_method_for_record)).to be false
|
35
|
+
expect(obj.respond_to?(:undefined_method_for_record.to_s)).to be false
|
36
|
+
expect{ obj.undefined_method_for_record }.to raise_error(NoMethodError)
|
37
|
+
expect{ obj.send("undefined_method_for_record") }.to raise_error(NoMethodError)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
RSpec.shared_examples "Concurrency support" do |key, dictionary, expected_values|
|
42
|
+
it "should support concurrency" do
|
43
|
+
#start = Time.now
|
44
|
+
max_threads = 128
|
45
|
+
times_for_threads = 1_024
|
46
|
+
idx = Random.rand(0...expected_values.size)
|
47
|
+
rnd_key = expected_values.keys[idx]
|
48
|
+
rnd_val = expected_values[rnd_key]
|
49
|
+
Thread.abort_on_exception = true
|
50
|
+
th = (1..max_threads).map do |n|
|
51
|
+
Thread.new do
|
52
|
+
Thread.stop
|
53
|
+
times_for_threads.times do |t|
|
54
|
+
Thread.current[:obj] = dictionary.record_at(key)
|
55
|
+
expect( Thread.current[:obj].send(rnd_key) ).to eq(rnd_val)
|
56
|
+
expect( dictionary.feature_at(key, rnd_key) ).to eq(rnd_val)
|
57
|
+
Thread.pass
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
sleep 0.01 while th[max_threads-1].status!='sleep'
|
62
|
+
th.map(&:run).map(&:join)
|
63
|
+
#warn "Example 'should support concurrency' finish in #{Time.now-start}"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
RSpec.shared_examples "Map all source data" do |index_keys, record_data, dictionary, record_type, field_list|
|
68
|
+
it "should map all source data" do
|
69
|
+
record_data.each do |record|
|
70
|
+
index_keys.each do |key|
|
71
|
+
obj = dictionary.record_at(record[key])
|
72
|
+
expect(obj).not_to be_nil, "#{key.inspect} > #{record[key].inspect}"
|
73
|
+
expect(obj).to be_a(record_type)
|
74
|
+
expect(obj).to be_frozen
|
75
|
+
field_list.each do |field|
|
76
|
+
feature = dictionary.feature_at(record[key], field)
|
77
|
+
expect(feature).to eq(record[field])
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
RSpec.shared_examples "Handle specific record" do |note, record_key, record_data, dictionary|
|
85
|
+
it "should handle specific record as #{record_key.inspect} (#{note})" do
|
86
|
+
obj = dictionary.record_at(record_key)
|
87
|
+
expect(obj).not_to be_nil, "#{record_key.inspect} not found into dictionary #{dictionary.class}"
|
88
|
+
record_data.each do |key, value|
|
89
|
+
field = obj.send(key)
|
90
|
+
expect(field).to eq(value)
|
91
|
+
feature = dictionary.feature_at(record_key, key)
|
92
|
+
expect(feature).to eq(value)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
RSpec.shared_examples "Dictionary Data not modifiable" do |record_key, key, dictionary|
|
98
|
+
it "data should be not modifiable" do
|
99
|
+
expect(dictionary).to be_frozen
|
100
|
+
obj = dictionary.record_at(record_key)
|
101
|
+
expect(obj).to be_frozen
|
102
|
+
expect{ eval("obj.#{key} << 'aaa'") }.
|
103
|
+
to raise_error(FrozenError)
|
104
|
+
expect{ eval("dictionary.feature_at('#{record_key}', #{key.inspect}) << 'aaa'") }.
|
105
|
+
to raise_error(FrozenError)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
RSpec.shared_examples "Dictionary with wrong key" do |record_key, field_list, dictionary|
|
110
|
+
it "should raise exception for wrong value as #{record_key.inspect}" do
|
111
|
+
expect{dictionary.record_at(record_key)}.
|
112
|
+
to raise_error(DcmDict::DictionaryError)
|
113
|
+
field_list.each do |field|
|
114
|
+
expect { dictionary.feature_at(record_key, field) }.
|
115
|
+
to raise_error(DcmDict::DictionaryError)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2014-2020 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
|
+
using DcmDict::Refine::ArrayRefine
|
25
|
+
using DcmDict::Refine::StringRefine
|
26
|
+
using DcmDict::Refine::SymbolRefine
|
27
|
+
|
28
|
+
RSpec.shared_examples "Raise exception for wrong input" do |tags, uids, tag_proc|
|
29
|
+
describe "should raise exception for wrong input" do
|
30
|
+
describe "for data element" do
|
31
|
+
tags.each do |tag|
|
32
|
+
DcmDict::Dictionary::DataElementMethod.each do |method|
|
33
|
+
expr = "#{tag_proc.call(tag)}.#{method.to_s}"
|
34
|
+
it "with #{expr}" do
|
35
|
+
# expect{eval(expr)}.to raise_error(DcmDict::DictionaryError, "Unable to find reference for tag '#{tag}' as #{tag.class}")
|
36
|
+
expect{eval(expr)}.to raise_error(DcmDict::DictionaryError)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "and for uid" do
|
43
|
+
uids.each do |uid|
|
44
|
+
DcmDict::Dictionary::UidMethod.each do |method|
|
45
|
+
expr = "#{uid.inspect}.#{method.to_s}"
|
46
|
+
it "with #{expr}" do
|
47
|
+
# expect{eval(expr)}.to raise_error(DcmDict::DictionaryError, "Unable to find reference for uid '#{uid}' as #{uid.class}")
|
48
|
+
expect{eval(expr)}.to raise_error(DcmDict::DictionaryError)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|