oddb2xml 1.2.6 → 1.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,22 @@
1
+ === 1.2.9 / 01.02.2013
2
+
3
+ * Remove ARTLIM and LIMCD
4
+ * Update to use swissINDEX if duplicated nonpharma
5
+ * Merge branch 'master' of ywesee.github.com:zdavatz/oddb2xml
6
+ * Improve Cli#run crearly
7
+
8
+ === 1.2.8 / 01.02.2013
9
+
10
+ * Update SMCAT to use Packungen.xls
11
+ * Merge branch 'master' of ywesee.github.com:zdavatz/oddb2xml
12
+ * Add additional Non-Pharma products
13
+
14
+ === 1.2.7 / 31.01.2013
15
+
16
+ * Update to use lppv for article.xml and oddb.dat
17
+ * Update to use pharmacode if SwissmedicNo5 == '0'
18
+ * Update to include limitations in It-Codes
19
+
1
20
  === 1.2.6 / 30.01.2013
2
21
 
3
22
  * Update to exclude 14-EAN for oddb_with_migel.dat
@@ -19,12 +19,17 @@ spec/cli_spec.rb
19
19
  spec/compressor_spec.rb
20
20
  spec/data/XMLPublications.zip
21
21
  spec/data/epha_interactions.csv
22
+ spec/data/oddb2xml_files_bm_update.txt
23
+ spec/data/oddb2xml_files_lppv.txt
22
24
  spec/data/oddb_article.xml
23
25
  spec/data/oddb_fi.xml
24
26
  spec/data/oddb_fi_product.xml
25
27
  spec/data/oddb_limitation.xml
26
28
  spec/data/oddb_product.xml
27
29
  spec/data/oddb_substance.xml
30
+ spec/data/oddb2xml_files_nonpharma.xls
31
+ spec/data/oddb2xml_files_lppv.txt
32
+ spec/data/oddb2xml_files_bm_update.txt
28
33
  spec/data/swissindex.xml
29
34
  spec/data/swissindex_nonpharma.xml
30
35
  spec/data/swissindex_pharma.xml
@@ -38,7 +43,6 @@ spec/data/swissmedic_orphans.xls
38
43
  spec/data/wsdl.xml
39
44
  spec/data/wsdl_nonpharma.xml
40
45
  spec/data/wsdl_pharma.xml
41
- spec/data/ywesee_bm_update.txt
42
46
  spec/downloader_spec.rb
43
47
  spec/extractor_spec.rb
44
48
  spec/spec_helper.rb
data/README.md CHANGED
@@ -42,18 +42,21 @@ see `--help`.
42
42
 
43
43
  ```
44
44
  $ oddb2xml --help
45
- oddb2xml ver.1.2.2
45
+ oddb2xml ver.1.2.7
46
46
  Usage:
47
47
  oddb2xml [option]
48
48
  -a T, --append=T Additional target. T, only 'nonpharma' is available.
49
49
  -c F, --compress=F Compress format F. {tar.gz|zip}
50
- -f dat, create dat files according to IGM-11 standard.
51
- -h, --help Show this help message.
52
- -o fi, create fi xml files.
53
- -t S, --tag-suffix=S XML tag suffix S. Default is none. [A-z0-9_]
50
+ -f F, --format=F File format F, default is xml. {xml|dat}
51
+ If F is given, -o option is ignored.
52
+ -o O, --optional=O Optional output. O, only 'fi' is available.
53
+ -i I, --include=I Include target option for 'dat' format. only 'ean14' is available.
54
+ 'xml' format includes always ean14 records.
55
+ -t S, --tag-suffix=S XML tag suffix S. Default is none. [A-z0-9]
54
56
  If S is given, it is also used as prefix of filename.
55
- ```
57
+ -h, --help Show this help message.
56
58
 
59
+ ```
57
60
 
58
61
  ## Option examples
59
62
 
@@ -81,6 +84,9 @@ If you need the XSD files, generate them yourself using the javabeans tool:
81
84
 
82
85
  this will generate you a valid XSD file that can be used to validate against the XML file.
83
86
 
87
+ i.e.:
88
+ * /home/zeno/.software/xmlbeans-2.6.0/bin/inst2xsd oddb_article.xml -outPrefix oddb_article
89
+
84
90
  ## XML files
85
91
 
86
92
  xml files generated are:
@@ -17,18 +17,19 @@ end
17
17
 
18
18
  module Oddb2xml
19
19
  class Builder
20
- attr_accessor :subject, :index, :items, :flags,
21
- :actions,
22
- :orphans, :fridges,
23
- :infos, :packs, :ean14,
24
- :tag_suffix
20
+ attr_accessor :subject, :index, :items, :flags, :lppvs,
21
+ :actions, :migel, :orphans, :fridges,
22
+ :infos, :packs,
23
+ :ean14, :tag_suffix
25
24
  def initialize
26
25
  @subject = nil
27
26
  @index = {}
28
27
  @items = {}
29
28
  @flags = {}
29
+ @lppvs = {}
30
30
  @infos = {}
31
31
  @packs = {}
32
+ @migel = {}
32
33
  @actions = []
33
34
  @orphans = []
34
35
  @fridges = []
@@ -59,14 +60,39 @@ module Oddb2xml
59
60
  @articles = [] # base is 'DE'
60
61
  @index['DE'].each_pair do |pharmacode, index|
61
62
  object = {
62
- :de => index,
63
- :fr => @index['FR'][pharmacode],
63
+ :de => index,
64
+ :fr => @index['FR'][pharmacode],
64
65
  }
66
+ if migel = @migel[pharmacode]
67
+ # delete duplicates
68
+ @migel[pharmacode] = nil
69
+ end
65
70
  if seq = @items[pharmacode]
66
71
  object[:seq] = seq
67
72
  end
68
73
  @articles << object
69
74
  end
75
+ # add
76
+ @migel.values.compact.each do |migel|
77
+ next if migel[:pharmacode].empty?
78
+ object = {}
79
+ %w[de fr].each do |lang|
80
+ pac = {
81
+ :ean => migel[:ean],
82
+ :pharmacode => migel[:pharmacode],
83
+ :status => 'I',
84
+ :stat_date => '',
85
+ :lang => lang.capitalize,
86
+ :desc => migel["desc_#{lang}".intern],
87
+ :atc_code => '',
88
+ :additional_desc => migel[:additional_desc],
89
+ :company_ean => migel[:company_ean],
90
+ :company_name => migel[:company_name],
91
+ }
92
+ object[lang.intern] = pac
93
+ end
94
+ @articles << object
95
+ end
70
96
  end
71
97
  end
72
98
  def prepare_substances
@@ -179,11 +205,11 @@ module Oddb2xml
179
205
  ) {
180
206
  @limitations.each do |lim|
181
207
  xml.LIM('DT' => '') {
182
- xml.LIMCD lim[:key] # swissmedic_number8 or swissmedic_number5
208
+ xml.LIMCD lim[:key] # swissmedic_number8, swissmedic_number5 or pharmacode
183
209
  xml.IT lim[:it]
184
210
  xml.LIMTYP lim[:type]
185
211
  xml.LIMVAL lim[:value]
186
- xml.LIMNAMEBAG lim[:code] # LIMCD
212
+ xml.LIMNAMEBAG lim[:code] # original LIMCD
187
213
  xml.LIMNIV lim[:niv]
188
214
  xml.DSCRD lim[:desc_de]
189
215
  xml.DSCRF lim[:desc_fr]
@@ -455,6 +481,11 @@ module Oddb2xml
455
481
  if obj[:seq]
456
482
  bg_pac = obj[:seq][:packages][de_pac[:pharmacode]]
457
483
  end
484
+ if de_pac[:ean].length == 13
485
+ num = de_pac[:ean][4,8].intern # :swissmedic_number5
486
+ elsif bg_pac
487
+ num = bg_pac[:swissmedic_number8].intern
488
+ end
458
489
  xml.ART('DT' => '') {
459
490
  xml.PHAR de_pac[:pharmacode] unless de_pac[:pharmacode].empty?
460
491
  #xml.GRPCD
@@ -463,8 +494,12 @@ module Oddb2xml
463
494
  if obj[:seq]
464
495
  xml.PRDNO obj[:seq][:product_key] unless obj[:seq][:product_key].empty?
465
496
  end
466
- if bg_pac
497
+ if bg_pac # bag xml
467
498
  xml.SMCAT bg_pac[:swissmedic_category] unless bg_pac[:swissmedic_category].empty?
499
+ elsif @packs[num] and @packs[num][:swissmedic_category] # Packungen.xls
500
+ xml.SMCAT @packs[num][:swissmedic_category]
501
+ end
502
+ if bg_pac
468
503
  xml.SMNO bg_pac[:swissmedic_number8] unless bg_pac[:swissmedic_number8].empty?
469
504
  end
470
505
  #xml.HOSPCD
@@ -578,18 +613,16 @@ module Oddb2xml
578
613
  #xml.LINENO
579
614
  #xml.CDVAL
580
615
  #}
581
- if bg_pac
582
- bg_pac[:limitations].each do |lim|
583
- xml.ARTLIM {
584
- xml.LIMCD lim[:code] unless lim[:code].empty?
585
- }
586
- end
587
- end
588
- #xml.ARTINS {
589
- #xml.VDAT
590
- #xml.INCD
591
- #xml.NINCD
616
+ #xml.ARTLIM {
617
+ # xml.LIMCD
592
618
  #}
619
+ if @lppvs[de_pac[:ean]]
620
+ xml.ARTINS {
621
+ #xml.VDAT
622
+ #xml.INCD
623
+ xml.NINCD 20
624
+ }
625
+ end
593
626
  }
594
627
  end
595
628
  xml.RESULT {
@@ -763,7 +796,13 @@ module Oddb2xml
763
796
  ).to_s[0, DAT_LEN[:ABEZ]].gsub(/"/, '')
764
797
  row << "%#{DAT_LEN[:PRMO]}s" % (pac ? format_price(pac[:prices][:exf_price][:price].to_s) : ('0' * DAT_LEN[:PRMO]))
765
798
  row << "%#{DAT_LEN[:PRPU]}s" % (pac ? format_price(pac[:prices][:pub_price][:price].to_s) : ('0' * DAT_LEN[:PRPU]))
766
- row << "%#{DAT_LEN[:CKZL]}s" % (pac ? '1' : '3') # sl_entry or not
799
+ row << "%#{DAT_LEN[:CKZL]}s" % if (@lppvs[de_pac[:ean]])
800
+ '2'
801
+ elsif pac # sl_entry
802
+ '1'
803
+ else
804
+ '3'
805
+ end
767
806
  row << "%#{DAT_LEN[:CLAG]}s" % if ((num && num.to_s =~ /(\d{5})(\d{3})/) and
768
807
  @fridges.include?($1.to_s))
769
808
  '1'
@@ -17,94 +17,40 @@ module Oddb2xml
17
17
  @mutex = Mutex.new
18
18
  @items = {} # Items from Preparations.xml in BAG
19
19
  @index = {} # Base index from swissINDEX
20
- @flags = {} # narcotics flag from ywesee
20
+ @flags = {} # narcotics flag files repo
21
+ @lppvs = {} # lppv.txt from files repo
21
22
  @infos = {} # [option] FI from SwissmedicInfo
22
23
  @packs = {} # [option] Packungen from Swissmedic for dat
24
+ @migel = {} # [addition] additional Non Pharma products from files repo
23
25
  @actions = [] # [addition] interactions from epha
24
26
  @orphans = [] # [addition] Orphaned drugs from Swissmedic xls
25
27
  @fridges = [] # [addition] ReFridge drugs from Swissmedic xls
26
28
  LANGUAGES.each do |lang|
27
29
  @index[lang] = {}
28
30
  end
31
+ @_message = false
29
32
  end
30
33
  def run
31
34
  threads = []
32
- # swissmedic-info
33
35
  if @options[:format] != :dat
34
36
  if @options[:fi]
35
- threads << Thread.new do
36
- downloader = SwissmedicInfoDownloader.new
37
- xml = downloader.download
38
- @mutex.synchronize do
39
- hsh = SwissmedicInfoExtractor.new(xml).to_hash
40
- @infos = hsh
41
- end
42
- end
43
- end
44
- # swissmedic - orphan, fridge
45
- [:orphans, :fridges].each do |type|
46
- threads << Thread.new do
47
- downloader = SwissmedicDownloader.new(type)
48
- bin = downloader.download
49
- self.instance_variable_set("@#{type.to_s}", SwissmedicExtractor.new(bin, type).to_arry)
50
- end
51
- end
52
- # epha
53
- threads << Thread.new do
54
- downloader = EphaDownloader.new
55
- str = downloader.download
56
- @mutex.synchronize do
57
- @actions = EphaExtractor.new(str).to_arry
58
- end
59
- end
60
- else # dat
61
- # swissmedic - package
62
- threads << Thread.new do
63
- downloader = SwissmedicDownloader.new(:packages)
64
- bin = downloader.download
65
- @mutex.synchronize do
66
- @packs = SwissmedicExtractor.new(bin, :packages).to_hash
67
- end
37
+ threads << download(:fachinfo) # swissmedic-info
68
38
  end
69
- end
70
- # ywesee
71
- threads << Thread.new do
72
- downloader = YweseeBMDownloader.new
73
- str = downloader.download
74
- @mutex.synchronize do
75
- @flags = YweseeBMExtractor.new(str).to_hash
39
+ [:orphan, :fridge].each do |type|
40
+ threads << download(type) # swissmedic
76
41
  end
42
+ threads << download(:interaction) # epha
77
43
  end
78
- # bag
79
- threads << Thread.new do
80
- downloader = BagXmlDownloader.new(@options)
81
- xml = downloader.download
82
- @mutex.synchronize do
83
- hsh = BagXmlExtractor.new(xml).to_hash
84
- @items = hsh
85
- end
44
+ if @options[:nonpharma]
45
+ threads << download(:migel) # oddb2xml_files
86
46
  end
87
- @_message = false
47
+ threads << download(:package) # swissmedic
48
+ threads << download(:bm_update) # oddb2xml_files
49
+ threads << download(:lppv) # oddb2xml_files
50
+ threads << download(:bag) # bag.e-mediat
88
51
  LANGUAGES.each do |lang|
89
- # swissindex
90
52
  types.each do |type|
91
- threads << Thread.new do
92
- downloader = SwissIndexDownloader.new(@options, type, lang)
93
- begin
94
- xml = downloader.download
95
- rescue SystemExit
96
- @mutex.synchronize do
97
- unless @_message # hook only one exit
98
- @_message = true
99
- exit
100
- end
101
- end
102
- end
103
- @mutex.synchronize do
104
- hsh = SwissIndexExtractor.new(xml, type).to_hash
105
- @index[lang][type] = hsh
106
- end
107
- end
53
+ threads << download(:index, type, lang) # swissindex
108
54
  end
109
55
  end
110
56
  begin
@@ -141,15 +87,16 @@ module Oddb2xml
141
87
  builder.subject = sbj
142
88
  end
143
89
  # common sources
144
- builder.items = @items
145
- builder.flags = @flags
146
- # additions
147
- %w[actions orphans fridges].each do |addition|
148
- builder.send("#{addition}=".intern, self.instance_variable_get("@#{addition}"))
149
- end
150
- # optionals
90
+ builder.items = @items
91
+ builder.flags = @flags
92
+ builder.lppvs = @lppvs
93
+ # optional sources
151
94
  builder.infos = @infos
152
95
  builder.packs = @packs
96
+ # additional sources
97
+ %w[actions orphans fridges migel].each do |addition|
98
+ builder.send("#{addition}=".intern, self.instance_variable_get("@#{addition}"))
99
+ end
153
100
  builder.tag_suffix = @options[:tag_suffix]
154
101
  end
155
102
  output = ''
@@ -182,6 +129,93 @@ module Oddb2xml
182
129
  raise Interrupt
183
130
  end
184
131
  end
132
+ def download(what, type=nil, lang=nil)
133
+ case what
134
+ when :fachinfo
135
+ Thread.new do
136
+ downloader = SwissmedicInfoDownloader.new
137
+ xml = downloader.download
138
+ @mutex.synchronize do
139
+ hsh = SwissmedicInfoExtractor.new(xml).to_hash
140
+ @infos = hsh
141
+ end
142
+ end
143
+ when :orphan, :fridge
144
+ type = (what.to_s + "s").intern
145
+ Thread.new do
146
+ downloader = SwissmedicDownloader.new(type)
147
+ bin = downloader.download
148
+ self.instance_variable_set("@#{type.to_s}", SwissmedicExtractor.new(bin, type).to_arry)
149
+ end
150
+ when :interaction
151
+ Thread.new do
152
+ downloader = EphaDownloader.new
153
+ str = downloader.download
154
+ @mutex.synchronize do
155
+ @actions = EphaExtractor.new(str).to_arry
156
+ end
157
+ end
158
+ when :migel
159
+ Thread.new do
160
+ downloader = MigelDownloader.new
161
+ bin = downloader.download
162
+ @mutex.synchronize do
163
+ @migel = MigelExtractor.new(bin).to_hash
164
+ end
165
+ end
166
+ when :package
167
+ Thread.new do
168
+ downloader = SwissmedicDownloader.new(:packages)
169
+ bin = downloader.download
170
+ @mutex.synchronize do
171
+ @packs = SwissmedicExtractor.new(bin, :packages).to_hash
172
+ end
173
+ end
174
+ when :bm_update
175
+ Thread.new do
176
+ downloader = BMUpdateDownloader.new
177
+ str = downloader.download
178
+ @mutex.synchronize do
179
+ @flags = BMUpdateExtractor.new(str).to_hash
180
+ end
181
+ end
182
+ when :lppv
183
+ Thread.new do
184
+ downloader = LppvDownloader.new
185
+ str = downloader.download
186
+ @mutex.synchronize do
187
+ @lppvs = LppvExtractor.new(str).to_hash
188
+ end
189
+ end
190
+ when :bag
191
+ Thread.new do
192
+ downloader = BagXmlDownloader.new(@options)
193
+ xml = downloader.download
194
+ @mutex.synchronize do
195
+ hsh = BagXmlExtractor.new(xml).to_hash
196
+ @items = hsh
197
+ end
198
+ end
199
+ when :index
200
+ Thread.new do
201
+ downloader = SwissIndexDownloader.new(@options, type, lang)
202
+ begin
203
+ xml = downloader.download
204
+ rescue SystemExit
205
+ @mutex.synchronize do
206
+ unless @_message # hook only one exit
207
+ @_message = true
208
+ exit
209
+ end
210
+ end
211
+ end
212
+ @mutex.synchronize do
213
+ hsh = SwissIndexExtractor.new(xml, type).to_hash
214
+ @index[lang][type] = hsh
215
+ end
216
+ end
217
+ end
218
+ end
185
219
  def compress
186
220
  compressor = Compressor.new(prefix, @options)
187
221
  files.values.each do |file|
@@ -42,7 +42,7 @@ module Oddb2xml
42
42
  xml << bytes
43
43
  bytes = nil
44
44
  end
45
- io.close
45
+ io.close if io.respond_to?(:close)
46
46
  end
47
47
  end
48
48
  end
@@ -162,7 +162,30 @@ XML
162
162
  rescue Timeout::Error
163
163
  retrievable? ? retry : raise
164
164
  ensure
165
- io.close unless io.closed?
165
+ io.close if io and !io.closed?
166
+ if File.exists?(file)
167
+ File.unlink(file)
168
+ end
169
+ end
170
+ end
171
+ end
172
+ class MigelDownloader < Downloader
173
+ def init
174
+ super
175
+ @url ||= 'https://github.com/zdavatz/oddb2xml_files/raw/master/NON-Pharma.xls'
176
+ end
177
+ def download
178
+ file = "oddb2xml_files_nonpharma.xls"
179
+ begin
180
+ response = @agent.get(@url)
181
+ response.save_as(file)
182
+ response = nil # win
183
+ io = File.open(file, 'rb')
184
+ return io.read
185
+ rescue Timeout::Error
186
+ retrievable? ? retry : raise
187
+ ensure
188
+ io.close if io and !io.closed? # win
166
189
  if File.exists?(file)
167
190
  File.unlink(file)
168
191
  end
@@ -228,20 +251,16 @@ XML
228
251
  rescue Timeout::Error
229
252
  retrievable? ? retry : raise
230
253
  ensure
231
- io.close unless io.closed? # win
254
+ io.close if io and !io.closed? # win
232
255
  if File.exists?(file)
233
256
  File.unlink(file)
234
257
  end
235
258
  end
236
259
  end
237
260
  end
238
- class YweseeBMDownloader < Downloader
239
- def init
240
- super
241
- @url ||= 'http://www.ywesee.com/uploads/Main/BM_Update.txt'
242
- end
243
- def download
244
- file = 'ywesee_bm_update.txt'
261
+ # txt filse
262
+ module TxtDownloadMethods
263
+ def download_as(file)
245
264
  begin
246
265
  response = @agent.get(@url)
247
266
  response.save_as(file)
@@ -251,11 +270,33 @@ XML
251
270
  rescue Timeout::Error
252
271
  retrievable? ? retry : raise
253
272
  ensure
254
- io.close unless io.closed? # win
273
+ io.close if io and !io.closed? # win
255
274
  if File.exists?(file)
256
275
  File.unlink(file)
257
276
  end
258
277
  end
259
278
  end
260
279
  end
280
+ class BMUpdateDownloader < Downloader
281
+ include TxtDownloadMethods
282
+ def init
283
+ super
284
+ @url ||= 'https://raw.github.com/zdavatz/oddb2xml_files/master/BM_Update.txt'
285
+ end
286
+ def download
287
+ file = 'oddb2xml_files_bm_update.txt'
288
+ download_as(file)
289
+ end
290
+ end
291
+ class LppvDownloader < Downloader
292
+ include TxtDownloadMethods
293
+ def init
294
+ super
295
+ @url ||= 'https://raw.github.com/zdavatz/oddb2xml_files/master/LPPV.txt'
296
+ end
297
+ def download
298
+ file = 'oddb2xml_files_lppv.txt'
299
+ download_as(file)
300
+ end
301
+ end
261
302
  end
@@ -70,15 +70,25 @@ module Oddb2xml
70
70
  }
71
71
  }
72
72
  }
73
- # limitations
73
+ # related all limitations
74
74
  item[:packages][phar][:limitations] = []
75
75
  limitations = Hash.new{|h,k| h[k] = [] }
76
- # seq - level
76
+ # in seq
77
77
  limitations[:seq] = (lims = seq.xpath('.//Limitations/Limitation')) ? lims.to_a : nil
78
- # pac - level
78
+ # in it-codes
79
+ limitations[:itc] = (lims = seq.xpath('.//ItCodes/ItCode/Limitations/Limitation')) ? lims.to_a : nil
80
+ # in pac
79
81
  limitations[:pac] = (lims = pac.xpath('.//Limitations/Limitation')) ? lims.to_a : nil
80
82
  limitations.each_pair do |key, lims|
81
- key = (key == :pac ? item[:packages][phar][:swissmedic_number8] : item[:swissmedic_number5])
83
+ key = case key
84
+ when :pac
85
+ item[:packages][phar][:swissmedic_number8]
86
+ when :seq
87
+ item[:swissmedic_number5]
88
+ when :itc
89
+ phar
90
+ end
91
+ key = phar if (key.empty? or key == '0')
82
92
  lims.each do |lim|
83
93
  limitation = {
84
94
  :it => item[:it_code],
@@ -204,6 +214,30 @@ module Oddb2xml
204
214
  end
205
215
  end
206
216
  end
217
+ class MigelExtractor < Extractor
218
+ def initialize(bin)
219
+ io = StringIO.new(bin)
220
+ book = Spreadsheet.open(io)
221
+ @sheet = book.worksheet(0)
222
+ end
223
+ def to_hash
224
+ data = {}
225
+ @sheet.each_with_index do |row, i|
226
+ next if i == 0
227
+ phar = row[1].to_s
228
+ data[phar] = {
229
+ :ean => row[0].to_i.to_s,
230
+ :pharmacode => phar,
231
+ :desc_de => row[3],
232
+ :desc_fr => row[4],
233
+ :additional_desc => row[5], # quantity
234
+ :company_name => row[6],
235
+ :company_ean => row[7].to_i.to_s,
236
+ }
237
+ end
238
+ data
239
+ end
240
+ end
207
241
  class SwissmedicInfoExtractor < Extractor
208
242
  def to_hash
209
243
  data = Hash.new{|h,k| h[k] = [] }
@@ -257,18 +291,25 @@ module Oddb2xml
257
291
  data
258
292
  end
259
293
  end
260
- class YweseeBMExtractor < Extractor
294
+ # txt files
295
+ module TxtMethods
261
296
  def initialize(str)
262
297
  @io = StringIO.new(str)
263
298
  end
264
299
  def to_hash
265
300
  data = {}
266
301
  while line = @io.gets
267
- next if line =~ /\d{13}/
302
+ next unless line =~ /\d{13}/
268
303
  ean = line.chomp.gsub("\"", '')
269
304
  data[ean] = true
270
305
  end
271
306
  data
272
307
  end
273
308
  end
309
+ class BMUpdateExtractor < Extractor
310
+ include TxtMethods
311
+ end
312
+ class LppvExtractor < Extractor
313
+ include TxtMethods
314
+ end
274
315
  end
@@ -1,3 +1,3 @@
1
1
  module Oddb2xml
2
- VERSION = "1.2.6"
2
+ VERSION = "1.2.9"
3
3
  end
@@ -35,7 +35,7 @@ describe Oddb2xml::Compressor do
35
35
  end
36
36
  context "when swiss prefix is given" do
37
37
  before(:each) do
38
- @compressor = Oddb2xml::Compressor.new('swiss', 'tar.gz')
38
+ @compressor = Oddb2xml::Compressor.new('swiss', {:compress_ext => 'tar.gz'})
39
39
  end
40
40
  it 'should have formated filename with datetime' do
41
41
  @compressor.instance_variable_get(:@compress_file).
@@ -44,7 +44,7 @@ describe Oddb2xml::Compressor do
44
44
  end
45
45
  context "when tar.gz ext is given" do
46
46
  before(:each) do
47
- @compressor = Oddb2xml::Compressor.new('oddb', 'tar.gz')
47
+ @compressor = Oddb2xml::Compressor.new('oddb', {:compress_ext => 'tar.gz'})
48
48
  end
49
49
  it 'should have formated filename with datetime' do
50
50
  @compressor.instance_variable_get(:@compress_file).
@@ -53,7 +53,7 @@ describe Oddb2xml::Compressor do
53
53
  end
54
54
  context "when zip ext is given" do
55
55
  before(:each) do
56
- @compressor = Oddb2xml::Compressor.new('oddb', 'zip')
56
+ @compressor = Oddb2xml::Compressor.new('oddb', {:compress_ext => 'zip'})
57
57
  end
58
58
  it 'should have formated filename with datetime' do
59
59
  @compressor.instance_variable_get(:@compress_file).
@@ -83,7 +83,7 @@ describe Oddb2xml::Compressor do
83
83
  end
84
84
  context 'with zip' do
85
85
  before(:each) do
86
- @compressor = Oddb2xml::Compressor.new('oddb', 'zip')
86
+ @compressor = Oddb2xml::Compressor.new('oddb', {:compress_ext => 'zip'})
87
87
  end
88
88
  it_behaves_like 'any compressor'
89
89
  end
@@ -0,0 +1,4 @@
1
+ 7680581420034
2
+ 7680581420140
3
+ 7680581420157
4
+ 7680581420058
@@ -49,7 +49,7 @@ describe Oddb2xml::SwissIndexDownloader do
49
49
  end
50
50
  context 'Pharma with DE' do
51
51
  before(:each) do
52
- @downloader = Oddb2xml::SwissIndexDownloader.new(:pharma, 'DE')
52
+ @downloader = Oddb2xml::SwissIndexDownloader.new({}, :pharma, 'DE')
53
53
  end
54
54
  it_behaves_like 'any downloader'
55
55
  context 'when download_by is called with DE' do
@@ -67,7 +67,7 @@ describe Oddb2xml::SwissIndexDownloader do
67
67
  end
68
68
  context 'NonPharma with FR' do
69
69
  before(:each) do
70
- @downloader = Oddb2xml::SwissIndexDownloader.new(:nonpharma, 'FR')
70
+ @downloader = Oddb2xml::SwissIndexDownloader.new({}, :nonpharma, 'FR')
71
71
  end
72
72
  it_behaves_like 'any downloader'
73
73
  context 'when download_by is called with FR' do
@@ -94,13 +94,13 @@ describe Oddb2xml::SwissmedicDownloader do
94
94
  end
95
95
  it_behaves_like 'any downloader'
96
96
  context 'download_by for orphans xls' do
97
- let(:io) { @downloader.download }
98
- it 'should return valid IO' do
99
- io.should be_a IO
100
- io.bytes.should_not nil
97
+ let(:bin) { @downloader.download }
98
+ it 'should return valid Binary-String' do
99
+ bin.should be_a String
100
+ bin.bytes.should_not nil
101
101
  end
102
102
  it 'should clean up current directory' do
103
- io.should_not raise_error(Timeout::Error)
103
+ bin.should_not raise_error(Timeout::Error)
104
104
  File.exist?('oddb_orphans.xls').should be(false)
105
105
  end
106
106
  end
@@ -111,13 +111,13 @@ describe Oddb2xml::SwissmedicDownloader do
111
111
  @downloader = Oddb2xml::SwissmedicDownloader.new(:fridges)
112
112
  end
113
113
  context 'download_by for fridges xls' do
114
- let(:io) { @downloader.download }
115
- it 'should return valid IO' do
116
- io.should be_a IO
117
- io.bytes.should_not nil
114
+ let(:bin) { @downloader.download }
115
+ it 'should return valid Binary-String' do
116
+ bin.should be_a String
117
+ bin.bytes.should_not nil
118
118
  end
119
119
  it 'should clean up current directory' do
120
- io.should_not raise_error(Timeout::Error)
120
+ bin.should_not raise_error(Timeout::Error)
121
121
  File.exist?('oddb_fridges.xls').should be(false)
122
122
  end
123
123
  end
@@ -133,7 +133,7 @@ describe Oddb2xml::SwissmedicInfoDownloader do
133
133
  it_behaves_like 'any downloader'
134
134
  context 'when download is called' do
135
135
  let(:xml) { @downloader.download }
136
- it 'should parse zip to string' do
136
+ it 'should parse zip to String' do
137
137
  xml.should be_a String
138
138
  xml.length.should_not == 0
139
139
  end
@@ -157,34 +157,74 @@ describe Oddb2xml::EphaDownloader do
157
157
  end
158
158
  it_behaves_like 'any downloader'
159
159
  context 'when download is called' do
160
- let(:io) { @downloader.download }
161
- it 'should read csv to IO Object' do
162
- io.should be_a IO
163
- io.bytes.should_not nil
160
+ let(:csv) { @downloader.download }
161
+ it 'should read csv as String' do
162
+ csv.should be_a String
163
+ csv.bytes.should_not nil
164
164
  end
165
165
  it 'should clean up current directory' do
166
- io.should_not raise_error(Timeout::Error)
166
+ csv.should_not raise_error(Timeout::Error)
167
167
  File.exist?('epha_interactions.csv').should be(false)
168
168
  end
169
169
  end
170
170
  end
171
171
 
172
- describe Oddb2xml::YweseeBMDownloader do
172
+ describe Oddb2xml::BMUpdateDownloader do
173
+ include ServerMockHelper
174
+ before(:each) do
175
+ setup_bm_update_server_mock
176
+ @downloader = Oddb2xml::BMUpdateDownloader.new
177
+ end
178
+ it_behaves_like 'any downloader'
179
+ context 'when download is called' do
180
+ let(:txt) { @downloader.download }
181
+ it 'should read txt as String' do
182
+ txt.should be_a String
183
+ txt.bytes.should_not nil
184
+ end
185
+ it 'should clean up current directory' do
186
+ txt.should_not raise_error(Timeout::Error)
187
+ File.exist?('oddb2xml_files_bm_update.txt').should be(false)
188
+ end
189
+ end
190
+ end
191
+
192
+ describe Oddb2xml::LppvDownloader do
193
+ include ServerMockHelper
194
+ before(:each) do
195
+ setup_lppv_server_mock
196
+ @downloader = Oddb2xml::LppvDownloader.new
197
+ end
198
+ it_behaves_like 'any downloader'
199
+ context 'when download is called' do
200
+ let(:txt) { @downloader.download }
201
+ it 'should read txt as String' do
202
+ txt.should be_a String
203
+ txt.bytes.should_not nil
204
+ end
205
+ it 'should clean up current directory' do
206
+ txt.should_not raise_error(Timeout::Error)
207
+ File.exist?('oddb2xml_files_lppv.txt').should be(false)
208
+ end
209
+ end
210
+ end
211
+
212
+ describe Oddb2xml::MigelDownloader do
173
213
  include ServerMockHelper
174
214
  before(:each) do
175
- setup_ywesee_server_mock
176
- @downloader = Oddb2xml::YweseeBMDownloader.new
215
+ setup_migel_server_mock
216
+ @downloader = Oddb2xml::MigelDownloader.new
177
217
  end
178
218
  it_behaves_like 'any downloader'
179
219
  context 'when download is called' do
180
- let(:io) { @downloader.download }
181
- it 'should read txt to IO Object' do
182
- io.should be_a IO
183
- io.bytes.should_not nil
220
+ let(:bin) { @downloader.download }
221
+ it 'should read xls as Binary-String' do
222
+ bin.should be_a String
223
+ bin.bytes.should_not nil
184
224
  end
185
225
  it 'should clean up current directory' do
186
- io.should_not raise_error(Timeout::Error)
187
- File.exist?('ywesee_bm_update.txt').should be(false)
226
+ bin.should_not raise_error(Timeout::Error)
227
+ File.exist?('oddb2xml_files_nonpharma.txt').should be(false)
188
228
  end
189
229
  end
190
230
  end
@@ -22,7 +22,9 @@ module ServerMockHelper
22
22
  setup_swissmedic_server_mock
23
23
  setup_swissmedic_info_server_mock
24
24
  setup_epha_server_mock
25
- setup_ywesee_server_mock
25
+ setup_bm_update_server_mock
26
+ setup_lppv_server_mock
27
+ setup_migel_server_mock
26
28
  end
27
29
  def setup_bag_xml_server_mock
28
30
  # zip
@@ -154,20 +156,48 @@ module ServerMockHelper
154
156
  :headers => {'Content-Type' => 'text/csv; charset=utf-8'},
155
157
  :body => stub_response)
156
158
  end
157
- def setup_ywesee_server_mock
159
+ def setup_bm_update_server_mock
158
160
  # txt
159
- stub_txt_url = 'http://www.ywesee.com/uploads/Main/BM_Update.txt'
160
- stub_response = File.read(File.expand_path('../data/ywesee_bm_update.txt', __FILE__))
161
+ stub_txt_url = 'https://raw.github.com/zdavatz/oddb2xml_files/master/BM_Update.txt'
162
+ stub_response = File.read(File.expand_path('../data/oddb2xml_files_bm_update.txt', __FILE__))
161
163
  stub_request(:get, stub_txt_url).
162
164
  with(:headers => {
163
165
  'Accept' => '*/*',
164
- 'Host' => 'www.ywesee.com',
166
+ 'Host' => 'raw.github.com',
165
167
  }).
166
168
  to_return(
167
169
  :status => 200,
168
170
  :headers => {'Content-Type' => 'text/plain; charset=utf-8'},
169
171
  :body => stub_response)
170
172
  end
173
+ def setup_lppv_server_mock
174
+ # txt
175
+ stub_txt_url = 'https://raw.github.com/zdavatz/oddb2xml_files/master/LPPV.txt'
176
+ stub_response = File.read(File.expand_path('../data/oddb2xml_files_lppv.txt', __FILE__))
177
+ stub_request(:get, stub_txt_url).
178
+ with(:headers => {
179
+ 'Accept' => '*/*',
180
+ 'Host' => 'raw.github.com',
181
+ }).
182
+ to_return(
183
+ :status => 200,
184
+ :headers => {'Content-Type' => 'text/plain; charset=utf-8'},
185
+ :body => stub_response)
186
+ end
187
+ def setup_migel_server_mock
188
+ # xls
189
+ stub_xls_url = 'https://github.com/zdavatz/oddb2xml_files/raw/master/NON-Pharma.xls'
190
+ stub_response = File.read(File.expand_path('../data/oddb2xml_files_nonpharma.xls', __FILE__))
191
+ stub_request(:get, stub_xls_url).
192
+ with(:headers => {
193
+ 'Accept' => '*/*',
194
+ 'Host' => 'github.com',
195
+ }).
196
+ to_return(
197
+ :status => 200,
198
+ :headers => {'Content-Type' => 'application/octet-stream; charset=utf-8'},
199
+ :body => stub_response)
200
+ end
171
201
  end
172
202
 
173
203
  RSpec.configure do |config|
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.2.6
4
+ version: 1.2.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-30 00:00:00.000000000 Z
12
+ date: 2013-02-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rubyzip
16
- requirement: &7579920 !ruby/object:Gem::Requirement
16
+ requirement: &10903560 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *7579920
24
+ version_requirements: *10903560
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: archive-tar-minitar
27
- requirement: &7579260 !ruby/object:Gem::Requirement
27
+ requirement: &10902760 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *7579260
35
+ version_requirements: *10902760
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: mechanize
38
- requirement: &7578660 !ruby/object:Gem::Requirement
38
+ requirement: &10901880 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *7578660
46
+ version_requirements: *10901880
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: nokogiri
49
- requirement: &7578060 !ruby/object:Gem::Requirement
49
+ requirement: &10900980 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *7578060
57
+ version_requirements: *10900980
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: savon
60
- requirement: &7577380 !ruby/object:Gem::Requirement
60
+ requirement: &10900160 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '2.0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *7577380
68
+ version_requirements: *10900160
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: spreadsheet
71
- requirement: &7576740 !ruby/object:Gem::Requirement
71
+ requirement: &10899260 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *7576740
79
+ version_requirements: *10899260
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rspec
82
- requirement: &7576020 !ruby/object:Gem::Requirement
82
+ requirement: &10898260 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *7576020
90
+ version_requirements: *10898260
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: webmock
93
- requirement: &7575460 !ruby/object:Gem::Requirement
93
+ requirement: &10896980 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *7575460
101
+ version_requirements: *10896980
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: ZenTest
104
- requirement: &7574940 !ruby/object:Gem::Requirement
104
+ requirement: &10895520 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *7574940
112
+ version_requirements: *10895520
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: hoe
115
- requirement: &7574380 !ruby/object:Gem::Requirement
115
+ requirement: &10894700 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: '3.4'
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *7574380
123
+ version_requirements: *10894700
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: rdoc
126
- requirement: &7573720 !ruby/object:Gem::Requirement
126
+ requirement: &10893480 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *7573720
134
+ version_requirements: *10893480
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: rdoc
137
- requirement: &7572680 !ruby/object:Gem::Requirement
137
+ requirement: &10892260 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ~>
@@ -142,10 +142,10 @@ dependencies:
142
142
  version: '3.10'
143
143
  type: :development
144
144
  prerelease: false
145
- version_requirements: *7572680
145
+ version_requirements: *10892260
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: hoe
148
- requirement: &7570120 !ruby/object:Gem::Requirement
148
+ requirement: &10891580 !ruby/object:Gem::Requirement
149
149
  none: false
150
150
  requirements:
151
151
  - - ~>
@@ -153,7 +153,7 @@ dependencies:
153
153
  version: '2.13'
154
154
  type: :development
155
155
  prerelease: false
156
- version_requirements: *7570120
156
+ version_requirements: *10891580
157
157
  description: oddb2xml creates xml files using swissINDEX, BAG-XML and Swissmedic.
158
158
  email: yasaka@ywesee.com, zdavatz@ywesee.com
159
159
  executables:
@@ -184,12 +184,15 @@ files:
184
184
  - spec/compressor_spec.rb
185
185
  - spec/data/XMLPublications.zip
186
186
  - spec/data/epha_interactions.csv
187
+ - spec/data/oddb2xml_files_bm_update.txt
188
+ - spec/data/oddb2xml_files_lppv.txt
187
189
  - spec/data/oddb_article.xml
188
190
  - spec/data/oddb_fi.xml
189
191
  - spec/data/oddb_fi_product.xml
190
192
  - spec/data/oddb_limitation.xml
191
193
  - spec/data/oddb_product.xml
192
194
  - spec/data/oddb_substance.xml
195
+ - spec/data/oddb2xml_files_nonpharma.xls
193
196
  - spec/data/swissindex.xml
194
197
  - spec/data/swissindex_nonpharma.xml
195
198
  - spec/data/swissindex_pharma.xml
@@ -203,7 +206,6 @@ files:
203
206
  - spec/data/wsdl.xml
204
207
  - spec/data/wsdl_nonpharma.xml
205
208
  - spec/data/wsdl_pharma.xml
206
- - spec/data/ywesee_bm_update.txt
207
209
  - spec/downloader_spec.rb
208
210
  - spec/extractor_spec.rb
209
211
  - spec/spec_helper.rb