oddb2xml 1.6.1 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'rubyzip'
3
+ gem 'rubyzip', '0.9.9'
4
4
  gem 'archive-tar-minitar'
5
5
  gem 'mechanize', '~> 2.5.1'
6
6
  gem 'nokogiri'
@@ -1,3 +1,7 @@
1
+ === 1.6.2 / 09.12.2013
2
+
3
+ * Read article with no pharmacode from BAG.xml Preparation.xml
4
+
1
5
  === 1.6.1 / 02.12.2013
2
6
 
3
7
  * Add pub_price from zurRose
@@ -74,85 +74,86 @@ module Oddb2xml
74
74
  item[:pharmacodes] = []
75
75
  item[:packages] = {} # pharmacode => package
76
76
  seq.xpath('.//Pack').each do |pac|
77
- if phar = pac.attr('Pharmacode')
78
- phar = correct_code(phar.to_s, 7)
79
- # as common key with swissINDEX
80
- item[:pharmacodes] << phar
81
- # packages
82
- item[:packages][phar] = {
83
- :pharmacode => phar,
84
- :ean => (ean = pac.at_xpath('.//GTIN')) ? ean.text : '',
85
- :swissmedic_category => (cat = pac.at_xpath('.//SwissmedicCategory')) ? cat.text : '',
86
- :swissmedic_number8 => (num = pac.at_xpath('.//SwissmedicNo8')) ? num.text.rjust(8, '0') : '',
87
- :narcosis_flag => (flg = pac.at_xpath('.//FlagNarcosis')) ? flg.text : '',
88
- :prices => {
89
- :exf_price => {
90
- :price => (exf = pac.at_xpath('.//ExFactoryPrice/Price')) ? exf.text : '',
91
- :valid_date => (exf = pac.at_xpath('.//ExFactoryPrice/ValidFromDate')) ? exf.text : '',
92
- :price_code => (exf = pac.at_xpath('.//ExFactoryPrice/PriceTypeCode')) ? exf.text : '',
93
- },
94
- :pub_price => {
95
- :price => (pub = pac.at_xpath('.//PublicPrice/Price')) ? pub.text : '',
96
- :valid_date => (pub = pac.at_xpath('.//PublicPrice/ValidFromDate')) ? pub.text : '',
97
- :price_code => (pub = pac.at_xpath('.//PublicPrice/PriceTypeCode')) ? pub.text : '',
98
- }
77
+ phar = pac.attr('Pharmacode')
78
+ phar = correct_code(phar.to_s, 7)
79
+ ean = pac.at_xpath('.//GTIN')
80
+ search_key = phar.to_i != 0 ? phar : ean.text
81
+ # as common key with swissINDEX
82
+ item[:pharmacodes] << phar
83
+ # packages
84
+ item[:packages][search_key] = {
85
+ :pharmacode => phar,
86
+ :ean => (ean) ? ean.text : '',
87
+ :swissmedic_category => (cat = pac.at_xpath('.//SwissmedicCategory')) ? cat.text : '',
88
+ :swissmedic_number8 => (num = pac.at_xpath('.//SwissmedicNo8')) ? num.text.rjust(8, '0') : '',
89
+ :narcosis_flag => (flg = pac.at_xpath('.//FlagNarcosis')) ? flg.text : '',
90
+ :prices => {
91
+ :exf_price => {
92
+ :price => (exf = pac.at_xpath('.//ExFactoryPrice/Price')) ? exf.text : '',
93
+ :valid_date => (exf = pac.at_xpath('.//ExFactoryPrice/ValidFromDate')) ? exf.text : '',
94
+ :price_code => (exf = pac.at_xpath('.//ExFactoryPrice/PriceTypeCode')) ? exf.text : '',
95
+ },
96
+ :pub_price => {
97
+ :price => (pub = pac.at_xpath('.//PublicPrice/Price')) ? pub.text : '',
98
+ :valid_date => (pub = pac.at_xpath('.//PublicPrice/ValidFromDate')) ? pub.text : '',
99
+ :price_code => (pub = pac.at_xpath('.//PublicPrice/PriceTypeCode')) ? pub.text : '',
99
100
  }
100
101
  }
101
- # related all limitations
102
- item[:packages][phar][:limitations] = []
103
- limitations = Hash.new{|h,k| h[k] = [] }
104
- # in seq
105
- limitations[:seq] = (lims = seq.xpath('.//Limitations/Limitation')) ? lims.to_a : nil
106
- # in it-codes
107
- limitations[:itc] = (lims = seq.xpath('.//ItCodes/ItCode/Limitations/Limitation')) ? lims.to_a : nil
108
- # in pac
109
- limitations[:pac] = (lims = pac.xpath('.//Limitations/Limitation')) ? lims.to_a : nil
110
- limitations.each_pair do |lim_key, lims|
111
- key = ''
112
- id = ''
113
- case lim_key
114
- when :seq, :itc
115
- key = :swissmedic_number5
116
- id = item[key].to_s
117
- when :pac
118
- key = :swissmedic_number8
119
- id = item[:packages][phar][key].to_s
120
- end
121
- if id.empty? or id == '0'
122
- key = :pharmacode
123
- id = phar.to_s
124
- end
125
- lims.each do |lim|
126
- limitation = {
127
- :it => item[:it_code],
128
- :key => key,
129
- :id => id,
130
- :code => (lic = lim.at_xpath('.//LimitationCode')) ? lic.text : '',
131
- :type => (lit = lim.at_xpath('.//LimitationType')) ? lit.text : '',
132
- :value => (liv = lim.at_xpath('.//LimitationValue')) ? liv.text : '',
133
- :niv => (niv = lim.at_xpath('.//LimitationNiveau')) ? niv.text : '',
134
- :desc_de => (dsc = lim.at_xpath('.//DescriptionDe')) ? dsc.text : '',
135
- :desc_fr => (dsc = lim.at_xpath('.//DescriptionFr')) ? dsc.text : '',
136
- :vdate => (dat = lim.at_xpath('.//ValidFromDate')) ? dat.text : '',
137
- }
138
- deleted = false
139
- if upto = ((thr = lim.at_xpath('.//ValidThruDate')) ? thr.text : nil) and
140
- upto =~ /\d{2}\.\d{2}\.\d{2}/
141
- begin
142
- deleted = true if Date.strptime(upto, '%d.%m.%y') >= Date.today
143
- rescue ArgumentError
144
- end
102
+ }
103
+ # related all limitations
104
+ item[:packages][search_key][:limitations] = []
105
+ limitations = Hash.new{|h,k| h[k] = [] }
106
+ # in seq
107
+ limitations[:seq] = (lims = seq.xpath('.//Limitations/Limitation')) ? lims.to_a : nil
108
+ # in it-codes
109
+ limitations[:itc] = (lims = seq.xpath('.//ItCodes/ItCode/Limitations/Limitation')) ? lims.to_a : nil
110
+ # in pac
111
+ limitations[:pac] = (lims = pac.xpath('.//Limitations/Limitation')) ? lims.to_a : nil
112
+ limitations.each_pair do |lim_key, lims|
113
+ key = ''
114
+ id = ''
115
+ case lim_key
116
+ when :seq, :itc
117
+ key = :swissmedic_number5
118
+ id = item[key].to_s
119
+ when :pac
120
+ key = :swissmedic_number8
121
+ id = item[:packages][search_key][key].to_s
122
+ end
123
+ if id.empty? or id == '0'
124
+ key = :pharmacode
125
+ id = phar.to_s
126
+ end
127
+ lims.each do |lim|
128
+ limitation = {
129
+ :it => item[:it_code],
130
+ :key => key,
131
+ :id => id,
132
+ :code => (lic = lim.at_xpath('.//LimitationCode')) ? lic.text : '',
133
+ :type => (lit = lim.at_xpath('.//LimitationType')) ? lit.text : '',
134
+ :value => (liv = lim.at_xpath('.//LimitationValue')) ? liv.text : '',
135
+ :niv => (niv = lim.at_xpath('.//LimitationNiveau')) ? niv.text : '',
136
+ :desc_de => (dsc = lim.at_xpath('.//DescriptionDe')) ? dsc.text : '',
137
+ :desc_fr => (dsc = lim.at_xpath('.//DescriptionFr')) ? dsc.text : '',
138
+ :vdate => (dat = lim.at_xpath('.//ValidFromDate')) ? dat.text : '',
139
+ }
140
+ deleted = false
141
+ if upto = ((thr = lim.at_xpath('.//ValidThruDate')) ? thr.text : nil) and
142
+ upto =~ /\d{2}\.\d{2}\.\d{2}/
143
+ begin
144
+ deleted = true if Date.strptime(upto, '%d.%m.%y') >= Date.today
145
+ rescue ArgumentError
145
146
  end
146
- limitation[:del] = deleted
147
- item[:packages][phar][:limitations] << limitation
148
147
  end
148
+ limitation[:del] = deleted
149
+ item[:packages][search_key][:limitations] << limitation
149
150
  end
150
- # limitation points
151
- pts = pac.at_xpath('.//PointLimitations/PointLimitation/Points') # only first points
152
- item[:packages][phar][:limitation_points] = pts ? pts.text : ''
153
- # pharmacode => seq (same data)
154
- data[phar] = item
155
151
  end
152
+ # limitation points
153
+ pts = pac.at_xpath('.//PointLimitations/PointLimitation/Points') # only first points
154
+ item[:packages][search_key][:limitation_points] = pts ? pts.text : ''
155
+ # pharmacode => seq (same data)
156
+ data[search_key] = item
156
157
  end
157
158
  end
158
159
  data
@@ -1,3 +1,3 @@
1
1
  module Oddb2xml
2
- VERSION = "1.6.1"
2
+ VERSION = "1.6.2"
3
3
  end
@@ -14,7 +14,7 @@ shared_examples_for 'any compressor' do
14
14
  @compressor.finalize!.should == true
15
15
  compress_file = @compressor.instance_variable_get(:@compress_file)
16
16
  File.exists?(compress_file).should == true
17
- File.unstub!(:unlink)
17
+ File.unstub(:unlink)
18
18
  end
19
19
  end
20
20
 
@@ -36,7 +36,7 @@ describe Oddb2xml::BagXmlDownloader do
36
36
  xml.should =~ /DescriptionDe/
37
37
  end
38
38
  it 'should clean up current directory' do
39
- xml.should_not raise_error(Timeout::Error)
39
+ expect { xml }.not_to raise_error
40
40
  File.exist?('XMLPublications.zip').should be(false)
41
41
  end
42
42
  end
@@ -100,7 +100,7 @@ describe Oddb2xml::SwissmedicDownloader do
100
100
  bin.bytes.should_not nil
101
101
  end
102
102
  it 'should clean up current directory' do
103
- bin.should_not raise_error(Timeout::Error)
103
+ expect { bin }.not_to raise_error
104
104
  File.exist?('oddb_orphan.xls').should be(false)
105
105
  end
106
106
  end
@@ -117,7 +117,7 @@ describe Oddb2xml::SwissmedicDownloader do
117
117
  bin.bytes.should_not nil
118
118
  end
119
119
  it 'should clean up current directory' do
120
- bin.should_not raise_error(Timeout::Error)
120
+ expect { bin }.not_to raise_error
121
121
  File.exist?('oddb_fridge.xls').should be(false)
122
122
  end
123
123
  end
@@ -134,7 +134,7 @@ describe Oddb2xml::SwissmedicDownloader do
134
134
  bin.bytes.should_not nil
135
135
  end
136
136
  it 'should clean up current directory' do
137
- bin.should_not raise_error(Timeout::Error)
137
+ expect { bin }.not_to raise_error
138
138
  File.exist?('oddb_package.xls').should be(false)
139
139
  end
140
140
  end
@@ -160,7 +160,7 @@ describe Oddb2xml::SwissmedicInfoDownloader do
160
160
  xml.should =~ /content/
161
161
  end
162
162
  it 'should clean up current directory' do
163
- xml.should_not raise_error(Timeout::Error)
163
+ expect { xml }.not_to raise_error
164
164
  File.exist?('swissmedic_info.zip').should be(false)
165
165
  end
166
166
  end
@@ -180,7 +180,7 @@ describe Oddb2xml::EphaDownloader do
180
180
  csv.bytes.should_not nil
181
181
  end
182
182
  it 'should clean up current directory' do
183
- csv.should_not raise_error(Timeout::Error)
183
+ expect { csv }.not_to raise_error
184
184
  File.exist?('epha_interactions.csv').should be(false)
185
185
  end
186
186
  end
@@ -200,7 +200,7 @@ describe Oddb2xml::BMUpdateDownloader do
200
200
  txt.bytes.should_not nil
201
201
  end
202
202
  it 'should clean up current directory' do
203
- txt.should_not raise_error(Timeout::Error)
203
+ expect { txt }.not_to raise_error
204
204
  File.exist?('oddb2xml_files_bm_update.txt').should be(false)
205
205
  end
206
206
  end
@@ -220,7 +220,7 @@ describe Oddb2xml::LppvDownloader do
220
220
  txt.bytes.should_not nil
221
221
  end
222
222
  it 'should clean up current directory' do
223
- txt.should_not raise_error(Timeout::Error)
223
+ expect { txt }.not_to raise_error
224
224
  File.exist?('oddb2xml_files_lppv.txt').should be(false)
225
225
  end
226
226
  end
@@ -240,7 +240,7 @@ describe Oddb2xml::MigelDownloader do
240
240
  bin.bytes.should_not nil
241
241
  end
242
242
  it 'should clean up current directory' do
243
- bin.should_not raise_error(Timeout::Error)
243
+ expect { bin }.not_to raise_error
244
244
  File.exist?('oddb2xml_files_nonpharma.txt').should be(false)
245
245
  end
246
246
  end
@@ -261,7 +261,7 @@ describe Oddb2xml::MedregbmDownloader do
261
261
  txt.bytes.should_not nil
262
262
  end
263
263
  it 'should clean up current directory' do
264
- txt.should_not raise_error(Timeout::Error)
264
+ expect { txt }.not_to raise_error
265
265
  File.exist?('oddb_company.xls').should be(false)
266
266
  end
267
267
  end
@@ -278,7 +278,7 @@ describe Oddb2xml::MedregbmDownloader do
278
278
  txt.bytes.should_not nil
279
279
  end
280
280
  it 'should clean up current directory' do
281
- txt.should_not raise_error(Timeout::Error)
281
+ expect { txt }.not_to raise_error
282
282
  File.exist?('oddb_person.xls').should be(false)
283
283
  end
284
284
  end
@@ -299,7 +299,7 @@ describe Oddb2xml::ZurroseDownloader do
299
299
  dat.bytes.should_not nil
300
300
  end
301
301
  it 'should clean up current directory' do
302
- dat.should_not raise_error(Timeout::Error)
302
+ expect { dat }.not_to raise_error
303
303
  File.exist?('oddb2xml_zurrose_transfer.dat').should be(false)
304
304
  end
305
305
  end
@@ -6,6 +6,65 @@ describe Oddb2xml::Extractor do
6
6
  it "pending"
7
7
  end
8
8
 
9
+ describe Oddb2xml::TxtExtractorMethods do
10
+ it "pending"
11
+ end
12
+
13
+ describe Oddb2xml::BagXmlExtractor do
14
+ context 'should handle articles with and without pharmacode' do
15
+ subject do
16
+ dat = File.read(File.expand_path('../data/Preparation.xml', __FILE__))
17
+ Oddb2xml::BagXmlExtractor.new(dat).to_hash
18
+ end
19
+ it {
20
+ @items = subject.to_hash
21
+ with_pharma = @items['1699947']
22
+ expect(with_pharma).not_to be_nil
23
+ expect(with_pharma[:atc_code]).not_to be_nil
24
+ expect(with_pharma[:pharmacodes]).not_to be_nil
25
+ expect(with_pharma[:packages].size).to eq(1)
26
+ expect(with_pharma[:packages].first[0]).to eq('1699947')
27
+ expect(with_pharma[:packages].first[1][:prices][:pub_price][:price]).to eq('205.3')
28
+ expect(@items.size).to eq(2)
29
+ no_pharma = @items['7680620690084']
30
+ expect(no_pharma).not_to be_nil
31
+ expect(no_pharma[:atc_code]).not_to be_nil
32
+ expect(no_pharma[:pharmacodes]).not_to be_nil
33
+ expect(no_pharma[:packages].size).to eq(1)
34
+ expect(no_pharma[:packages].first[0]).to eq('7680620690084')
35
+ expect(no_pharma[:packages].first[1][:prices][:pub_price][:price]).to eq('27.8')
36
+ }
37
+ end
38
+ end
39
+
40
+ describe Oddb2xml::SwissIndexExtractor do
41
+ it "pending"
42
+ end
43
+
44
+ describe Oddb2xml::SwissmedicExtractor do
45
+ it "pending"
46
+ end
47
+
48
+ describe Oddb2xml::MigelExtractor do
49
+ it "pending"
50
+ end
51
+
52
+ describe Oddb2xml::SwissmedicInfoExtractor do
53
+ it "pending"
54
+ end
55
+
56
+ describe Oddb2xml::EphaExtractor do
57
+ it "pending"
58
+ end
59
+
60
+ describe Oddb2xml::MedregbmExtractor do
61
+ it "pending"
62
+ end
63
+
64
+ describe Oddb2xml::ZurroseExtractor do
65
+ it "pending"
66
+ end
67
+
9
68
  describe Oddb2xml::ZurroseExtractor do
10
69
  context 'when transfer.dat is empty' do
11
70
  subject { Oddb2xml::ZurroseExtractor.new("") }
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.1
4
+ version: 1.6.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-12-02 00:00:00.000000000 Z
12
+ date: 2013-12-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rubyzip