oddb2xml 1.6.6 → 1.6.7

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.
data/Gemfile CHANGED
@@ -6,6 +6,7 @@ gem 'mechanize', '~> 2.5.1'
6
6
  gem 'nokogiri'
7
7
  gem 'savon', '>= 2.0'
8
8
  gem 'spreadsheet'
9
+ gem 'rubyXL'
9
10
 
10
11
  group :development do
11
12
  gem 'rspec'
@@ -71,6 +71,7 @@ GEM
71
71
  diff-lcs (>= 1.1.3, < 2.0)
72
72
  rspec-mocks (2.14.4)
73
73
  ruby-ole (1.2.11.7)
74
+ rubyXL (1.2.10)
74
75
  rubyntlm (0.3.4)
75
76
  rubyzip (0.9.9)
76
77
  safe_yaml (0.9.7)
@@ -111,6 +112,7 @@ DEPENDENCIES
111
112
  pry-debugger
112
113
  rdoc
113
114
  rspec
115
+ rubyXL
114
116
  rubyzip (= 0.9.9)
115
117
  savon (>= 2.0)
116
118
  spreadsheet
@@ -1,3 +1,7 @@
1
+ === 1.6.7 / 07.01.2013
2
+
3
+ * Adapted to swissmedic xlsx files
4
+
1
5
  === 1.6.6 / 12.12.2013
2
6
 
3
7
  * Added spec for generating *.dat file
@@ -45,15 +45,17 @@ spec/data/oddb_substance.xml
45
45
  spec/data/swissindex.xml
46
46
  spec/data/swissindex_nonpharma.xml
47
47
  spec/data/swissindex_pharma.xml
48
+ spec/data/swissmedic_fridge.xlsx
48
49
  spec/data/swissmedic_fridges.html
49
50
  spec/data/swissmedic_fridges.xls
50
51
  spec/data/swissmedic_info.html
51
52
  spec/data/swissmedic_info.zip
52
53
  spec/data/swissmedic_info_2.html
54
+ spec/data/swissmedic_orphan.xls
53
55
  spec/data/swissmedic_orphans.html
54
56
  spec/data/swissmedic_orphans.xls
57
+ spec/data/swissmedic_package.xlsx
55
58
  spec/data/swissmedic_packages.html
56
- spec/data/swissmedic_packages.xls
57
59
  spec/data/wsdl.xml
58
60
  spec/data/wsdl_nonpharma.xml
59
61
  spec/data/wsdl_pharma.xml
@@ -6,6 +6,7 @@ require 'oddb2xml/downloader'
6
6
  require 'oddb2xml/extractor'
7
7
  require 'oddb2xml/compressor'
8
8
  require 'oddb2xml/util'
9
+ require 'rubyXL'
9
10
 
10
11
  module Oddb2xml
11
12
  class Cli
@@ -229,20 +229,20 @@ XML
229
229
  @type = type
230
230
  case @type
231
231
  when :orphan
232
- action = "daten/00081/index.html?lang=de"
233
- @xpath = "//div[@id='sprungmarke0_4']//a[@title='Humanarzneimittel']"
232
+ action = "arzneimittel/00156/00221/00222/00223/00224/00227/00228/index.html?lang=de"
233
+ @xpath = "//div[@id='sprungmarke10_3']//a[@title='Humanarzneimittel']"
234
234
  when :fridge
235
- action = "daten/00080/00254/index.html?lang=de"
236
- @xpath = "//table[@class='swmTableFlex']//a[@title='B3.1.35-d.xls']"
235
+ action = "arzneimittel/00156/00221/00222/00235/index.html?lang=de"
236
+ @xpath = "//div[@id='sprungmarke10_2']//a[@title='Excel-Version']"
237
237
  when :package
238
- action = "daten/00080/00251/index.html?lang=de"
239
- @xpath = "//div[@id='sprungmarke0_7']//a[@title='Excel-Version Zugelassene Verpackungen*']"
238
+ action = "arzneimittel/00156/00221/00222/00230/index.html?lang=de"
239
+ @xpath = "//div[@id='sprungmarke10_7']//a[@title='Excel-Version Zugelassene Verpackungen*']"
240
240
  end
241
241
  url = "http://www.swissmedic.ch/#{action}"
242
242
  super({}, url)
243
243
  end
244
244
  def download
245
- file = "swissmedic_#{@type}.xls"
245
+ @type == :orphan ? file = "swissmedic_#{@type}.xls" : file = "swissmedic_#{@type}.xlsx"
246
246
  begin
247
247
  page = @agent.get(@url)
248
248
  if link_node = page.search(@xpath).first
@@ -253,13 +253,11 @@ XML
253
253
  response = nil # win
254
254
  end
255
255
  end
256
- io = File.open(file, 'rb')
257
- return io.read
256
+ return File.expand_path(file)
258
257
  rescue Timeout::Error, Errno::ETIMEDOUT
259
258
  retrievable? ? retry : raise
260
259
  ensure
261
- io.close if io and !io.closed?
262
- Oddb2xml.download_finished(file)
260
+ Oddb2xml.download_finished(file, false)
263
261
  end
264
262
  end
265
263
  end
@@ -196,11 +196,14 @@ module Oddb2xml
196
196
  end
197
197
  end
198
198
  class SwissmedicExtractor < Extractor
199
- def initialize(bin, type)
200
- io = StringIO.new(bin)
201
- book = Spreadsheet.open(io, 'rb')
202
- @sheet = book.worksheet(0)
199
+ def initialize(filename, type)
203
200
  @type = type
201
+ if type == :orphan
202
+ book = Spreadsheet.open(filename, 'rb')
203
+ @sheet = book.worksheet(0)
204
+ else
205
+ @sheet = RubyXL::Parser.parse(File.expand_path(filename)).worksheets[0]
206
+ end
204
207
  end
205
208
  def to_arry
206
209
  data = []
@@ -208,15 +211,16 @@ module Oddb2xml
208
211
  when :orphan
209
212
  i = 1
210
213
  @sheet.each do |row|
211
- if number = extract_number(row, i)
212
- data << number.to_s
214
+ number = row[1].to_i
215
+ if number != 0
216
+ data << sprintf("%05d", number)
213
217
  end
214
218
  end
215
219
  when :fridge
216
220
  i,c = 1,7
217
221
  @sheet.each do |row|
218
- if number = extract_number(row, i) and row[c] and row[c].to_s == 'x'
219
- data << row[i].to_s
222
+ if row[i] and number = row[i].value and row[c] and row[c].value.to_s.downcase == 'x'
223
+ data << sprintf("%05d", number)
220
224
  end
221
225
  end
222
226
  end
@@ -237,20 +241,21 @@ module Oddb2xml
237
241
  sub = 14 # :substance_swissmedic
238
242
  @sheet.each_with_index do |row, i|
239
243
  next if (i <= 1)
240
- no8 = sprintf('%05d',row[i_5].to_i) + sprintf('%03d',row[i_3].to_i)
241
- prodno = sprintf('%05d',row[i_5].to_i) + row[p_1_2].to_i.to_s
244
+ next unless row[i_5] and row[i_3]
245
+ no8 = sprintf('%05d',row[i_5].value.to_i) + sprintf('%03d',row[i_3].value.to_i)
246
+ prodno = sprintf('%05d',row[i_5].value.to_i) + row[p_1_2].value.to_i.to_s
242
247
  unless no8.empty?
243
248
  next if no8.to_i == 0
244
249
  ean_base12 = "7680#{no8}"
245
250
  data[no8.intern] = {
246
251
  :ean => (ean_base12.ljust(12, '0') + calc_checksum(ean_base12)),
247
- :prodno => prodno,
248
- :ith_swissmedic => row[ith].to_s,
249
- :swissmedic_category => row[cat].to_s,
250
- :atc_code => row[atc].to_s,
251
- :package_size => row[siz].to_s,
252
- :einheit_swissmedic => row[eht].to_s,
253
- :substance_swissmedic => row[sub].to_s,
252
+ :prodno => prodno ? prodno : '',
253
+ :ith_swissmedic => row[ith] ? row[ith].value.to_s : '',
254
+ :swissmedic_category => row[cat].value.to_s,
255
+ :atc_code => row[atc] ? row[atc].value.to_s : '',
256
+ :package_size => row[siz] ? row[siz].value.to_s : '',
257
+ :einheit_swissmedic => row[eht] ? row[eht].value.to_s : '',
258
+ :substance_swissmedic => row[sub] ? row[sub].value.to_s : '',
254
259
  :is_tier => (row[typ] == 'Tierarzneimittel' ? true : false),
255
260
  }
256
261
  end
@@ -16,14 +16,14 @@ module Oddb2xml
16
16
  false
17
17
  end
18
18
 
19
- def Oddb2xml.download_finished(file)
19
+ def Oddb2xml.download_finished(file, remove_file = true)
20
20
  dest = "#{Backup}/#{File.basename(file)}"
21
21
  if @options[:skip_download]
22
22
  FileUtils.makedirs(Backup)
23
23
  FileUtils.cp(file, dest, :verbose => false)
24
24
  end
25
25
  begin
26
- File.unlink(file) if File.exists?(file)
26
+ File.unlink(file) if File.exists?(file) and remove_file
27
27
  rescue Errno::EACCES # Permission Denied on Windows
28
28
  end
29
29
  end
@@ -1,3 +1,3 @@
1
1
  module Oddb2xml
2
- VERSION = "1.6.6"
2
+ VERSION = "1.6.7"
3
3
  end
@@ -63,13 +63,37 @@ describe Oddb2xml::SwissmedicInfoExtractor do
63
63
  subject { Oddb2xml::SwissmedicInfoExtractor.new("") }
64
64
  it { expect(subject.to_hash).to be_empty }
65
65
  end
66
- context 'can parse swissmedic_packages.xls' do
66
+ context 'can parse swissmedic_package.xlsx' do
67
67
  it {
68
- filename = File.join(File.dirname(__FILE__), 'data/swissmedic_packages.xls')
69
- bin = IO.read(filename)
70
- @packs = Oddb2xml::SwissmedicExtractor.new(bin, :package).to_hash
71
- expect(@packs.size).to eq(14)
72
- }
68
+ filename = File.join(File.dirname(__FILE__), 'data/swissmedic_package.xlsx')
69
+ @packs = Oddb2xml::SwissmedicExtractor.new(filename, :package).to_hash
70
+ expect(@packs.size).to eq(14)
71
+ first = @packs.first[1]
72
+ expect(first[:atc_code]).to eq('J06AA')
73
+ expect(first[:swissmedic_category]).to eq('B')
74
+ expect(first[:package_size]).to eq('3')
75
+ expect(first[:einheit_swissmedic]).to eq('Suppositorien')
76
+ expect(first[:substance_swissmedic]).to eq('globulina equina (immunisé avec coeur, tissu pulmonaire, reins de porcins)')
77
+ expect(@packs.first[0].to_s).to eq('00274001')
78
+ }
79
+ end
80
+ context 'can parse swissmedic_fridge.xlsx' do
81
+ it {
82
+ filename = File.join(File.dirname(__FILE__), 'data/swissmedic_fridge.xlsx')
83
+ @packs = Oddb2xml::SwissmedicExtractor.new(filename, :fridge).to_arry
84
+ expect(@packs.size).to eq(17)
85
+ expect(@packs[0]).to eq("58618")
86
+ expect(@packs[1]).to eq("00696")
87
+ }
88
+ end
89
+ context 'can parse swissmedic_orphan.xls' do
90
+ it {
91
+ filename = File.join(File.dirname(__FILE__), 'data/swissmedic_orphan.xls')
92
+ @packs = Oddb2xml::SwissmedicExtractor.new(filename, :orphan).to_arry
93
+ expect(@packs.size).to eq(72)
94
+ expect(@packs.first).to eq("62132")
95
+ expect(@packs[7]).to eq("00687")
96
+ }
73
97
  end
74
98
  end
75
99
 
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.6.6
4
+ version: 1.6.7
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-12-12 00:00:00.000000000 Z
12
+ date: 2014-01-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rubyzip
@@ -229,15 +229,17 @@ files:
229
229
  - spec/data/swissindex.xml
230
230
  - spec/data/swissindex_nonpharma.xml
231
231
  - spec/data/swissindex_pharma.xml
232
+ - spec/data/swissmedic_fridge.xlsx
232
233
  - spec/data/swissmedic_fridges.html
233
234
  - spec/data/swissmedic_fridges.xls
234
235
  - spec/data/swissmedic_info.html
235
236
  - spec/data/swissmedic_info.zip
236
237
  - spec/data/swissmedic_info_2.html
238
+ - spec/data/swissmedic_orphan.xls
237
239
  - spec/data/swissmedic_orphans.html
238
240
  - spec/data/swissmedic_orphans.xls
241
+ - spec/data/swissmedic_package.xlsx
239
242
  - spec/data/swissmedic_packages.html
240
- - spec/data/swissmedic_packages.xls
241
243
  - spec/data/wsdl.xml
242
244
  - spec/data/wsdl_nonpharma.xml
243
245
  - spec/data/wsdl_pharma.xml