Module: Extensions::HL7::Segment::ClassMethods
- Defined in:
- lib/core_ext/segment.rb
Instance Method Summary collapse
- #description ⇒ Object
- #field(index) ⇒ Object
- #field_description(field_index) ⇒ Object
- #from_hash(type, hash) ⇒ Object
- #index_for(field_name) ⇒ Object
- #is_required? ⇒ Boolean
- #mappings ⇒ Object
Instance Method Details
#description ⇒ Object
102 103 104 |
# File 'lib/core_ext/segment.rb', line 102 def description "" end |
#field(index) ⇒ Object
84 85 86 87 88 |
# File 'lib/core_ext/segment.rb', line 84 def field(index) fields.each do |field| return field if field[1][:idx] == index end end |
#field_description(field_index) ⇒ Object
106 107 108 |
# File 'lib/core_ext/segment.rb', line 106 def field_description(field_index) "" end |
#from_hash(type, hash) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/core_ext/segment.rb', line 90 def from_hash(type, hash) clazz = eval("::HL7::Message::Segment::#{type}") instance = clazz.new instance.hash = hash fields = clazz.fields fields.keys.each do |field| instance.send("#{field}=",hash[field.to_s.camelize(:lower)]) end instance end |
#index_for(field_name) ⇒ Object
114 115 116 117 118 119 120 121 |
# File 'lib/core_ext/segment.rb', line 114 def index_for(field_name) index = self.fields.collect {|field| field[0]}.index(field_name) rescue -1 if index < 0 return -1 else return index + 1 end end |
#is_required? ⇒ Boolean
110 111 112 |
# File 'lib/core_ext/segment.rb', line 110 def is_required? false end |
#mappings ⇒ Object
123 124 125 126 127 128 129 |
# File 'lib/core_ext/segment.rb', line 123 def mappings field_mappings = self.fields.inject([]) {|arr, k| arr << {field_name: k[0].to_s.gsub("_", " ").titleize, type: "String", field_code: k[1][:idx]}; arr} { metadata: {segment_code: self.to_s.split("::").last, display_name: ""}, fields: field_mappings } end |