Class: Line

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_astm/line.rb

Constant Summary collapse

TYPES =
{
  "H" => "Header",
  "MSH" => "Hl7_Header",
  "OBX" => "Hl7_Observation",
  "PID" => "Hl7_Patient",
  "OBR" => "Hl7_Order",
  "P" => "Patient",
  "Q" => "Query",
  "O" => "Order",
  "R" => "Result",
  "L" => "Terminator"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Line

sets the types, and fields we can have processing based on line.



32
33
34
35
36
37
38
39
40
41
# File 'lib/ruby_astm/line.rb', line 32

def initialize(args)
  self.fields = []
  raise "no text provided" unless args[:text]
  if args[:text]
    args[:text].split(/\|/).each do |field|
      self.fields << field
    end
  end
  detect_type
end

Instance Attribute Details

#fieldsObject

Returns the value of attribute fields.



18
19
20
# File 'lib/ruby_astm/line.rb', line 18

def fields
  @fields
end

#textObject

Returns the value of attribute text.



16
17
18
# File 'lib/ruby_astm/line.rb', line 16

def text
  @text
end

#typeObject

Returns the value of attribute type.



20
21
22
# File 'lib/ruby_astm/line.rb', line 20

def type
  @type
end

Instance Method Details

#detect_typeObject



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ruby_astm/line.rb', line 43

def detect_type
  #puts "detecting line type: #{self.text}"
  line_type = self.fields[0]
  return unless line_type
  line_type.scan(/(?<ltype>[A-Z]+)/) { |ltype| 
    if Line::TYPES[ltype[0]]
      self.type = Line::TYPES[ltype[0]]
    end
  }    

end