Class: SimpleHL7::MSHSegment
- Defined in:
- lib/simple_hl7/msh_segment.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ MSHSegment
constructor
A new instance of MSHSegment.
- #separator_chars ⇒ Object
- #to_hl7(separator_chars) ⇒ Object
Methods inherited from Segment
current_separator_char, #name, start_index, subcomposite_class, #to_a
Methods inherited from Composite
#[], #[]=, current_separator_char, #each, #get_subcomposite, #map, #set_subcomposite, start_index, subcomposite_class, #to_a, #to_s
Constructor Details
#initialize ⇒ MSHSegment
Returns a new instance of MSHSegment.
3 4 5 6 7 |
# File 'lib/simple_hl7/msh_segment.rb', line 3 def initialize super('MSH') self[1] = '|' self[2] = '^~\&' end |
Class Method Details
.parse(str) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/simple_hl7/msh_segment.rb', line 18 def self.parse(str) msh = new msh[1] = str[3] msh[2] = str[4..7] fields = parse_subcomposite_hash(str[9, str.length], msh.separator_chars) fields.each { |index, subc| msh.set_subcomposite(index + 3, subc) } msh end |
Instance Method Details
#separator_chars ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/simple_hl7/msh_segment.rb', line 9 def separator_chars enc_chars = @subcomposites[2].to_s SeparatorCharacters.new(@subcomposites[1].to_s, enc_chars[0], enc_chars[1], enc_chars[2], enc_chars[3]) end |
#to_hl7(separator_chars) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/simple_hl7/msh_segment.rb', line 28 def to_hl7(separator_chars) sep_char = self.class.current_separator_char(separator_chars) base_msh = "#{name}#{self[1]}#{self[2]}" max_index = @subcomposites.keys.max rest_msh = (3..max_index).map { |i| @subcomposites[i].to_hl7(separator_chars) if @subcomposites[i] }.join(sep_char) [base_msh, rest_msh].join(sep_char) end |