module HL7::MessageBatchParser
Public Instance Methods
parse( inobj )
click to toggle source
parse a String
or Enumerable object into an HL7::Message
if possible
-
returns a new
HL7::Message
if successful
# File lib/message_parser.rb, line 24 def parse( inobj ) HL7::Message.new do |msg| msg.parse( inobj ) end end
parse_batch(batch) { |message| ... }
click to toggle source
# File lib/message_parser.rb, line 2 def parse_batch(batch) # :yields: message raise HL7::ParseError, 'badly_formed_batch_message' unless batch.hl7_batch? batch = clean_batch_for_jruby batch raise HL7::ParseError, 'empty_batch_message' unless match = /\rMSH/.match(batch) match.post_match.split(/\rMSH/).each do |_msg| if md = /\rBTS/.match(_msg) # TODO: Validate the message count in the BTS segment # should == index + 1 _msg = md.pre_match end yield 'MSH' + _msg end end
Private Instance Methods
clean_batch_for_jruby(batch)
click to toggle source
JRuby seems to change our literal r characters in sample messages (from here documents) into newlines. We make a copy here, reverting to carriage returns. The input is unchanged.
This does not occur when posts are received with CR characters, only in sample messages from here documents. The expensive copy is only incurred when the batch message has a newline character in it.
# File lib/message_parser.rb, line 40 def clean_batch_for_jruby(batch) batch.gsub("\n", "\r") if batch.include?("\n") end