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
92 93 94 |
# File 'lib/core_ext/segment.rb', line 92 def description "" end |
#field(index) ⇒ Object
74 75 76 77 78 |
# File 'lib/core_ext/segment.rb', line 74 def field(index) fields.each do |field| return field if field[1][:idx] == index end end |
#field_description(field_index) ⇒ Object
96 97 98 |
# File 'lib/core_ext/segment.rb', line 96 def field_description(field_index) "" end |
#from_hash(type, hash) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/core_ext/segment.rb', line 80 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
104 105 106 107 108 109 110 111 |
# File 'lib/core_ext/segment.rb', line 104 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
100 101 102 |
# File 'lib/core_ext/segment.rb', line 100 def is_required? false end |
#mappings ⇒ Object
113 114 115 116 117 118 119 120 |
# File 'lib/core_ext/segment.rb', line 113 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 |