Class: HL7::Message::SegmentGenerator

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

Overview

Methods for creating segments in Message

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(element, last_seg, delimiter) ⇒ SegmentGenerator

Returns a new instance of SegmentGenerator.



20
21
22
23
24
25
26
27
# File 'lib/segment_generator.rb', line 20

def initialize(element, last_seg, delimiter)
  @element = element
  @last_seg = last_seg
  @delimiter = delimiter

  @seg_parts = HL7::MessageParser.split_by_delimiter(element,
    delimiter.element)
end

Instance Attribute Details

#delimiterObject (readonly)

Returns the value of attribute delimiter.



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

def delimiter
  @delimiter
end

#elementObject (readonly)

Returns the value of attribute element.



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

def element
  @element
end

#last_segObject (readonly)

Returns the value of attribute last_seg.



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

def last_seg
  @last_seg
end

#seg_nameObject

Returns the value of attribute seg_name.



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

def seg_name
  @seg_name
end

#seg_partsObject

Returns the value of attribute seg_parts.



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

def seg_parts
  @seg_parts
end

Instance Method Details

#buildObject



37
38
39
40
# File 'lib/segment_generator.rb', line 37

def build
  klass = get_segment_class
  klass.new(@element, [@delimiter.element, @delimiter.item])
end

#get_segment_classObject



42
43
44
45
46
47
48
49
50
51
# File 'lib/segment_generator.rb', line 42

def get_segment_class
  segment_to_search = @seg_name.to_sym
  segment_to_search = @seg_name if RUBY_VERSION < "1.9"

  if HL7::Message::Segment.constants.index(segment_to_search)
    eval(format("HL7::Message::Segment::%s", @seg_name))
  else
    HL7::Message::Segment::Default
  end
end

#valid_segments_parts?Boolean

Returns:

  • (Boolean)

Raises:



29
30
31
32
33
34
35
# File 'lib/segment_generator.rb', line 29

def valid_segments_parts?
  return true if @seg_parts&.length&.positive?

  raise HL7::EmptySegmentNotAllowed if HL7.configuration.empty_segment_is_error

  false
end