oddb2xml 2.1.7 → 2.1.8
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.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +60 -54
- data/History.txt +9 -0
- data/README.md +3 -0
- data/lib/oddb2xml/builder.rb +278 -300
- data/lib/oddb2xml/cli.rb +45 -55
- data/lib/oddb2xml/downloader.rb +23 -19
- data/lib/oddb2xml/extractor.rb +19 -21
- data/lib/oddb2xml/util.rb +2 -1
- data/lib/oddb2xml/version.rb +1 -1
- data/lib/oddb2xml/xml_definitions.rb +29 -12
- data/oddb2xml.gemspec +14 -10
- data/spec/builder_spec.rb +318 -406
- data/spec/calc_spec.rb +7 -14
- data/spec/cli_spec.rb +119 -51
- data/spec/downloader_spec.rb +372 -115
- data/spec/extractor_spec.rb +126 -44
- data/spec/fixtures/vcr_cassettes/oddb2xml.json +1 -0
- data/spec/galenic_spec.rb +1 -3
- data/spec/options_spec.rb +0 -13
- data/spec/parslet_spec.rb +0 -6
- data/spec/spec_helper.rb +105 -240
- data/test_options.rb +7 -2
- metadata +92 -50
- data/spec/data/swissindex.xml +0 -56
- data/spec/data/swissindex_NonPharma_DE.xml +0 -65
- data/spec/data/swissindex_NonPharma_FR.xml +0 -65
- data/spec/data/swissindex_Pharma_DE.xml +0 -82
- data/spec/data/swissindex_Pharma_FR.xml +0 -82
- data/spec/data/swissindex_nonpharma.xml +0 -65
- data/spec/data/swissindex_pharma.xml +0 -82
- data/spec/data/swissmedic_package-galenic.xlsx +0 -0
data/spec/calc_spec.rb
CHANGED
@@ -1,9 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
begin
|
4
|
-
require 'pry'
|
5
|
-
rescue LoadError
|
6
|
-
end
|
7
3
|
require 'pp'
|
8
4
|
require 'spec_helper'
|
9
5
|
require "rexml/document"
|
@@ -13,6 +9,8 @@ include Oddb2xml
|
|
13
9
|
|
14
10
|
describe Oddb2xml::Calc do
|
15
11
|
RunAllTests = true
|
12
|
+
before(:all) do VCR.eject_cassette; VCR.insert_cassette('oddb2xml') end
|
13
|
+
after(:all) do VCR.eject_cassette end
|
16
14
|
|
17
15
|
after(:each) do
|
18
16
|
FileUtils.rm(Dir.glob(File.join(Oddb2xml::WorkDir, '*.*')))
|
@@ -21,7 +19,7 @@ describe Oddb2xml::Calc do
|
|
21
19
|
before(:each) do
|
22
20
|
FileUtils.rm(Dir.glob(File.join(Oddb2xml::WorkDir, '*.xml')))
|
23
21
|
FileUtils.rm(Dir.glob(File.join(Oddb2xml::WorkDir, '*.csv')))
|
24
|
-
setup_epha_atc_csv_mock
|
22
|
+
# setup_epha_atc_csv_mock
|
25
23
|
end
|
26
24
|
|
27
25
|
Line_1 = 'I) Glucoselösung: glucosum anhydricum 150 g ut glucosum monohydricum, natrii dihydrogenophosphas dihydricus 2.34 g, zinci acetas dihydricus 6.58 mg, aqua ad iniectabilia q.s. ad solutionem pro 500 ml.'
|
@@ -303,10 +301,6 @@ if RunAllTests
|
|
303
301
|
src = File.expand_path(File.join(File.dirname(__FILE__), 'data', 'swissmedic_package-galenic.xlsx'))
|
304
302
|
dest = File.join(Oddb2xml::WorkDir, 'swissmedic_package.xlsx')
|
305
303
|
FileUtils.makedirs(Oddb2xml::WorkDir)
|
306
|
-
FileUtils.cp(src, dest, { :verbose => true, :preserve => true})
|
307
|
-
FileUtils.cp(File.expand_path(File.join(File.dirname(__FILE__), 'data', 'XMLPublications.zip')),
|
308
|
-
File.join(Oddb2xml::WorkDir, 'downloads'),
|
309
|
-
{ :verbose => true, :preserve => true})
|
310
304
|
cli.run
|
311
305
|
expected = [
|
312
306
|
'oddb_calc.xml',
|
@@ -347,9 +341,10 @@ if RunAllTests
|
|
347
341
|
result.should eq value.to_s
|
348
342
|
}
|
349
343
|
matri_name = 'Matricariae Extractum Isopropanolicum Liquidum'
|
350
|
-
XPath.match( doc, "//ARTICLE[GTIN='
|
351
|
-
|
352
|
-
# XPath.match( doc, "//ARTICLE[GTIN='
|
344
|
+
XPath.match( doc, "//ARTICLE[GTIN='7680002770014']/NAME").first.text.should eq "Coeur-Vaisseaux Sérocytol, suppositoire"
|
345
|
+
XPath.match( doc, "//ARTICLE[GTIN='7680545250363']").first.should eq nil
|
346
|
+
# XPath.match( doc, "//ARTICLE[GTIN='7680545250363']/COMPOSITIONS/COMPOSITION/SUBSTANCES/SUBSTANCE/SUBSTANCE_NAME")
|
347
|
+
# find{|x| x.text.eql?("Alprostadilum")}.text.should eq 'Alprostadilum'
|
353
348
|
XPath.match( doc, "//ARTICLE[GTIN='7680458820202']/NAME").last.text.should eq 'Magnesiumchlorid 0,5 molar B. Braun, Zusatzampulle für Infusionslösungen'
|
354
349
|
XPath.match( doc, "//ARTICLE[GTIN='7680458820202']/GALENIC_FORM").last.text.should match /Ampulle/i
|
355
350
|
XPath.match( doc, "//ARTICLE[GTIN='7680555940018']/COMPOSITIONS/COMPOSITION/LABEL").first.text.should eq 'I'
|
@@ -360,7 +355,6 @@ if RunAllTests
|
|
360
355
|
|
361
356
|
XPath.match( doc, "//ARTICLE[GTIN='7680434541015']/COMPOSITIONS/COMPOSITION/SUBSTANCES/SUBSTANCE/SUBSTANCE_NAME").
|
362
357
|
find{|x| x.text.eql?(matri_name)}.text.should eq matri_name
|
363
|
-
# XPath.match( doc, "//ARTICLE[GTIN='7680434541015']/NAME").last.text.should eq 'Kamillin Medipharm'
|
364
358
|
XPath.match( doc, "//ARTICLE[GTIN='7680434541015']/NAME").last.text.should eq 'Kamillin Medipharm, Bad'
|
365
359
|
XPath.match( doc, "//ARTICLE[GTIN='7680434541015']/GALENIC_FORM").last.text.should eq 'Bad'
|
366
360
|
XPath.match( doc, "//ARTICLE[GTIN='7680434541015']/COMPOSITIONS/COMPOSITION/SUBSTANCES/SUBSTANCE/QTY").first.text.should eq '98.9'
|
@@ -374,7 +368,6 @@ if RunAllTests
|
|
374
368
|
|
375
369
|
XPath.match( doc, "//ARTICLE[GTIN='7680446250592']/COMPOSITIONS/COMPOSITION/SUBSTANCES/SUBSTANCE/SALTS/SALT/SUBSTANCE_NAME").first.text.should eq 'Ceftriaxonum Natricum'
|
376
370
|
|
377
|
-
# XPath.match( doc, "//ARTICLE[GTIN='7680611860045']/NAME").first.text.should eq 'Nutriflex Omega special'
|
378
371
|
XPath.match( doc, "//ARTICLE[GTIN='7680611860045']/NAME").first.text.should eq 'Nutriflex Omega special, Infusionsemulsion 2500 ml'
|
379
372
|
XPath.match( doc, "//ARTICLE[GTIN='7680611860045']/GALENIC_FORM").first.text.should eq 'Infusionsemulsion'
|
380
373
|
XPath.match( doc, "//ARTICLE[GTIN='7680611860045']/SELLING_UNITS").first.text.should eq '5'
|
data/spec/cli_spec.rb
CHANGED
@@ -2,20 +2,6 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
module Kernel
|
6
|
-
def cli_capture(stream)
|
7
|
-
begin
|
8
|
-
stream = stream.to_s
|
9
|
-
eval "$#{stream} = StringIO.new"
|
10
|
-
yield
|
11
|
-
result = eval("$#{stream}").string
|
12
|
-
ensure
|
13
|
-
eval "$#{stream} = #{stream.upcase}"
|
14
|
-
end
|
15
|
-
result
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
5
|
RSpec::Matchers.define :have_option do |option|
|
20
6
|
match do |interface|
|
21
7
|
key = option.keys.first
|
@@ -29,16 +15,16 @@ RSpec::Matchers.define :have_option do |option|
|
|
29
15
|
end
|
30
16
|
|
31
17
|
shared_examples_for 'any interface for product' do
|
32
|
-
it {
|
18
|
+
it { @cli.should respond_to(:run) }
|
33
19
|
it 'should run successfully' do
|
34
|
-
|
20
|
+
@cli_output.should match(/products/)
|
35
21
|
end
|
36
22
|
end
|
37
23
|
|
38
24
|
shared_examples_for 'any interface for address' do
|
39
|
-
it {
|
25
|
+
it { buildr_capture(:stdout) { @cli.should respond_to(:run) } }
|
40
26
|
it 'should run successfully' do
|
41
|
-
|
27
|
+
@cli_output.should match(/addresses/)
|
42
28
|
end
|
43
29
|
end
|
44
30
|
|
@@ -46,78 +32,154 @@ describe Oddb2xml::Cli do
|
|
46
32
|
# Setting ShouldRun to false and changing one -> if true allows you
|
47
33
|
# to run easily the failing test
|
48
34
|
include ServerMockHelper
|
49
|
-
before(:
|
35
|
+
before(:all) do
|
36
|
+
VCR.eject_cassette
|
37
|
+
VCR.insert_cassette('oddb2xml')
|
50
38
|
@savedDir = Dir.pwd
|
51
39
|
cleanup_directories_before_run
|
52
|
-
setup_server_mocks
|
53
40
|
Dir.chdir(Oddb2xml::WorkDir)
|
54
41
|
end
|
55
|
-
after(:
|
42
|
+
after(:all) do
|
56
43
|
Dir.chdir(@savedDir) if @savedDir and File.directory?(@savedDir)
|
57
44
|
cleanup_compressor
|
58
45
|
end
|
46
|
+
|
47
|
+
context 'when -t md option is given' do
|
48
|
+
before(:all) do
|
49
|
+
cleanup_directories_before_run
|
50
|
+
options = Oddb2xml::Options.new
|
51
|
+
options.parser.parse!('-t md'.split(' '))
|
52
|
+
@cli = Oddb2xml::Cli.new(options.opts)
|
53
|
+
@cli_output = buildr_capture(:stdout) { @cli.run }
|
54
|
+
end
|
55
|
+
it_behaves_like 'any interface for product'
|
56
|
+
it 'should have tag_suffix option' do
|
57
|
+
@cli.should have_option(:tag_suffix=> 'MD')
|
58
|
+
end
|
59
|
+
it 'should not create a compressed file' do
|
60
|
+
Dir.glob(File.join(Oddb2xml::WorkDir, 'oddb_*.tar.gz')).first.should be_nil
|
61
|
+
Dir.glob(File.join(Oddb2xml::WorkDir, 'oddb_*.zip')).first.should be_nil
|
62
|
+
end
|
63
|
+
it 'should create xml files with prefix swiss_' do
|
64
|
+
expected = [
|
65
|
+
'md_product.xml',
|
66
|
+
'md_article.xml',
|
67
|
+
'md_limitation.xml',
|
68
|
+
'md_substance.xml',
|
69
|
+
'md_interaction.xml',
|
70
|
+
'md_code.xml'
|
71
|
+
]
|
72
|
+
expected.each{
|
73
|
+
|name|
|
74
|
+
expect(Dir.glob(File.join(Oddb2xml::WorkDir, name)).size).to eq 1
|
75
|
+
expect(File.size(File.join(Oddb2xml::WorkDir, name))).to be >= 1024
|
76
|
+
}
|
77
|
+
end
|
78
|
+
it 'should produce a correct report' do
|
79
|
+
@cli_output.should match(/Pharma products:/)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
59
83
|
context 'when -c tar.gz option is given' do
|
60
|
-
|
84
|
+
before(:all) do
|
85
|
+
cleanup_directories_before_run
|
61
86
|
options = Oddb2xml::Options.new
|
62
87
|
options.parser.parse!('-c tar.gz'.split(' '))
|
63
|
-
Oddb2xml::Cli.new(options.opts)
|
88
|
+
@cli = Oddb2xml::Cli.new(options.opts)
|
89
|
+
@cli_output = buildr_capture(:stdout) { @cli.run }
|
90
|
+
# @cli_output = @cli.run # to debug
|
64
91
|
end
|
92
|
+
|
65
93
|
it_behaves_like 'any interface for product'
|
94
|
+
it 'should not create any xml file' do
|
95
|
+
@cli_output.should match(/Pharma/)
|
96
|
+
Dir.glob(File.join(Oddb2xml::WorkDir, 'oddb_*.xml')).each do |file|
|
97
|
+
File.exists?(file).should be_false
|
98
|
+
end
|
99
|
+
end
|
66
100
|
it 'should have compress option' do
|
67
|
-
cli.should have_option(:compress_ext => 'tar.gz')
|
101
|
+
@cli.should have_option(:compress_ext => 'tar.gz')
|
68
102
|
end
|
69
103
|
it 'should create tar.gz file' do
|
70
|
-
cli_capture(:stdout) { cli.run }.should match(/Pharma/)
|
71
104
|
file = Dir.glob(File.join(Dir.pwd, 'oddb_*.tar.gz')).first
|
72
105
|
File.exists?(file).should eq true
|
73
106
|
end
|
74
107
|
it 'should not create any xml file' do
|
75
|
-
cli_capture(:stdout) { cli.run }.should match(/Pharma/)
|
76
108
|
Dir.glob(File.join(Oddb2xml::WorkDir, 'oddb_*.xml')).each do |file|
|
77
109
|
File.exists?(file).should be_false
|
78
110
|
end
|
79
111
|
end
|
80
112
|
end
|
113
|
+
|
81
114
|
context 'when -c zip option is given' do
|
82
|
-
|
115
|
+
before(:all) do
|
116
|
+
cleanup_directories_before_run
|
83
117
|
options = Oddb2xml::Options.new
|
84
118
|
options.parser.parse!('-c zip'.split(' '))
|
85
|
-
Oddb2xml::Cli.new(options.opts)
|
119
|
+
@cli = Oddb2xml::Cli.new(options.opts)
|
120
|
+
@cli_output = buildr_capture(:stdout) { @cli.run }
|
86
121
|
end
|
87
122
|
it_behaves_like 'any interface for product'
|
88
123
|
it 'should have compress option' do
|
89
|
-
cli.should have_option(:compress_ext => 'zip')
|
124
|
+
@cli.should have_option(:compress_ext => 'zip')
|
90
125
|
end
|
91
126
|
it 'should create zip file' do
|
92
|
-
|
127
|
+
@cli_output.should match(/Pharma/)
|
93
128
|
file = Dir.glob(File.join(Dir.pwd, 'oddb_*.zip')).first
|
94
129
|
File.exists?(file).should eq true
|
95
130
|
end
|
96
131
|
it 'should not create any xml file' do
|
97
132
|
Dir.glob(File.join(Oddb2xml::WorkDir, 'oddb_*.xml')).each do |file| FileUtil.rm_f(file) end
|
98
|
-
|
133
|
+
@cli_output.should match(/Pharma/)
|
99
134
|
Dir.glob(File.join(Oddb2xml::WorkDir, 'oddb_*.xml')).each do |file|
|
100
135
|
File.exists?(file).should be_false
|
101
136
|
end
|
102
137
|
end
|
103
138
|
end
|
139
|
+
|
140
|
+
context 'when -f dat option is given' do
|
141
|
+
before(:all) do
|
142
|
+
cleanup_directories_before_run
|
143
|
+
options = Oddb2xml::Options.new
|
144
|
+
options.parser.parse!('-f dat'.split(' '))
|
145
|
+
@cli = Oddb2xml::Cli.new(options.opts)
|
146
|
+
@cli_output = buildr_capture(:stdout) { @cli.run }
|
147
|
+
end
|
148
|
+
it_behaves_like 'any interface for product'
|
149
|
+
it 'should have nonpharma option' do
|
150
|
+
@cli.should have_option(:format => :dat, :extended => false)
|
151
|
+
end
|
152
|
+
it 'should create the needed files' do
|
153
|
+
@cli_output.should match(/\sPharma\s/)
|
154
|
+
expected = [
|
155
|
+
'duplicate_ean13_from_zur_rose.txt',
|
156
|
+
'zurrose_transfer.dat',
|
157
|
+
'oddb.dat',
|
158
|
+
].each{ |file|
|
159
|
+
File.exists?(File.join(Oddb2xml::WorkDir, file)).should eq true
|
160
|
+
}
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
104
164
|
context 'when -a nonpharma option is given' do
|
105
|
-
|
165
|
+
before(:all) do
|
166
|
+
cleanup_directories_before_run
|
106
167
|
options = Oddb2xml::Options.new
|
107
168
|
options.parser.parse!('-a nonpharma'.split(' '))
|
108
|
-
Oddb2xml::Cli.new(options.opts)
|
169
|
+
@cli = Oddb2xml::Cli.new(options.opts)
|
170
|
+
@cli_output = buildr_capture(:stdout) { @cli.run }
|
109
171
|
end
|
110
172
|
it_behaves_like 'any interface for product'
|
111
173
|
it 'should have nonpharma option' do
|
112
|
-
cli.should have_option(:nonpharma => true)
|
174
|
+
@cli.should have_option(:nonpharma => true)
|
113
175
|
end
|
114
176
|
it 'should not create any compressed file' do
|
115
|
-
|
177
|
+
@cli_output.should match(/NonPharma/)
|
116
178
|
Dir.glob(File.join(Oddb2xml::WorkDir, 'oddb_*.tar.gz')).first.should be_nil
|
117
179
|
Dir.glob(File.join(Oddb2xml::WorkDir, 'oddb_*.zip')).first.should be_nil
|
118
180
|
end
|
119
181
|
it 'should create xml files' do
|
120
|
-
|
182
|
+
@cli_output.should match(/NonPharma/)
|
121
183
|
expected = [
|
122
184
|
'oddb_product.xml',
|
123
185
|
'oddb_article.xml',
|
@@ -132,22 +194,24 @@ describe Oddb2xml::Cli do
|
|
132
194
|
end
|
133
195
|
end
|
134
196
|
context 'when -t _swiss option is given' do
|
135
|
-
|
197
|
+
before(:all) do
|
198
|
+
cleanup_directories_before_run
|
136
199
|
options = Oddb2xml::Options.new
|
137
200
|
options.parser.parse!('-t _swiss'.split(' '))
|
138
|
-
Oddb2xml::Cli.new(options.opts)
|
201
|
+
@cli = Oddb2xml::Cli.new(options.opts)
|
202
|
+
@cli_output = buildr_capture(:stdout) { @cli.run }
|
139
203
|
end
|
140
204
|
it_behaves_like 'any interface for product'
|
141
205
|
it 'should have tag_suffix option' do
|
142
|
-
cli.should have_option(:tag_suffix=> '_SWISS')
|
206
|
+
@cli.should have_option(:tag_suffix=> '_SWISS')
|
143
207
|
end
|
144
208
|
it 'should not create any compressed file' do
|
145
|
-
|
209
|
+
@cli_output.should match(/Pharma/)
|
146
210
|
Dir.glob(File.join(Oddb2xml::WorkDir, 'oddb_*.tar.gz')).first.should be_nil
|
147
211
|
Dir.glob(File.join(Oddb2xml::WorkDir, 'oddb_*.zip')).first.should be_nil
|
148
212
|
end
|
149
213
|
it 'should create xml files with prefix swiss_' do
|
150
|
-
|
214
|
+
@cli_output.should match(/Pharma/)
|
151
215
|
expected = [
|
152
216
|
'swiss_product.xml',
|
153
217
|
'swiss_article.xml',
|
@@ -162,22 +226,24 @@ describe Oddb2xml::Cli do
|
|
162
226
|
end
|
163
227
|
end
|
164
228
|
context 'when -o fi option is given' do
|
165
|
-
|
229
|
+
before(:all) do
|
230
|
+
cleanup_directories_before_run
|
166
231
|
options = Oddb2xml::Options.new
|
167
232
|
options.parser.parse!('-o fi'.split(' '))
|
168
|
-
Oddb2xml::Cli.new(options.opts)
|
233
|
+
@cli = Oddb2xml::Cli.new(options.opts)
|
234
|
+
@cli_output = buildr_capture(:stdout) { @cli.run }
|
169
235
|
end
|
170
236
|
it_behaves_like 'any interface for product'
|
171
237
|
it 'should have nonpharma option' do
|
172
|
-
cli.should have_option(:fi => true)
|
238
|
+
@cli.should have_option(:fi => true)
|
173
239
|
end
|
174
240
|
it 'should not create any compressed file' do
|
175
|
-
|
241
|
+
@cli_output.should match(/Pharma/)
|
176
242
|
Dir.glob(File.join(Oddb2xml::WorkDir, 'oddb_*.tar.gz')).first.should be_nil
|
177
243
|
Dir.glob(File.join(Oddb2xml::WorkDir, 'oddb_*.zip')).first.should be_nil
|
178
244
|
end
|
179
245
|
it 'should create xml files' do
|
180
|
-
|
246
|
+
@cli_output.should match(/Pharma/)
|
181
247
|
expected = [
|
182
248
|
'oddb_fi.xml',
|
183
249
|
'oddb_fi_product.xml',
|
@@ -194,22 +260,24 @@ describe Oddb2xml::Cli do
|
|
194
260
|
end
|
195
261
|
end
|
196
262
|
context 'when -x address option is given' do
|
197
|
-
|
263
|
+
before(:all) do
|
264
|
+
cleanup_directories_before_run
|
198
265
|
options = Oddb2xml::Options.new
|
199
266
|
options.parser.parse!('-x address'.split(' '))
|
200
|
-
Oddb2xml::Cli.new(options.opts)
|
267
|
+
@cli = Oddb2xml::Cli.new(options.opts)
|
268
|
+
@cli_output = buildr_capture(:stdout) { @cli.run }
|
201
269
|
end
|
202
270
|
it_behaves_like 'any interface for address'
|
203
271
|
it 'should have address option' do
|
204
|
-
cli.should have_option(:address=> true)
|
272
|
+
@cli.should have_option(:address=> true)
|
205
273
|
end
|
206
274
|
it 'should not create any compressed file' do
|
207
|
-
|
275
|
+
@cli_output.should match(/addresses/)
|
208
276
|
Dir.glob(File.join(Oddb2xml::WorkDir, 'oddb_*.tar.gz')).first.should be_nil
|
209
277
|
Dir.glob(File.join(Oddb2xml::WorkDir, 'oddb_*.zip')).first.should be_nil
|
210
278
|
end
|
211
279
|
it 'should create xml files' do
|
212
|
-
|
280
|
+
@cli_output.should match(/addresses/)
|
213
281
|
expected = [
|
214
282
|
'oddb_betrieb.xml',
|
215
283
|
'oddb_medizinalperson.xml',
|