class HQMF1::Attribute
Represents a HQMF
measure attribute
Public Class Methods
new(entry)
click to toggle source
Create a new instance based on the supplied HQMF
@param [Nokogiri::XML::Element] entry the measure attribute element
# File lib/hqmf-parser/1.0/attribute.rb, line 9 def initialize(entry) @entry = entry end
Public Instance Methods
code()
click to toggle source
Get the attribute code @return [String] the code
# File lib/hqmf-parser/1.0/attribute.rb, line 15 def code if (@entry.at_xpath('./cda:code/@code')) @entry.at_xpath('./cda:code/@code').value elsif @entry.at_xpath('./cda:code/@nullFlavor') @entry.at_xpath('./cda:code/@nullFlavor').value end end
const_name()
click to toggle source
Get a JS friendly constant name for this measure attribute
# File lib/hqmf-parser/1.0/attribute.rb, line 58 def const_name components = name.gsub(/\W/,' ').split.collect {|word| word.strip.upcase } components.join '_' end
id()
click to toggle source
Get the attribute id, used elsewhere in the document to refer to the attribute @return [String] the id
# File lib/hqmf-parser/1.0/attribute.rb, line 35 def id attr_val('./cda:id/@root') end
name()
click to toggle source
Get the attribute name @return [String] the name
# File lib/hqmf-parser/1.0/attribute.rb, line 25 def name if (@entry.at_xpath('./cda:code/@displayName')) @entry.at_xpath('./cda:code/@displayName').value elsif @entry.at_xpath('cda:code/cda:originalText') @entry.at_xpath('cda:code/cda:originalText').text end end
to_json()
click to toggle source
# File lib/hqmf-parser/1.0/attribute.rb, line 63 def to_json json = {self.const_name => build_hash(self, [:code,:value,:unit,:name,:id])} extend_json_for_enhanced_model(json) end
unit()
click to toggle source
Get the unit of the attribute value or nil if none is defined @return [String] the unit
# File lib/hqmf-parser/1.0/attribute.rb, line 53 def unit attr_val('./cda:value/@unit') end
value()
click to toggle source
Get the attribute value @return [String] the value
# File lib/hqmf-parser/1.0/attribute.rb, line 41 def value val = attr_val('./cda:value/@value') val ||= attr_val('./cda:value/@extension') if val val else @entry.at_xpath('./cda:value').inner_text end end
Private Instance Methods
code_xml_to_json(entry_xpath)
click to toggle source
# File lib/hqmf-parser/1.0/attribute.rb, line 109 def code_xml_to_json(entry_xpath) { :type => attr_val("#{entry_xpath}/@xsi:type") || 'CD', :system => attr_val("#{entry_xpath}/@codeSystem"), :code => attr_val("#{entry_xpath}/@code"), :code_list_id => attr_val("#{entry_xpath}/@valueSet"), :title => attr_val("#{entry_xpath}/@displayName"), :null_flavor => attr_val("#{entry_xpath}/@nullFlavor"), :original_text => @entry.at_xpath("#{entry_xpath}/cda:originalText").try(:inner_text) } end
extend_json_for_enhanced_model(json)
click to toggle source
# File lib/hqmf-parser/1.0/attribute.rb, line 70 def extend_json_for_enhanced_model(json) if (@entry.at_xpath('./cda:id')) json[self.const_name][:id_obj] = id_xml_to_json('./cda:id') end if (@entry.at_xpath('./cda:code')) json[self.const_name][:code_obj] = code_xml_to_json('./cda:code') end if (@entry.at_xpath('./cda:value')) value_hash = { :type => attr_val('./cda:value/@xsi:type')} case value_hash[:type] when 'II' value_hash.merge!(id_xml_to_json('./cda:value')) when 'CD' value_hash.merge!(code_xml_to_json('./cda:value')) when 'ED' value_hash[:value] = @entry.at_xpath('./cda:value').inner_text value_hash[:media_type] = attr_val('./cda:value/@mediaType') else if (attr_val('./cda:value/@value')) value_hash.merge!(HQMF1::Value.new(@entry.at_xpath('./cda:value')).to_json) value_hash[:expression] = @entry.at_xpath('./cda:value/cda:expression').try(:inner_text).try(:strip) else value_hash[:value] = @entry.at_xpath('./cda:value').inner_text.try(:strip) end end json[self.const_name][:value_obj] = value_hash end json end
id_xml_to_json(entry_xpath)
click to toggle source
# File lib/hqmf-parser/1.0/attribute.rb, line 102 def id_xml_to_json(entry_xpath) { :root => attr_val("#{entry_xpath}/@root"), :extension => attr_val("#{entry_xpath}/@extension") } end