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,48 @@
|
|
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_relative 'base_record'
|
25
|
+
|
26
|
+
module DcmDict
|
27
|
+
module Dictionary
|
28
|
+
UidMethodMap = {uid_value: :uid_value,
|
29
|
+
uid: :uid_value,
|
30
|
+
uid_name: :uid_name,
|
31
|
+
uid_type: :uid_type }.freeze
|
32
|
+
|
33
|
+
UidMethod = UidMethodMap.flatten.uniq.freeze
|
34
|
+
|
35
|
+
# Class to handle uid record from source dictionary data
|
36
|
+
class UidRecord < BaseRecord
|
37
|
+
def initialize(data)
|
38
|
+
super
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
def method_map
|
43
|
+
UidMethodMap
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,79 @@
|
|
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
|
+
module DcmDict
|
25
|
+
module Encoder
|
26
|
+
module DataToCode
|
27
|
+
using DcmDict::Refine::Internal::ArrayRefineInternal
|
28
|
+
|
29
|
+
# Convert data element +data+ to Ruby code using +indent+ spaces indentation
|
30
|
+
def self.data_element_data_to_code(data, indent=4)
|
31
|
+
indent = 4 unless indent
|
32
|
+
tag_ary_str = "[0x#{data[:tag_ary].tag_group_str},0x#{data[:tag_ary].tag_element_str}]"
|
33
|
+
"#{' '*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]}'},"
|
34
|
+
end
|
35
|
+
|
36
|
+
# Source data element header
|
37
|
+
def self.data_element_header
|
38
|
+
<<END
|
39
|
+
module DcmDict
|
40
|
+
module SourceData
|
41
|
+
DataElementsData = [
|
42
|
+
END
|
43
|
+
end
|
44
|
+
|
45
|
+
# Source data element footer
|
46
|
+
def self.data_element_footer
|
47
|
+
<<END
|
48
|
+
]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
END
|
52
|
+
end
|
53
|
+
|
54
|
+
# Source uid header
|
55
|
+
def self.uid_header
|
56
|
+
<<END
|
57
|
+
module DcmDict
|
58
|
+
module SourceData
|
59
|
+
UidValuesData = [
|
60
|
+
END
|
61
|
+
end
|
62
|
+
|
63
|
+
# Source uid footer
|
64
|
+
def self.uid_footer
|
65
|
+
<<END
|
66
|
+
]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
END
|
70
|
+
end
|
71
|
+
|
72
|
+
# Convert uid +data+ to Ruby code using +indent+ spaces indentation
|
73
|
+
def self.uid_data_to_code(data, indent=4)
|
74
|
+
indent = 4 unless indent
|
75
|
+
"#{' '*indent}{ uid_value: '#{data[:uid_value]}', uid_name: \"#{data[:uid_name]}\", uid_type: #{data[:uid_type].inspect}},"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
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
|
+
module DcmDict
|
25
|
+
|
26
|
+
# Dictionary Exception class
|
27
|
+
class DictionaryError < StandardError
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,38 @@
|
|
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
|
+
module DcmDict
|
25
|
+
module Ext
|
26
|
+
|
27
|
+
# Extension for object class
|
28
|
+
class ::Object
|
29
|
+
|
30
|
+
# Check for nil or 'empty' object
|
31
|
+
def nil_or_empty?
|
32
|
+
return empty? if(respond_to?(:empty?))
|
33
|
+
nil?
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,34 @@
|
|
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
|
+
module DcmDict
|
25
|
+
module Refine
|
26
|
+
module ArrayRefine
|
27
|
+
|
28
|
+
refine Array do
|
29
|
+
include DcmDict::Refine::DataElementRefine
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
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
|
+
module DcmDict
|
25
|
+
module Refine
|
26
|
+
|
27
|
+
# Module to manage data element record data
|
28
|
+
module DataElementRefine
|
29
|
+
DcmDict::Dictionary::DataElementMethod.each do |method|
|
30
|
+
define_method(method) do
|
31
|
+
Dictionary::TheDataElementDictionary.feature_at(self, method)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,97 @@
|
|
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
|
+
module DcmDict
|
25
|
+
module Refine
|
26
|
+
module Internal
|
27
|
+
module ArrayRefineInternal
|
28
|
+
|
29
|
+
refine Array do
|
30
|
+
# Tag group as number
|
31
|
+
def tag_group_num
|
32
|
+
check_dicom_tag
|
33
|
+
self[0]
|
34
|
+
end
|
35
|
+
|
36
|
+
# Tag element as number
|
37
|
+
def tag_element_num
|
38
|
+
check_dicom_tag
|
39
|
+
self[1]
|
40
|
+
end
|
41
|
+
|
42
|
+
# Tag group as string
|
43
|
+
def tag_group_str
|
44
|
+
tag_group_num.to_s(16).rjust(4, '0').upcase()
|
45
|
+
end
|
46
|
+
|
47
|
+
# Tag element as string
|
48
|
+
def tag_element_str
|
49
|
+
tag_element_num.to_s(16).rjust(4, '0').upcase()
|
50
|
+
end
|
51
|
+
|
52
|
+
# Tag as string
|
53
|
+
def to_tag_str
|
54
|
+
"(#{tag_group_str},#{tag_element_str})"
|
55
|
+
end
|
56
|
+
|
57
|
+
# Tag as Native Dicom Model tag
|
58
|
+
def to_tag_ndm
|
59
|
+
"#{tag_group_str}#{tag_element_str}"
|
60
|
+
end
|
61
|
+
|
62
|
+
# Tag as array
|
63
|
+
def to_tag_ary
|
64
|
+
[tag_group_num, tag_element_num]
|
65
|
+
end
|
66
|
+
|
67
|
+
# Check for group length tag
|
68
|
+
def group_length_tag?
|
69
|
+
tag_element_num == 0
|
70
|
+
end
|
71
|
+
|
72
|
+
# Check for private creator tag
|
73
|
+
def private_creator_tag?
|
74
|
+
(tag_group_num.odd? && (tag_element_num < 0xff))
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
def check_dicom_tag
|
79
|
+
return true if ( (self.size==2) &&
|
80
|
+
valid_tag_value?(0) &&
|
81
|
+
valid_tag_value?(1) )
|
82
|
+
raise "Wrong object definition for Tag Array"
|
83
|
+
end
|
84
|
+
|
85
|
+
def valid_tag_value?(index)
|
86
|
+
value = self[index]
|
87
|
+
return true if ( (value.is_a?(Integer)) &&
|
88
|
+
(value.bit_length <=16) &&
|
89
|
+
(value >=0) )
|
90
|
+
raise "Wrong value at index #{index} for Tag Array"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,71 @@
|
|
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
|
+
module DcmDict
|
25
|
+
module Refine
|
26
|
+
module Internal
|
27
|
+
module HashRefineInternal
|
28
|
+
|
29
|
+
refine Hash do
|
30
|
+
# Check/update content for data tag field
|
31
|
+
def check_base_data_tag_field!
|
32
|
+
check_tag_ps!
|
33
|
+
check_placeholder_data!
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
# Check for mandatory :tag_ps key
|
38
|
+
def check_tag_ps!
|
39
|
+
tag_ps = self[:tag_ps]
|
40
|
+
raise "Missing tag_ps field" if tag_ps.nil_or_empty?
|
41
|
+
tag_ps.upcase!
|
42
|
+
end
|
43
|
+
|
44
|
+
# Check for place holder tag data
|
45
|
+
def check_placeholder_data!
|
46
|
+
# PS3.5:
|
47
|
+
# For some Data Elements, no Name or Keyword or VR or VM is specified;
|
48
|
+
# these are "placeholders" that are not assigned but will not be reused.
|
49
|
+
tag_ps = self[:tag_ps]
|
50
|
+
raise "Missing tag_ps field" if tag_ps.nil_or_empty?
|
51
|
+
fill_nil_or_empty_value(:tag_name) { "Placeholder #{tag_ps}" }
|
52
|
+
fill_nil_or_empty_value(:tag_key) do
|
53
|
+
new_key = tag_ps.gsub(',','_').gsub(/[\(\)]/,'')
|
54
|
+
"Placeholder_#{new_key}"
|
55
|
+
end
|
56
|
+
fill_nil_or_empty_value(:tag_vr) { [:UN] }
|
57
|
+
fill_nil_or_empty_value(:tag_vm) { ['1'] }
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
def fill_nil_or_empty_value(key)
|
62
|
+
if self[key].nil_or_empty?
|
63
|
+
self[key] = yield
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
#
|
3
|
+
# Copyright (C) 2014-2020 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
|
+
module DcmDict
|
26
|
+
module Refine
|
27
|
+
module Internal
|
28
|
+
module StringRefineInternal
|
29
|
+
|
30
|
+
refine String do
|
31
|
+
|
32
|
+
# Remove zero width spaces (-> "") and leading/trailing whitespace
|
33
|
+
def dcm_unspace
|
34
|
+
zero_width_space = "\u200B"
|
35
|
+
self.gsub(zero_width_space, '').strip
|
36
|
+
end
|
37
|
+
|
38
|
+
# Convert tag key to tag symbol -> 'PatientName' -> :patient_name
|
39
|
+
def tag_key_to_sym
|
40
|
+
self.gsub('IDs', 'IDS').
|
41
|
+
gsub('3D', '_3D').
|
42
|
+
gsub('RTROI', 'RT_ROI').
|
43
|
+
gsub('DVHROI', 'DVH_ROI').
|
44
|
+
gsub('OCTZ', 'OCT_Z').
|
45
|
+
gsub('WADORS', 'WADO_RS').
|
46
|
+
gsub('STOWRS', 'STOW_RS').
|
47
|
+
gsub('CIExy', 'CIEXY').
|
48
|
+
gsub('RGBLUT', 'RGB_LUT').
|
49
|
+
gsub('VOILUT', 'VOI_LUT').
|
50
|
+
gsub('CTDIvol', 'CTDIVol').
|
51
|
+
gsub('XAXRF', 'XA_XRF').
|
52
|
+
gsub('CurrentInuA', 'Current_in_ua_').
|
53
|
+
gsub('TimeInuS', 'Time_in_us').
|
54
|
+
gsub('ExposureInuAs', 'Exposure_in_uas_').
|
55
|
+
gsub('dBdt', '_db_dt_').
|
56
|
+
gsub(/([A-Z])([a-z])/,'_\1\2').
|
57
|
+
gsub(/([a-z])([A-Z])/,'\1_\2').
|
58
|
+
gsub(/\A_/,'').
|
59
|
+
gsub(/_\z/,'').
|
60
|
+
downcase.
|
61
|
+
to_sym
|
62
|
+
end
|
63
|
+
|
64
|
+
# Tag group as number
|
65
|
+
def tag_group_num
|
66
|
+
tag_group_str.hex
|
67
|
+
end
|
68
|
+
|
69
|
+
# Tag element as number
|
70
|
+
def tag_element_num
|
71
|
+
tag_element_str.hex
|
72
|
+
end
|
73
|
+
|
74
|
+
# Tag group as string
|
75
|
+
def tag_group_str
|
76
|
+
self.to_tag_ndm[0..3]
|
77
|
+
end
|
78
|
+
|
79
|
+
# Tag element as string
|
80
|
+
def tag_element_str
|
81
|
+
self.to_tag_ndm[4..7]
|
82
|
+
end
|
83
|
+
|
84
|
+
# Tag as Native Dicom Model tag ('(0010,0010)' -> '00100010')
|
85
|
+
def to_tag_ndm
|
86
|
+
check_dicom_tag
|
87
|
+
self.gsub(/[\(|\),]/, '').upcase
|
88
|
+
end
|
89
|
+
|
90
|
+
# Tag as array ('(0010,0010)' -> [0x0010, 0x0010])
|
91
|
+
def to_tag_ary
|
92
|
+
[tag_group_num, tag_element_num]
|
93
|
+
end
|
94
|
+
|
95
|
+
# Tag as string ('00100010'/'(0010,0010)' -> '(0010,0010)')
|
96
|
+
def to_tag_str
|
97
|
+
"(#{tag_group_str},#{tag_element_str})"
|
98
|
+
end
|
99
|
+
|
100
|
+
# Convert uid type to symbol
|
101
|
+
def uid_type_to_sym
|
102
|
+
self.gsub(/[ -\/]/, '_').
|
103
|
+
downcase.
|
104
|
+
to_sym
|
105
|
+
end
|
106
|
+
|
107
|
+
# Check for valid uid value
|
108
|
+
def uid_value?
|
109
|
+
(self.length <= 64) &&
|
110
|
+
(/^(([0-9][\.])|([1-9][0-9]*[\.]))*(([0-9])|([1-9][0-9]*))$/.match(self) != nil)
|
111
|
+
end
|
112
|
+
|
113
|
+
# Check for group length tag
|
114
|
+
def group_length_tag?
|
115
|
+
tag_element_num == 0
|
116
|
+
end
|
117
|
+
|
118
|
+
# Check for private creator tag
|
119
|
+
def private_creator_tag?
|
120
|
+
(tag_group_num.odd? && (tag_element_num < 0xff))
|
121
|
+
end
|
122
|
+
|
123
|
+
private
|
124
|
+
def check_dicom_tag
|
125
|
+
return true if (/^[0-9|A-F]{8}$/.match(self) ||
|
126
|
+
/^[\(][0-9a-fA-F]{4}[\)\,\(][0-9a-fA-F]{4}\)$/.match(self))
|
127
|
+
raise "wrong value for tag #{self.inspect}"
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|