module YAHL7::V2::AliasFieldNames

This module can be included into a class to make the `define_field_names` macro available. This macro allows you to define repetitive field name aliases in a quick and easy fashion.

For example:

include YAHL7::V2::AliasFieldNames

 define_field_names({ patient_identifier_list: 3 })

Will define a method named `patient_identifier_list` which fetches the third field from the segment.

If you want to define more complex methods, you can exclude them from this hash and define them manually.

Public Class Methods

included(base) click to toggle source
# File lib/yahl7/v2/alias_field_names.rb, line 21
def self.included(base)
  base.extend(ClassMethods)
end

Public Instance Methods

make_field(klass, value) click to toggle source
# File lib/yahl7/v2/alias_field_names.rb, line 29
def make_field(klass, value)
  value = normalize_value(value)
  return nil if value.nil?

  if klass.respond_to?(:repeated?) && klass.repeated?(value)
    value.map { |v| new_class_value(klass, v) }
  else
    new_class_value(klass, value)
  end
end
new_class_value(klass, value) click to toggle source
# File lib/yahl7/v2/alias_field_names.rb, line 40
def new_class_value(klass, value)
  case klass.name
  when 'YAHL7::V2::DataType::FT' then klass.new(value, parse_options)
  else klass.new(value)
  end
end
normalize_value(value) click to toggle source
# File lib/yahl7/v2/alias_field_names.rb, line 25
def normalize_value(value)
  value.nil? || value == '' ? nil : value
end