oddb2xml 2.5.0 → 2.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/Elexis_Artikelstamm_v003.xsd +387 -0
  4. data/Elexis_Artikelstamm_v5.xsd +513 -0
  5. data/Gemfile +2 -6
  6. data/History.txt +11 -0
  7. data/README.md +35 -27
  8. data/artikelstamm.md +68 -0
  9. data/bin/compare_v5 +41 -0
  10. data/bin/oddb2xml +3 -15
  11. data/data/article_overrides.yaml +51859 -0
  12. data/data/gtin2ignore.yaml +30510 -0
  13. data/data/product_overrides.yaml +4 -0
  14. data/lib/oddb2xml/builder.rb +543 -192
  15. data/lib/oddb2xml/cli.rb +82 -62
  16. data/lib/oddb2xml/compare.rb +189 -0
  17. data/lib/oddb2xml/compressor.rb +6 -3
  18. data/lib/oddb2xml/downloader.rb +79 -64
  19. data/lib/oddb2xml/extractor.rb +67 -40
  20. data/lib/oddb2xml/options.rb +76 -77
  21. data/lib/oddb2xml/parslet_compositions.rb +18 -1
  22. data/lib/oddb2xml/util.rb +25 -3
  23. data/lib/oddb2xml/version.rb +1 -1
  24. data/oddb2xml.gemspec +8 -5
  25. data/oddb2xml.xsd +1 -0
  26. data/spec/artikelstamm_spec.rb +383 -0
  27. data/spec/builder_spec.rb +147 -118
  28. data/spec/calc_spec.rb +3 -15
  29. data/spec/cli_spec.rb +24 -35
  30. data/spec/compare_spec.rb +24 -0
  31. data/spec/compressor_spec.rb +1 -3
  32. data/spec/data/Elexis_Artikelstamm_v5.xsd +513 -0
  33. data/spec/data/Preparations.xml +2200 -0
  34. data/spec/data/Publications.xls +0 -0
  35. data/spec/data/artikelstamm_N_010917.xml +39 -0
  36. data/spec/data/artikelstamm_N_011217.xml +17 -0
  37. data/spec/data/artikelstamm_P_010917.xml +86 -0
  38. data/spec/data/artikelstamm_P_011217.xml +63 -0
  39. data/spec/data/oddb2xml_files_lppv.txt +2 -0
  40. data/spec/data/refdata_NonPharma.xml +38 -0
  41. data/spec/data/refdata_Pharma.xml +220 -0
  42. data/spec/data/swissmedic_orphan.xlsx +0 -0
  43. data/spec/data/swissmedic_package.xlsx +0 -0
  44. data/spec/data/transfer.dat +59 -19
  45. data/spec/data/v5_first.xml +102 -0
  46. data/spec/data/v5_second.xml +184 -0
  47. data/spec/data_helper.rb +72 -0
  48. data/spec/downloader_spec.rb +19 -27
  49. data/spec/extractor_spec.rb +27 -33
  50. data/spec/fixtures/vcr_cassettes/artikelstamm.json +1 -0
  51. data/spec/options_spec.rb +73 -66
  52. data/spec/spec_helper.rb +73 -24
  53. data/test_options.rb +4 -2
  54. metadata +100 -21
  55. data/spec/data/XMLPublications.zip +0 -0
  56. data/spec/data/compressor/oddb_article.xml +0 -0
  57. data/spec/data/compressor/oddb_fi.xml +0 -0
  58. data/spec/data/compressor/oddb_fi_product.xml +0 -0
  59. data/spec/data/compressor/oddb_limitation.xml +0 -0
  60. data/spec/data/compressor/oddb_product.xml +0 -0
  61. data/spec/data/compressor/oddb_substance.xml +0 -0
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'spec_helper'
4
4
  require "rexml/document"
5
+ require 'webmock/rspec'
5
6
  include REXML
6
7
  RUN_ALL = true
7
8
 
@@ -28,7 +29,7 @@ ARTICLE_MISSING_ELEMENTS = [
28
29
 
29
30
  ARTICLE_ZURROSE_ELEMENTS = [
30
31
  ['ARTICLE/ART/REF_DATA', '0'],
31
- ['ARTICLE/ART/ARTCOMP/COMPNO', '7601001000858'],
32
+ ['ARTICLE/ART/ARTCOMP/COMPNO', '7601001000896'],
32
33
  ['ARTICLE/ART/ARTPRI/PTYP', 'PEXF'],
33
34
  ['ARTICLE/ART/ARTPRI/PTYP', 'PPUB'],
34
35
  ['ARTICLE/ART/ARTPRI/PTYP', 'ZURROSE'],
@@ -37,6 +38,28 @@ ARTICLE_ZURROSE_ELEMENTS = [
37
38
  ['ARTICLE/ART/ARTINS/NINCD', '20'],
38
39
  ]
39
40
 
41
+ ARTICLE_NAROPIN = %(<REF_DATA>1</REF_DATA>
42
+ <PHAR>1882189</PHAR>
43
+ <SMCAT>B</SMCAT>
44
+ <SMNO>54015011</SMNO>
45
+ <PRODNO>5401501</PRODNO>
46
+ <SALECD>I</SALECD>
47
+ <CDBG>N</CDBG>
48
+ <BG>N</BG>
49
+ <DSCRD>NAROPIN Inj Lös 0.2 % 10ml Duofit Amp 5 Stk</DSCRD>
50
+ <DSCRF>NAROPIN sol inj 0.2 % 10ml amp duofit 5 pce</DSCRF>
51
+ <SORTD>NAROPIN INJ LÖS 0.2 % 10ML DUOFIT AMP 5 STK</SORTD>
52
+ <SORTF>NAROPIN SOL INJ 0.2 % 10ML AMP DUOFIT 5 PCE</SORTF>
53
+ <ARTCOMP>
54
+ <COMPNO>7601001402539</COMPNO>
55
+ </ARTCOMP>
56
+ <ARTBAR>
57
+ <CDTYP>E13</CDTYP>
58
+ <BC>7680540150118</BC>
59
+ <BCSTAT>A</BCSTAT>
60
+ </ARTBAR>
61
+ </ART>)
62
+
40
63
  ARTICLE_COMMON_ELEMENTS = [
41
64
  ['ARTICLE/ART/REF_DATA', '1'],
42
65
  ['ARTICLE/ART/SMCAT', 'A'],
@@ -59,10 +82,6 @@ ARTICLE_COMMON_ELEMENTS = [
59
82
  ['ARTICLE/ART/BG', 'N'],
60
83
  ['ARTICLE/ART/ARTBAR/BC', Oddb2xml::ORPHAN_GTIN.to_s],
61
84
  ['ARTICLE/ART/ARTBAR/BC', Oddb2xml::FRIDGE_GTIN.to_s],
62
- ['ARTICLE/ART/DSCRD', 'NAROPIN Inj Lös 0.2 % 5 Polybag 100 ml'],
63
- ['ARTICLE/ART/DSCRF', 'NAROPIN sol inj 0.2 % 5 polybag 100 ml'],
64
- ['ARTICLE/ART/SORTD', 'NAROPIN INJ LÖS 0.2 % 5 POLYBAG 100 ML'],
65
- ['ARTICLE/ART/SORTF', 'NAROPIN SOL INJ 0.2 % 5 POLYBAG 100 ML'],
66
85
  ['ARTICLE/ART/SYN1D', 'Hirudoid'],
67
86
  ['ARTICLE/ART/SYN1F', 'Hirudoid'],
68
87
  ['ARTICLE/ART/SLOPLUS', '2'],
@@ -226,12 +245,18 @@ MEDIZINALPERSON_ELEMENT_TESTS = [
226
245
  ['Personen/Person/BTM_Berechtigung', 'BTM_Berechtigung'],
227
246
  ]
228
247
 
229
- def check_result(rexml, nbr_record)
230
- expect(XPath.match(rexml, '//RESULT/NBR_RECORD').size).to eq 1
231
- expect(XPath.match(rexml, '//RESULT/NBR_RECORD').first.text.to_i).to eq nbr_record
232
- expect(XPath.match(rexml, '//RESULT/OK_ERROR').first.text).to eq 'OK'
233
- expect(XPath.match(rexml, '//RESULT/ERROR_CODE').first.text).to eq nil
234
- expect(XPath.match(rexml, '//RESULT/MESSAGE').first.text).to eq nil
248
+ def check_result(inhalt, nbr_record)
249
+ [ "<NBR_RECORD>",
250
+ "<OK_ERROR>",
251
+ '<OK_ERROR>OK</OK_ERROR>',
252
+ ].each do |what|
253
+ expect(inhalt.scan(what).size).to eq 1
254
+ end
255
+ expect(inhalt.index('<OK_ERROR>OK</OK_ERROR>')).to be > 0
256
+ expect(inhalt.index('<ERROR_CODE/>')).to be > 0
257
+ m = /<NBR_RECORD>(\d+)<\/NBR_RECORD>/.match(inhalt)
258
+ expect(m).not_to be nil
259
+ expect(m[1].to_i).to eq nbr_record
235
260
  end
236
261
 
237
262
  def checkItemForRefdata(doc, pharmacode, isRefdata)
@@ -292,27 +317,29 @@ def check_article_IGM_format(line, price_kendural=825, add_80_percents=false)
292
317
  return [found_SL, found_non_SL]
293
318
  end
294
319
 
320
+ def validate_via_xsd(xsd_file, xml_file)
321
+ xsd =open(xsd_file).read
322
+ xsd_rtikelstamm_xml = Nokogiri::XML::Schema(xsd)
323
+ doc = Nokogiri::XML(File.read(xml_file))
324
+ xsd_rtikelstamm_xml.validate(doc).each do
325
+ |error|
326
+ if error.message
327
+ puts "Failed validating #{xml_file} with #{File.size(xml_file)} bytes using XSD from #{xsd_file}"
328
+ puts "CMD: xmllint --noout --schema #{xsd_file} #{xml_file}"
329
+ end
330
+ msg = "expected #{error.message} to be nil\nfor #{xml_file}"
331
+ puts msg
332
+ expect(error.message).to be_nil, msg
333
+ end
334
+ end
335
+
295
336
  def check_validation_via_xsd
296
- @oddb2xml_xsd = File.expand_path(File.join(File.dirname(__FILE__), '..', 'oddb2xml.xsd'))
297
- @oddb_calc_xsd = File.expand_path(File.join(File.dirname(__FILE__), '..', 'oddb_calc.xsd'))
298
- expect(File.exists?(@oddb2xml_xsd)).to eq true
299
- expect(File.exists?(@oddb_calc_xsd)).to eq true
300
337
  files = Dir.glob('*.xml')
301
- xsd_oddb2xml = Nokogiri::XML::Schema(File.read(@oddb2xml_xsd))
302
- xsd_oddb_calc = Nokogiri::XML::Schema(File.read(@oddb_calc_xsd))
303
338
  files.each{
304
339
  |file|
305
340
  next if /#{Time.now.year}/.match(file)
306
- doc = Nokogiri::XML(File.read(file))
307
- xsd2use = /oddb_calc/.match(file) ? xsd_oddb_calc : xsd_oddb2xml
308
- xsd2use.validate(doc).each do
309
- |error|
310
- if error.message
311
- puts "Failed validating #{file} with #{File.size(file)} bytes using XSD from #{@oddb2xml_xsd}"
312
- puts "cmd would be: xsdvalidate #{@oddb2xml_xsd} #{file}"
313
- end
314
- expect(error.message).to be_nil, "expected #{error.message} to be nil\nfor #{file} content \n#{File.read(file)}"
315
- end
341
+ xsd2use = /oddb_calc/.match(file) ? @oddb_calc_xsd : @oddb2xml_xsd
342
+ validate_via_xsd(xsd2use, File.expand_path(file))
316
343
  }
317
344
  end
318
345
 
@@ -352,7 +379,6 @@ end
352
379
  def checkAndGetProductWithGTIN(doc, gtin)
353
380
  products = XPath.match( doc, "//PRD[GTIN=#{gtin.to_s}]")
354
381
  gtins = XPath.match( doc, "//PRD[GTIN=#{gtin.to_s}]/GTIN")
355
- binding.pry unless gtins.size == 1
356
382
  expect(gtins.size).to eq 1
357
383
  expect(gtins.first.text).to eq gtin.to_s
358
384
  # return product
@@ -378,6 +404,7 @@ def checkArticleXml(checkERYTHROCIN = true)
378
404
 
379
405
  desitin = checkAndGetArticleWithGTIN(doc, Oddb2xml::LEVETIRACETAM_GTIN)
380
406
  expect(desitin).not_to eq nil
407
+ # TODO: why is this now nil? desitin.elements['ATC'].text.should == 'N03AX14'
381
408
  expect(desitin.elements['DSCRD'].text).to eq("LEVETIRACETAM DESITIN Mini Filmtab 250 mg 30 Stk")
382
409
  expect(desitin.elements['DSCRF'].text).to eq('LEVETIRACETAM DESITIN mini cpr pel 250 mg 30 pce')
383
410
  expect(desitin.elements['REF_DATA'].text).to eq('1')
@@ -405,6 +432,7 @@ def checkArticleXml(checkERYTHROCIN = true)
405
432
  expect(zyvoxid.elements['DSCRD'].text).to eq 'ZYVOXID Filmtabl 600 mg 10 Stk'
406
433
 
407
434
  expect(XPath.match( doc, "//LIMPTS" ).size).to be >= 1
435
+ # TODO: desitin.elements['QTY'].text.should eq '250 mg'
408
436
  end
409
437
 
410
438
  def checkProductXml(nbr_record = -1)
@@ -414,7 +442,7 @@ def checkProductXml(nbr_record = -1)
414
442
  # check products
415
443
  content = IO.read(product_filename)
416
444
  doc = REXML::Document.new content
417
- check_result(doc, nbr_record)
445
+ check_result(content, nbr_record)
418
446
  expect(nbr_record).to eq content.scan(/<PRD/).size if nbr_record != -1
419
447
 
420
448
  desitin = checkAndGetProductWithGTIN(doc, Oddb2xml::LEVETIRACETAM_GTIN)
@@ -427,9 +455,8 @@ def checkProductXml(nbr_record = -1)
427
455
  expect(desitin.elements['EinheitSwissmedic'].text).to eq 'Tablette(n)'
428
456
  expect(desitin.elements['SubstanceSwissmedic'].text).to eq 'levetiracetamum'
429
457
  expect(desitin.elements['CompositionSwissmedic'].text).to eq 'levetiracetamum 250 mg, excipiens pro compressi obducti pro charta.'
430
-
431
458
  expect(desitin.elements['CPT/CPTCMP/LINE'].text).to eq '0'
432
- expect(desitin.elements['CPT/CPTCMP/SUBNO'].text).to eq '10'
459
+ expect(desitin.elements['CPT/CPTCMP/SUBNO'].text).to eq '14'
433
460
  expect(desitin.elements['CPT/CPTCMP/QTY'].text).to eq '250'
434
461
  expect(desitin.elements['CPT/CPTCMP/QTYU'].text).to eq 'mg'
435
462
 
@@ -441,31 +468,32 @@ def checkProductXml(nbr_record = -1)
441
468
  puts "checkProductXml has #{XPath.match( doc, "//GTIN" ).find_all{|x| true}.size} GTIN"
442
469
  puts "checkProductXml has #{XPath.match( doc, "//PRODNO" ).find_all{|x| true}.size} PRODNO"
443
470
  end
444
- expect(XPath.match( doc, "//PRD" ).find_all{|x| true}.size).to eq(NrPackages)
445
- expect(XPath.match( doc, "//GTIN" ).find_all{|x| true}.size).to eq(NrPackages)
446
- expect(XPath.match( doc, "//PRODNO" ).find_all{|x| true}.size).to eq(NrProdno)
447
-
448
471
  hirudoid = checkAndGetProductWithGTIN(doc, Oddb2xml::HIRUDOID_GTIN)
449
472
  expect(hirudoid.elements['ATC'].text).to eq('C05BA01') # modified by atc.csv!
450
473
  end
451
474
 
452
475
  describe Oddb2xml::Builder do
453
- NrExtendedArticles = 34
454
- NrSubstances = 14
455
- NrLimitations = 5
456
- NrInteractions = 5
476
+ NrExtendedArticles = 67
477
+ NrSubstances = 25
478
+ NrLimitations = 12
479
+
480
+ NrInteractions = 2
457
481
  NrCodes = 5
458
- NrProdno = 23
459
- NrPackages = 24
460
- NrProducts = 19
482
+ NrProdno = 31
483
+ NrPackages = 38
484
+ NrProducts = 32
461
485
  RegExpDesitin = /1125819012LEVETIRACETAM DESITIN Mini Filmtab 250 mg 30 Stk/
462
486
  include ServerMockHelper
463
- def common_run_init
487
+ def common_run_init(options = {})
464
488
  @savedDir = Dir.pwd
489
+ @oddb2xml_xsd = File.expand_path(File.join(File.dirname(__FILE__), '..', 'oddb2xml.xsd'))
490
+ @oddb_calc_xsd = File.expand_path(File.join(File.dirname(__FILE__), '..', 'oddb_calc.xsd'))
491
+ expect(File.exist?(@oddb2xml_xsd)).to eq true
492
+ expect(File.exist?(@oddb_calc_xsd)).to eq true
465
493
  cleanup_directories_before_run
466
494
  FileUtils.makedirs(Oddb2xml::WorkDir)
467
495
  Dir.chdir(Oddb2xml::WorkDir)
468
- VCR.eject_cassette; VCR.insert_cassette('oddb2xml')
496
+ mock_downloads
469
497
  end
470
498
 
471
499
  after(:all) do
@@ -474,19 +502,18 @@ describe Oddb2xml::Builder do
474
502
  context 'when default options are given' do
475
503
  before(:all) do
476
504
  common_run_init
477
- options = Oddb2xml::Options.new
478
- # @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options.opts).run }
479
- Oddb2xml::Cli.new(options.opts).run # to debug
505
+ Oddb2xml::Cli.new({}).run # to debug
480
506
  @doc = Nokogiri::XML(File.open(oddb_article_xml))
507
+ @inhalt = File.read(oddb_article_xml)
481
508
  @rexml = REXML::Document.new File.read(oddb_article_xml)
482
509
  end
483
510
 
484
- it 'should return produce a oddb_article.xml' do
511
+ it 'should produce a oddb_article.xml' do
485
512
  expect(File.exists?(oddb_article_xml)).to eq true
486
513
  end
487
514
 
488
515
  it 'should have a correct NBR_RECORD in oddb_article.xml' do
489
- check_result(@rexml, NrProducts)
516
+ check_result(@inhalt, NrProducts)
490
517
  end
491
518
 
492
519
  it 'oddb_article.xml should contain a SHA256' do
@@ -503,9 +530,12 @@ describe Oddb2xml::Builder do
503
530
  check_validation_via_xsd
504
531
  end
505
532
 
506
- context 'XSD article' do
507
- check_attributes(oddb_article_xml, ARTICLE_ATTRIBUTE_TESTS)
508
- check_elements(oddb_article_xml, ARTICLE_COMMON_ELEMENTS)
533
+ check_attributes(oddb_article_xml, ARTICLE_ATTRIBUTE_TESTS)
534
+ check_elements(oddb_article_xml, ARTICLE_COMMON_ELEMENTS)
535
+
536
+ it 'should validate XSD article' do
537
+ @inhalt = File.read(oddb_article_xml)
538
+ expect(File.read(oddb_article_xml).scan(ARTICLE_NAROPIN).size).to eq 1
509
539
  end
510
540
 
511
541
  context 'XSD betrieb' do
@@ -522,7 +552,7 @@ describe Oddb2xml::Builder do
522
552
 
523
553
  it 'should have a correct insulin (gentechnik) for 7680532900196' do
524
554
  expect(XPath.match( @rexml, "//ART/[BC='7680532900196']").size).to eq 1
525
- expect(XPath.match( @rexml, "//ART//GEN_PRODUCTION").size).to eq 2
555
+ expect(XPath.match( @rexml, "//ART//GEN_PRODUCTION").size).to be >= 1
526
556
  expect(XPath.match( @rexml, "//ART//GEN_PRODUCTION").first.text).to eq 'X'
527
557
  expect(XPath.match( @rexml, "//ART//INSULIN_CATEGORY").size).to eq 1
528
558
  expect(XPath.match( @rexml, "//ART//INSULIN_CATEGORY").first.text).to eq 'Insulinanalog: schnell wirkend'
@@ -534,8 +564,10 @@ describe Oddb2xml::Builder do
534
564
  expect(XPath.match( doc, "//COOL='1']").size).to eq 1
535
565
  end
536
566
 
537
- it 'should have a correct drug information for 7680555610041' do
538
- expect(XPath.match( @rexml, "//ART/[BC='7680555610041']").size).to eq 1
567
+ ean_with_drug_index = 7680555610041
568
+ it "should have a correct drug information for #{ean_with_drug_index}" do
569
+ doc = REXML::Document.new IO.read(checkAndGetArticleXmlName)
570
+ expect(XPath.match( @rexml, "//ART/[BC='#{ean_with_drug_index}']").size).to eq 1
539
571
  expect(XPath.match( @rexml, "//ART//DRUG_INDEX").size).to eq 1
540
572
  expect(XPath.match( @rexml, "//ART//DRUG_INDEX").first.text).to eq 'd'
541
573
  found = false
@@ -556,20 +588,17 @@ describe Oddb2xml::Builder do
556
588
  common_run_init
557
589
  @oddb_fi_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_fi.xml'))
558
590
  @oddb_fi_product_xml = File.expand_path(File.join(Oddb2xml::WorkDir, 'oddb_fi_product.xml'))
559
- options = Oddb2xml::Options.new
560
- options.parser.parse!(['-o'])
561
- # @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options.opts).run }
562
- Oddb2xml::Cli.new(options.opts).run
591
+ options = Oddb2xml::Options.parse(['-o', '--log'])
592
+ # @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options).run }
593
+ Oddb2xml::Cli.new(options).run
563
594
  end
564
595
 
565
596
  it 'should have a correct NBR_RECORD in oddb_fi_product.xml' do
566
- rexml = REXML::Document.new File.read('oddb_fi_product.xml')
567
- check_result(rexml, 0)
597
+ check_result( File.read('oddb_fi_product.xml'), 0)
568
598
  end
569
599
 
570
600
  it 'should have a correct NBR_RECORD in oddb_fi.xml' do
571
- rexml = REXML::Document.new File.read('oddb_fi.xml')
572
- check_result(rexml, 2)
601
+ check_result( File.read('oddb_fi.xml'), 2)
573
602
  end
574
603
 
575
604
  it 'should return produce a correct oddb_fi.xml' do
@@ -580,12 +609,11 @@ describe Oddb2xml::Builder do
580
609
  m = /<paragraph><!\[CDATA\[(.+)\n(.*)/.match(inhalt.to_s)
581
610
  expect(m[1]).to eq '<?xml version="1.0" encoding="utf-8"?><div xmlns="http://www.w3.org/1999/xhtml">'
582
611
  expected = '<p class="s2"> </p>'
583
- skip { expect(m[2]).to eq '<p class="s4" id="section1"><span class="s2"><span>Zyvoxid</span></span><sup class="s3"><span>®</span></sup></p>' }
612
+ skip { m[2].should eq '<p class="s4" id="section1"><span class="s2"><span>Zyvoxid</span></span><sup class="s3"><span>®</span></sup></p>' }
584
613
  expect(File.exists?(@oddb_fi_product_xml)).to eq true
585
614
  inhalt = IO.read(@oddb_fi_product_xml)
586
615
  end
587
616
 
588
- if RUN_ALL
589
617
  it 'should produce valid xml files' do
590
618
  skip "Niklaus does not know how to create a valid oddb_fi_product.xml"
591
619
  # check_validation_via_xsd
@@ -601,10 +629,9 @@ if RUN_ALL
601
629
  context 'when -f dat is given' do
602
630
  before(:all) do
603
631
  common_run_init
604
- options = Oddb2xml::Options.new
605
- options.parser.parse!('-f dat --log'.split(' '))
606
- @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options.opts).run }
607
- # Oddb2xml::Cli.new(options.opts).run # to debug
632
+ options = Oddb2xml::Options.parse('-f dat --log')
633
+ @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options).run }
634
+ # Oddb2xml::Cli.new(options).run # to debug
608
635
  end
609
636
 
610
637
  it 'should contain the correct values fo CMUT from transfer.dat' do
@@ -616,7 +643,7 @@ if RUN_ALL
616
643
  expect(oddb_dat).to match(/^..3/), "should have a record with '3' in CMUT field"
617
644
  expect(oddb_dat).to match(RegExpDesitin), "should have Desitin"
618
645
  IO.readlines(dat_filename).each{ |line| check_article_IGM_format(line, 0) }
619
- m = /.+DIAPHIN Trocke.*7680555610041.+/.match(oddb_dat)
646
+ m = /.+KENDURAL Depottabl 30 Stk.*7680353660163.+/.match(oddb_dat)
620
647
  expect(m[0].size).to eq 97 # size of IGM 1 record
621
648
  expect(m[0][74]).to eq '3'
622
649
  end
@@ -625,10 +652,8 @@ if RUN_ALL
625
652
  context 'when --append -f dat is given' do
626
653
  before(:all) do
627
654
  common_run_init
628
- options = Oddb2xml::Options.new
629
- options.parser.parse!('--append -f dat'.split(' '))
630
- # Oddb2xml::Cli.new(options.opts).run
631
- @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options.opts).run }
655
+ options = Oddb2xml::Options.parse('--append -f dat')
656
+ @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options).run }
632
657
  end
633
658
 
634
659
  it 'should generate a valid oddb_with_migel.dat' do
@@ -650,20 +675,35 @@ if RUN_ALL
650
675
  context 'when --append -I 80 -e is given' do
651
676
  before(:all) do
652
677
  common_run_init
653
- options = Oddb2xml::Options.new
654
- options.parser.parse!('--append -I 80 -e'.split(' '))
655
- Oddb2xml::Cli.new(options.opts).run
656
- # @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options.opts).run }
678
+ options = Oddb2xml::Options.parse('--append -I 80 -e')
679
+ Oddb2xml::Cli.new(options).run
680
+ # @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options).run }
657
681
  end
658
682
 
659
683
  it "oddb_article with stuf from ZurRose", :skip => "ZurRose contains ERYTHROCIN i.v. Troc*esteekensub 1000 mg Amp [!]" do
660
684
  checkArticleXml
661
685
  end
662
686
 
687
+ # Zeno used oddb2xml -e -I 45 -c zip for oddb_arcticle for artikelstamm 7680172330414 3605520301605
688
+ it 'should add GTIN 7680172330414 which is marked as inactive in transfer.dat' do
689
+ @inhalt = IO.read(oddb_article_xml)
690
+ expect(@inhalt.index('7680172330414')).not_to be nil
691
+ end
692
+
693
+ it 'should add GTIN 3605520301605 Armani Attitude which is marked as inactive in transfer.dat' do
694
+ @inhalt = IO.read(oddb_article_xml)
695
+ # <SALECD>I</SALECD>
696
+
697
+ expect(@inhalt.index('3605520301605')).not_to be nil
698
+ end
699
+
663
700
  context 'XSD' do
664
701
  check_attributes(oddb_article_xml, ARTICLE_ATTRIBUTE_TESTS)
665
702
  check_elements(oddb_article_xml, ARTICLE_COMMON_ELEMENTS)
666
703
  check_elements(oddb_article_xml, ARTICLE_ZURROSE_ELEMENTS)
704
+ it 'should contain NAROPIN' do
705
+ expect(File.read(oddb_article_xml).scan(ARTICLE_NAROPIN).size).to eq 1
706
+ end
667
707
  end
668
708
 
669
709
  it 'should emit a correct oddb_article.xml' do
@@ -679,19 +719,17 @@ if RUN_ALL
679
719
  checkPrices(true)
680
720
  end
681
721
  end
682
- end
683
722
 
684
- if RUN_ALL
685
723
  context 'when option -e is given' do
686
724
  before(:all) do
687
725
  common_run_init
688
- options = Oddb2xml::Options.new
689
- options.parser.parse!('-e'.split(' '))
690
- Oddb2xml::Cli.new(options.opts)
726
+ options = Oddb2xml::Options.parse('-e')
727
+ puts options
728
+ @cli = Oddb2xml::Cli.new(options)
691
729
  if RUN_ALL
692
- @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options.opts).run }
730
+ @res = buildr_capture(:stdout){ @cli.run }
693
731
  else
694
- Oddb2xml::Cli.new(options.opts).run
732
+ @cli.run
695
733
  end
696
734
  end
697
735
 
@@ -706,8 +744,7 @@ if RUN_ALL
706
744
  end
707
745
 
708
746
  it 'should have a correct NBR_RECORD in oddb_code.xml' do
709
- rexml = REXML::Document.new File.read(oddb_code_xml)
710
- check_result(rexml, NrCodes)
747
+ check_result(File.read(oddb_code_xml), NrCodes)
711
748
  end
712
749
 
713
750
  context 'XSD interaction' do
@@ -716,8 +753,7 @@ if RUN_ALL
716
753
  end
717
754
 
718
755
  it 'should have a correct NBR_RECORD in oddb_interaction.xml' do
719
- rexml = REXML::Document.new File.read(oddb_interaction_xml)
720
- check_result(rexml, NrInteractions)
756
+ check_result(File.read(oddb_interaction_xml), NrInteractions)
721
757
  end
722
758
 
723
759
  context 'XSD substance' do
@@ -726,8 +762,7 @@ if RUN_ALL
726
762
  end
727
763
 
728
764
  it 'should have a correct NBR_RECORD in oddb_substance.xml' do
729
- rexml = REXML::Document.new File.read('oddb_substance.xml')
730
- check_result(rexml, NrSubstances)
765
+ check_result(File.read('oddb_substance.xml'), NrSubstances)
731
766
  end
732
767
 
733
768
  it 'should emit a correct oddb_article.xml' do
@@ -759,7 +794,7 @@ if RUN_ALL
759
794
  expect(XPath.match( doc, "//REF_DATA" ).size).to be > 0
760
795
  checkItemForRefdata(doc, "1699947", 1) # 3TC Filmtabl 150 mg SMNO 53662013 IKSNR 53‘662, 53‘663
761
796
  checkItemForRefdata(doc, "0598003", 0) # SOFRADEX Gtt Auric 8 ml
762
- checkItemForRefdata(doc, "5366964", 1) # 1-DAY ACUVUE moist jour
797
+ checkItemForRefdata(doc, "5366964", 0) # 1-DAY ACUVUE moist jour
763
798
  unless SkipMigelDownloader
764
799
  novopen = checkItemForRefdata(doc, "3036984", 1) # NovoPen 4 Injektionsgerät blue In NonPharma (a MiGel product)
765
800
  expect(novopen.elements['ARTBAR/BC'].text).to eq '0'
@@ -768,8 +803,7 @@ if RUN_ALL
768
803
 
769
804
  it 'should generate SALECD A for migel (NINCD 13)' do
770
805
  doc = REXML::Document.new File.new(checkAndGetArticleXmlName)
771
- article = XPath.match( doc, "//ART[ARTINS/NINCD=13]").first
772
- article = XPath.match( doc, "//ART[PHAR=5366964]").first
806
+ article = XPath.match( doc, "//ART[PHAR=4236863]").first
773
807
  expect(article.elements['SALECD'].text).to eq('A')
774
808
  expect(article.elements['ARTINS/NINCD'].text).to eq('13')
775
809
  end
@@ -791,7 +825,7 @@ if RUN_ALL
791
825
  expect(XPath.match( doc, "//PHAR" ).find_all{|x| x.text.match('5366964') }.size).to eq(1)
792
826
  expect(dscrds.size).to eq(NrExtendedArticles)
793
827
  expect(XPath.match( doc, "//PRODNO" ).find_all{|x| true}.size).to be >= 1
794
- expect(XPath.match( doc, "//PRODNO" ).find_all{|x| x.text.match('0027701') }.size).to eq(0)
828
+ expect(XPath.match( doc, "//PRODNO" ).find_all{|x| x.text.match('0027701') }.size).to eq(1)
795
829
  expect(XPath.match( doc, "//PRODNO" ).find_all{|x| x.text.match('6206901') }.size).to eq(1)
796
830
  end
797
831
 
@@ -805,8 +839,7 @@ if RUN_ALL
805
839
  end
806
840
 
807
841
  it 'should have a correct NBR_RECORD in oddb_limitation.xml' do
808
- rexml = REXML::Document.new File.read('oddb_limitation.xml')
809
- check_result(rexml, NrLimitations)
842
+ check_result(File.read('oddb_limitation.xml'), NrLimitations)
810
843
  end
811
844
 
812
845
  it 'should emit a correct oddb_limitation.xml' do
@@ -817,10 +850,10 @@ if RUN_ALL
817
850
  limitations = XPath.match( doc, "//LIM" )
818
851
  expect(limitations.size).to eql NrLimitations
819
852
  expect(XPath.match( doc, "//SwissmedicNo5" ).find_all{|x| x.text.match('28486') }.size).to eq(1)
820
- expect(XPath.match( doc, "//LIMNAMEBAG" ).find_all{|x| x.text.match('ZYVOXID') }.size).to eq(1)
821
- expect(XPath.match( doc, "//LIMNAMEBAG" ).find_all{|x| x.text.match('070240') }.size).to eq(1)
822
- expect(XPath.match( doc, "//DSCRD" ).find_all{|x| x.text.match(/^Gesamthaft zugelassen/) }.size).to eq(1)
823
- expect(XPath.match( doc, "//DSCRD" ).find_all{|x| x.text.match(/^Behandlung nosokomialer Pneumonien/) }.size).to eq(1)
853
+ expect(XPath.match( doc, "//LIMNAMEBAG" ).find_all{|x| x.text.match('ZYVOXID') }.size).to eq(2)
854
+ expect(XPath.match( doc, "//LIMNAMEBAG" ).find_all{|x| x.text.match('070240') }.size).to be >= 1
855
+ expect(XPath.match( doc, "//DSCRD" ).find_all{|x| x.text.match(/^Gesamthaft zugelassen/) }.size).to be >= 1
856
+ expect(XPath.match( doc, "//DSCRD" ).find_all{|x| x.text.match(/^Behandlung nosokomialer Pneumonien/) }.size).to be >= 1
824
857
  end
825
858
 
826
859
  it 'should emit a correct oddb_substance.xml' do
@@ -833,7 +866,7 @@ if RUN_ALL
833
866
  it 'should emit a correct oddb_interaction.xml' do
834
867
  doc = REXML::Document.new File.new(File.join(Oddb2xml::WorkDir, 'oddb_interaction.xml'))
835
868
  titles = XPath.match( doc, "//TITD" )
836
- expect(titles.size).to eq 5
869
+ expect(titles.size).to eq 2
837
870
  expect(titles.find_all{|x| x.text.match('Keine Interaktion') }.size).to be >= 1
838
871
  expect(titles.find_all{|x| x.text.match('Erhöhtes Risiko für Myopathie und Rhabdomyolyse') }.size).to eq(1)
839
872
  end
@@ -859,19 +892,17 @@ if RUN_ALL
859
892
  checkItemForSALECD(doc, Oddb2xml::SOFRADEX_GTIN, 'I') # SOFRADEX
860
893
  end
861
894
  end
862
- if RUN_ALL
863
895
  context 'testing -e -I 80 option' do
864
896
  before(:all) do
865
897
  common_run_init
866
- options = Oddb2xml::Options.new
867
- options.parser.parse!('-e -I 80'.split(' '))
868
- @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options.opts).run }
898
+ options = Oddb2xml::Options.parse('-e -I 80 --log')
899
+ # @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options).run }
900
+ @res = Oddb2xml::Cli.new(options).run
869
901
  end
870
902
 
871
903
  it 'should add 80 percent to zur_rose pubbprice' do
872
904
  expect(File.exists?(oddb_article_xml)).to eq true
873
905
  FileUtils.cp(oddb_article_xml, File.join(Oddb2xml::WorkDir, 'tst-e80.xml'))
874
- checkProductXml(NrPackages)
875
906
  checkArticleXml
876
907
  checkPrices(true)
877
908
  end
@@ -880,17 +911,17 @@ if RUN_ALL
880
911
  expect(File.exists?(oddb_article_xml)).to eq true
881
912
  doc = REXML::Document.new IO.read(oddb_article_xml)
882
913
  article = XPath.match( doc, "//ART[PHAR=5822801]").first
883
- expect(article.elements['DSCRD'].text).to match(/EPIMINERAL/)
914
+ expect(article.elements['DSCRD'].text).to match /EPIMINERAL/i
884
915
  end
885
916
 
886
- it 'should generate a correct oddb_product.xml' do
917
+ it 'should generate a correct number of packages in oddb_product.xml' do
887
918
  checkProductXml(NrPackages)
888
919
  end
889
920
 
890
921
  it 'should generate an article with the COOL (fridge) attribute' do
891
922
  doc = REXML::Document.new File.new(oddb_article_xml)
892
923
  fridge_product = checkAndGetArticleWithGTIN(doc, Oddb2xml::FRIDGE_GTIN)
893
- expect(fridge_product.elements['COOL'].text).to eq '1'
924
+ expect(fridge_product.elements['COOL'].text).to eq('1')
894
925
  end
895
926
 
896
927
  it 'should generate a correct oddb_article.xml' do
@@ -901,9 +932,8 @@ if RUN_ALL
901
932
  context 'when -f dat -p is given' do
902
933
  before(:all) do
903
934
  common_run_init
904
- options = Oddb2xml::Options.new
905
- options.parser.parse!('-f dat -p'.split(' '))
906
- @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options.opts).run }
935
+ options = Oddb2xml::Options.parse('-f dat -p')
936
+ @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options).run }
907
937
  end
908
938
 
909
939
  it 'should report correct number of items' do
@@ -918,15 +948,15 @@ if RUN_ALL
918
948
  expect(oddb_dat).to match(/^..3/), "should have a record with '3' in CMUT field"
919
949
  expect(oddb_dat).to match(RegExpDesitin), "should have Desitin"
920
950
  IO.readlines(dat_filename).each{ |line| check_article_IGM_format(line, 0) }
951
+ # oddb_dat.should match(/^..1/), "should have a record with '1' in CMUT field" # we have no
921
952
  end
922
953
  end
923
954
 
924
955
  context 'when -f dat -I 80 is given' do
925
956
  before(:all) do
926
957
  common_run_init
927
- options = Oddb2xml::Options.new
928
- options.parser.parse!('-f dat -I 80'.split(' '))
929
- @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options.opts).run }
958
+ options = Oddb2xml::Options.parse('-f dat -I 80')
959
+ @res = buildr_capture(:stdout){ Oddb2xml::Cli.new(options).run }
930
960
  end
931
961
 
932
962
  it 'should report correct number of items' do
@@ -949,6 +979,5 @@ if RUN_ALL
949
979
  expect(out.chomp).to eq '<NAME_DE>SENSURA Mio 1t Uro 10-33 midi con lig so op 10 Stk</NAME_DE>'
950
980
  end
951
981
  end
952
- end
953
- end
982
+
954
983
  end