ruby-hl7 1.3.2 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/configuration.rb +30 -0
- data/lib/core_ext/date_time.rb +19 -15
- data/lib/core_ext/string.rb +2 -0
- data/lib/helpers/time_formatter_helper.rb +42 -0
- data/lib/message.rb +72 -75
- data/lib/message_parser.rb +17 -15
- data/lib/ruby-hl7.rb +26 -16
- data/lib/segment.rb +63 -47
- data/lib/segment_default.rb +6 -4
- data/lib/segment_fields.rb +27 -25
- data/lib/segment_generator.rb +12 -15
- data/lib/segment_list_storage.rb +15 -14
- data/lib/segments/aig.rb +2 -0
- data/lib/segments/ail.rb +2 -0
- data/lib/segments/aip.rb +2 -0
- data/lib/segments/ais.rb +2 -0
- data/lib/segments/dg1.rb +2 -10
- data/lib/segments/err.rb +2 -0
- data/lib/segments/evn.rb +2 -1
- data/lib/segments/ft1.rb +13 -13
- data/lib/segments/fts.rb +2 -0
- data/lib/segments/gt1.rb +4 -6
- data/lib/segments/in1.rb +2 -1
- data/lib/segments/mfe.rb +2 -0
- data/lib/segments/mfi.rb +2 -0
- data/lib/segments/mrg.rb +2 -0
- data/lib/segments/msa.rb +2 -2
- data/lib/segments/msh.rb +3 -2
- data/lib/segments/nk1.rb +48 -8
- data/lib/segments/nte.rb +6 -5
- data/lib/segments/obr.rb +4 -3
- data/lib/segments/obx.rb +2 -1
- data/lib/segments/orc.rb +8 -10
- data/lib/segments/oru.rb +2 -1
- data/lib/segments/pid.rb +19 -10
- data/lib/segments/prd.rb +2 -1
- data/lib/segments/prt.rb +23 -0
- data/lib/segments/pv1.rb +2 -1
- data/lib/segments/pv2.rb +64 -51
- data/lib/segments/qrd.rb +2 -1
- data/lib/segments/qrf.rb +2 -1
- data/lib/segments/rf1.rb +2 -1
- data/lib/segments/rgs.rb +2 -0
- data/lib/segments/rol.rb +22 -0
- data/lib/segments/sch.rb +2 -0
- data/lib/segments/sft.rb +2 -0
- data/lib/segments/spm.rb +2 -0
- data/lib/segments/tq1.rb +2 -0
- data/lib/segments/txa.rb +30 -0
- data/lib/test/hl7_messages.rb +118 -117
- data/lib/version.rb +5 -0
- metadata +18 -165
- data/.gitignore +0 -7
- data/.rubocop.yml +0 -127
- data/.travis.yml +0 -20
- data/Gemfile +0 -3
- data/Gemfile.lock +0 -66
- data/LICENSE +0 -19
- data/NOTES.md +0 -141
- data/README.rdoc +0 -47
- data/Rakefile +0 -76
- data/VERSION +0 -1
- data/VERSION.yml +0 -4
- data/examples/proxy_server.rb +0 -26
- data/ruby-hl7.gemspec +0 -39
- data/spec/ail_segment_spec.rb +0 -28
- data/spec/aip_segment_spec.rb +0 -31
- data/spec/basic_parsing_spec.rb +0 -319
- data/spec/batch_parsing_spec.rb +0 -52
- data/spec/child_segment_spec.rb +0 -66
- data/spec/core_ext/date_time_spec.rb +0 -43
- data/spec/default_segment_spec.rb +0 -31
- data/spec/dg1_spec.rb +0 -42
- data/spec/dynamic_segment_def_spec.rb +0 -37
- data/spec/err_segment_spec.rb +0 -26
- data/spec/evn_segment_spec.rb +0 -23
- data/spec/ft1_segment_spec.rb +0 -35
- data/spec/fts_segment_spec.rb +0 -19
- data/spec/gt1_segment_spec.rb +0 -32
- data/spec/in1_segment_spec.rb +0 -34
- data/spec/message_spec.rb +0 -53
- data/spec/messages_spec.rb +0 -24
- data/spec/mfe_segment_spec.rb +0 -28
- data/spec/mfi_segment_spec.rb +0 -28
- data/spec/msa_segment_spec.rb +0 -27
- data/spec/msh_segment_spec.rb +0 -28
- data/spec/nk1_segment_spec.rb +0 -26
- data/spec/obr_segment_spec.rb +0 -45
- data/spec/obx_segment_spec.rb +0 -68
- data/spec/orc_segment_spec.rb +0 -27
- data/spec/pid_segment_spec.rb +0 -78
- data/spec/prd_segment_spec.rb +0 -29
- data/spec/pv1_segment_spec.rb +0 -23
- data/spec/rf1_segment_spec.rb +0 -29
- data/spec/sch_segment_spec.rb +0 -32
- data/spec/segment_field_spec.rb +0 -110
- data/spec/segment_generator_spec.rb +0 -32
- data/spec/segment_list_storage_spec.rb +0 -47
- data/spec/segment_spec.rb +0 -38
- data/spec/sft_segment_spec.rb +0 -26
- data/spec/spec_helper.rb +0 -13
- data/spec/speed_parsing_spec.rb +0 -19
- data/spec/spm_segment_spec.rb +0 -26
data/lib/segment.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Ruby Object representation of an hl7 2.x message segment
|
2
4
|
# The segments can be setup to provide aliases to specific fields with
|
3
5
|
# optional validation code that is run when the field is modified
|
@@ -19,12 +21,12 @@
|
|
19
21
|
#
|
20
22
|
class HL7::Message::Segment
|
21
23
|
extend HL7::Message::SegmentListStorage
|
24
|
+
extend TimeFormatterHelper
|
25
|
+
|
22
26
|
include HL7::Message::SegmentFields
|
23
27
|
|
24
28
|
attr_accessor :segment_parent
|
25
|
-
attr_reader :element_delim
|
26
|
-
attr_reader :item_delim
|
27
|
-
attr_reader :segment_weight
|
29
|
+
attr_reader :element_delim, :item_delim, :segment_weight
|
28
30
|
|
29
31
|
METHOD_MISSING_FOR_INITIALIZER = <<-END
|
30
32
|
def method_missing( sym, *args, &blk )
|
@@ -38,7 +40,7 @@ class HL7::Message::Segment
|
|
38
40
|
# delims:: an optional array of delimiters, where
|
39
41
|
# delims[0] = element delimiter
|
40
42
|
# delims[1] = item delimiter
|
41
|
-
def initialize(raw_segment="", delims=[], &blk)
|
43
|
+
def initialize(raw_segment = "", delims = [], &blk)
|
42
44
|
@segments_by_name = {}
|
43
45
|
@field_total = 0
|
44
46
|
@is_child = false
|
@@ -47,31 +49,31 @@ class HL7::Message::Segment
|
|
47
49
|
|
48
50
|
@elements = elements_from_segment(raw_segment)
|
49
51
|
|
50
|
-
|
51
|
-
callctx = eval( "self", blk.binding )
|
52
|
-
def callctx.__seg__(val=nil)
|
53
|
-
@__seg_val__ ||= val
|
54
|
-
end
|
55
|
-
callctx.__seg__(self)
|
56
|
-
# TODO: find out if this pollutes the calling namespace permanently...
|
52
|
+
return unless block_given?
|
57
53
|
|
58
|
-
|
59
|
-
|
60
|
-
|
54
|
+
callctx = eval("self", blk.binding, __FILE__, __LINE__)
|
55
|
+
def callctx.__seg__(val = nil)
|
56
|
+
@__seg_val__ ||= val
|
61
57
|
end
|
58
|
+
callctx.__seg__(self)
|
59
|
+
# TODO: find out if this pollutes the calling namespace permanently...
|
60
|
+
|
61
|
+
eval(METHOD_MISSING_FOR_INITIALIZER, blk.binding)
|
62
|
+
yield self
|
63
|
+
eval("class << self; remove_method :method_missing;end", blk.binding, __FILE__, __LINE__)
|
62
64
|
end
|
63
65
|
|
64
66
|
# Breaks the raw segment into elements
|
65
67
|
# raw_segment:: is an optional String or Array which will be used as the
|
66
68
|
# segment's field data
|
67
69
|
def elements_from_segment(raw_segment)
|
68
|
-
if
|
70
|
+
if raw_segment.is_a? Array
|
69
71
|
elements = raw_segment
|
70
72
|
else
|
71
|
-
elements = HL7::MessageParser.split_by_delimiter(
|
72
|
-
|
73
|
+
elements = HL7::MessageParser.split_by_delimiter(raw_segment,
|
74
|
+
@element_delim)
|
73
75
|
if raw_segment == ""
|
74
|
-
elements[0] = self.class.to_s.split(
|
76
|
+
elements[0] = self.class.to_s.split("::").last
|
75
77
|
elements << ""
|
76
78
|
end
|
77
79
|
end
|
@@ -79,26 +81,26 @@ class HL7::Message::Segment
|
|
79
81
|
end
|
80
82
|
|
81
83
|
def to_info
|
82
|
-
"%s: empty segment >> %s"
|
84
|
+
format("%s: empty segment >> %s", self.class.to_s, @elements.inspect)
|
83
85
|
end
|
84
86
|
|
85
87
|
# output the HL7 spec version of the segment
|
86
88
|
def to_s
|
87
|
-
@elements.join(
|
89
|
+
@elements.join(@element_delim)
|
88
90
|
end
|
89
91
|
|
90
92
|
# at the segment level there is no difference between to_s and to_hl7
|
91
|
-
|
93
|
+
alias_method :to_hl7, :to_s
|
92
94
|
|
93
95
|
# handle the e<number> field accessor
|
94
96
|
# and any aliases that didn't get added to the system automatically
|
95
|
-
def method_missing(
|
96
|
-
base_str = sym.to_s.
|
97
|
+
def method_missing(sym, *args, &blk)
|
98
|
+
base_str = sym.to_s.delete("=")
|
97
99
|
base_sym = base_str.to_sym
|
98
100
|
|
99
|
-
if self.class.fields.include?(
|
101
|
+
if self.class.fields.include?(base_sym)
|
100
102
|
# base_sym is ok, let's move on
|
101
|
-
elsif /e([0-9]+)
|
103
|
+
elsif /e([0-9]+)/ =~ base_str
|
102
104
|
# base_sym should actually be $1, since we're going by
|
103
105
|
# element id number
|
104
106
|
base_sym = $1.to_i
|
@@ -106,26 +108,25 @@ class HL7::Message::Segment
|
|
106
108
|
super
|
107
109
|
end
|
108
110
|
|
109
|
-
if sym.to_s.include?(
|
110
|
-
write_field(
|
111
|
+
if sym.to_s.include?("=")
|
112
|
+
write_field(base_sym, args)
|
113
|
+
elsif args.length.positive?
|
114
|
+
write_field(base_sym, args.flatten.select {|arg| arg })
|
111
115
|
else
|
112
|
-
|
113
|
-
write_field( base_sym, args.flatten.select { |arg| arg } )
|
114
|
-
else
|
115
|
-
read_field( base_sym )
|
116
|
-
end
|
116
|
+
read_field(base_sym)
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
120
|
# sort-compare two Segments, 0 indicates equality
|
121
|
-
def <=>(
|
122
|
-
return nil unless other.
|
121
|
+
def <=>(other)
|
122
|
+
return nil unless other.is_a?(HL7::Message::Segment)
|
123
123
|
|
124
124
|
# per Comparable docs: http://www.ruby-doc.org/core/classes/Comparable.html
|
125
|
-
diff =
|
126
|
-
return -1 if diff
|
127
|
-
return 1 if diff
|
128
|
-
|
125
|
+
diff = weight - other.weight
|
126
|
+
return -1 if diff.positive?
|
127
|
+
return 1 if diff.negative?
|
128
|
+
|
129
|
+
0
|
129
130
|
end
|
130
131
|
|
131
132
|
# get the defined sort-weight of this segment class
|
@@ -147,6 +148,7 @@ class HL7::Message::Segment
|
|
147
148
|
# yield each element in the segment
|
148
149
|
def each # :yields: element
|
149
150
|
return unless @elements
|
151
|
+
|
150
152
|
@elements.each { |e| yield e }
|
151
153
|
end
|
152
154
|
|
@@ -157,25 +159,26 @@ class HL7::Message::Segment
|
|
157
159
|
end
|
158
160
|
|
159
161
|
def has_children?
|
160
|
-
|
162
|
+
respond_to?(:children)
|
161
163
|
end
|
162
164
|
|
163
|
-
|
164
|
-
|
165
|
+
private
|
166
|
+
|
167
|
+
def self.singleton # :nodoc:
|
165
168
|
class << self; self end
|
166
169
|
end
|
167
170
|
|
168
171
|
def setup_delimiters(delims)
|
169
|
-
delims = [
|
172
|
+
delims = [delims].flatten
|
170
173
|
|
171
|
-
@element_delim =
|
172
|
-
@item_delim =
|
174
|
+
@element_delim = delims.length.positive? ? delims[0] : "|"
|
175
|
+
@item_delim = delims.length > 1 ? delims[1] : "^"
|
173
176
|
end
|
174
177
|
|
175
178
|
# DSL element to define a segment's sort weight
|
176
179
|
# returns the segment's current weight by default
|
177
180
|
# segments are sorted ascending
|
178
|
-
def self.weight(new_weight=nil)
|
181
|
+
def self.weight(new_weight = nil)
|
179
182
|
if new_weight
|
180
183
|
singleton.module_eval do
|
181
184
|
@my_weight = new_weight
|
@@ -184,12 +187,25 @@ class HL7::Message::Segment
|
|
184
187
|
|
185
188
|
singleton.module_eval do
|
186
189
|
return 999 unless @my_weight
|
190
|
+
|
187
191
|
@my_weight
|
188
192
|
end
|
189
193
|
end
|
190
194
|
|
191
|
-
def self.convert_to_ts(value)
|
192
|
-
value.
|
195
|
+
def self.convert_to_ts(value) # :nodoc:
|
196
|
+
if value.is_a?(Time) || value.is_a?(DateTime)
|
197
|
+
hl7_formatted_timestamp(value)
|
198
|
+
elsif value.is_a?(Date)
|
199
|
+
hl7_formatted_date(value)
|
200
|
+
else
|
201
|
+
value
|
202
|
+
end
|
193
203
|
end
|
194
204
|
|
205
|
+
def self.sanitize_admin_sex!(value)
|
206
|
+
raise HL7::InvalidDataError, "bad administrative sex value (not F|M|O|U|A|N|C)" unless /^[FMOUANC]$/.match(value) || value.nil? || value == ""
|
207
|
+
|
208
|
+
value ||= ""
|
209
|
+
value
|
210
|
+
end
|
195
211
|
end
|
data/lib/segment_default.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Provide a catch-all information preserving segment
|
2
4
|
# * nb: aliases are not provided BUT you can use the numeric element accessor
|
3
5
|
#
|
@@ -7,12 +9,12 @@
|
|
7
9
|
# seg.e2 = "KIN HERE"
|
8
10
|
#
|
9
11
|
class HL7::Message::Segment::Default < HL7::Message::Segment
|
10
|
-
def initialize(raw_segment="", delims=[])
|
11
|
-
segs = [] if
|
12
|
+
def initialize(raw_segment = "", delims = [])
|
13
|
+
segs = [] if raw_segment == ""
|
12
14
|
segs ||= raw_segment
|
13
|
-
super(
|
15
|
+
super(segs, delims)
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
17
19
|
# load our segments
|
18
|
-
Dir["#{File.dirname(__FILE__)}/segments/*.rb"].each {
|
20
|
+
Dir["#{File.dirname(__FILE__)}/segments/*.rb"].each {|ext| load ext }
|
data/lib/segment_fields.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# SegmentFields
|
2
4
|
# class HL7::Message::Segment::NK1 < HL7::Message::Segment
|
3
5
|
# weight 100 # segments are sorted ascendingly
|
@@ -20,8 +22,8 @@ module HL7::Message::SegmentFields
|
|
20
22
|
# * blk is an optional validation/convertion proc which MUST
|
21
23
|
# take a parameter and always return a value for the field (it will be
|
22
24
|
# used on read/write calls)
|
23
|
-
def add_field(
|
24
|
-
options = { :idx
|
25
|
+
def add_field(name, options = {}, &blk)
|
26
|
+
options = { :idx => -1, :blk => blk }.merge!(options)
|
25
27
|
name ||= :id
|
26
28
|
namesym = name.to_sym
|
27
29
|
@field_cnt ||= 1
|
@@ -32,10 +34,10 @@ module HL7::Message::SegmentFields
|
|
32
34
|
|
33
35
|
singleton.module_eval do
|
34
36
|
@fields ||= {}
|
35
|
-
@fields[
|
37
|
+
@fields[namesym] = options
|
36
38
|
end
|
37
39
|
|
38
|
-
|
40
|
+
class_eval <<-END, __FILE__, __LINE__ + 1
|
39
41
|
def #{name}(val=nil)
|
40
42
|
unless val
|
41
43
|
read_field( :#{namesym} )
|
@@ -51,14 +53,14 @@ module HL7::Message::SegmentFields
|
|
51
53
|
END
|
52
54
|
end
|
53
55
|
|
54
|
-
def fields
|
56
|
+
def fields # :nodoc:
|
55
57
|
singleton.module_eval do
|
56
58
|
(@fields ||= [])
|
57
59
|
end
|
58
60
|
end
|
59
61
|
|
60
62
|
def alias_field(new_field_name, old_field_name)
|
61
|
-
|
63
|
+
class_eval <<-END, __FILE__, __LINE__ + 1
|
62
64
|
def #{new_field_name}(val=nil)
|
63
65
|
raise HL7::InvalidDataError.new unless self.class.fields[:#{old_field_name}]
|
64
66
|
unless val
|
@@ -76,50 +78,50 @@ module HL7::Message::SegmentFields
|
|
76
78
|
end
|
77
79
|
end
|
78
80
|
|
79
|
-
def field_info(
|
81
|
+
def field_info(name) # :nodoc:
|
80
82
|
field_blk = nil
|
81
83
|
idx = name # assume we've gotten a integer
|
82
|
-
unless name.
|
83
|
-
fld_info = self.class.fields[
|
84
|
+
unless name.is_a?(Integer)
|
85
|
+
fld_info = self.class.fields[name]
|
84
86
|
idx = fld_info[:idx].to_i
|
85
87
|
field_blk = fld_info[:blk]
|
86
88
|
end
|
87
89
|
|
88
|
-
[
|
90
|
+
[idx, field_blk]
|
89
91
|
end
|
90
92
|
|
91
|
-
def [](
|
93
|
+
def [](index)
|
92
94
|
@elements[index]
|
93
95
|
end
|
94
96
|
|
95
|
-
def []=(
|
97
|
+
def []=(index, value)
|
96
98
|
@elements[index] = value.to_s
|
97
99
|
end
|
98
100
|
|
99
|
-
def read_field(
|
100
|
-
idx, field_blk = field_info(
|
101
|
+
def read_field(name) # :nodoc:
|
102
|
+
idx, field_blk = field_info(name)
|
101
103
|
return nil unless idx
|
102
|
-
return nil if
|
104
|
+
return nil if idx >= @elements.length
|
103
105
|
|
104
|
-
ret = @elements[
|
105
|
-
ret = ret.first if
|
106
|
-
ret = field_blk.call(
|
106
|
+
ret = @elements[idx]
|
107
|
+
ret = ret.first if ret.is_a?(Array) && ret.length == 1
|
108
|
+
ret = field_blk.call(ret) if field_blk
|
107
109
|
ret
|
108
110
|
end
|
109
111
|
|
110
|
-
def write_field(
|
111
|
-
idx, field_blk = field_info(
|
112
|
+
def write_field(name, value) # :nodoc:
|
113
|
+
idx, field_blk = field_info(name)
|
112
114
|
return nil unless idx
|
113
115
|
|
114
|
-
if
|
116
|
+
if idx >= @elements.length
|
115
117
|
# make some space for the incoming field, missing items are assumed to
|
116
118
|
# be empty, so this is valid per the spec -mg
|
117
|
-
missing = ("," * (idx
|
119
|
+
missing = ("," * (idx - @elements.length)).split(",", -1)
|
118
120
|
@elements += missing
|
119
121
|
end
|
120
122
|
|
121
|
-
value = value.first if
|
122
|
-
value = field_blk.call(
|
123
|
-
@elements[
|
123
|
+
value = value.first if value.is_a?(Array) && value.length == 1
|
124
|
+
value = field_blk.call(value) if field_blk
|
125
|
+
@elements[idx] = value.to_s
|
124
126
|
end
|
125
127
|
end
|
data/lib/segment_generator.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Class for grouping the messages delimiter
|
2
4
|
class HL7::Message::Delimiter
|
3
5
|
attr_accessor :item, :element, :segment
|
@@ -11,9 +13,7 @@ end
|
|
11
13
|
|
12
14
|
# Methods for creating segments in Message
|
13
15
|
class HL7::Message::SegmentGenerator
|
14
|
-
|
15
|
-
attr_reader :element, :last_seg
|
16
|
-
attr_reader :delimiter
|
16
|
+
attr_reader :element, :last_seg, :delimiter
|
17
17
|
|
18
18
|
attr_accessor :seg_parts, :seg_name
|
19
19
|
|
@@ -22,24 +22,21 @@ class HL7::Message::SegmentGenerator
|
|
22
22
|
@last_seg = last_seg
|
23
23
|
@delimiter = delimiter
|
24
24
|
|
25
|
-
@seg_parts = HL7::MessageParser.split_by_delimiter(
|
26
|
-
|
25
|
+
@seg_parts = HL7::MessageParser.split_by_delimiter(element,
|
26
|
+
delimiter.element)
|
27
27
|
end
|
28
28
|
|
29
29
|
def valid_segments_parts?
|
30
|
-
return true if @seg_parts
|
30
|
+
return true if @seg_parts&.length&.positive?
|
31
31
|
|
32
|
-
if HL7.
|
33
|
-
|
34
|
-
|
35
|
-
return false
|
36
|
-
end
|
32
|
+
raise HL7::EmptySegmentNotAllowed if HL7.configuration.empty_segment_is_error
|
33
|
+
|
34
|
+
false
|
37
35
|
end
|
38
36
|
|
39
37
|
def build
|
40
38
|
klass = get_segment_class
|
41
|
-
|
42
|
-
new_seg
|
39
|
+
klass.new(@element, [@delimiter.element, @delimiter.item])
|
43
40
|
end
|
44
41
|
|
45
42
|
def get_segment_class
|
@@ -47,9 +44,9 @@ class HL7::Message::SegmentGenerator
|
|
47
44
|
segment_to_search = @seg_name if RUBY_VERSION < "1.9"
|
48
45
|
|
49
46
|
if HL7::Message::Segment.constants.index(segment_to_search)
|
50
|
-
eval("HL7::Message::Segment::%s"
|
47
|
+
eval(format("HL7::Message::Segment::%s", @seg_name))
|
51
48
|
else
|
52
49
|
HL7::Message::Segment::Default
|
53
50
|
end
|
54
51
|
end
|
55
|
-
end
|
52
|
+
end
|
data/lib/segment_list_storage.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This module includes methods for storing segments inside segments.
|
2
4
|
# has_children(child_types) defines three methods dynamically.
|
3
5
|
|
@@ -8,11 +10,12 @@ module HL7::Message::SegmentListStorage
|
|
8
10
|
if defined?(@child_types)
|
9
11
|
@child_types << child_type.to_sym
|
10
12
|
else
|
11
|
-
has_children [
|
13
|
+
has_children [child_type.to_sym]
|
12
14
|
end
|
13
15
|
end
|
14
16
|
|
15
|
-
|
17
|
+
private
|
18
|
+
|
16
19
|
# allows a segment to store other segment objects
|
17
20
|
# used to handle associated lists like one OBR to many OBX segments
|
18
21
|
def has_children(child_types)
|
@@ -30,8 +33,8 @@ module HL7::Message::SegmentListStorage
|
|
30
33
|
end
|
31
34
|
|
32
35
|
def define_method_accepts
|
33
|
-
|
34
|
-
define_method(
|
36
|
+
class_eval do
|
37
|
+
define_method(:accepts?) do |t|
|
35
38
|
t = t.to_sym if t.respond_to?(:to_sym)
|
36
39
|
!!child_types.index(t)
|
37
40
|
end
|
@@ -39,7 +42,7 @@ module HL7::Message::SegmentListStorage
|
|
39
42
|
end
|
40
43
|
|
41
44
|
def define_method_children
|
42
|
-
|
45
|
+
class_eval do
|
43
46
|
define_method(:children) do
|
44
47
|
unless defined?(@my_children)
|
45
48
|
p = self
|
@@ -48,27 +51,25 @@ module HL7::Message::SegmentListStorage
|
|
48
51
|
@parental = p
|
49
52
|
alias :old_append :<<
|
50
53
|
|
51
|
-
def <<(
|
54
|
+
def <<(value)
|
52
55
|
# do nothing if value is nil
|
53
56
|
return unless value
|
54
57
|
|
55
58
|
# make sure it's an array
|
56
59
|
value = [value].flatten
|
57
|
-
value.map{|item| append(item)}
|
60
|
+
value.map {|item| append(item) }
|
58
61
|
end
|
59
62
|
|
60
63
|
def append(value)
|
61
|
-
unless
|
62
|
-
raise HL7::Exception
|
64
|
+
unless value.is_a?(HL7::Message::Segment)
|
65
|
+
raise HL7::Exception, "attempting to append non-segment to a segment list"
|
63
66
|
end
|
64
67
|
|
65
68
|
value.segment_parent = @parental
|
66
69
|
k = @parental
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
k.segment_parent << value if k && k.segment_parent
|
71
|
-
old_append( value )
|
70
|
+
k = k.segment_parent while k&.segment_parent && !k.segment_parent.is_a?(HL7::Message)
|
71
|
+
k.segment_parent << value if k&.segment_parent
|
72
|
+
old_append(value)
|
72
73
|
end
|
73
74
|
end
|
74
75
|
end
|
data/lib/segments/aig.rb
CHANGED
data/lib/segments/ail.rb
CHANGED
data/lib/segments/aip.rb
CHANGED
data/lib/segments/ais.rb
CHANGED
data/lib/segments/dg1.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module HL7
|
2
4
|
class Message::Segment::DG1 < HL7::Message::Segment
|
3
5
|
weight 92
|
@@ -24,15 +26,5 @@ module HL7
|
|
24
26
|
add_field :attestation_date_time do |value|
|
25
27
|
convert_to_ts(value)
|
26
28
|
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
def self.convert_to_ts(value) #:nodoc:
|
31
|
-
if value.is_a?(Time) || value.is_a?(Date)
|
32
|
-
value.to_hl7
|
33
|
-
else
|
34
|
-
value
|
35
|
-
end
|
36
|
-
end
|
37
29
|
end
|
38
30
|
end
|
data/lib/segments/err.rb
CHANGED
data/lib/segments/evn.rb
CHANGED
data/lib/segments/ft1.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module HL7
|
2
4
|
class Message::Segment::FT1 < HL7::Message::Segment
|
3
5
|
weight 10
|
@@ -12,7 +14,7 @@ module HL7
|
|
12
14
|
end
|
13
15
|
add_field :transaction_type
|
14
16
|
add_field :transaction_code
|
15
|
-
add_field :transaction_description
|
17
|
+
add_field :transaction_description
|
16
18
|
add_field :transaction_description_alt
|
17
19
|
add_field :transaction_quantity
|
18
20
|
add_field :transaction_amount_extended
|
@@ -35,29 +37,27 @@ module HL7
|
|
35
37
|
add_field :unit_cost
|
36
38
|
add_field :filler_order_number
|
37
39
|
add_field :entered_by
|
38
|
-
|
40
|
+
|
39
41
|
# https://en.wikipedia.org/wiki/Current_Procedural_Terminology (CPT)
|
40
42
|
add_field :procedure_code
|
41
43
|
|
42
44
|
add_field :procedure_code_modifier
|
43
|
-
add_field :advanced_beneficiary_notice_code
|
44
|
-
add_field :medically_necessary_duplicate_procedure_reason
|
45
|
+
add_field :advanced_beneficiary_notice_code
|
46
|
+
add_field :medically_necessary_duplicate_procedure_reason
|
45
47
|
add_field :ndc_code
|
46
48
|
add_field :payment_reference_id
|
47
49
|
add_field :transaction_reference_key
|
48
50
|
add_field :performing_facility
|
49
|
-
add_field :ordering_facility
|
51
|
+
add_field :ordering_facility
|
50
52
|
add_field :item_number
|
51
|
-
add_field :model_number
|
52
|
-
add_field :special_processing_code
|
53
|
+
add_field :model_number
|
54
|
+
add_field :special_processing_code
|
53
55
|
add_field :clinic_code
|
54
|
-
add_field :referral_number
|
56
|
+
add_field :referral_number
|
55
57
|
add_field :authorization_number
|
56
|
-
add_field :service_provider_taxonomy_code
|
58
|
+
add_field :service_provider_taxonomy_code
|
57
59
|
add_field :revenue_code
|
58
|
-
add_field :prescription_number
|
60
|
+
add_field :prescription_number
|
59
61
|
add_field :ndc_qty_and_uom
|
60
|
-
|
61
|
-
|
62
62
|
end
|
63
|
-
end
|
63
|
+
end
|
data/lib/segments/fts.rb
CHANGED
data/lib/segments/gt1.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module HL7
|
2
4
|
class Message::Segment::GT1 < HL7::Message::Segment
|
3
5
|
add_field :set_id
|
@@ -9,11 +11,7 @@ module HL7
|
|
9
11
|
add_field :guarantor_business_phone
|
10
12
|
add_field :guarantor_date_of_birth
|
11
13
|
add_field :guarantor_sex do |sex|
|
12
|
-
|
13
|
-
raise HL7::InvalidDataError.new( "bad administrative sex value (not F|M|O|U|A|N|C)" )
|
14
|
-
end
|
15
|
-
sex = "" unless sex
|
16
|
-
sex
|
14
|
+
sanitize_admin_sex!(sex)
|
17
15
|
end
|
18
16
|
add_field :guarantor_type
|
19
17
|
add_field :guarantor_relationship
|
@@ -72,4 +70,4 @@ module HL7
|
|
72
70
|
add_field :guarantor_birth_place
|
73
71
|
add_field :vip_indicator
|
74
72
|
end
|
75
|
-
end
|
73
|
+
end
|
data/lib/segments/in1.rb
CHANGED
data/lib/segments/mfe.rb
CHANGED
data/lib/segments/mfi.rb
CHANGED