class Oddb2xml::RefdataExtractor
Public Class Methods
Source
# File lib/oddb2xml/extractor.rb, line 204 def initialize(xml, type) @type = (type == :pharma ? "PHARMA" : "NONPHARMA") super(xml) end
Calls superclass method
Oddb2xml::Extractor::new
Public Instance Methods
Source
# File lib/oddb2xml/extractor.rb, line 209 def to_hash data = {} result = SwissRegArticles.parse(@xml.sub(STRIP_FOR_SAX_MACHINE, ""), lazy: true) result.Article.each do |article| article_type = article.MedicinalProduct.ProductClassification.ProductClass if article_type != @type next end ean13 = @type == "PHARMA" ? article.PackagedProduct.DataCarrierIdentifier : article.MedicinalProduct.Identifier if ean13.size < 13 puts "Refdata #{@type} use 13 chars not #{ean13.size} for #{ean13}" if $VERBOSE ean13 = ean13.rjust(13, "0") end if ean13.size == 14 && ean13[0] == "0" puts "Refdata #{@type} remove leading '0' for #{ean13}" if $VERBOSE ean13 = ean13[1..-1] end item = {} item[:ean13] = ean13 item[:no8] = article.PackagedProduct.RegulatedAuthorisationIdentifier || "" item[:data_origin] = "refdata" item[:refdata] = true item[:_type] = @type.downcase.to_sym item[:last_change] = "" # TODO: Date and time of last data change item[:desc_de] = "" item[:desc_fr] = "" item[:desc_it] = "" article.PackagedProduct.Name.each do |name| if name.Language == "DE" item[:desc_de] = name.FullName elsif name.Language == "FR" item[:desc_fr] = name.FullName elsif name.Language == "IT" item[:desc_it] = name.FullName end end item[:atc_code] = article.MedicinalProduct.ProductClassification.Atc || "" item[:company_name] = article.PackagedProduct.Holder.Name || "" item[:company_ean] = article.PackagedProduct.Holder.Identifier || "" data[ean13] = item end data end