oddb2xml 1.5.1 → 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,9 @@
1
+ === 1.5.2 / 12.06.2013
2
+
3
+ * Improve NINCD detection
4
+ - Update timeout handling
5
+ - Improve pharmacode detection
6
+
1
7
  === 1.5.1 / 10.06.2013
2
8
 
3
9
  * Update oddb2xml to handle pharmacode that is started with "0"
@@ -667,18 +667,7 @@ module Oddb2xml
667
667
  #xml.ARTLIM {
668
668
  # xml.LIMCD
669
669
  #}
670
- seq = @items[de_idx[:pharmacode]]
671
- nincd = if @lppvs[de_idx[:ean]] # LPPV
672
- 20
673
- elsif seq # BAG-XML (SL/LS)
674
- 10
675
- elsif (de_idx[:migel] or # MiGel (xls)
676
- de_idx[:_type] == :nonpharma) # MiGel (swissindex)
677
- 13
678
- else
679
- nil
680
- end
681
- if nincd
670
+ if nincd = detect_nincd(de_idx)
682
671
  xml.ARTINS {
683
672
  #xml.VDAT
684
673
  #xml.INCD
@@ -855,6 +844,26 @@ module Oddb2xml
855
844
  end
856
845
  _builder.to_xml
857
846
  end
847
+ def detect_nincd(de_idx)
848
+ if @lppvs[de_idx[:ean]] # LPPV
849
+ 20
850
+ elsif @items[de_idx[:pharmacode]] # BAG-XML (SL/LS)
851
+ 10
852
+ elsif (de_idx[:migel] or # MiGel (xls)
853
+ de_idx[:_type] == :nonpharma) # MiGel (swissindex)
854
+ 13
855
+ else
856
+ # fallback via EAN
857
+ bag_entry_via_ean = @items.values.select do |i|
858
+ i[:packages].values.select {|_pac| _pac[:ean] == de_idx[:ean] }.length != 0
859
+ end.length
860
+ if bag_entry_via_ean > 0
861
+ 10
862
+ else
863
+ nil
864
+ end
865
+ end
866
+ end
858
867
 
859
868
  ### --- see oddb2tdat
860
869
  DAT_LEN = {
@@ -14,7 +14,7 @@ module Oddb2xml
14
14
  response = nil # win
15
15
  io = File.open(file, option)
16
16
  return io.read
17
- rescue Timeout::Error
17
+ rescue Timeout::Error, Errno::ETIMEDOUT
18
18
  retrievable? ? retry : raise
19
19
  ensure
20
20
  io.close if io and !io.closed? # win
@@ -144,7 +144,7 @@ module Oddb2xml
144
144
  response = nil # win
145
145
  end
146
146
  return read_xml_form_zip(/^Preparation/iu, file)
147
- rescue Timeout::Error
147
+ rescue Timeout::Error, Errno::ETIMEDOUT
148
148
  retrievable? ? retry : raise
149
149
  ensure
150
150
  if File.exists?(file)
@@ -197,7 +197,7 @@ XML
197
197
  end
198
198
  rescue HTTPI::SSLError
199
199
  exit # catch me in Cli class
200
- rescue Timeout::Error
200
+ rescue Timeout::Error, Errno::ETIMEDOUT
201
201
  retrievable? ? retry : raise
202
202
  end
203
203
  end
@@ -231,7 +231,7 @@ XML
231
231
  end
232
232
  io = File.open(file, 'rb')
233
233
  return io.read
234
- rescue Timeout::Error
234
+ rescue Timeout::Error, Errno::ETIMEDOUT
235
235
  retrievable? ? retry : raise
236
236
  ensure
237
237
  io.close if io and !io.closed?
@@ -265,7 +265,7 @@ XML
265
265
  response = nil # win
266
266
  end
267
267
  return read_xml_form_zip(/^AipsDownload_/iu, file)
268
- rescue Timeout::Error
268
+ rescue Timeout::Error, Errno::ETIMEDOUT
269
269
  retrievable? ? retry : raise
270
270
  rescue NoMethodError
271
271
  # pass
@@ -24,6 +24,13 @@ module Oddb2xml
24
24
  def initialize(xml)
25
25
  @xml = xml
26
26
  end
27
+ def correct_code(pharmacode, length=7)
28
+ if pharmacode.length != length # restore zero at the beginnig
29
+ ("%0#{length}i" % pharmacode.to_i)
30
+ else
31
+ pharmacode
32
+ end
33
+ end
27
34
  end
28
35
  class BMUpdateExtractor < Extractor
29
36
  include TxtExtractorMethods
@@ -68,12 +75,13 @@ module Oddb2xml
68
75
  item[:packages] = {} # pharmacode => package
69
76
  seq.xpath('.//Pack').each do |pac|
70
77
  if phar = pac.attr('Pharmacode')
71
- phar = phar.to_s
78
+ phar = correct_code(phar.to_s, 7)
72
79
  # as common key with swissINDEX
73
80
  item[:pharmacodes] << phar
74
81
  # packages
75
82
  item[:packages][phar] = {
76
83
  :pharmacode => phar,
84
+ :ean => (ean = pac.at_xpath('.//GTIN')) ? ean.text : '',
77
85
  :swissmedic_category => (cat = pac.at_xpath('.//SwissmedicCategory')) ? cat.text : '',
78
86
  :swissmedic_number8 => (num = pac.at_xpath('.//SwissmedicNo8')) ? num.text.rjust(8, '0') : '',
79
87
  :narcosis_flag => (flg = pac.at_xpath('.//FlagNarcosis')) ? flg.text : '',
@@ -176,9 +184,7 @@ module Oddb2xml
176
184
  item[:company_ean] = (gln = comp.at_xpath('.//GLN')) ? gln.text : ''
177
185
  end
178
186
  unless item[:pharmacode].empty?
179
- if item[:pharmacode].length != 7 # restore zero at the beginnig
180
- item[:pharmacode] = ("%07i" % item[:pharmacode])
181
- end
187
+ item[:pharmacode] = correct_code(item[:pharmacode].to_s, 7)
182
188
  unless data[item[:pharmacode]] # pharmacode => GTINs
183
189
  data[item[:pharmacode]] = []
184
190
  end
@@ -286,7 +292,7 @@ module Oddb2xml
286
292
  data = {}
287
293
  @sheet.each_with_index do |row, i|
288
294
  next if i.zero?
289
- phar = row[1].to_s
295
+ phar = correct_code(row[1].to_s.gsub(/[^0-9]/, ''), 7)
290
296
  data[phar] = {
291
297
  :ean => row[0].to_i.to_s,
292
298
  :pharmacode => phar,
@@ -1,3 +1,3 @@
1
1
  module Oddb2xml
2
- VERSION = "1.5.1"
2
+ VERSION = "1.5.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oddb2xml
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.5.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-10 00:00:00.000000000 Z
12
+ date: 2013-06-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rubyzip