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.
data/spec/builder_spec.rb CHANGED
@@ -3,71 +3,240 @@
3
3
  require 'spec_helper'
4
4
  require "rexml/document"
5
5
  include REXML
6
+ RUN_ALL = false
7
+ def checkItemForRefdata(doc, pharmacode, isRefdata)
8
+ article = XPath.match( doc, "//ART[PHAR=#{pharmacode.to_s}]").first
9
+ name = article.elements['DSCRD'].text
10
+ refdata = article.elements['REF_DATA'].text
11
+ smno = article.elements['SMNO'] ? article.elements['SMNO'].text : 'nil'
12
+ puts "checking doc for gtin #{gtin} isRefdata #{isRefdata} == #{refdata}. SMNO: #{smno} #{name}" if $VERBOSE
13
+ article.elements['REF_DATA'].text.should == isRefdata.to_s
14
+ article
15
+ end
6
16
 
7
- module Kernel
8
- def buildr_capture(stream)
9
- begin
10
- stream = stream.to_s
11
- eval "$#{stream} = StringIO.new"
12
- yield
13
- result = eval("$#{stream}").string
14
- ensure
15
- eval "$#{stream} = #{stream.upcase}"
16
- end
17
- result
17
+ def check_article_IGM_format(line, price_kendural=825, add_80_percents=false)
18
+ typ = line[0..1]
19
+ name = line[10..59]
20
+ ckzl = line[72]
21
+ ciks = line[75]
22
+ price_exf = line[60..65].to_i
23
+ price_reseller = line[66..71].to_i
24
+ price_public = line[66..71].to_i
25
+ typ.should eq '11'
26
+ puts "check_article_IGM_format: #{price_exf} #{price_public} CKZL is #{ckzl} CIKS is #{ciks} name #{name} " if $VERBOSE
27
+ found_SL = false
28
+ found_non_SL = false
29
+
30
+ if /7680353660163\d$/.match(line) # KENDURAL Depottabl 30 Stk
31
+ puts "found_SL for #{line}" if $VERBOSE
32
+ found_SL = true
33
+ line[60..65].should eq '000491'
34
+ price_exf.should eq 491
35
+ ckzl.should eq '1'
36
+ price_public.should eq price_kendural # this is a SL-product. Therefore we may not have a price increase
37
+ line[66..71].should eq '000'+price_kendural.to_s # the dat format requires leading zeroes and not point
18
38
  end
19
- end
20
39
 
21
- def setup_package_xlsx_for_calc
22
- src = File.expand_path(File.join(File.dirname(__FILE__), 'data', 'swissmedic_package-galenic.xlsx'))
23
- dest = File.join(Oddb2xml::WorkDir, 'swissmedic_package.xlsx')
24
- FileUtils.makedirs(Oddb2xml::WorkDir)
25
- FileUtils.cp(src, dest, { :verbose => false, :preserve => true})
26
- FileUtils.cp(File.expand_path(File.join(File.dirname(__FILE__), 'data', 'XMLPublications.zip')),
27
- File.join(Oddb2xml::WorkDir, 'downloads'),
28
- { :verbose => false, :preserve => true})
40
+ if /7680403330459\d$/.match(line) # CARBADERM
41
+ found_non_SL = true
42
+ puts "found_non_SL for #{line}" if $VERBOSE
43
+ ckzl.should eq '3'
44
+ if add_80_percents
45
+ price_reseller.should eq 2919 # = 1545*1.8 this is a non SL-product. Therefore we must increase its price as requsted
46
+ line[66..71].should eq '002919' # dat format requires leading zeroes and not poin
47
+ else
48
+ price_reseller.should eq 2770 # this is a non SL-product, but no price increase was requested
49
+ line[66..71].should eq '002770' # the dat format requires leading zeroes and not point
50
+ end
51
+ line[60..65].should eq '001622' # the dat format requires leading zeroes and not point
52
+ price_exf.should eq 1622 # this is a non SL-product, but no price increase was requested
53
+ end
54
+ return [found_SL, found_non_SL]
29
55
  end
30
56
 
31
57
  def check_validation_via_xsd
32
58
  @oddb2xml_xsd = File.expand_path(File.join(File.dirname(__FILE__), '..', 'oddb2xml.xsd'))
59
+ @oddb_calc_xsd = File.expand_path(File.join(File.dirname(__FILE__), '..', 'oddb_calc.xsd'))
33
60
  File.exists?(@oddb2xml_xsd).should eq true
61
+ File.exists?(@oddb_calc_xsd).should eq true
34
62
  files = Dir.glob('*.xml')
35
- xsd = Nokogiri::XML::Schema(File.read(@oddb2xml_xsd))
63
+ xsd_oddb2xml = Nokogiri::XML::Schema(File.read(@oddb2xml_xsd))
64
+ xsd_oddb_calc = Nokogiri::XML::Schema(File.read(@oddb_calc_xsd))
36
65
  files.each{
37
66
  |file|
38
- $stderr.puts "Validating file #{file} with #{File.size(file)} bytes" if $VERBOSE
67
+ next if /#{Time.now.year}/.match(file)
39
68
  doc = Nokogiri::XML(File.read(file))
40
- xsd.validate(doc).each do |error| error.message.should be_nil end
69
+ xsd2use = /oddb_calc/.match(file) ? xsd_oddb_calc : xsd_oddb2xml
70
+ xsd2use.validate(doc).each do
71
+ |error|
72
+ if error.message
73
+ puts "Failed validating #{file} with #{File.size(file)} bytes using XSD from #{@oddb2xml_xsd}"
74
+ end
75
+ error.message.should be_nil
76
+ end
41
77
  }
42
78
  end
79
+
80
+ def checkPrices(increased = false)
81
+ doc = REXML::Document.new File.new(checkAndGetArticleXmlName)
82
+
83
+ sofradex = checkAndGetArticleWithGTIN(doc, Oddb2xml::SOFRADEX_GTIN)
84
+ sofradex.elements["ARTPRI[PTYP='ZURROSE']/PRICE"].text.should eq Oddb2xml::SOFRADEX_PRICE_ZURROSE.to_s
85
+ sofradex.elements["ARTPRI[PTYP='ZURROSEPUB']/PRICE"].text.should eq Oddb2xml::SOFRADEX_PRICE_ZURROSEPUB.to_s
86
+
87
+ lansoyl = checkAndGetArticleWithGTIN(doc, Oddb2xml::LANSOYL_GTIN)
88
+ lansoyl.elements["ARTPRI[PTYP='ZURROSE']/PRICE"].text.should eq Oddb2xml::LANSOYL_PRICE_ZURROSE.to_s
89
+ lansoyl.elements["ARTPRI[PTYP='ZURROSEPUB']/PRICE"].text.should eq Oddb2xml::LANSOYL_PRICE_ZURROSEPUB.to_s
90
+
91
+ desitin = checkAndGetArticleWithGTIN(doc, Oddb2xml::LEVETIRACETAM_GTIN)
92
+ desitin.elements["ARTPRI[PTYP='PPUB']/PRICE"].text.should eq Oddb2xml::LEVETIRACETAM_PRICE_PPUB.to_s
93
+ desitin.elements["ARTPRI[PTYP='ZURROSE']/PRICE"].text.should eq Oddb2xml::LEVETIRACETAM_PRICE_ZURROSE.to_s
94
+ desitin.elements["ARTPRI[PTYP='ZURROSEPUB']/PRICE"].text.to_f.should eq Oddb2xml::LEVETIRACETAM_PRICE_PPUB.to_f
95
+ if increased
96
+ lansoyl.elements["ARTPRI[PTYP='RESELLERPUB']/PRICE"].text.should eq Oddb2xml::LANSOYL_PRICE_RESELLER_PUB.to_s
97
+ sofradex.elements["ARTPRI[PTYP='RESELLERPUB']/PRICE"].text.should eq Oddb2xml::SOFRADEX_PRICE_RESELLER_PUB.to_s
98
+ desitin.elements["ARTPRI[PTYP='RESELLERPUB']/PRICE"].text.should eq Oddb2xml::LEVETIRACETAM_PRICE_RESELLER_PUB.to_s
99
+ else
100
+ lansoyl.elements["ARTPRI[PTYP='RESELLERPUB']"].should eq nil
101
+ sofradex.elements["ARTPRI[PTYP='RESELLERPUB']"].should eq nil
102
+ desitin.elements["ARTPRI[PTYP='RESELLERPUB']"].should eq nil
103
+ end
104
+ end
105
+
106
+ def checkAndGetArticleXmlName(tst=nil)
107
+ article_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_article.xml'))
108
+ File.exists?(article_xml).should eq true
109
+ FileUtils.cp(article_xml, File.join(Oddb2xml::WorkDir, "tst-#{tst}.xml")) if tst
110
+ article_xml
111
+ end
112
+
113
+ def checkAndGetProductWithGTIN(doc, gtin)
114
+ products = XPath.match( doc, "//PRD[GTIN=#{gtin.to_s}]")
115
+ gtins = XPath.match( doc, "//PRD[GTIN=#{gtin.to_s}]/GTIN")
116
+ gtins.size.should eq 1
117
+ gtins.first.text.should eq gtin.to_s
118
+ # return product
119
+ return products.size == 1 ? products.first : nil
120
+ end
121
+
122
+ def checkAndGetArticleWithGTIN(doc, gtin)
123
+ articles = XPath.match( doc, "//ART[ARTBAR/BC=#{gtin}]")
124
+ gtins = XPath.match( doc, "//ART[ARTBAR/BC=#{gtin}]/ARTBAR/BC")
125
+ gtins.size.should eq 1
126
+ gtins.first.text.should eq gtin.to_s
127
+ gtins.first
128
+ # return article
129
+ return articles.size == 1 ? articles.first : nil
130
+ end
131
+
132
+ def checkArticleXml
133
+ article_filename = checkAndGetArticleXmlName
134
+
135
+ # check articles
136
+ doc = REXML::Document.new IO.read(article_filename)
137
+ checkAndGetArticleWithGTIN(doc, Oddb2xml::THREE_TC_GTIN)
138
+ desitin = checkAndGetArticleWithGTIN(doc, Oddb2xml::LEVETIRACETAM_GTIN)
139
+ desitin.should_not eq nil
140
+ # TODO: why is this now nil? desitin.elements['ATC'].text.should == 'N03AX14'
141
+ desitin.elements['DSCRD'].text.should == "LEVETIRACETAM DESITIN Mini Filmtab 250 mg 30 Stk"
142
+ desitin.elements['DSCRF'].text.should == 'LEVETIRACETAM DESITIN mini cpr pel 250 mg 30 pce'
143
+ desitin.elements['REF_DATA'].text.should == '1'
144
+ desitin.elements['PHAR'].text.should == '5819012'
145
+ desitin.elements['SMCAT'].text.should == 'B'
146
+ desitin.elements['SMNO'].text.should == '62069008'
147
+ desitin.elements['VAT'].text.should == '2'
148
+ desitin.elements['PRODNO'].text.should == '620691'
149
+ desitin.elements['SALECD'].text.should == 'A'
150
+ desitin.elements['CDBG'].text.should == 'N'
151
+ desitin.elements['BG'].text.should == 'N'
152
+
153
+ erythrocin_gtin = '7680202580475' # picked up from zur rose
154
+ erythrocin = checkAndGetArticleWithGTIN(doc, erythrocin_gtin)
155
+ erythrocin.elements['DSCRD'].text.should == "ERYTHROCIN i.v. Trockensub 1000 mg Amp"
156
+
157
+ lansoyl = checkAndGetArticleWithGTIN(doc, Oddb2xml::LANSOYL_GTIN)
158
+ lansoyl.elements['DSCRD'].text.should eq 'LANSOYL Gel 225 g'
159
+ lansoyl.elements['REF_DATA'].text.should eq '1'
160
+ lansoyl.elements['SMNO'].text.should eq '32475019'
161
+ lansoyl.elements['PHAR'].text.should eq '0023722'
162
+ lansoyl.elements['ARTCOMP/COMPNO'].text.should == '7601001002012'
163
+
164
+ zyvoxid = checkAndGetArticleWithGTIN(doc, Oddb2xml::ZYVOXID_GTIN)
165
+ zyvoxid.elements['DSCRD'].text.should eq 'ZYVOXID Filmtabl 600 mg 10 Stk'
166
+
167
+ XPath.match( doc, "//LIMPTS" ).size.should >= 1
168
+ # TODO: desitin.elements['QTY'].text.should eq '250 mg'
169
+ end
170
+
171
+ def checkProductXml
172
+ product_filename = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_product.xml'))
173
+ File.exists?(product_filename).should eq true
174
+
175
+ # check products
176
+ doc = REXML::Document.new IO.read(product_filename)
177
+ desitin = checkAndGetProductWithGTIN(doc, Oddb2xml::LEVETIRACETAM_GTIN)
178
+ desitin.elements['ATC'].text.should == 'N03AX14'
179
+ desitin.elements['DSCRD'].text.should == "Levetiracetam DESITIN Minipacks mit Mini-Filmtabl 250 mg "
180
+ desitin.elements['DSCRF'].text.should == 'Levetiracetam DESITIN minipacks avec cpr pell mini 250 mg '
181
+ desitin.elements['PRODNO'].text.should eq '620691'
182
+ desitin.elements['IT'].text.should eq '01.07.1.'
183
+ desitin.elements['PackGrSwissmedic'].text.should eq '30'
184
+ desitin.elements['EinheitSwissmedic'].text.should eq 'Tablette(n)'
185
+ desitin.elements['SubstanceSwissmedic'].text.should eq 'levetiracetamum'
186
+ desitin.elements['CompositionSwissmedic'].text.should eq 'levetiracetamum 250 mg, excipiens pro compressi obducti pro charta.'
187
+
188
+ desitin.elements['CPT/CPTCMP/LINE'].text.should eq '0'
189
+ desitin.elements['CPT/CPTCMP/SUBNO'].text.should eq '8'
190
+ desitin.elements['CPT/CPTCMP/QTY'].text.should eq '250'
191
+ desitin.elements['CPT/CPTCMP/QTYU'].text.should eq 'mg'
192
+
193
+ checkAndGetProductWithGTIN(doc, Oddb2xml::THREE_TC_GTIN)
194
+ checkAndGetProductWithGTIN(doc, Oddb2xml::ZYVOXID_GTIN)
195
+ if $VERBOSE
196
+ puts "checkProductXml #{product_filename} #{File.size(product_filename)} #{File.mtime(product_filename)}"
197
+ puts "checkProductXml has #{XPath.match( doc, "//PRD" ).find_all{|x| true}.size} packages"
198
+ puts "checkProductXml has #{XPath.match( doc, "//GTIN" ).find_all{|x| true}.size} GTIN"
199
+ puts "checkProductXml has #{XPath.match( doc, "//PRODNO" ).find_all{|x| true}.size} PRODNO"
200
+ end
201
+ XPath.match( doc, "//PRD" ).find_all{|x| true}.size.should == NrPackages
202
+ XPath.match( doc, "//GTIN" ).find_all{|x| true}.size.should == NrPackages
203
+ XPath.match( doc, "//PRODNO" ).find_all{|x| true}.size.should == NrProdno
204
+
205
+ hirudoid = checkAndGetProductWithGTIN(doc, Oddb2xml::HIRUDOID_GTIN)
206
+ hirudoid.elements['ATC'].text.should == 'C05BA01' # modified by atc.csv!
207
+ end
208
+
43
209
  describe Oddb2xml::Builder do
44
- NrExtendedArticles = 78
45
- NrPharmaAndNonPharmaArticles = 60
46
- NrPharmaArticles = 5
47
- NrPackages = 18
210
+ NrExtendedArticles = 86
211
+ NrNonPharmaArticles = 66
212
+ NrPharmaArticles = 8
213
+ NrSubstances = 12
214
+ NrProdno = 20
215
+ NrPackages = 21
216
+ RegExpDesitin = /1125819012LEVETIRACETAM DESITIN Mini Filmtab 250 mg 30 Stk/
48
217
  include ServerMockHelper
49
- before(:each) do
218
+ def common_run_init
50
219
  @savedDir = Dir.pwd
51
220
  cleanup_directories_before_run
52
- setup_server_mocks
53
221
  Dir.chdir Oddb2xml::WorkDir
222
+ VCR.eject_cassette; VCR.insert_cassette('oddb2xml')
54
223
  end
55
- after(:each) do
224
+
225
+ after(:all) do
56
226
  Dir.chdir @savedDir if @savedDir and File.directory?(@savedDir)
57
227
  end
58
- context 'fachinfo' do
59
- let(:cli) do
60
- opts = {}
61
- @oddb_fi_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_fi.xml'))
62
- @oddb_fi_product_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_fi_product.xml'))
63
- options = Oddb2xml::Options.new
64
- options.parser.parse!(['-o'])
65
- Oddb2xml::Cli.new(options.opts)
228
+ if RUN_ALL
229
+ context 'when -o for fachinfo is given' do
230
+ before(:all) do
231
+ common_run_init
232
+ @oddb_fi_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_fi.xml'))
233
+ @oddb_fi_product_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_fi_product.xml'))
234
+ options = Oddb2xml::Options.new
235
+ options.parser.parse!(['-o'])
236
+ @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options.opts).run }
66
237
  end
67
238
 
68
239
  it 'should return produce a correct oddb_fi.xml' do
69
- # res = buildr_capture(:stdout){ cli.run }
70
- cli.run
71
240
  File.exists?(@oddb_fi_xml).should eq true
72
241
  inhalt = IO.read(@oddb_fi_xml)
73
242
  /<KMP/.match(inhalt.to_s).to_s.should eq '<KMP'
@@ -75,141 +244,60 @@ describe Oddb2xml::Builder do
75
244
  m = /<paragraph><!\[CDATA\[(.+)\n(.*)/.match(inhalt.to_s)
76
245
  m[1].should eq '<?xml version="1.0" encoding="utf-8"?><div xmlns="http://www.w3.org/1999/xhtml">'
77
246
  expected = '<p class="s2"> </p>'
78
- m[2].should eq '<p class="s2"> </p>'
247
+ m[2].should eq '<p class="s4" id="section1"><span class="s2"><span>Zyvoxid</span></span><sup class="s3"><span>®</span></sup></p>'
79
248
  File.exists?(@oddb_fi_product_xml).should eq true
80
249
  inhalt = IO.read(@oddb_fi_product_xml)
81
- skip "Niklaus does not know how to create a valid oddb_fi_product.xml"
82
- check_validation_via_xsd
83
- end
84
- end
85
-
86
- context 'XSD-generation: ' do
87
- let(:cli) do
88
- opts = {}
89
- @oddb2xml_xsd = File.expand_path(File.join(File.dirname(__FILE__), '..', 'oddb2xml.xsd'))
90
- @article_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_article.xml'))
91
- @product_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_product.xml'))
92
- options = Oddb2xml::Options.new
93
- options.parser.parse!([])
94
- Oddb2xml::Cli.new(options.opts)
95
250
  end
96
251
 
97
- it 'should return true when validating xml against oddb2xml.xsd' do
98
- res = buildr_capture(:stdout){ cli.run }
99
- File.exists?(@article_xml).should eq true
100
- File.exists?(@product_xml).should eq true
101
- check_validation_via_xsd
102
- end
103
- end
104
-
105
- context 'should handle BAG-articles with and without pharmacode' do
106
- it {
107
- dat = File.read(File.expand_path('../data/Preparations.xml', __FILE__))
108
- @items = Oddb2xml::BagXmlExtractor.new(dat).to_hash
109
- saved = @items.clone
110
- expect(@items.size).to eq(5)
111
- expect(saved).to eq(@items)
112
- }
113
- end
114
-
115
- context 'when no option is given' do
116
- let(:cli) do
117
- options = Oddb2xml::Options.new
118
- options.parser.parse!([])
119
- Oddb2xml::Cli.new(options.opts)
252
+ it 'should produce valid xml files' do
253
+ skip "Niklaus does not know how to create a valid oddb_fi_product.xml"
254
+ # check_validation_via_xsd
120
255
  end
121
256
 
122
- it 'should pass validating via oddb2xml.xsd' do
123
- check_validation_via_xsd
124
- end
125
-
126
257
  it 'should generate a valid oddb_product.xml' do
127
- res = buildr_capture(:stdout){ cli.run }
128
- res.should match(/products/)
129
- @article_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_article.xml'))
130
- File.exists?(@article_xml).should eq true
131
- article_xml = IO.read(@article_xml)
132
- product_filename = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_product.xml'))
133
- File.exists?(product_filename).should eq true
134
- unless /1\.8\.7/.match(RUBY_VERSION)
135
- product_xml = IO.read(product_filename)
136
- article_xml.should match(/3TC/)
137
- article_xml.should match(/<PHAR>1699947</)
138
- article_xml.should match(/<SMNO>53662013</)
139
- article_xml.should match(/<DSCRD>3TC Filmtabl 150 mg</)
140
- article_xml.should match(/<COMPNO>7601001392175</)
141
- article_xml.should match(/<BC>7680536620137</)
142
- article_xml.should match(/<VDAT>01.10.2011</)
143
- article_xml.should match(/<PTYP>PEXF</)
144
- article_xml.should match(/<PRICE>164.55</)
145
- article_xml.should match(/<PTYP>PPUB</)
146
- article_xml.should match(/<PRICE>205.3</)
147
- article_xml.should match(/Levetiracetam DESITIN/i) #
148
- article_xml.should match(/7680536620137/) # Pharmacode
149
- article_xml.should match(/<PRICE>13.49</)
150
- article_xml.should match(/<PRICE>27.8</)
151
-
152
- product_xml.should match(/3TC/)
153
- product_xml.should match(/7680620690084/) # Levetiracetam DESITIN
154
- product_xml.match(/<DSCRD>3TC Filmtabl 150 mg/).should_not == nil
155
- product_xml.match(/<GTIN>7680620690084/).should_not == nil
156
- product_xml.match(/<DSCRD>Levetiracetam DESITIN Filmtabl 250 mg/).should_not == nil
157
- product_xml.match(/<DSCRF>Levetiracetam DESITIN cpr pell 250 mg/).should_not == nil
158
- product_xml.match(/<SubstanceSwissmedic>levetiracetamum</)
159
- product_xml.match(/<CompositionSwissmedic>levetiracetamum 250 mg, excipiens pro compressi obducti pro charta.</).should_not == nil
160
- article_xml.scan(/<ART DT=/).size.should eq(NrPharmaArticles)
161
- article_xml.should match(/<PHAR>5819012</)
162
- article_xml.should match(/<DSCRD>LEVETIRACETAM DESITIN Filmtabl 250 mg/)
163
- article_xml.should match(/<COMPNO>7601001320451</)
164
-
165
- doc = REXML::Document.new File.new(product_filename)
166
- XPath.match( doc, "//PRD[GTIN='7680620690084']/ATC").first.text.should == 'N03AX14'
167
- XPath.match( doc, "//PRD[GTIN='7680161050583']/ATC").first.text.should == 'C05BA01' # modified by atc.csv!
168
- end
258
+ @res.should match(/products/)
259
+ checkProductXml
169
260
  end
170
261
  end
171
262
 
172
263
  context 'when -f dat is given' do
173
- let(:cli) do
264
+ before(:all) do
265
+ common_run_init
174
266
  options = Oddb2xml::Options.new
175
- options.parser.parse!('-f dat'.split(' '))
176
- Oddb2xml::Cli.new(options.opts)
267
+ options.parser.parse!('-f dat --log'.split(' '))
268
+ @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options.opts).run }
177
269
  end
178
270
 
179
271
  it 'should contain the correct values fo CMUT from zurrose_transfer.dat' do
180
- res = buildr_capture(:stdout){ cli.run }
181
- res.should match(/products/)
272
+ @res.should match(/products/)
182
273
  dat_filename = File.join(Oddb2xml::WorkDir, 'oddb.dat')
183
274
  File.exists?(dat_filename).should eq true
184
275
  oddb_dat = IO.read(dat_filename)
185
276
  oddb_dat.should match(/^..2/), "should have a record with '2' in CMUT field"
186
277
  oddb_dat.should match(/^..3/), "should have a record with '3' in CMUT field"
187
- oddb_dat.should match(/1115819012LEVETIRACETAM DESITIN Filmtabl 250 mg 30 Stk/), "should have Desitin"
188
- IO.readlines(dat_filename).each{ |line| check_article(line, false, false) }
189
- # oddb_dat.should match(/^..1/), "should have a record with '1' in CMUT field" # we have no
278
+ oddb_dat.should match(RegExpDesitin), "should have Desitin"
279
+ IO.readlines(dat_filename).each{ |line| check_article_IGM_format(line) }
190
280
  end
191
281
  end
192
282
 
193
283
  context 'when --append -f dat is given' do
194
- let(:cli) do
284
+ before(:all) do
285
+ common_run_init
195
286
  options = Oddb2xml::Options.new
196
287
  options.parser.parse!('--append -f dat'.split(' '))
197
- Oddb2xml::Cli.new(options.opts)
288
+ # Oddb2xml::Cli.new(options.opts).run
289
+ @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options.opts).run }
198
290
  end
199
291
 
200
292
  it 'should generate a valid oddb_with_migel.dat' do
201
- res = buildr_capture(:stdout){ cli.run }
202
- res.should match(/products/)
203
293
  dat_filename = File.join(Oddb2xml::WorkDir, 'oddb_with_migel.dat')
204
294
  File.exists?(dat_filename).should eq true
205
295
  oddb_dat = IO.read(dat_filename)
206
- oddb_dat.should match(/1115819012LEVETIRACETAM DESITIN Filmtabl 250 mg 30 Stk/), "should have Desitin"
207
- # oddb_dat.should match(/001349002780100B010710076806206900842/), "should match EAN of Desitin"
296
+ oddb_dat.should match(RegExpDesitin), "should have Desitin"
297
+ @res.should match(/products/)
208
298
  end
209
299
 
210
- it "should match EAN of Desitin. returns 0 at the moment" do
211
- res = buildr_capture(:stdout){ cli.run }
212
- res.should match(/products/)
300
+ it "should match EAN 76806206900842 of Desitin" do
213
301
  dat_filename = File.join(Oddb2xml::WorkDir, 'oddb_with_migel.dat')
214
302
  File.exists?(dat_filename).should eq true
215
303
  oddb_dat = IO.read(dat_filename)
@@ -218,88 +306,65 @@ describe Oddb2xml::Builder do
218
306
  end
219
307
 
220
308
  context 'when --append -I 80 -e is given' do
221
- let(:cli) do
309
+ before(:all) do
310
+ common_run_init
222
311
  options = Oddb2xml::Options.new
223
312
  options.parser.parse!('--append -I 80 -e'.split(' '))
224
- setup_package_xlsx_for_calc
225
- Oddb2xml::Cli.new(options.opts)
313
+ @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options.opts).run }
226
314
  end
227
315
 
228
- it 'should contain the correct prices' do
229
- cleanup_directories_before_run
230
- res = buildr_capture(:stdout){ cli.run }
231
- @article_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_article.xml'))
232
- File.exists?(@article_xml).should eq true
233
- article_xml = IO.read(@article_xml)
234
- product_filename = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_product.xml'))
235
- File.exists?(product_filename).should eq true
236
- doc = REXML::Document.new File.new(@article_xml)
237
- unless /1\.8\.7/.match(RUBY_VERSION)
238
- price_zur_rose_pub = XPath.match( doc, "//ART[DSCRD='SOFRADEX Gtt Auric']/ARTPRI[PTYP='ZURROSEPUB']/PRICE").first.text
239
- price_zur_rose_pub.should eq '15.45'
240
- price_reseller_pub = XPath.match( doc, "//ART[DSCRD='SOFRADEX Gtt Auric']/ARTPRI[PTYP='RESELLERPUB']/PRICE").first.text
241
- price_reseller_pub.should eq '12.9'
242
- price_zur_rose = XPath.match( doc, "//ART[DSCRD='SOFRADEX Gtt Auric']/ARTPRI[PTYP='ZURROSE']/PRICE").first.text
243
- price_zur_rose.should eq '7.18'
244
- end
316
+ it 'should emit a correct oddb_article.xml' do
317
+ checkArticleXml
245
318
  end
246
- end
247
319
 
320
+ it 'should generate a valid oddb_product.xml' do
321
+ @res.should match(/products/)
322
+ checkProductXml
323
+ end
324
+
325
+ it 'should contain the correct (increased) prices' do
326
+ checkPrices(true)
327
+ end
328
+ end
329
+ end
248
330
  context 'when option -e is given' do
249
- let(:cli) do
331
+ before(:all) do
332
+ common_run_init
250
333
  options = Oddb2xml::Options.new
251
334
  options.parser.parse!('-e'.split(' '))
252
- cleanup_directories_before_run
253
- setup_package_xlsx_for_calc
254
335
  Oddb2xml::Cli.new(options.opts)
336
+ @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options.opts).run }
255
337
  end
256
338
 
257
- it 'should contain the correct prices' do
258
- res = buildr_capture(:stdout){ cli.run }
259
- @article_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_article.xml'))
260
- File.exists?(@article_xml).should eq true
261
- article_xml = IO.read(@article_xml)
262
- product_filename = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_product.xml'))
263
- File.exists?(product_filename).should eq true
264
- doc = REXML::Document.new File.new(@article_xml)
265
- unless /1\.8\.7/.match(RUBY_VERSION)
266
- price_zur_rose = XPath.match( doc, "//ART[DSCRD='SOFRADEX Gtt Auric']/ARTPRI[PTYP='ZURROSE']/PRICE").first.text
267
- price_zur_rose.should eq '7.18'
268
- price_zur_rose_pub = XPath.match( doc, "//ART[DSCRD='SOFRADEX Gtt Auric']/ARTPRI[PTYP='ZURROSEPUB']/PRICE").first.text
269
- price_zur_rose_pub.should eq '15.45'
270
- price_reseller_pub = XPath.match( doc, "//ART[DSCRD='SOFRADEX Gtt Auric']/ARTPRI[PTYP='RESELLERPUB']/PRICE")
271
- price_reseller_pub.size.should eq 0
272
- end
339
+ it 'should emit a correct oddb_article.xml' do
340
+ checkArticleXml
341
+ end
342
+
343
+ it 'should produce a correct oddb_product.xml' do
344
+ checkProductXml
273
345
  end
274
346
 
275
- def checkItemForRefdata(doc, pharmacode, isRefdata)
276
- article = XPath.match( doc, "//ART[PHAR=#{pharmacode.to_s}]").first
277
- name = article.elements['DSCRD'].text
278
- refdata = article.elements['REF_DATA'].text
279
- smno = article.elements['SMNO'] ? article.elements['SMNO'].text : 'nil'
280
- puts "checking doc for pharmacode #{pharmacode} isRefdata #{isRefdata} == #{refdata}. SMNO: #{smno} #{name}" if $VERBOSE
281
- article.elements['REF_DATA'].text.should == isRefdata.to_s
347
+ it 'should report correct output on stdout' do
348
+ @res.should match(/NonPharma products/)
349
+ @res.should match(/NonPharma products: #{NrNonPharmaArticles}/)
350
+ end
282
351
 
352
+ it 'should contain the correct (normal) prices' do
353
+ checkPrices(false)
283
354
  end
284
355
 
285
356
  it 'should generate the flag non-refdata' do
286
- res = buildr_capture(:stdout){ cli.run }
287
- @article_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_article.xml'))
288
- File.exists?(@article_xml).should eq true
289
- FileUtils.cp(@article_xml, File.join(Oddb2xml::WorkDir, 'tst-non-refdata.xml'))
290
- article_xml = IO.read(@article_xml)
291
- doc = REXML::Document.new File.new(@article_xml)
357
+ doc = REXML::Document.new File.new(checkAndGetArticleXmlName('non-refdata'))
292
358
  XPath.match( doc, "//REF_DATA" ).size.should > 0
293
359
  checkItemForRefdata(doc, "1699947", 1) # 3TC Filmtabl 150 mg SMNO 53662013 IKSNR 53‘662, 53‘663
294
- checkItemForRefdata(doc, "0028470", 0) # Complamin
295
- checkItemForRefdata(doc, "3036984", 1) # NovoPen 4 Injektionsgerät blue In NonPharma (a MiGel product)
360
+ checkItemForRefdata(doc, "0598003", 0) # SOFRADEX Gtt Auric 8 ml
296
361
  checkItemForRefdata(doc, "5366964", 1) # 1-DAY ACUVUE moist jour
362
+ novopen = checkItemForRefdata(doc, "3036984", 0) # NovoPen 4 Injektionsgerät blue In NonPharma (a MiGel product)
363
+ expect(novopen.elements['ARTBAR/BC'].text).to eq '0'
297
364
  end
298
365
 
299
366
  it 'should generate SALECD A for migel (NINCD 13)' do
300
- res = buildr_capture(:stdout){ cli.run }
301
- @article_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_article.xml'))
302
- doc = REXML::Document.new File.new(@article_xml)
367
+ doc = REXML::Document.new File.new(checkAndGetArticleXmlName)
303
368
  article = XPath.match( doc, "//ART[ARTINS/NINCD=13]").first
304
369
  article = XPath.match( doc, "//ART[PHAR=5366964]").first
305
370
  article.elements['SALECD'].text.should == 'A'
@@ -309,28 +374,16 @@ describe Oddb2xml::Builder do
309
374
  it 'should pass validating via oddb2xml.xsd' do
310
375
  check_validation_via_xsd
311
376
  end
312
-
377
+
313
378
  it 'should not contain veterinary iksnr 47066 CANIPHEDRIN' do
314
- res = buildr_capture(:stdout){ cli.run }
315
- res.should match(/NonPharma/i)
316
- res.should match(/NonPharma products: #{NrPharmaAndNonPharmaArticles}/)
317
- @article_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_article.xml'))
318
- File.exists?(@article_xml).should eq true
319
- article_xml = IO.read(@article_xml)
320
- doc = REXML::Document.new File.new(@article_xml)
379
+ doc = REXML::Document.new File.new(checkAndGetArticleXmlName)
321
380
  dscrds = XPath.match( doc, "//ART" )
322
381
  XPath.match( doc, "//BC" ).find_all{|x| x.text.match('47066') }.size.should == 0
323
382
  XPath.match( doc, "//DSCRD" ).find_all{|x| x.text.match(/CANIPHEDRIN/) }.size.should == 0
324
383
  end
325
384
 
326
385
  it 'should handle not duplicate pharmacode 5366964' do
327
- res = buildr_capture(:stdout){ cli.run }
328
- res.should match(/NonPharma/i)
329
- res.should match(/NonPharma products: #{NrPharmaAndNonPharmaArticles}/)
330
- @article_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_article.xml'))
331
- File.exists?(@article_xml).should eq true
332
- article_xml = IO.read(@article_xml)
333
- doc = REXML::Document.new File.new(@article_xml)
386
+ doc = REXML::Document.new File.new(checkAndGetArticleXmlName)
334
387
  dscrds = XPath.match( doc, "//ART" )
335
388
  XPath.match( doc, "//PHAR" ).find_all{|x| x.text.match('5366964') }.size.should == 1
336
389
  dscrds.size.should == NrExtendedArticles
@@ -339,275 +392,134 @@ describe Oddb2xml::Builder do
339
392
  end
340
393
 
341
394
  it 'should load correct number of nonpharma' do
342
- res = buildr_capture(:stdout){ cli.run }
343
- res.should match(/NonPharma/i)
344
- res.should match(/NonPharma products: #{NrPharmaAndNonPharmaArticles}/)
345
- @article_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_article.xml'))
346
- File.exists?(@article_xml).should eq true
347
- article_xml = IO.read(@article_xml)
348
- doc = REXML::Document.new File.new(@article_xml)
395
+ doc = REXML::Document.new File.new(checkAndGetArticleXmlName)
349
396
  dscrds = XPath.match( doc, "//ART" )
350
397
  dscrds.size.should == NrExtendedArticles
351
398
  XPath.match( doc, "//PHAR" ).find_all{|x| x.text.match('1699947') }.size.should == 1 # swissmedic_packages Cardio-Pulmo-Rénal Sérocytol, suppositoire
352
- XPath.match( doc, "//PHAR" ).find_all{|x| x.text.match('2465312') }.size.should == 1 # from swissindex_pharma.xml"
353
- XPath.match( doc, "//PHAR" ).find_all{|x| x.text.match('0000000') }.size.should == 1 # from swissindex_pharma.xml
399
+ XPath.match( doc, "//PHAR" ).find_all{|x| x.text.match('2465312') }.size.should == 1 # from refdata_pharma.xml"
400
+ XPath.match( doc, "//PHAR" ).find_all{|x| x.text.match('0000000') }.size.should == 1 # from refdata_pharma.xml
354
401
  end
355
402
 
356
403
  it 'should emit a correct oddb_limitation.xml' do
357
- res = buildr_capture(:stdout){ cli.run }
358
404
  # check limitations
359
405
  limitation_filename = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_limitation.xml'))
360
406
  File.exists?(limitation_filename).should eq true
361
- limitation_xml = IO.read(limitation_filename)
362
- limitation_xml.should match(/Die aufgeführten Präparat/)
363
407
  doc = REXML::Document.new File.new(limitation_filename)
364
408
  limitations = XPath.match( doc, "//LIM" )
365
- limitations.size.should == 4
409
+ limitations.size.should >= 4
366
410
  XPath.match( doc, "//SwissmedicNo5" ).find_all{|x| x.text.match('28486') }.size.should == 1
367
- XPath.match( doc, "//Pharmacode" ).find_all{|x| x.text.match('3817150') }.size.should == 2
368
- XPath.match( doc, "//LIMNAMEBAG" ).find_all{|x| x.text.match('ALFARÉ') }.size.should == 1
369
- XPath.match( doc, "//LIMNAMEBAG" ).find_all{|x| x.text.match('070110') }.size.should == 1
370
- end
371
-
372
- it 'should emit a correct oddb_article.xml' do
373
- res = buildr_capture(:stdout){ cli.run }
374
- @article_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_article.xml'))
375
- File.exists?(@article_xml).should eq true
376
- article_xml = IO.read(@article_xml)
377
- doc = REXML::Document.new File.new(@article_xml)
378
- unless /1\.8\.7/.match(RUBY_VERSION)
379
- # check articles
380
- article_xml.should match(/3TC/)
381
- article_xml.should match(/<PHAR>1699947</)
382
- article_xml.should match(/<SMNO>53662013</)
383
- article_xml.should match(/<DSCRD>3TC Filmtabl 150 mg</)
384
- article_xml.should match(/<COMPNO>7601001392175</)
385
- article_xml.should match(/<BC>7680536620137</)
386
- article_xml.should match(/<VDAT>01.10.2011</)
387
- article_xml.should match(/<PTYP>PEXF</)
388
- article_xml.should match(/<PRICE>164.55</)
389
- article_xml.should match(/<PTYP>PPUB</)
390
- article_xml.should match(/<PRICE>205.3</)
391
- article_xml.should match(/Levetiracetam DESITIN/i) #
392
- article_xml.should match(/7680536620137/) # Pharmacode
393
- article_xml.should match(/<PRICE>13.49</)
394
- article_xml.should match(/<PRICE>27.8</)
395
- article_xml.scan(/<ART DT=/).size.should eq(NrExtendedArticles) # we should find some articles
396
- article_xml.should match(/<PHAR>5819012</)
397
- article_xml.should match(/<DSCRD>LEVETIRACETAM DESITIN Filmtabl 250 mg/)
398
- article_xml.should match(/<COMPNO>7601001320451</)
399
- # check ZYVOXID in article
400
- article_xml.should match(/7680555580054/) # ZYVOXID
401
- article_xml.should match(/ZYVOXID/i)
402
-
403
- doc = REXML::Document.new File.new @article_xml
404
- dscrds = XPath.match( doc, "//DSCRD" )
405
- dscrds.find_all{|x| x.text.match('ZYVOXID Filmtabl 600 mg') }.size.should == 1
406
-
407
- end
408
- #pending 'Checking for LIMPTS' # XPath.match( doc, "//LIMPTS" ).size.should == 1
411
+ XPath.match( doc, "//LIMNAMEBAG" ).find_all{|x| x.text.match('ZYVOXID') }.size.should == 1
412
+ XPath.match( doc, "//LIMNAMEBAG" ).find_all{|x| x.text.match('070240') }.size.should == 1
413
+ XPath.match( doc, "//DSCRD" ).find_all{|x| x.text.match(/^Gesamthaft zugelassen/) }.size.should == 1
414
+ XPath.match( doc, "//DSCRD" ).find_all{|x| x.text.match(/^Behandlung nosokomialer Pneumonien/) }.size.should == 1
409
415
  end
410
416
 
411
417
  it 'should emit a correct oddb_substance.xml' do
412
- res = buildr_capture(:stdout){ cli.run }
413
418
  doc = REXML::Document.new File.new(File.join(Oddb2xml::WorkDir, 'oddb_substance.xml'))
414
419
  names = XPath.match( doc, "//NAML" )
415
- names.size.should == 11
420
+ names.size.should == NrSubstances
416
421
  names.find_all{|x| x.text.match('Lamivudinum') }.size.should == 1
417
422
  end
418
423
 
419
424
  it 'should emit a correct oddb_interaction.xml' do
420
- res = buildr_capture(:stdout){ cli.run }
421
425
  doc = REXML::Document.new File.new(File.join(Oddb2xml::WorkDir, 'oddb_interaction.xml'))
422
426
  titles = XPath.match( doc, "//TITD" )
423
- titles.size.should == 2
424
- titles.find_all{|x| x.text.match('Keine Interaktion') }.size.should == 1
427
+ titles.size.should eq 5
428
+ titles.find_all{|x| x.text.match('Keine Interaktion') }.size.should >= 1
425
429
  titles.find_all{|x| x.text.match('Erhöhtes Risiko für Myopathie und Rhabdomyolyse') }.size.should == 1
426
430
  end
427
431
 
428
- it 'should emit a correct oddb_product.xml' do
429
- res = buildr_capture(:stdout){ cli.run }
430
- res.should match(/products/)
431
- product_filename = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_product.xml'))
432
- File.exists?(product_filename).should eq true
433
-
434
- unless /1\.8\.7/.match(RUBY_VERSION)
435
- # check articles
436
-
437
- # check products
438
- product_xml = IO.read(product_filename)
439
- product_xml.should match(/3TC/)
440
- product_xml.should match(/7680620690084/) # Levetiracetam DESITIN
441
-
442
- product_xml.should match(/7680555580054/) # ZYVOXID
443
- product_xml.should_not match(/ZYVOXID/i)
444
- end
445
- doc = REXML::Document.new File.new(product_filename)
446
- XPath.match( doc, "//PRD" ).find_all{|x| true}.size.should == NrPackages
447
- XPath.match( doc, "//GTIN" ).find_all{|x| true}.size.should == NrPackages
448
- XPath.match( doc, "//PRODNO" ).find_all{|x| true}.size.should == 1
449
- end
450
-
451
- def checkItemForSALECD(doc, pharmacode, expected)
452
- article = XPath.match( doc, "//ART[PHAR=#{pharmacode.to_s}]").first
432
+ def checkItemForSALECD(doc, ean13, expected)
433
+ article = XPath.match( doc, "//ART[ARTBAR/BC=#{ean13.to_s}]").first
453
434
  name = article.elements['DSCRD'].text
454
435
  salecd = article.elements['SALECD'].text
455
436
  if $VERBOSE or article.elements['SALECD'].text != expected.to_s
456
- puts "checking doc for pharmacode #{pharmacode} expected #{expected} == #{salecd}. #{name}"
437
+ puts "checking doc for ean13 #{ean13} expected #{expected} == #{salecd}. #{name}"
457
438
  puts article.text
458
439
  end
459
440
  article.elements['SALECD'].text.should == expected.to_s
460
441
  end
442
+
461
443
  it 'should generate the flag SALECD' do
462
- res = buildr_capture(:stdout){ cli.run }
463
444
  @article_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_article.xml'))
464
445
  File.exists?(@article_xml).should eq true
465
446
  FileUtils.cp(@article_xml, File.join(Oddb2xml::WorkDir, 'tst-SALECD.xml'))
466
447
  article_xml = IO.read(@article_xml)
467
448
  doc = REXML::Document.new File.new(@article_xml)
468
449
  XPath.match( doc, "//REF_DATA" ).size.should > 0
469
- checkItemForSALECD(doc, "0020244", 'A') # FERRO-GRADUMET Depottabl 30 Stk
470
- checkItemForSALECD(doc, "0598003", 'I') # SOFRADEX
450
+ checkItemForSALECD(doc, Oddb2xml::FERRO_GRADUMET_GTIN, 'A') # FERRO-GRADUMET Depottabl 30 Stk
451
+ checkItemForSALECD(doc, Oddb2xml::SOFRADEX_GTIN, 'I') # SOFRADEX
471
452
  end
472
453
  end
473
-
474
- context 'testing -e option' do
475
- let(:cli) do
476
- options = Oddb2xml::Options.new
477
- options.parser.parse!('-e --skip-download'.split(' '))
478
- setup_package_xlsx_for_calc
479
- Oddb2xml::Cli.new(options.opts)
480
- end
481
-
482
- let(:cli_I80) do
454
+ if RUN_ALL
455
+ context 'testing -e -I 80 option' do
456
+ before(:all) do
457
+ common_run_init
483
458
  options = Oddb2xml::Options.new
484
- options.parser.parse!('-e -I 80 --skip-download'.split(' '))
485
- setup_package_xlsx_for_calc
486
- Oddb2xml::Cli.new(options.opts)
459
+ options.parser.parse!('-e -I 80'.split(' '))
460
+ @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options.opts).run }
487
461
  end
488
- search_path_reseller = "//ART[PHAR=0023722]/ARTPRI[PTYP='RESELLERPUB']/PRICE"
489
- search_path_rose = "//ART[PHAR=0023722]/ARTPRI[PTYP='ZURROSE']/PRICE"
490
- search_path_pub = "//ART[PHAR=0023722]/ARTPRI[PTYP='ZURROSEPUB']/PRICE"
491
- # sl-entries have a PPUB price
492
- search_path_desitin = "//ART[SMNO='62069008']/ARTPRI[PTYP='PPUB']/PRICE"
493
462
 
494
- it 'should should return the ZurRose prive if -e' do
495
- res = buildr_capture(:stdout){ cli.run }
496
- @article_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_article.xml'))
497
- File.exists?(@article_xml).should eq true
498
- FileUtils.cp(@article_xml, File.join(Oddb2xml::WorkDir, 'tst-e.xml'))
499
- article_xml = IO.read(@article_xml)
500
- doc = REXML::Document.new File.new(@article_xml)
501
- XPath.match( doc, "//REF_DATA" ).size.should > 0
502
- article = XPath.match( doc, "//ART[PHAR=0023722]").first
503
- name = article.elements['DSCRD'].text
504
- refdata = article.elements['REF_DATA'].text
505
- smno = article.elements['SMNO'] ? article.elements['SMNO'].text : 'nil'
506
- XPath.match( doc, search_path_rose).size.should eq 1
507
- XPath.match( doc, search_path_rose).first.text.should eq '9.85'
508
- XPath.match( doc, search_path_reseller).size.should eq 0
509
- price = 15.20 # This is the zurrose pub price.
510
- XPath.match( doc, search_path_pub).first.text.to_f.should eq price
511
- XPath.match( doc, search_path_desitin).first.text.should eq '27.8'
512
- end
513
-
514
- it 'should add 80 percent to zur_rose pubbprice if -I 80' do
515
- res = buildr_capture(:stdout){ cli_I80.run }
463
+ it 'should add 80 percent to zur_rose pubbprice' do
516
464
  @article_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_article.xml'))
517
465
  File.exists?(@article_xml).should eq true
518
466
  FileUtils.cp(@article_xml, File.join(Oddb2xml::WorkDir, 'tst-e80.xml'))
519
- article_xml = IO.read(@article_xml)
520
- doc = REXML::Document.new File.new(@article_xml)
521
- article = XPath.match( doc, "//ART[PHAR=0023722]").first
522
- name = article.elements['DSCRD'].text
523
- refdata = article.elements['REF_DATA'].text
524
- smno = article.elements['SMNO'] ? article.elements['SMNO'].text : 'nil'
525
- XPath.match( doc, search_path_rose).size.should eq 1
526
- XPath.match( doc, search_path_rose).first.text.should eq '9.85'
527
- XPath.match( doc, search_path_pub).first.text
528
- XPath.match( doc, search_path_pub).first.text.should eq '15.20'
529
- XPath.match( doc, search_path_reseller).size.should eq 1
530
- XPath.match( doc, search_path_reseller).first.text.should eq '17.75'
531
-
532
- XPath.match( doc, search_path_desitin).first.text.should eq '27.8'
533
-
534
- # sl-entries have a PPUB price, but no ZURROSEPUB, and vice versa
535
- XPath.match( doc, "//ART[PHAR=0023722]/ARTPRI[PTYP='PPUB']").size.should eq 0
536
- XPath.match( doc, "//ART[SMNO='62069008']/ARTPRI[PTYP='ZURROSEPUB']").size.should eq 0
537
- XPath.match( doc, "//ART[SMNO='62069008']/ARTPRI[PTYP='RESELLERPUB']").size.should eq 0
467
+ checkProductXml
468
+ checkArticleXml
469
+ checkPrices(true)
538
470
  end
539
- end
540
471
 
541
- # Check IGM-Format
542
- def check_article(line, check_prices = false, add_80_percents=0)
543
- typ = line[0..1]
544
- name = line[10..59]
545
- ckzl = line[72]
546
- ciks = line[75]
547
- price_exf = line[60..65].to_i
548
- price_reseller = line[66..71].to_i
549
- price_public = line[66..71].to_i
550
- typ.should eq '11'
551
- puts "check_article: #{price_doctor} #{price_public} CKZL is #{ckzl} CIKS is #{ciks} name #{name} " if $VERBOSE
552
- return unless check_prices
553
- if /11116999473TC/.match(line)
554
- line[60..65].should eq '016455'
555
- price_exf.should eq 16455
556
- ckzl.should eq '1'
557
- price_public.should eq 20530 # this is a SL-product. Therefore we may not have a price increase
558
- line[66..71].should eq '020530' # the dat format requires leading zeroes and not point
559
- end
560
- if /1130598003SOFRADEX/.match(line)
561
- # 1130598003SOFRADEX Gtt Auric 8 ml 000718001545300B120130076803169501572
562
- ckzl.should eq '3'
563
- if add_80_percents
564
- price_reseller.should eq 1292 # = 1545*1.8 this is a non SL-product. Therefore we must increase its price as requsted
565
- line[66..71].should eq '001292' # dat format requires leading zeroes and not poin
566
- else
567
- price_reseller.should eq 718 # this is a non SL-product, but no price increase was requested
568
- line[66..71].should eq '000718' # the dat format requires leading zeroes and not point
569
- end if false
570
- line[60..65].should eq '000718' # the dat format requires leading zeroes and not point
571
- price_exf.should eq 718 # this is a non SL-product, but no price increase was requested
472
+ it 'should generate a correct oddb_product.xml' do
473
+ checkProductXml
474
+ end
475
+ it 'should generate a correct oddb_article.xml' do
476
+ checkArticleXml
572
477
  end
573
478
  end
574
479
 
575
480
  context 'when -f dat -p is given' do
576
- let(:cli) do
481
+ before(:all) do
482
+ common_run_init
577
483
  options = Oddb2xml::Options.new
578
484
  options.parser.parse!('-f dat -p'.split(' '))
579
- Oddb2xml::Cli.new(options.opts)
485
+ @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options.opts).run }
486
+ end
487
+
488
+ it 'should report correct number of items' do
489
+ @res.should match(/products/)
580
490
  end
581
491
 
582
492
  it 'should contain the correct values fo CMUT from zurrose_transfer.dat' do
583
- res = buildr_capture(:stdout){ cli.run }
584
- res.should match(/products/)
585
493
  dat_filename = File.join(Oddb2xml::WorkDir, 'oddb.dat')
586
494
  File.exists?(dat_filename).should eq true
587
495
  oddb_dat = IO.read(dat_filename)
588
496
  oddb_dat.should match(/^..2/), "should have a record with '2' in CMUT field"
589
497
  oddb_dat.should match(/^..3/), "should have a record with '3' in CMUT field"
590
- oddb_dat.should match(/1115819012LEVETIRACETAM DESITIN Filmtabl 250 mg 30 Stk/), "should have Desitin"
591
- IO.readlines(dat_filename).each{ |line| check_article(line, true, false) }
498
+ oddb_dat.should match(RegExpDesitin), "should have Desitin"
499
+ IO.readlines(dat_filename).each{ |line| check_article_IGM_format(line) }
592
500
  # oddb_dat.should match(/^..1/), "should have a record with '1' in CMUT field" # we have no
593
501
  end
594
502
  end
595
503
 
596
504
  context 'when -f dat -I 80 is given' do
597
- let(:cli) do
505
+ before(:all) do
506
+ common_run_init
598
507
  options = Oddb2xml::Options.new
599
508
  options.parser.parse!('-f dat -I 80'.split(' '))
600
- Oddb2xml::Cli.new(options.opts)
509
+ @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options.opts).run }
601
510
  end
511
+
512
+ it 'should report correct number of items' do
513
+ @res.should match(/products/)
514
+ end
515
+
602
516
  it 'should contain the corect prices' do
603
- res = buildr_capture(:stdout){ cli.run }
604
- # res = cli.run
605
- res.should match(/products/)
606
517
  dat_filename = File.join(Oddb2xml::WorkDir, 'oddb.dat')
607
518
  File.exists?(dat_filename).should eq true
608
519
  oddb_dat = IO.read(dat_filename)
609
520
  oddb_dat_lines = IO.readlines(dat_filename)
610
- IO.readlines(dat_filename).each{ |line| check_article(line, true, true) }
521
+ IO.readlines(dat_filename).each{ |line| check_article_IGM_format(line, 883, true) }
611
522
  end
612
523
  end
613
524
  end
525
+ end