diff --git a/Gemfile.lock b/Gemfile.lock index b39808e..cdc0820 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,8 +7,9 @@ PATH nokogiri (~> 1.5.10) parslet (~> 1.7.0) rubyXL (~> 3.3.1) + rubyntlm (>= 0.3.2) rubyzip (~> 1.1.3) - savon (~> 2.4.0) + savon (~> 2.10.0) sax-machine (~> 0.1.0) spreadsheet (~> 1.0.0) @@ -16,7 +17,7 @@ GEM remote: https://rubygems.org/ specs: addressable (2.3.8) - akami (1.2.2) + akami (1.3.1) gyoku (>= 0.4.0) nokogiri archive-tar-minitar (0.5.2) @@ -35,12 +36,13 @@ GEM diff-lcs (1.2.5) domain_name (0.5.24) unf (>= 0.0.5, < 1.0.0) - gyoku (1.1.1) + gyoku (1.3.1) builder (>= 2.1.2) - httpi (2.1.1) + httpi (2.4.0) rack - rubyntlm (~> 0.3.2) - json (1.8.2) + json (1.8.3) + macaddr (1.7.1) + systemu (~> 2.6.2) mechanize (2.5.1) domain_name (~> 0.5, >= 0.5.1) mime-types (~> 1.17, >= 1.17.2) @@ -54,7 +56,7 @@ GEM net-http-digest_auth (1.4) net-http-persistent (2.9.4) nokogiri (1.5.11) - nori (2.3.0) + nori (2.6.0) ntlm-http (0.1.1) parslet (1.7.0) blankslate (>= 2.0, <= 4.0) @@ -65,7 +67,7 @@ GEM pry-debugger (0.2.3) debugger (~> 1.3) pry (>= 0.9.10, < 0.11.0) - rack (1.6.0) + rack (1.6.1) rake (10.4.2) rdoc (4.2.0) json (~> 1.4) @@ -89,26 +91,29 @@ GEM rubyntlm (0.3.4) rubyzip (1.1.7) safe_yaml (1.0.4) - savon (2.4.0) - akami (~> 1.2.0) + savon (2.10.1) + akami (~> 1.2) builder (>= 2.1.2) - gyoku (~> 1.1.0) - httpi (~> 2.1.0) + gyoku (~> 1.2) + httpi (~> 2.3) nokogiri (>= 1.4.0) - nori (~> 2.3.0) - wasabi (~> 3.2.2) + nori (~> 2.4) + uuid (~> 2.3.7) + wasabi (~> 3.4) sax-machine (0.1.0) nokogiri (> 0.0.0) slop (3.6.0) spreadsheet (1.0.3) ruby-ole (>= 1.0) + systemu (2.6.5) unf (0.1.4) unf_ext unf_ext (0.0.7.1) - wasabi (3.2.3) + uuid (2.3.8) + macaddr (~> 1.0) + wasabi (3.5.0) httpi (~> 2.0) - mime-types (< 2.0.0) - nokogiri (>= 1.4.0) + nokogiri (>= 1.4.2) webmock (1.21.0) addressable (>= 2.3.6) crack (>= 0.3.2) diff --git a/bin/oddb2xml b/bin/oddb2xml index 43adcf2..1ecb901 100755 --- a/bin/oddb2xml +++ b/bin/oddb2xml @@ -1,54 +1,16 @@ #!/usr/bin/env ruby +# +# This file was generated by Bundler. +# +# The application 'oddb2xml' is installed as part of a gem, and +# this file is here to facilitate running it. +# require 'pathname' +ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) -root = Pathname.new(__FILE__).realpath.parent.parent -$:.unshift root.join('lib') if $0 == __FILE__ +require 'rubygems' +require 'bundler/setup' -require 'optparse' -require 'oddb2xml' -require 'oddb2xml/options' - -options = Oddb2xml::Options.new - -args = ARGV.dup -begin - options.parser.parse!(args) -rescue OptionParser::MissingArgument, - OptionParser::InvalidArgument, - OptionParser::InvalidOption - puts Oddb2xml::Options.help - exit -end - -opts = options.opts -if args.size > 0 - puts "Please remove unused parameters #{args}" - exit 2 -end - -# TEMP -if path = args.first - opts[:transfer_dat] = path -end - -startTime = Time.now -ui = Oddb2xml::Cli.new(opts) -begin - if opts[:format] == :xml - opts[:ean14] = true # force - end - #puts opts if opts[:debug] - if RUBY_VERSION.to_f < 1.9 - message = <<-MES -Once you find some time, please upgrade your Ruby to 1.9.3 ;) -then you will not see anymore warnings - MES - warn message - end - ui.run -rescue Interrupt - exit -end -diff = (Time.now-startTime).to_i -puts "#{Time.now}: #{__LINE__} done. Took #{diff} seconds"; $stdout.sync +load Gem.bin_path('oddb2xml', 'oddb2xml') diff --git a/lib/oddb2xml/builder.rb b/lib/oddb2xml/builder.rb index 7cd57e1..0598877 100644 --- a/lib/oddb2xml/builder.rb +++ b/lib/oddb2xml/builder.rb @@ -84,12 +84,9 @@ module Oddb2xml @articles = nil if reset unless @articles Oddb2xml.log("prepare_articles starting with #{@articles ? @articles.size : 'no'} articles") - @articles = [] # base is 'DE' - @index['DE'].each_pair do |phar, indices| - obj = { - :de => indices, - :fr => @index['FR'][phar], - } + @articles = [] + @index.each_pair do |phar, indices| + obj = indices.first if migel = @migel[phar] # delete duplicates @migel[phar] = nil @@ -103,37 +100,29 @@ module Oddb2xml # add @migel.values.compact.each do |migel| next if migel[:pharmacode].empty? - obj = {} - %w[de fr].each do |lang| - entry = { - :ean => migel[:ean], - :pharmacode => migel[:pharmacode], - :stat_date => '', - :lang => lang.capitalize, - :desc => migel["desc_#{lang}".intern], - :atc_code => '', - :additional_desc => migel[:additional_desc], - :company_ean => migel[:company_ean], - :company_name => migel[:company_name], - :migel => true, - } - obj[lang.intern] = [entry] - end + obj = { + :ean => migel[:ean], + :pharmacode => migel[:pharmacode], + :stat_date => '', + :name_de => migel[:name_de], + :name_fr => migel[:name_fr], + :atc_code => '', + :additional_desc => migel[:additional_desc], + :company_ean => migel[:company_ean], + :company_name => migel[:company_name], + :migel => true, + } @articles << obj end nrAdded = 0 if @options[:extended] Oddb2xml.log("prepare_articles prepare_local_index") local_index = {} - %w[de fr].each { |lang| local_index[lang] = {} } - %w[de fr].each { - |lang| @articles.each{|article| - ean = article[lang.intern][0][:ean] - next if ean == nil or ean.to_i == 0 - local_index[lang][ean] = article - } - } + ean = article[:ean] + next if ean == nil or ean.to_i == 0 + local_index[ean] = article + } Oddb2xml.log("prepare_articles extended") @infos_zur_rose.each{ |ean13, info| @@ -143,34 +132,28 @@ module Oddb2xml @pharmacode[pharmacode][:pub_price] = info[:pub_price] next end - obj = {} found = false - %w[de fr].each do |lang| - # existing = @articles.find{|art| art[lang.intern] and art[lang.intern][0][:ean] == ean13 } - - existing = local_index[lang][ean13] - if existing - found = true - existing[:price] = info[:price] - existing[:pub_price] = info[:pub_price] - else - entry = { - :desc => info[:description], - :status => info[:status] == '3' ? 'I' : 'A', # from ZurRose, we got 1,2 or 3 means aktive, aka available in trade - :atc_code => '', - :ean => ean13, - :lang => lang.capitalize, - :pharmacode => pharmacode, - :price => info[:price], - :pub_price => info[:pub_price], - :type => info[:type], - } - obj[lang.intern] = [entry] - @index[lang.upcase][ean13] = entry - end + existing = local_index[ean13] + if existing + found = true + existing[:price] = info[:price] + existing[:pub_price] = info[:pub_price] + else + entry = { + :desc => info[:description], + :status => info[:status] == '3' ? 'I' : 'A', # from ZurRose, we got 1,2 or 3 means aktive, aka available in trade + :atc_code => '', + :ean => ean13, + :lang => 'DX', + :pharmacode => pharmacode, + :price => info[:price], + :pub_price => info[:pub_price], + :type => info[:type], + } + @index[ean13] = entry end unless found - @articles << obj + @articles << entry nrAdded += 1 end } @@ -234,15 +217,15 @@ module Oddb2xml def prepare_products unless @products @products = [] - @index['DE'].each_pair do |phar, indices| + @index.each_pair do |phar, indices| indices.each_with_index do |index, i| next if index and index.is_a?(Hash) and index[:atc_code] and /^Q/i.match(index[:atc_code]) obj = { :seq => @items[phar] ? @items[phar] : @items[index[:ean]], :pac => nil, :no8 => nil, - :de => index, - :fr => @index['FR'][phar][i], + :name_de => index[:name_de], + :name_fr => index[:name_fr], :st => index[:status], # swissINDEX and Packungen.xls(if swissINDEX does not have EAN) :ean => index[:ean], @@ -748,21 +731,20 @@ module Oddb2xml xml.ARTICLE(XML_OPTIONS) { @articles.each do |obj| idx += 1 - Oddb2xml.log "build_article #{idx} of #{@articles.size} articles" if idx % 500 == 0 - obj[:de].each_with_index do |de_idx, i| - fr_idx = obj[:fr][i] # swissindex FR - pac,no8 = nil,de_idx[:ean][4..11] # BAG-XML(SL/LS) + Oddb2xml.log "build_article #{idx} of #{@articles.size} articles" if idx % 500 == 0 + next unless obj[:ean] + pac,no8 = nil,obj[:ean][4..11] # BAG-XML(SL/LS) pack_info = nil pack_info = @packs[no8.intern] if no8 # info from Packungen.xlsx from swissmedic_info ppac = nil # Packungen - ean = de_idx[:ean] + ean = obj[:ean] next if pack_info and /Tierarzneimittel/.match(pack_info[:list_code]) - next if de_idx[:desc] and /ad us vet/i.match(de_idx[:desc]) + next if obj[:desc] and /ad us vet/i.match(obj[:desc]) - pharma_code = de_idx[:pharmacode] + pharma_code = obj[:pharmacode] ean = nil if ean.match(/^000000/) if obj[:seq] - pac = obj[:seq][:packages][de_idx[:pharmacode]] + pac = obj[:seq][:packages][obj[:pharmacode]] pac = obj[:seq][:packages][ean] unless pac else pac = @items[ean][:packages][ean] if @items and ean and @items[ean] and @items[ean][:packages] @@ -775,8 +757,8 @@ module Oddb2xml info_zur_rose = @infos_zur_rose[ean] # zurrose end xml.ART('DT' => '') { - xml.REF_DATA (de_idx[:refdata] || @migel[pharma_code]) ? '1' : '0' - xml.PHAR de_idx[:pharmacode] unless de_idx[:pharmacode].empty? + xml.REF_DATA (obj[:refdata] || @migel[pharma_code]) ? '1' : '0' + xml.PHAR obj[:pharmacode] unless obj[:pharmacode].empty? #xml.GRPCD #xml.CDS01 #xml.CDS02 @@ -798,7 +780,7 @@ module Oddb2xml xml.VAT info_zur_rose[:vat] end - nincd = detect_nincd(de_idx) + nincd = detect_nincd(obj) (nincd and nincd == 13) ? xml.SALECD('A') : xml.SALECD( (info_zur_rose && info_zur_rose[:cmut] != '3') ? 'A' : 'I') # XML_OPTIONS if pac and pac[:limitation_points] #xml.INSLIM @@ -817,11 +799,17 @@ module Oddb2xml xml.BG(flag ? 'Y' : 'N') end #xml.EXP - xml.QTY de_idx[:additional_desc] if de_idx[:additional_desc] and not de_idx[:additional_desc].empty? - xml.DSCRD de_idx[:desc] if de_idx[:desc] and not de_idx[:desc].empty? - xml.DSCRF fr_idx[:desc] if fr_idx[:desc] and not fr_idx[:desc].empty? - xml.SORTD de_idx[:desc].upcase if de_idx[:desc] and not de_idx[:desc].empty? - xml.SORTF fr_idx[:desc].upcase if fr_idx[:desc] and not fr_idx[:desc].empty? + xml.QTY obj[:additional_desc] if obj[:additional_desc] and not obj[:additional_desc].empty? + if obj[:name_de] and not obj[:name_de].empty? + xml.DSCRD obj[:name_de] + xml.SORTD obj[:name_de].upcase + elsif info_zur_rose and info_zur_rose[:description] and not info_zur_rose[:description].empty? + xml.DSCRD info_zur_rose[:description] + elsif obj[:desc] + xml.DSCRD obj[:desc] + end + xml.DSCRF obj[:name_fr] if obj[:name_fr] and not obj[:name_fr].empty? + xml.SORTF obj[:name_fr].upcase if obj[:name_fr] and not obj[:name_fr].empty? #xml.QTYUD #xml.QTYUF #xml.IMG @@ -848,8 +836,8 @@ module Oddb2xml #xml.BAGSL #xml.BAGSLC #xml.LOACD - if de_idx[:stat_date] - xml.OUTSAL de_idx[:stat_date] if de_idx[:stat_date] and not de_idx[:stat_date].empty? + if obj[:stat_date] + xml.OUTSAL obj[:stat_date] if obj[:stat_date] and not obj[:stat_date].empty? end #xml.STTOX #xml.NOTI @@ -865,7 +853,7 @@ module Oddb2xml #xml.DEL xml.ARTCOMP { # use ean13(gln) as COMPNO - xml.COMPNO de_idx[:company_ean] if de_idx[:company_ean] and not de_idx[:company_ean].empty? + xml.COMPNO obj[:company_ean] if obj[:company_ean] and not obj[:company_ean].empty? #xml.ROLE #xml.ARTNO1 #xml.ARTNO2 @@ -932,7 +920,6 @@ module Oddb2xml } end } - end if obj[:de] end xml.RESULT { xml.OK_ERROR 'OK' @@ -1158,8 +1145,7 @@ module Oddb2xml def build_dat prepare_articles rows = [] - @articles.each do |obj| - obj[:de].each_with_index do |idx, i| + @articles.each do |idx| ean = idx[:ean] next if ((ean.to_s.length != 13) and !ean14) next if idx[:type] == :nonpharma @@ -1167,7 +1153,7 @@ module Oddb2xml pack_info = nil # Oddb2tdat.parse pac,no8 = nil,nil - if obj[:seq] and obj[:seq][:packages] + if false # obj[:seq] and obj[:seq][:packages] pac = obj[:seq][:packages][idx[:pharmacode]] pac = obj[:seq][:packages][ean] unless pac else @@ -1240,7 +1226,6 @@ module Oddb2xml row << "%0#{DAT_LEN[:CEAN]}d" % (ean.match(/^000000/) ? 0 : ean.to_i) row << "%#{DAT_LEN[:CMWS]}s" % '2' # pharma rows << row - end end rows.join("\n") end @@ -1248,13 +1233,12 @@ module Oddb2xml reset = true prepare_articles(reset) rows = [] - @articles.each do |obj| - obj[:de].each_with_index do |idx, i| + @articles.each do |idx| row = '' next if ((idx[:ean].to_s.length != 13) and !ean14) - # Oddb2tdat.parse_migel + phar = idx[:pharmacode] row << "%#{DAT_LEN[:RECA]}s" % '11' - row << "%#{DAT_LEN[:CMUT]}s" % if (phar = idx[:pharmacode] and phar.size > 3) + row << "%#{DAT_LEN[:CMUT]}s" % if (phar and phar.size > 3) '1' else '3' @@ -1275,7 +1259,6 @@ module Oddb2xml row << idx[:ean].to_s.rjust(DAT_LEN[:CEAN], '0') row << "%#{DAT_LEN[:CMWS]}s" % '1' # nonpharma rows << row - end end rows.join("\n") end diff --git a/lib/oddb2xml/cli.rb b/lib/oddb2xml/cli.rb index 69df5c8..451093e 100644 --- a/lib/oddb2xml/cli.rb +++ b/lib/oddb2xml/cli.rb @@ -16,7 +16,6 @@ module Oddb2xml SUBJECTS = %w[product article] ADDITIONS = %w[substance limitation interaction code] OPTIONALS = %w[fi fi_product] - LANGUAGES = %w[DE FR] # EN does not exist def initialize(args) @options = args Oddb2xml.save_options(@options) @@ -36,9 +35,7 @@ module Oddb2xml # addres @companies = [] # betrieb @people = [] # medizinalperson - LANGUAGES.each do |lang| - @index[lang] = {} - end + @index = {} @_message = false end def run @@ -69,10 +66,8 @@ module Oddb2xml threads << download(:bm_update) # oddb2xml_files threads << download(:lppv) # oddb2xml_files threads << download(:bag) # bag.e-mediat - LANGUAGES.each do |lang| - types.each do |type| - threads << download(:index, type, lang) # swissindex - end + types.each do |type| + threads << download(:index, type) # swissindex end end begin @@ -110,11 +105,8 @@ module Oddb2xml else # product if @options[:format] != :dat index = {} - LANGUAGES.each do |lang| - index[lang] = {} unless index[lang] - types.each do |type| - index[lang].merge!(@index[lang][type]) if @index[lang][type] - end + types.each do |type| + index.merge!(@index[type]) if @index[type] end builder.index = index builder.subject = sbj @@ -137,9 +129,6 @@ module Oddb2xml if !@options[:address] and (@options[:format] == :dat) types.each do |type| index = {} - LANGUAGES.each do |lang| - index[lang] = @index[lang][type] - end _sbj = (type == :pharma ? :dat : :with_migel_dat) builder.index = index builder.subject = _sbj @@ -166,7 +155,7 @@ module Oddb2xml raise Interrupt end end - def download(what, type=nil, lang=nil) + def download(what, type=nil) case what when :company, :person var = (what == :company ? 'companies' : 'people') @@ -268,7 +257,7 @@ module Oddb2xml end when :index Thread.new do - downloader = SwissIndexDownloader.new(@options, type, lang) + downloader = SwissIndexDownloader.new(@options, type) begin xml = downloader.download rescue SystemExit @@ -281,7 +270,7 @@ module Oddb2xml end @mutex.synchronize do hsh = SwissIndexExtractor.new(xml, type).to_hash - @index[lang][type] = hsh + @index[type] = hsh end end end @@ -335,19 +324,16 @@ module Oddb2xml lines << ParseComposition.report end unless @options[:address] - LANGUAGES.each do |lang| - lines << lang - types.each do |type| - if @index[lang][type] - indices = @index[lang][type].values.flatten.length - if type == :nonpharma - migel_xls = @migel.values.compact.select{|m| !m[:pharmacode].empty? }.map{|m| m[:pharmacode] } - nonpharmas = @index[lang][type].keys - indices += (migel_xls - nonpharmas).length # ignore duplicates, null - lines << sprintf("\tNonPharma products: %i", indices) - else - lines << sprintf("\tPharma products: %i", indices) - end + types.each do |type| + if @index[type] + indices = @index[type].values.flatten.length + if type == :nonpharma + migel_xls = @migel.values.compact.select{|m| !m[:pharmacode].empty? }.map{|m| m[:pharmacode] } + nonpharmas = @index[type].keys + indices += (migel_xls - nonpharmas).length # ignore duplicates, null + lines << sprintf("\tNonPharma products: %i", indices) + else + lines << sprintf("\tPharma products: %i", indices) end end end diff --git a/lib/oddb2xml/downloader.rb b/lib/oddb2xml/downloader.rb index 8091a0f..5744ca2 100644 --- a/lib/oddb2xml/downloader.rb +++ b/lib/oddb2xml/downloader.rb @@ -204,10 +204,9 @@ module Oddb2xml end end class SwissIndexDownloader < Downloader - def initialize(options={}, type=:pharma, lang='DE') - @type = (type == :pharma ? 'Pharma' : 'NonPharma') - @lang = lang - url = "https://index.ws.e-mediat.net/Swissindex/#{@type}/ws_#{@type}_V101.asmx?WSDL" + def initialize(options={}, type=:pharma) + @type = (type.to_sym == :pharma ? 'Pharma' : 'NonPharma') + url = "http://refdatabase.refdata.ch/Service/Article.asmx?WSDL" super(options, url) end def init @@ -222,19 +221,22 @@ module Oddb2xml end def download begin - filename = "swissindex_#{@type}_#{@lang}.xml" - file2save = File.join(Downloads, "swissindex_#{@type}_#{@lang}.xml") + filename = "swissindex_#{@type}.xml" + file2save = File.join(Downloads, "swissindex_#{@type}.xml") return IO.read(file2save) if Oddb2xml.skip_download? and File.exists?(file2save) FileUtils.rm_f(file2save, :verbose => false) soap = < - - - #{@lang} - - + + + + + #{@type} + + + + XML - response = @client.call(:download_all, :xml => soap) + response = @client.call(:download, :xml => soap) if response.success? if xml = response.to_xml response = nil # win diff --git a/lib/oddb2xml/extractor.rb b/lib/oddb2xml/extractor.rb index 853e9a8..5c7e695 100644 --- a/lib/oddb2xml/extractor.rb +++ b/lib/oddb2xml/extractor.rb @@ -185,24 +185,23 @@ module Oddb2xml end def to_hash data = {} - result = PharmaEntry.parse(@xml.sub(Strip_For_Sax_Machine, ''), :lazy => true) - items = result.PHARMA.ITEM + result = ArticleEntry.parse(@xml.sub(Strip_For_Sax_Machine, ''), :lazy => true) + + items = result.ITEM items.each do |pac| item = {} item[:refdata] = true item[:_type] = @type.downcase.intern item[:ean] = (gtin = pac.GTIN) ? gtin: '' item[:pharmacode] = (phar = pac.PHAR) ? phar: '' - item[:stat_date] = (date = pac.SDATE) ? date: '' - item[:lang] = (lang = pac.LANG) ? lang: '' - item[:desc] = (dscr = pac.DSCR) ? dscr: '' + item[:stat_date] = (date = pac.DT) ? date: '' if false + item[:name_de] = (de = pac.NAME_DE) ? de: '' + item[:name_fr] = (fr = pac.NAME_FR) ? fr: '' item[:atc_code] = (code = pac.ATC) ? code.to_s : '' # as quantity text item[:additional_desc] = (dscr = pac.ADDSCR) ? dscr: '' - if comp = pac.COMP - item[:company_name] = (nam = comp.NAME) ? nam: '' - item[:company_ean] = (gln = comp.GLN) ? gln: '' - end + item[:company_name] = (auth = pac.AUTH_HOLDER_NAME) ? auth : '' + item[:company_ean] = (auth_gln = pac.AUTH_HOLDER_GLN) ? auth_gln : '' unless item[:pharmacode].empty? item[:pharmacode] = correct_code(item[:pharmacode].to_s, 7) unless data[item[:pharmacode]] # pharmacode => GTINs @@ -501,6 +500,7 @@ module Oddb2xml :ean => ean13, :vat => line[96], :description => line[10..59].sub(/\s+$/, ''), + :name_de => line[10..59].sub(/\s+$/, ''), :additional_desc => '', :pharmacode => pharma_code, :price => sprintf("%.2f", line[60,6].gsub(/(\d{2})$/, '.\1').to_f), diff --git a/lib/oddb2xml/xml_definitions.rb b/lib/oddb2xml/xml_definitions.rb index 763dd44..7d42ce4 100644 --- a/lib/oddb2xml/xml_definitions.rb +++ b/lib/oddb2xml/xml_definitions.rb @@ -169,7 +169,19 @@ class CompElement element :GLN end -class ItemContent +%( new when from refdata + + PHARMA + 7680555580054 + 2465312 + 55558005 + ZYVOXID Filmtabl 600 mg 10 Stk + ZYVOXID cpr pell 600 mg 10 pce + J01XX08 + Pfizer AG + 7601001010604 + +class ItemContentOld include SAXMachine attribute :DT element :GTIN @@ -183,19 +195,47 @@ class ItemContent element :COMP, :class => CompElement end -class PharmaContent +class PharmaContentOld include SAXMachine attribute :CREATION_DATETIME elements :ITEM, :class => ItemContent end -class PharmaEntry +class PharmaEntryOld include SAXMachine element :CREATION_DATETIME element :NONPHARMA, :as => :PHARMA, :class => PharmaContent element :PHARMA, :class => PharmaContent end +) +class ItemContent + include SAXMachine + attribute :DT + element :ATYPE + element :GTIN + element :PHAR + element :SWMC_AUTHNR + element :NAME_DE + element :NAME_FR +# element :STATUS +# element :SDATE +# element :LANG +# element :DSCR +# element :ADDSCR + element :ATC + element :AUTH_HOLDER_NAME + element :AUTH_HOLDER_GLN + +end + +class ArticleEntry + include SAXMachine + element :CREATION_DATETIME + elements :ITEM, :class => ItemContent +end + + class ItemContent include SAXMachine attribute :DT diff --git a/oddb2xml.gemspec b/oddb2xml.gemspec index 798fd58..84c9c5e 100644 --- a/oddb2xml.gemspec +++ b/oddb2xml.gemspec @@ -24,12 +24,13 @@ Gem::Specification.new do |spec| spec.add_dependency 'archive-tar-minitar', '~> 0.5.2' spec.add_dependency 'mechanize', '~> 2.5.1' spec.add_dependency 'nokogiri', '~> 1.5.10' - spec.add_dependency 'savon', '~> 2.4.0' + spec.add_dependency 'savon', '~> 2.10.0 ' spec.add_dependency 'spreadsheet', '~> 1.0.0' spec.add_dependency 'rubyXL', '~> 3.3.1' spec.add_dependency 'sax-machine', '~> 0.1.0' spec.add_dependency 'parslet', '~> 1.7.0' - + spec.add_dependency 'rubyntlm', '>= 0.3.2' + spec.add_development_dependency "bundler" spec.add_development_dependency "rake" spec.add_development_dependency "rspec" diff --git a/spec/builder_spec.rb b/spec/builder_spec.rb index 0d2924e..c44cedd 100644 --- a/spec/builder_spec.rb +++ b/spec/builder_spec.rb @@ -41,7 +41,7 @@ def check_validation_via_xsd } end describe Oddb2xml::Builder do - NrExtendedArticles = 78 + NrExtendedArticles = 79 NrPharmaAndNonPharmaArticles = 60 NrPharmaArticles = 5 NrPackages = 18 @@ -67,14 +67,15 @@ describe Oddb2xml::Builder do end it 'should return true when validating xml against oddb2xml.xsd' do - res = buildr_capture(:stdout){ cli.run } + #res = buildr_capture(:stdout){ cli.run } + res = cli.run File.exists?(@article_xml).should eq true File.exists?(@product_xml).should eq true check_validation_via_xsd end end - context 'should handle BAG-articles with and without pharmacode' do + context 'should handle BAG-articles with and without pharmacode' do it { dat = File.read(File.expand_path('../data/Preparations.xml', __FILE__)) @items = Oddb2xml::BagXmlExtractor.new(dat).to_hash @@ -96,8 +97,9 @@ describe Oddb2xml::Builder do end it 'should generate a valid oddb_product.xml' do - res = buildr_capture(:stdout){ cli.run } - res.should match(/products/) + # res = buildr_capture(:stdout){ cli.run } + res = cli.run + # res.should match(/products/) @article_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_article.xml')) File.exists?(@article_xml).should eq true article_xml = IO.read(@article_xml) @@ -105,10 +107,24 @@ describe Oddb2xml::Builder do File.exists?(product_filename).should eq true unless /1\.8\.7/.match(RUBY_VERSION) product_xml = IO.read(product_filename) + product_xml.should match(/3TC/) + product_xml.should match(/7680620690084/) # Levetiracetam DESITIN + product_xml.match(/3TC Filmtabl 150 mg 60 Stk/).should_not == nil + product_xml.match(/7680620690084/).should_not == nil + product_xml.match(/Levetiracetam DESITIN Filmtabl 250 mg/).should_not == nil + product_xml.match(/Levetiracetam DESITIN cpr pell 250 mg/).should_not == nil + product_xml.match(/levetiracetamumlevetiracetamum 250 mg, excipiens pro compressi obducti pro charta.5819012LEVETIRACETAM DESITIN Filmtabl 250 mg/) + article_xml.should match(/76010013204511699947536620133TC Filmtabl 150 mg3TC Filmtabl 150 mg 60 Stk7601001392175768053662013701.10.201113.4927.83TC Filmtabl 150 mg/).should_not == nil - product_xml.match(/7680620690084/).should_not == nil - product_xml.match(/Levetiracetam DESITIN Filmtabl 250 mg/).should_not == nil - product_xml.match(/Levetiracetam DESITIN cpr pell 250 mg/).should_not == nil - product_xml.match(/levetiracetamumlevetiracetamum 250 mg, excipiens pro compressi obducti pro charta.5819012LEVETIRACETAM DESITIN Filmtabl 250 mg/) - article_xml.should match(/76010013204511699947536620133TC Filmtabl 150 mg3TC Filmtabl 150 mg 60 Stk7601001392175768053662013701.10.2011 - + - - - 733905577161 - 5366964 - A - 2012-08-22T00:00:00 - FR - 1-DAY ACUVUE moist jour -2.00dpt BC 8.5 - 30 pce - - Johnson & Johnson Consumer (Health Care / OTC) - - - - 0000000000000 - 00000 - A - 2002-05-23T00:00:00 - DE - Foo 1000 mg - Amp - - EXAMPLE.COM AG - 0000000000000 - +
+ + NONPHARMA + 733905577161 + 5366964 + 1-DAY ACUVUE Moist Tag -2.00dpt BC 8.5 30 Stk + 1-DAY ACUVUE moist jour -2.00dpt BC 8.5 30 pce + Johnson & Johnson Consumer (Health Care / OTC) - + + + NONPHARMA 0000000000001 00001 - A - 2002-05-23T00:00:00 - DE - Bar 10 Stk - 10 Stk - - EXAMPLE.ORG AG - + Bar 10 Stk + Bar 10 pce + EXAMPLE.ORG AG - + + + + NONPHARMA 0000000000002 00002 - A - 2002-05-23T00:00:00 - DE - Baz 10 Tablet - 5 Stk - - EXAMPLE.AC AG - + Bar 10 Tablet + Bar 10 tablets + EXAMPLE.AC AG + OK - 3 + 44929 - +
diff --git a/spec/data/swissindex_pharma.xml b/spec/data/swissindex_pharma.xml index 2450cc8..810e45f 100644 --- a/spec/data/swissindex_pharma.xml +++ b/spec/data/swissindex_pharma.xml @@ -1,82 +1,63 @@ - - - CREATION_DATETIME="2012-10-18T06:31:19.4687619+02:00" - xmlns="http://example.com/test"> - - 733905577161 - 5366964 - A - 2012-08-22T00:00:00 - FR - 1-DAY ACUVUE moist jour -2.00dpt BC 8.5 - 30 pce - - Johnson & Johnson Consumer (Health Care / OTC) - +
+ + NONPHARMA + 733905577161 + 5366964 + 1-DAY ACUVUE Moist Tag -2.00dpt BC 8.5 30 Stk + 1-DAY ACUVUE moist jour -2.00dpt BC 8.5 30 pce + Johnson & Johnson Consumer (Health Care / OTC) - + + PHARMA 7680536620137 1699947 - A - 1996-03-20T00:00:00 - DE - 3TC Filmtabl 150 mg - 60 Stk + 53662013 + 3TC Filmtabl 150 mg 60 Stk + 3TC cpr pell 150 mg 60 pce J05AF05 - - ViiV Healthcare GmbH - 7601001392175 - + ViiV Healthcare GmbH + 7601001392175 - + + PHARMA 7680620690084 5819012 - A - 2013-10-26T00:00:00 - DE - LEVETIRACETAM DESITIN Filmtabl 250 mg - 30 Stk + 62069008 + LEVETIRACETAM DESITIN Mini Filmtab 250 mg 30 Stk + LEVETIRACETAM DESITIN mini cpr pel 250 mg 30 pce N03AX14 - - Desitin Pharma GmbH - 7601001320451 - + Desitin Pharma GmbH + 7601001320451 - + + PHARMA 7680555580054 2465312 - A - 2002-01-16T00:00:00 - DE - ZYVOXID Filmtabl 600 mg - 10 Stk + 55558005 + ZYVOXID Filmtabl 600 mg 10 Stk + ZYVOXID cpr pell 600 mg 10 pce J01XX08 - - Pfizer AG - 7601001010604 - + Pfizer AG + 7601001010604 - - 7680316950157 - 598003 - A - 2012-04-13T00:00:00 - DE - SOFRADEX Gtt Auric - 8 ml - S02CA06 - - Sanofi-Aventis (Suisse) SA - 7601001002340 - + + PHARMA + 7680651540013 + 5950031 + 65154001 + LEVETIRACETAM DESITIN Filmtabl 250 mg 30 Stk + LEVETIRACETAM DESITIN cpr pell 250 mg 30 pce + N03AX14 + Desitin Pharma GmbH + 7601001320451 - + OK - 2 + 44929 - +
diff --git a/spec/downloader_spec.rb b/spec/downloader_spec.rb index 0d1f39d..e90406c 100644 --- a/spec/downloader_spec.rb +++ b/spec/downloader_spec.rb @@ -76,6 +76,7 @@ describe Oddb2xml::SwissIndexDownloader do end end end + context 'NonPharma with FR' do before(:each) do @downloader = Oddb2xml::SwissIndexDownloader.new({}, :nonpharma, 'FR') diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 69f9d62..633e6bf 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -87,30 +87,27 @@ module ServerMockHelper :headers => {'Content-Type' => 'application/zip; charset=utf-8'}, :body => stub_response) end - def setup_swiss_index_server_mock(types =['NonPharma', 'Pharma'], languages=['DE', 'FR']) + def setup_swiss_index_server_mock(types =['Pharma', 'NonPharma']) types.each do |type| - languages.each do |language| - # wsdl - stub_wsdl_url = "https://index.ws.e-mediat.net/Swissindex/#{type}/ws_#{type}_V101.asmx?WSDL" - first_file = File.join(Oddb2xml::SpecData, "wsdl_#{type.downcase}.xml") - stub_response_wsdl = File.read(File.join(Oddb2xml::SpecData, "wsdl_#{type.downcase}.xml")) - stub_request(:get, stub_wsdl_url). - with(:headers => { - 'Accept' => '*/*', - }). - to_return( - :status => 200, - :headers => {'Content-Type' => 'text/xml; charset=utf-8'}, - :body => stub_response_wsdl) - # soap (dummy) - stub_soap_url = 'https://example.com/test' - stub_file = File.join(Oddb2xml::SpecData, "swissindex_#{type}_#{language}.xml") - stub_response = File.read(stub_file) - stub_request(:post, "https://example.com/test"). - with(:body => "\n\n\n #{language}\n\n\n", - :headers => {'Accept'=>'*/*', 'Content-Type'=>'text/xml;charset=UTF-8', 'Soapaction'=>'"http://example.com/DownloadAll"', 'User-Agent'=>'Ruby'}). - to_return(:status => 200, :body => stub_response, :headers => {}) - end + stub_wsdl_url = "http://refdatabase.refdata.ch/Service/Article.asmx?WSDL" + stub_file = File.join(Oddb2xml::SpecData, "swissindex_#{type.downcase}.xml") + stub_response_wsdl = File.read(File.join(Oddb2xml::SpecData, "wsdl_refdata_service_article.xml")) + stub_request(:get, stub_wsdl_url). + with(:headers => { + 'Accept' => '*/*', + }). + to_return( + :status => 200, + :headers => {'Content-Type' => 'text/xml; charset=utf-8'}, + :body => stub_response_wsdl) + stub_response_wsdl = stub_response_wsdl.sub('NonPharma', 'Pharma') if type.eql?('Pharma') + stub_response = File.read(stub_file) + stub_request(:post, "http://refdatabase.refdata.ch/Service/Article.asmx"). + with(:body => "\n\n \n \n #{type}\n \n \n \n\n", + :headers => {'Accept'=>'*/*', 'Content-Length'=> type.eql?('Pharma') ? '429' : '432', 'Content-Type'=>'text/xml;charset=UTF-8', + 'Soapaction'=>"\"http://refdatabase.refdata.ch/Pharma/Download\"", 'User-Agent'=>'Ruby'}). + to_return(:status => 200, :body => stub_response, :headers => {}) + end end