lib/hqmf-parser/1.0/attribute.rb in health-data-standards-3.4.6 vs lib/hqmf-parser/1.0/attribute.rb in health-data-standards-3.5.0
- old
+ new
@@ -59,10 +59,63 @@
components = name.gsub(/\W/,' ').split.collect {|word| word.strip.upcase }
components.join '_'
end
def to_json
- {self.const_name => build_hash(self, [:code,:value,:unit,:name,:id])}
+ json = {self.const_name => build_hash(self, [:code,:value,:unit,:name,:id])}
+ extend_json_for_enhanced_model(json)
end
-
+
+ private
+
+ 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
+
+ def id_xml_to_json(entry_xpath)
+ {
+ :root => attr_val("#{entry_xpath}/@root"),
+ :extension => attr_val("#{entry_xpath}/@extension")
+ }
+ end
+
+ 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
end
end
\ No newline at end of file