oddb2xml 2.2.4 → 2.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 84a23f65760db47f4653ff96f2943f0364a4dee1
4
- data.tar.gz: 36e79aaf87df21115e89c3ba2de44c0a761c4cfc
3
+ metadata.gz: 29ab2dd3e034c77a8a14f037099a49e719458003
4
+ data.tar.gz: 90308c0322b82f6237cd3be9156b10d9940296de
5
5
  SHA512:
6
- metadata.gz: 4ff309b8715951736506b8ffa5eb8aae6676fa30510cdc90393dd7fb7e3cca1114ab85b6aaa8f37e280e9f1d19c69d134f3f49f03bfa62d3fdfcdf3e3c8d4550
7
- data.tar.gz: ac32285e7bb4fd698821c7fced89b93edcfc5c53d125070f7e1606bf9a85052166dc31018fbeb713c853a71a66fd4988811f9f15ac38b80965a7db26e2e94837
6
+ metadata.gz: d7a88dca646f60b07c249e6093c5398dd90cdf1b04499300c944fbe1fb2bd314290086f5a242fe388152becbe70e99285f6592c5a864330278b15733487886fc
7
+ data.tar.gz: 90ade83f9f451ee82810b6b781cf1d8cc52f2bc5c395f61f1b459cc707fdf1b5b7fa5720e560ec7928906edc4141a6d317b09628e553291a1caf34b502b4ec9e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- oddb2xml (2.2.4)
4
+ oddb2xml (2.2.5)
5
5
  archive-tar-minitar
6
6
  httpi (>= 2.4.1)
7
7
  mechanize
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ === 2.2.5 / 09.09.2015
2
+
3
+ * Added field GEN_PRODUCTION, INSULIN_CATEGORY and DRUG_INDEX
4
+ * Removed downloads of old BM_update from ywesee, as we have a better info about the drugs now
5
+
1
6
  === 2.2.4 / 09.09.2015
2
7
 
3
8
  * Fixed unit tests error introduced by the new column order of Packungen.xlsx
data/README.md CHANGED
@@ -284,7 +284,6 @@ We use the following files:
284
284
  * https://index.ws.e-mediat.net/Swissindex/NonPharma/ws_Pharma_V101.asmx
285
285
  * http://download.swissmedicinfo.ch/ (AipsDownload)
286
286
  * https://raw.githubusercontent.com/zdavatz/oddb2xml_files/master/LPPV.txt
287
- * https://raw.githubusercontent.com/zdavatz/oddb2xml_files/master/BM_Update.txt
288
287
  * https://raw.githubusercontent.com/epha/robot/master/data/manual/swissmedic/atc.csv
289
288
 
290
289
  ## Rules for matching GTIN (aka EAN13), product number and IKSNR
@@ -703,11 +703,12 @@ module Oddb2xml
703
703
  ean13 = (ean12 + Oddb2xml.calc_checksum(ean12))
704
704
  items[ean13] = info
705
705
  xml.ARTICLE {
706
- xml.GTIN ean13
707
- xml.NAME info.column_c
708
- xml.PKG_SIZE info.pkg_size
709
- xml.SELLING_UNITS info.selling_units
710
- xml.MEASURE info.measure # Nur wenn Lösung wen Spalte M ml, Spritze
706
+ xml.GTIN ean13
707
+ xml.NAME info.column_c
708
+ xml.PKG_SIZE info.pkg_size
709
+ xml.SELLING_UNITS info.selling_units
710
+ xml.MEASURE info.measure # Nur wenn Lösung wen Spalte M ml, Spritze
711
+
711
712
  if info.galenic_form.is_a?(String)
712
713
  xml.GALENIC_FORM info.galenic_form
713
714
  xml.GALENIC_GROUP "Unknown"
@@ -764,7 +765,6 @@ module Oddb2xml
764
765
  ean = obj[:ean]
765
766
  next if pack_info and /Tierarzneimittel/.match(pack_info[:list_code])
766
767
  next if obj[:desc_de] and /ad us vet/i.match(obj[:desc_de])
767
-
768
768
  pharma_code = obj[:pharmacode]
769
769
  ean = 0 if sprintf('%013d', ean).match(/^000000/)
770
770
  if obj[:seq]
@@ -787,7 +787,10 @@ module Oddb2xml
787
787
  #xml.CDS01
788
788
  #xml.CDS02
789
789
  if ppac
790
- xml.SMCAT ppac[:swissmedic_category] unless ppac[:swissmedic_category].empty?
790
+ xml.SMCAT ppac[:swissmedic_category] unless ppac[:swissmedic_category].empty?
791
+ xml.GEN_PRODUCTION ppac[:gen_production] unless ppac[:gen_production].empty?
792
+ xml.INSULIN_CATEGORY ppac[:insulin_category] unless ppac[:insulin_category].empty?
793
+ xml.DRUG_INDEX ppac[:drug_index] unless ppac[:drug_index].empty?
791
794
  end
792
795
  if no8 and !no8.to_s.empty?
793
796
  if ean and ean.to_s[0..3] == "7680"
@@ -817,7 +820,7 @@ module Oddb2xml
817
820
  end
818
821
  #xml.TEMP
819
822
  if ean
820
- flag = @flags[ean.to_s]
823
+ flag = (ppac && !ppac[:drug_index].empty?) ? true : false
821
824
  # as same flag
822
825
  xml.CDBG(flag ? 'Y' : 'N')
823
826
  xml.BG(flag ? 'Y' : 'N')
@@ -1180,6 +1183,9 @@ module Oddb2xml
1180
1183
  next if obj[:type] == :nonpharma
1181
1184
  row = ''
1182
1185
  pack_info = nil
1186
+ if (x = @packs.find{|k,v| v[:ean].to_i == ean})
1187
+ pack_info = x[1]
1188
+ end
1183
1189
  # Oddb2tdat.parse
1184
1190
  pac,no8 = nil,nil
1185
1191
  if obj[:seq] and obj[:seq][:packages]
@@ -1191,7 +1197,6 @@ module Oddb2xml
1191
1197
  # :swissmedic_numbers
1192
1198
  if pac
1193
1199
  no8 = pac[:swissmedic_number8].intern
1194
- pack_info = @packs[no8.intern] if no8
1195
1200
  end
1196
1201
  if pac and pac[:prices] == nil and no8
1197
1202
  ppac = ((ppac = pack_info and ppac[:is_tier]) ? ppac : nil)
@@ -1236,8 +1241,7 @@ module Oddb2xml
1236
1241
  else
1237
1242
  '0'
1238
1243
  end
1239
- row << "%#{DAT_LEN[:CBGG]}s" % if ((pac && pac[:narcosis_flag] == 'Y') or # BAGXml
1240
- (@flags[ean])) # ywesee BM_update
1244
+ row << "%#{DAT_LEN[:CBGG]}s" % if (pack_info && pack_info[:drug_index])
1241
1245
  '3'
1242
1246
  else
1243
1247
  '0'
data/lib/oddb2xml/cli.rb CHANGED
@@ -24,7 +24,6 @@ module Oddb2xml
24
24
  # product
25
25
  @items = {} # Items from Preparations.xml in BAG, using GTINs as key
26
26
  @refdata_types = {} # Base index from refdata
27
- @flags = {} # narcotics flag files repo
28
27
  @lppvs = {} # lppv.txt from files repo
29
28
  @infos = {} # [option] FI from SwissmedicInfo
30
29
  @packs = {} # [option] Packungen from Swissmedic for dat
@@ -63,7 +62,6 @@ module Oddb2xml
63
62
  end
64
63
  threads << download(:zurrose)
65
64
  threads << download(:package) # swissmedic
66
- threads << download(:bm_update) # oddb2xml_files
67
65
  threads << download(:lppv) # oddb2xml_files
68
66
  threads << download(:bag) # bag.e-mediat
69
67
  types.each do |type|
@@ -228,17 +226,6 @@ module Oddb2xml
228
226
  @packs
229
227
  end
230
228
  end
231
- when :bm_update
232
- begin # instead of Thread.new do
233
- downloader = BMUpdateDownloader.new
234
- str = downloader.download
235
- Oddb2xml.log("BMUpdateDownloader str #{str.size} bytes")
236
- @mutex.synchronize do
237
- @flags = BMUpdateExtractor.new(str).to_hash
238
- Oddb2xml.log("BMUpdateExtractor added #{@flags.size} flags")
239
- @flags
240
- end
241
- end
242
229
  when :lppv
243
230
  begin # instead of Thread.new do
244
231
  downloader = LppvDownloader.new
@@ -133,13 +133,6 @@ module Oddb2xml
133
133
  download_as('epha_interactions.csv', 'r')
134
134
  end
135
135
  end
136
- class BMUpdateDownloader < Downloader
137
- include DownloadMethod
138
- def download
139
- @url ||= 'https://raw.githubusercontent.com/zdavatz/oddb2xml_files/master/BM_Update.txt'
140
- download_as('oddb2xml_files_bm_update.txt', 'r')
141
- end
142
- end
143
136
  class LppvDownloader < Downloader
144
137
  include DownloadMethod
145
138
  def download
@@ -28,9 +28,6 @@ module Oddb2xml
28
28
  @xml = xml
29
29
  end
30
30
  end
31
- class BMUpdateExtractor < Extractor
32
- include TxtExtractorMethods
33
- end
34
31
  class LppvExtractor < Extractor
35
32
  include TxtExtractorMethods
36
33
  end
@@ -96,7 +93,6 @@ module Oddb2xml
96
93
  :ean => (ean) ? ean : '',
97
94
  :swissmedic_category => (cat = pac.SwissmedicCategory) ? cat : '',
98
95
  :swissmedic_number8 => (num = pac.SwissmedicNo8) ? num.rjust(8, '0') : '',
99
- :narcosis_flag => (flg = pac.FlagNarcosis) ? flg : '',
100
96
  :prices => { :exf_price => exf, :pub_price => pub },
101
97
  }
102
98
  # related all limitations
@@ -294,6 +290,9 @@ module Oddb2xml
294
290
  :composition_swissmedic => row[comp] ? row[comp].value.to_s : '',
295
291
  :sequence_name => row[seq_name] ? row[seq_name].value.to_s : '',
296
292
  :is_tier => (row[list_code] == 'Tierarzneimittel' ? true : false),
293
+ :gen_production => row[COLUMNS_JULY_2015.keys.index(:gen_production)].value.to_s,
294
+ :insulin_category => row[COLUMNS_JULY_2015.keys.index(:insulin_category)].value.to_s,
295
+ :drug_index => row[COLUMNS_JULY_2015.keys.index(:drug_index)].value.to_s,
297
296
  }
298
297
  end
299
298
  end
@@ -1,3 +1,3 @@
1
1
  module Oddb2xml
2
- VERSION = "2.2.4"
2
+ VERSION = "2.2.5"
3
3
  end
data/oddb2xml.xsd CHANGED
@@ -109,6 +109,9 @@
109
109
  </xs:element>
110
110
  <xs:element ref="ns1:PHAR"/>
111
111
  <xs:element minOccurs="0" ref="ns1:SMCAT"/>
112
+ <xs:element minOccurs="0" name="GEN_PRODUCTION" type="xs:string" />
113
+ <xs:element minOccurs="0" name="INSULIN_CATEGORY" type="xs:string" />
114
+ <xs:element minOccurs="0" name="DRUG_INDEX" type="xs:string" />
112
115
  <xs:element minOccurs="0" ref="ns1:SMNO"/>
113
116
  <xs:element minOccurs="0" ref="ns1:PRODNO"/>
114
117
  <xs:element minOccurs="0" ref="ns1:VAT"/>
data/spec/builder_spec.rb CHANGED
@@ -187,7 +187,7 @@ def checkProductXml
187
187
  desitin.elements['CompositionSwissmedic'].text.should eq 'levetiracetamum 250 mg, excipiens pro compressi obducti pro charta.'
188
188
 
189
189
  desitin.elements['CPT/CPTCMP/LINE'].text.should eq '0'
190
- desitin.elements['CPT/CPTCMP/SUBNO'].text.should eq '8'
190
+ desitin.elements['CPT/CPTCMP/SUBNO'].text.should eq '9'
191
191
  desitin.elements['CPT/CPTCMP/QTY'].text.should eq '250'
192
192
  desitin.elements['CPT/CPTCMP/QTYU'].text.should eq 'mg'
193
193
 
@@ -210,8 +210,8 @@ end
210
210
  describe Oddb2xml::Builder do
211
211
  NrExtendedArticles = 86
212
212
  NrSubstances = 12
213
- NrProdno = 19
214
- NrPackages = 20
213
+ NrProdno = 21
214
+ NrPackages = 22
215
215
  RegExpDesitin = /1125819012LEVETIRACETAM DESITIN Mini Filmtab 250 mg 30 Stk/
216
216
  include ServerMockHelper
217
217
  def common_run_init
@@ -229,23 +229,22 @@ describe Oddb2xml::Builder do
229
229
  common_run_init
230
230
  options = Oddb2xml::Options.new
231
231
  @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options.opts).run }
232
+ # Oddb2xml::Cli.new(options.opts).run # to debug
233
+ @article_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_article.xml'))
234
+ @doc = Nokogiri::XML(File.open(@article_xml))
235
+ @rexml = REXML::Document.new File.read(@article_xml)
232
236
  end
233
237
 
234
238
  it 'should return produce a oddb_article.xml' do
235
- @article_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_article.xml'))
236
239
  File.exists?(@article_xml).should eq true
237
240
  end
238
241
 
239
242
  it 'oddb_article.xml should contain a SHA256' do
240
- @article_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_article.xml'))
241
- content = IO.read(@article_xml)
242
- doc = REXML::Document.new File.new(@article_xml)
243
- expect( XPath.match( doc, "//ART").first.attributes['DT']).to match /\d{4}-\d{2}-\d{2}/
244
- expect( XPath.match( doc, "//ART").first.attributes['SHA256'].size).to eq 64
243
+ expect(XPath.match(@rexml, "//ART" ).first.attributes['SHA256'].size).to eq 64
244
+ expect(XPath.match(@rexml, "//ART" ).size).to eq XPath.match(@rexml, "//ART" ).size
245
245
  end
246
246
 
247
247
  it 'should be possible to verify the oddb_article.xml' do
248
- @article_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_article.xml'))
249
248
  result = Oddb2xml.verify_sha256(@article_xml)
250
249
  expect(result)
251
250
  end
@@ -253,6 +252,30 @@ describe Oddb2xml::Builder do
253
252
  it 'should be possible to verify all xml files against our XSD' do
254
253
  check_validation_via_xsd
255
254
  end
255
+
256
+ it 'should have a correct insulin (gentechnik) for 7680532900196' do
257
+ expect(XPath.match( @rexml, "//ART/[BC='7680532900196']").size).to eq 1
258
+ expect(XPath.match( @rexml, "//ART//GEN_PRODUCTION").size).to eq 1
259
+ expect(XPath.match( @rexml, "//ART//GEN_PRODUCTION").first.text).to eq 'X'
260
+ expect(XPath.match( @rexml, "//ART//INSULIN_CATEGORY").size).to eq 1
261
+ expect(XPath.match( @rexml, "//ART//INSULIN_CATEGORY").first.text).to eq 'Insulinanalog: schnell wirkend'
262
+ end
263
+
264
+ it 'should have a correct drug information for 7680555610041' do
265
+ expect(XPath.match( @rexml, "//ART/[BC='7680555610041']").size).to eq 1
266
+ expect(XPath.match( @rexml, "//ART//DRUG_INDEX").size).to eq 1
267
+ expect(XPath.match( @rexml, "//ART//DRUG_INDEX").first.text).to eq 'd'
268
+ found = false
269
+ XPath.match( @rexml, "//ART//CDBG").each{
270
+ |flag|
271
+ if flag.text.eql?('Y')
272
+ found = true
273
+ break
274
+ end
275
+ }
276
+ expect(found)
277
+ end
278
+
256
279
  end
257
280
 
258
281
  context 'when -o for fachinfo is given' do
@@ -296,6 +319,7 @@ if RUN_ALL
296
319
  options = Oddb2xml::Options.new
297
320
  options.parser.parse!('-f dat --log'.split(' '))
298
321
  @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options.opts).run }
322
+ # Oddb2xml::Cli.new(options.opts).run # to debug
299
323
  end
300
324
 
301
325
  it 'should contain the correct values fo CMUT from zurrose_transfer.dat' do
@@ -307,6 +331,9 @@ if RUN_ALL
307
331
  oddb_dat.should match(/^..3/), "should have a record with '3' in CMUT field"
308
332
  oddb_dat.should match(RegExpDesitin), "should have Desitin"
309
333
  IO.readlines(dat_filename).each{ |line| check_article_IGM_format(line) }
334
+ m = /.+DIAPHIN Trocke.*7680555610041.+/.match(oddb_dat)
335
+ expect(m[0].size).to eq 97 # size of IGM 1 record
336
+ expect(m[0][74]).to eq '3'
310
337
  end
311
338
  end
312
339
 
@@ -340,7 +367,8 @@ if RUN_ALL
340
367
  common_run_init
341
368
  options = Oddb2xml::Options.new
342
369
  options.parser.parse!('--append -I 80 -e'.split(' '))
343
- @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options.opts).run }
370
+ Oddb2xml::Cli.new(options.opts).run
371
+ # @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options.opts).run }
344
372
  end
345
373
 
346
374
  it "oddb_article with stuf from ZurRose", :skip => "ZurRose contains ERYTHROCIN i.v. Troc*esteekensub 1000 mg Amp [!]" do
data/spec/calc_spec.rb CHANGED
@@ -8,7 +8,6 @@ require "#{Dir.pwd}/lib/oddb2xml/calc"
8
8
  include Oddb2xml
9
9
 
10
10
  describe Oddb2xml::Calc do
11
- RunAllTests = true
12
11
  before(:all) do VCR.eject_cassette; VCR.insert_cassette('oddb2xml') end
13
12
  after(:all) do VCR.eject_cassette end
14
13
 
@@ -102,7 +101,7 @@ describe Oddb2xml::Calc do
102
101
  # :count => 10, :multi => 1, :dose => ''
103
102
  }
104
103
  )
105
- tst_nutriflex = TestExample.new('Nutriflex Lipid plus ohne Elektrolyte, Infusionsemulsion 1250ml',
104
+ Tst_nutriflex = TestExample.new('Nutriflex Lipid plus ohne Elektrolyte, Infusionsemulsion 1250ml',
106
105
  56089, 1, 1, 'Nutriflex Lipid plus, Infusionsemulsion, 1250ml',
107
106
  '5 x 1250', 'ml',
108
107
  'glucosum anhydricum, isoleucinum, leucinum, lysinum anhydricum, methioninum, phenylalaninum, threoninum, tryptophanum, valinum, argininum, histidinum, alaninum, acidum asparticum, acidum glutamicum, glycinum, prolinum, serinum, aminoacida, carbohydrata, materia crassa, sojae oleum, triglycerida saturata media',
@@ -128,7 +127,7 @@ Corresp. 5300 kJ.",
128
127
  }
129
128
  )
130
129
 
131
- tst_naropin = TestExample.new('Das ist eine Injektionslösung von einer Packung mit 5 x 100 ml',
130
+ Tst_naropin = TestExample.new('Das ist eine Injektionslösung von einer Packung mit 5 x 100 ml',
132
131
  54015, 01, 100, "Naropin 0,2 %, Infusionslösung / Injektionslösung",
133
132
  '1 x 5 x 100', 'ml',
134
133
  'ropivacainum',
@@ -139,7 +138,7 @@ Corresp. 5300 kJ.",
139
138
  }
140
139
  )
141
140
 
142
- if RunAllTests
141
+
143
142
  context 'should parse Solvens:' do
144
143
  text = 'Solvens: conserv.: alcohol benzylicus 18 mg, aqua ad iniectabilia q.s. ad solutionem pro 2 ml.'
145
144
  info = Calc.new('Solu-Cortef 100 mg, Injektions-/Infusionspräparat', nil, nil,
@@ -197,6 +196,7 @@ if RunAllTests
197
196
  specify { expect(result.selling_units).to eq 10 }
198
197
  specify { expect(result.measure).to eq 'ml' }
199
198
  end
199
+
200
200
  context 'should return correct value for Diamox, comprimés' do
201
201
  pkg_size_L = '1 x 25'
202
202
  einheit_M = 'Tablette(n)'
@@ -254,7 +254,7 @@ if RunAllTests
254
254
  end
255
255
  [tst_fluorglukose,
256
256
  tst_kamillin,
257
- tst_naropin,
257
+ Tst_naropin,
258
258
  tst_diamox,
259
259
  tst_mutagrip,
260
260
  ].each {
@@ -272,8 +272,8 @@ if RunAllTests
272
272
  }
273
273
 
274
274
  context 'find correct result for Injektionslösung' do
275
- info = Calc.new(tst_naropin.name_C, tst_naropin.package_size_L, tst_naropin.einheit_M, tst_naropin.active_substance_0, tst_naropin.composition_P)
276
- specify { expect(tst_naropin.url).to eq 'http://ch.oddb.org/de/gcc/drug/reg/54015/seq/01/pack/100' }
275
+ info = Calc.new(Tst_naropin.name_C, Tst_naropin.package_size_L, Tst_naropin.einheit_M, Tst_naropin.active_substance_0, Tst_naropin.composition_P)
276
+ specify { expect(Tst_naropin.url).to eq 'http://ch.oddb.org/de/gcc/drug/reg/54015/seq/01/pack/100' }
277
277
  specify { expect(info.galenic_form.description).to eq 'Infusionslösung/Injektionslösung' }
278
278
  specify { expect(info.galenic_group.description).to eq 'Injektion/Infusion' }
279
279
  specify { expect(info.pkg_size).to eq '1 x 5 x 100' }
@@ -290,103 +290,6 @@ if RunAllTests
290
290
  specify { expect(info.measure).to eq 'Kapsel(n)' }
291
291
  end
292
292
 
293
- run_time_options = '--calc --skip-download'
294
- context "when passing #{run_time_options}" do
295
- let(:cli) do
296
- options = Oddb2xml::Options.new
297
- options.parser.parse!(run_time_options.split(' '))
298
- Oddb2xml::Cli.new(options.opts)
299
- end
300
- it 'should create a correct xml and a csv file' do
301
- src = File.expand_path(File.join(File.dirname(__FILE__), 'data', 'swissmedic_package-galenic.xlsx'))
302
- dest = File.join(Oddb2xml::WorkDir, 'swissmedic_package.xlsx')
303
- FileUtils.makedirs(Oddb2xml::WorkDir)
304
- cli.run
305
- expected = [
306
- 'oddb_calc.xml',
307
- 'oddb_calc.csv',
308
- ].each { |file|
309
- full = File.join(Oddb2xml::WorkDir, file)
310
- expect(File.exists?(full)).to eq true
311
- }
312
- xml_file_name = File.join(Oddb2xml::WorkDir, 'oddb_calc.xml')
313
- xml = File.read(xml_file_name)
314
- oddb_calc_xsd = File.expand_path(File.join(File.dirname(__FILE__), '..', 'oddb_calc.xsd'))
315
- File.exists?(oddb_calc_xsd).should eq true
316
- xsd = Nokogiri::XML::Schema(File.read(oddb_calc_xsd))
317
- doc = Nokogiri::XML(File.read(xml_file_name))
318
- xsd.validate(doc).each do |error| expect(error).to be_nil end
319
- doc = REXML::Document.new xml
320
- gtin = '7680540151009'
321
- ean12 = '7680' + sprintf('%05d',tst_naropin.iksnr_A) + sprintf('%03d',tst_naropin.pack_K)
322
- ean13 = (ean12 + Oddb2xml.calc_checksum(ean12))
323
- ean13.should eq gtin
324
-
325
- tst_naropin.values_to_compare.each{
326
- | key, value |
327
- result = XPath.match( doc, "//ARTICLE[GTIN='#{gtin}']/#{key.to_s.upcase}").first.text
328
- puts "Testing key #{key.inspect} #{value.inspect} against #{result} seems to fail" unless result == value.to_s
329
- result.should eq value.to_s
330
- }
331
-
332
- gtin = '7680560890018'
333
- ean12 = '7680' + sprintf('%05d',tst_nutriflex.iksnr_A) + sprintf('%03d',tst_nutriflex.pack_K)
334
- ean13 = (ean12 + Oddb2xml.calc_checksum(ean12))
335
- ean13.should eq gtin
336
- tst_nutriflex.values_to_compare.each{
337
- | key, value |
338
- result = XPath.match( doc, "//ARTICLE[GTIN='#{gtin}']/#{key.to_s.upcase}").first.text
339
- puts "Testing key #{key.inspect} #{value.inspect} against #{result} seems to fail" unless result == value.to_s
340
- result.should eq value.to_s
341
- }
342
- matri_name = 'Matricariae Extractum Isopropanolicum Liquidum'
343
- XPath.match( doc, "//ARTICLE[GTIN='7680002770014']/NAME").first.text.should eq "Coeur-Vaisseaux Sérocytol, suppositoire"
344
- XPath.match( doc, "//ARTICLE[GTIN='7680545250363']").first.should eq nil
345
- # XPath.match( doc, "//ARTICLE[GTIN='7680545250363']/COMPOSITIONS/COMPOSITION/SUBSTANCES/SUBSTANCE/SUBSTANCE_NAME")
346
- # find{|x| x.text.eql?("Alprostadilum")}.text.should eq 'Alprostadilum'
347
- XPath.match( doc, "//ARTICLE[GTIN='7680458820202']/NAME").last.text.should eq 'Magnesiumchlorid 0,5 molar B. Braun, Zusatzampulle für Infusionslösungen'
348
- XPath.match( doc, "//ARTICLE[GTIN='7680458820202']/GALENIC_FORM").last.text.should match /Ampulle/i
349
- XPath.match( doc, "//ARTICLE[GTIN='7680555940018']/COMPOSITIONS/COMPOSITION/LABEL").first.text.should eq 'I'
350
- XPath.match( doc, "//ARTICLE[GTIN='7680555940018']/COMPOSITIONS/COMPOSITION/LABEL_DESCRIPTION").first.text.should eq 'Glucoselösung'
351
- XPath.match( doc, "//ARTICLE[GTIN='7680555940018']/COMPOSITIONS/COMPOSITION/LABEL").each{ |x| puts x.text }
352
- XPath.match( doc, "//ARTICLE[GTIN='7680555940018']/COMPOSITIONS/COMPOSITION/LABEL").last.text.should eq 'III'
353
- XPath.match( doc, "//ARTICLE[GTIN='7680555940018']/COMPOSITIONS/COMPOSITION/CORRESP").last.text.should eq '4240 kJ pro 1 l'
354
-
355
- XPath.match( doc, "//ARTICLE[GTIN='7680434541015']/COMPOSITIONS/COMPOSITION/SUBSTANCES/SUBSTANCE/SUBSTANCE_NAME").
356
- find{|x| x.text.eql?(matri_name)}.text.should eq matri_name
357
- XPath.match( doc, "//ARTICLE[GTIN='7680434541015']/NAME").last.text.should eq 'Kamillin Medipharm, Bad'
358
- XPath.match( doc, "//ARTICLE[GTIN='7680434541015']/GALENIC_FORM").last.text.should eq 'Bad'
359
- XPath.match( doc, "//ARTICLE[GTIN='7680434541015']/COMPOSITIONS/COMPOSITION/SUBSTANCES/SUBSTANCE/QTY").first.text.should eq '98.9'
360
- XPath.match( doc, "//ARTICLE[GTIN='7680300150105']/COMPOSITIONS/COMPOSITION/SUBSTANCES/SUBSTANCE/SUBSTANCE_NAME").first.text.should eq 'Lidocaini Hydrochloridum'
361
- XPath.match( doc, "//ARTICLE[GTIN='7680300150105']/COMPOSITIONS/COMPOSITION/SUBSTANCES/SUBSTANCE/UNIT").first.text.should eq 'mg/ml'
362
- XPath.match( doc, "//ARTICLE[GTIN='7680434541015']/COMPOSITIONS/COMPOSITION/SUBSTANCES/SUBSTANCE/CHEMICAL_SUBSTANCE/SUBSTANCE_NAME").first.text.should eq 'Levomenolum'
363
- XPath.match( doc, "//ARTICLE[GTIN='7680434541015']/COMPOSITIONS/COMPOSITION/SUBSTANCES/SUBSTANCE/CHEMICAL_SUBSTANCE/MORE_INFO").first.text.should eq 'ratio: 1:2-2.8'
364
- XPath.match( doc, "//ARTICLE[GTIN='7680434541015']/COMPOSITIONS/COMPOSITION/SUBSTANCES/SUBSTANCE/CHEMICAL_SUBSTANCE/DOSE_TEXT").first.text.should eq '10-50 mg'
365
- XPath.match( doc, "//ARTICLE[GTIN='7680434541015']/COMPOSITIONS/COMPOSITION/SUBSTANCES/SUBSTANCE/CHEMICAL_SUBSTANCE/QTY").first.should eq nil
366
- XPath.match( doc, "//ARTICLE[GTIN='7680434541015']/COMPOSITIONS/COMPOSITION/SUBSTANCES/SUBSTANCE/CHEMICAL_SUBSTANCE/UNIT").first.should eq nil
367
-
368
- XPath.match( doc, "//ARTICLE[GTIN='7680446250592']/COMPOSITIONS/COMPOSITION/SUBSTANCES/SUBSTANCE/SALTS/SALT/SUBSTANCE_NAME").first.text.should eq 'Ceftriaxonum Natricum'
369
-
370
- XPath.match( doc, "//ARTICLE[GTIN='7680611860045']/NAME").first.text.should eq 'Nutriflex Omega special, Infusionsemulsion 2500 ml'
371
- XPath.match( doc, "//ARTICLE[GTIN='7680611860045']/GALENIC_FORM").first.text.should eq 'Infusionsemulsion'
372
- XPath.match( doc, "//ARTICLE[GTIN='7680611860045']/SELLING_UNITS").first.text.should eq '5'
373
-
374
- XPath.match( doc, "//ARTICLE[GTIN='7680165980114']/COMPOSITIONS/COMPOSITION/EXCIPIENS/SUBSTANCE_NAME").first.text.should eq 'Excipiens ad solutionem'
375
- XPath.match( doc, "//ARTICLE[GTIN='7680165980114']/COMPOSITIONS/COMPOSITION/EXCIPIENS/QTY").first.text.should eq '1'
376
- XPath.match( doc, "//ARTICLE[GTIN='7680165980114']/COMPOSITIONS/COMPOSITION/EXCIPIENS/UNIT").first.text.should eq 'ml'
377
- XPath.match( doc, "//ARTICLE[GTIN='7680165980114']/NAME").first.text.should eq 'W-Tropfen'
378
- XPath.match( doc, "//ARTICLE[GTIN='7680165980114']/GALENIC_FORM").last.text.should eq 'Tropfen'
379
-
380
- XPath.match( doc, "//ARTICLE[GTIN='7680589430011']/NAME").first.text.should eq 'Apligraf'
381
- XPath.match( doc, "//ARTICLE[GTIN='7680589430011']/GALENIC_FORM").last.text.should eq 'Unbekannt' # TODO?? 'Scheibe(n)/disque(s)'
382
-
383
- XPath.match( doc, "//ARTICLE[GTIN='7680556740075']/NAME").first.text.should eq "Caverject DC 20, Injektionspräparat"
384
- XPath.match( doc, "//ARTICLE[GTIN='7680556740075']/COMPOSITIONS/COMPOSITION/SUBSTANCES/SUBSTANCE").size.should eq 6
385
- XPath.match( doc, "//ARTICLE[GTIN='7680556740075']/COMPOSITIONS/COMPOSITION/EXCIPIENS/SUBSTANCE_NAME").first.text.should eq "pro Vitro"
386
-
387
- end
388
- end
389
-
390
293
  context 'find correct result for Kamillin' do
391
294
  info = Calc.new(tst_kamillin.name_C, tst_kamillin.package_size_L, tst_kamillin.einheit_M, tst_kamillin.active_substance_0, tst_kamillin.composition_P)
392
295
  specify { expect(info.selling_units).to eq 25 }
@@ -413,7 +316,7 @@ if RunAllTests
413
316
  end
414
317
 
415
318
  context 'find correct result for Nutriflex' do
416
- info = Calc.new(tst_nutriflex.name_C, tst_nutriflex.package_size_L, tst_nutriflex.einheit_M, tst_nutriflex.active_substance_0, tst_nutriflex.composition_P)
319
+ info = Calc.new(Tst_nutriflex.name_C, Tst_nutriflex.package_size_L, Tst_nutriflex.einheit_M, Tst_nutriflex.active_substance_0, Tst_nutriflex.composition_P)
417
320
  specify { expect(info.selling_units).to eq 5 }
418
321
  specify { expect(info.galenic_form.description).to eq "Infusionsemulsion" }
419
322
  end
@@ -706,4 +609,148 @@ Die HILFSSTOFFE sind Aqua ad iniectabilia und Natrii chloridum.
706
609
  end
707
610
  end
708
611
  end
612
+
613
+ describe Oddb2xml::Calc do
614
+
615
+ before(:all) do
616
+ @savedDir = Dir.pwd
617
+ cleanup_directories_before_run
618
+ FileUtils.makedirs(Oddb2xml::WorkDir)
619
+ Dir.chdir Oddb2xml::WorkDir
620
+ VCR.eject_cassette; VCR.insert_cassette('oddb2xml')
621
+ @run_time_options = '--calc --skip-download'
622
+ @options = Oddb2xml::Options.new
623
+ @options.parser.parse!(@run_time_options.split(' '))
624
+ @oddb_calc_xml = File.join(Oddb2xml::WorkDir, 'oddb_calc.xml')
625
+ @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(@options.opts).run }
626
+ expect(File.exists?(@oddb_calc_xml)).to eq true
627
+ @doc = REXML::Document.new File.read(@oddb_calc_xml)
628
+ end
629
+
630
+ after(:all) do
631
+ Dir.chdir @savedDir if @savedDir and File.directory?(@savedDir)
632
+ end
633
+
634
+ context "when passing #{@run_time_options}" do
635
+ it 'should contain the new fields as per July 2015' do
636
+ # xml.GEN_PRODUCTION gen_production
637
+ # xml.INSULIN_CATEGORY insulin_category
638
+ # xml.DRUG_INDEX drug_index
639
+ expect(File.exists?(@oddb_calc_xml)).to eq true
640
+ end
641
+
642
+ it 'should create a correct xml and a csv file' do
643
+ src = File.expand_path(File.join(File.dirname(__FILE__), 'data', 'swissmedic_package-galenic.xlsx'))
644
+ dest = File.join(Oddb2xml::WorkDir, 'swissmedic_package.xlsx')
645
+ expected = [
646
+ 'oddb_calc.xml',
647
+ 'oddb_calc.csv',
648
+ ].each { |file|
649
+ full = File.join(Oddb2xml::WorkDir, file)
650
+ expect(File.exists?(full)).to eq true
651
+ }
652
+ oddb_calc_xsd = File.expand_path(File.join(File.dirname(__FILE__), '..', 'oddb_calc.xsd'))
653
+ File.exists?(oddb_calc_xsd).should eq true
654
+ xsd = Nokogiri::XML::Schema(File.read(oddb_calc_xsd))
655
+ doc = Nokogiri::XML(File.read(@oddb_calc_xml))
656
+ xsd.validate(doc).each do |error| expect(error).to be_nil end
657
+ end
658
+
659
+ it 'should create correct entries for narotin' do
660
+ gtin = '7680540151009'
661
+ ean12 = '7680' + sprintf('%05d',Tst_naropin.iksnr_A) + sprintf('%03d',Tst_naropin.pack_K)
662
+ ean13 = (ean12 + Oddb2xml.calc_checksum(ean12))
663
+ ean13.should eq gtin
664
+
665
+ Tst_naropin.values_to_compare.each{
666
+ | key, value |
667
+ result = XPath.match( @doc, "//ARTICLE[GTIN='#{gtin}']/#{key.to_s.upcase}").first.text
668
+ puts "Testing key #{key.inspect} #{value.inspect} against #{result} seems to fail" unless result == value.to_s
669
+ result.should eq value.to_s
670
+ }
671
+ end
672
+
673
+ it 'should create correct entries for narotin' do
674
+ gtin = '7680560890018'
675
+ ean12 = '7680' + sprintf('%05d',Tst_nutriflex.iksnr_A) + sprintf('%03d',Tst_nutriflex.pack_K)
676
+ ean13 = (ean12 + Oddb2xml.calc_checksum(ean12))
677
+ ean13.should eq gtin
678
+ Tst_nutriflex.values_to_compare.each{
679
+ | key, value |
680
+ result = XPath.match( @doc, "//ARTICLE[GTIN='#{gtin}']/#{key.to_s.upcase}").first.text
681
+ puts "Testing key #{key.inspect} #{value.inspect} against #{result} seems to fail" unless result == value.to_s
682
+ result.should eq value.to_s
683
+ }
684
+ end
685
+
686
+ it 'should create correct entries for 7680555940018' do
687
+ XPath.match( @doc, "//ARTICLE[GTIN='7680555940018']/COMPOSITIONS/COMPOSITION/LABEL").first.text.should eq 'I'
688
+ XPath.match( @doc, "//ARTICLE[GTIN='7680555940018']/COMPOSITIONS/COMPOSITION/LABEL_DESCRIPTION").first.text.should eq 'Glucoselösung'
689
+ XPath.match( @doc, "//ARTICLE[GTIN='7680555940018']/COMPOSITIONS/COMPOSITION/LABEL").each{ |x| puts x.text }
690
+ XPath.match( @doc, "//ARTICLE[GTIN='7680555940018']/COMPOSITIONS/COMPOSITION/LABEL").last.text.should eq 'III'
691
+ XPath.match( @doc, "//ARTICLE[GTIN='7680555940018']/COMPOSITIONS/COMPOSITION/CORRESP").last.text.should eq '4240 kJ pro 1 l'
692
+ end
693
+
694
+ it 'should create correct entries for Lidocaini' do
695
+ XPath.match( @doc, "//ARTICLE[GTIN='7680300150105']/COMPOSITIONS/COMPOSITION/SUBSTANCES/SUBSTANCE/SUBSTANCE_NAME").first.text.should eq 'Lidocaini Hydrochloridum'
696
+ XPath.match( @doc, "//ARTICLE[GTIN='7680300150105']/COMPOSITIONS/COMPOSITION/SUBSTANCES/SUBSTANCE/UNIT").first.text.should eq 'mg/ml'
697
+ end
698
+
699
+ it 'should create correct entries for Levomenolum' do
700
+ XPath.match( @doc, "//ARTICLE[GTIN='7680434541015']/COMPOSITIONS/COMPOSITION/SUBSTANCES/SUBSTANCE/CHEMICAL_SUBSTANCE/SUBSTANCE_NAME").first.text.should eq 'Levomenolum'
701
+ XPath.match( @doc, "//ARTICLE[GTIN='7680434541015']/COMPOSITIONS/COMPOSITION/SUBSTANCES/SUBSTANCE/CHEMICAL_SUBSTANCE/MORE_INFO").first.text.should eq 'ratio: 1:2-2.8'
702
+ XPath.match( @doc, "//ARTICLE[GTIN='7680434541015']/COMPOSITIONS/COMPOSITION/SUBSTANCES/SUBSTANCE/CHEMICAL_SUBSTANCE/DOSE_TEXT").first.text.should eq '10-50 mg'
703
+ XPath.match( @doc, "//ARTICLE[GTIN='7680434541015']/COMPOSITIONS/COMPOSITION/SUBSTANCES/SUBSTANCE/CHEMICAL_SUBSTANCE/QTY").first.should eq nil
704
+ XPath.match( @doc, "//ARTICLE[GTIN='7680434541015']/COMPOSITIONS/COMPOSITION/SUBSTANCES/SUBSTANCE/CHEMICAL_SUBSTANCE/UNIT").first.should eq nil
705
+ matri_name = 'Matricariae Extractum Isopropanolicum Liquidum'
706
+ XPath.match( @doc, "//ARTICLE[GTIN='7680434541015']/COMPOSITIONS/COMPOSITION/SUBSTANCES/SUBSTANCE/SUBSTANCE_NAME").
707
+ find{|x| x.text.eql?(matri_name)}.text.should eq matri_name
708
+ XPath.match( @doc, "//ARTICLE[GTIN='7680434541015']/NAME").last.text.should eq 'Kamillin Medipharm, Bad'
709
+ XPath.match( @doc, "//ARTICLE[GTIN='7680434541015']/GALENIC_FORM").last.text.should eq 'Bad'
710
+ XPath.match( @doc, "//ARTICLE[GTIN='7680434541015']/COMPOSITIONS/COMPOSITION/SUBSTANCES/SUBSTANCE/QTY").first.text.should eq '98.9'
711
+ end
712
+
713
+ it 'should create correct entries for Magnesiumchlorid' do
714
+ XPath.match( @doc, "//ARTICLE[GTIN='7680458820202']/NAME").last.text.should eq 'Magnesiumchlorid 0,5 molar B. Braun, Zusatzampulle für Infusionslösungen'
715
+ XPath.match( @doc, "//ARTICLE[GTIN='7680458820202']/GALENIC_FORM").last.text.should match /Ampulle/i
716
+ end
717
+
718
+ it 'should create correct entries for W-Tropfen' do
719
+ XPath.match( @doc, "//ARTICLE[GTIN='7680165980114']/COMPOSITIONS/COMPOSITION/EXCIPIENS/SUBSTANCE_NAME").first.text.should eq 'Excipiens ad solutionem'
720
+ XPath.match( @doc, "//ARTICLE[GTIN='7680165980114']/COMPOSITIONS/COMPOSITION/EXCIPIENS/QTY").first.text.should eq '1'
721
+ XPath.match( @doc, "//ARTICLE[GTIN='7680165980114']/COMPOSITIONS/COMPOSITION/EXCIPIENS/UNIT").first.text.should eq 'ml'
722
+ XPath.match( @doc, "//ARTICLE[GTIN='7680165980114']/NAME").first.text.should eq 'W-Tropfen'
723
+ XPath.match( @doc, "//ARTICLE[GTIN='7680165980114']/GALENIC_FORM").last.text.should eq 'Tropfen'
724
+ end
725
+
726
+ it 'should create correct entries for Coeur-Vaisseaux Sérocytol' do
727
+ XPath.match( @doc, "//ARTICLE[GTIN='7680002770014']/NAME").first.text.should eq "Coeur-Vaisseaux Sérocytol, suppositoire"
728
+ end
729
+
730
+ it 'should not have Alprostadilum' do
731
+ XPath.match( @doc, "//ARTICLE[GTIN='7680545250363']").first.should eq nil
732
+ end
733
+
734
+ it 'should create correct entries for Ceftriaxonum' do
735
+ XPath.match( @doc, "//ARTICLE[GTIN='7680446250592']/COMPOSITIONS/COMPOSITION/SUBSTANCES/SUBSTANCE/SALTS/SALT/SUBSTANCE_NAME").first.text.should eq 'Ceftriaxonum Natricum'
736
+
737
+ end
738
+
739
+ it 'should create correct entries for Nutriflex' do
740
+ XPath.match( @doc, "//ARTICLE[GTIN='7680611860045']/NAME").first.text.should eq 'Nutriflex Omega special, Infusionsemulsion 2500 ml'
741
+ XPath.match( @doc, "//ARTICLE[GTIN='7680611860045']/GALENIC_FORM").first.text.should eq 'Infusionsemulsion'
742
+ XPath.match( @doc, "//ARTICLE[GTIN='7680611860045']/SELLING_UNITS").first.text.should eq '5'
743
+ end
744
+
745
+ it 'should create correct entries for Apligraf' do
746
+ XPath.match( @doc, "//ARTICLE[GTIN='7680589430011']/NAME").first.text.should eq 'Apligraf'
747
+ XPath.match( @doc, "//ARTICLE[GTIN='7680589430011']/GALENIC_FORM").last.text.should eq 'Unbekannt' # TODO?? 'Scheibe(n)/disque(s)'
748
+ end
749
+
750
+ it 'should create correct entries for Caverject' do
751
+ XPath.match( @doc, "//ARTICLE[GTIN='7680556740075']/NAME").first.text.should eq "Caverject DC 20, Injektionspräparat"
752
+ XPath.match( @doc, "//ARTICLE[GTIN='7680556740075']/COMPOSITIONS/COMPOSITION/SUBSTANCES/SUBSTANCE").size.should eq 6
753
+ XPath.match( @doc, "//ARTICLE[GTIN='7680556740075']/COMPOSITIONS/COMPOSITION/EXCIPIENS/SUBSTANCE_NAME").first.text.should eq "pro Vitro"
754
+ end
755
+ end
709
756
  end
Binary file