oddb2xml 2.3.9 → 2.4.0

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: 6fca3e8cb403c6b1018420e04b9b1cbcb75c38ba
4
- data.tar.gz: c7dd0da5fee78db1d4455f8e3b3cc85509fecfbb
3
+ metadata.gz: 3ee7a2f5a9b16cb824676ba720cfc37bf14f293d
4
+ data.tar.gz: 3e75b9996fe29533d5479899630fa5b3e48a05f4
5
5
  SHA512:
6
- metadata.gz: cacc0a90106da5da0ef3fe85ddde95947aac9a023095b5eed345e4d6c1cd2a88cb55020b9d9fd390f94e17d548265766e73255d3a2e9a342bc61ba578eb1e572
7
- data.tar.gz: 4e2ef6fec5b3b7f1544ce1fb7d5322e99ba3af217189388523f2891521818ae5d21cc3516d823254e4d5f517059cd5916ac478a885fdb16dae3d368dc9b85a4d
6
+ metadata.gz: 2f8d17701b4cd24180ceb9ad11350ffe23b821e39bab8cde731f1e008a49eb52face6cc760c6dfcb76dbdc003260cb5eefbc0557ec68b0cd93b8b9d2443d54a6
7
+ data.tar.gz: 6157bec8affd1492a2858368bf454dca7e247cfa7bf157e6236a863eba3dcb342968c2376eb1e9f6ff2d1efcd4359c018e61a1b103e94ee584db99d3fb358ffa
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 2.4.0 /25.08.2016
2
+
3
+ * Remove transfer.zip in current directory. Added spec tests for downloaded files
4
+
1
5
  === 2.3.9 /23.08.2016
2
6
 
3
7
  * Get ZurRose data from http://pillbox.oddb.org/TRANSFER.ZIP
@@ -132,7 +132,9 @@ module Oddb2xml
132
132
  include DownloadMethod
133
133
  def download
134
134
  @url ||= 'https://download.epha.ch/cleaned/matrix.csv'
135
- download_as('epha_interactions.csv', 'r')
135
+ content = download_as('epha_interactions.csv', 'r')
136
+ FileUtils.rm_f('epha_interactions.csv', :verbose => true)
137
+ content
136
138
  end
137
139
  end
138
140
  class LppvDownloader < Downloader
@@ -152,7 +154,7 @@ module Oddb2xml
152
154
  Oddb2xml.log("ZurroseDownloader #{__LINE__} download #{@url} @url returns #{content.bytes}")
153
155
  content
154
156
  else
155
- file = File.join(WorkDir, 'transfer.zip')
157
+ file = File.join(Downloads, 'transfer.zip')
156
158
  unless Oddb2xml.skip_download(file)
157
159
  Oddb2xml.log "ZurroseDownloader #{__LINE__}: #{file}"
158
160
  begin
@@ -165,7 +167,7 @@ module Oddb2xml
165
167
  Oddb2xml.download_finished(file)
166
168
  end
167
169
  end
168
- read_xml_from_zip(/transfer.dat/, File.join(Downloads, File.basename(file)))
170
+ read_xml_from_zip(/transfer.dat/, file)
169
171
  dest = File.join(Downloads, 'transfer.dat')
170
172
  File.open(dest, 'r:iso-8859-1:utf-8').read
171
173
  end
@@ -1,3 +1,3 @@
1
1
  module Oddb2xml
2
- VERSION = "2.3.9"
2
+ VERSION = "2.4.0"
3
3
  end
data/spec/builder_spec.rb CHANGED
@@ -268,11 +268,11 @@ def check_article_IGM_format(line, price_kendural=825, add_80_percents=false)
268
268
  if /7680353660163\d$/.match(line) # KENDURAL Depottabl 30 Stk
269
269
  puts "found_SL for #{line}" if $VERBOSE
270
270
  found_SL = true
271
- expect(line[60..65]).to eq '000495'
272
- expect(price_exf).to eq 495
271
+ expect(line[60..65]).to eq '000496'
272
+ expect(price_exf).to eq 496
273
273
  expect(ckzl).to eq '1'
274
274
  expect(price_public).to eq price_kendural # this is a SL-product. Therefore we may not have a price increase
275
- expect(line[66..71]).to eq '000'+price_kendural.to_s # the dat format requires leading zeroes and not point
275
+ expect(line[66..71]).to eq '000'+sprintf('%03d', price_kendural) # the dat format requires leading zeroes and not point
276
276
  end
277
277
 
278
278
  if /7680403330459\d$/.match(line) # CARBADERM
@@ -392,7 +392,7 @@ def checkArticleXml(checkERYTHROCIN = true)
392
392
 
393
393
  erythrocin_gtin = '7680202580475' # picked up from zur rose
394
394
  erythrocin = checkAndGetArticleWithGTIN(doc, erythrocin_gtin)
395
- expect(erythrocin.elements['DSCRD'].text).to eq("ERYTHROCIN i.v. Trockensub 1000 mg Amp [!]") if checkERYTHROCIN
395
+ expect(erythrocin.elements['DSCRD'].text).to eq("ERYTHROCIN i.v. Trockensub 1000 mg Amp") if checkERYTHROCIN
396
396
 
397
397
  lansoyl = checkAndGetArticleWithGTIN(doc, Oddb2xml::LANSOYL_GTIN)
398
398
  expect(lansoyl.elements['DSCRD'].text).to eq 'LANSOYL Gel 225 g'
@@ -616,7 +616,7 @@ if RUN_ALL
616
616
  expect(oddb_dat).to match(/^..2/), "should have a record with '2' in CMUT field"
617
617
  expect(oddb_dat).to match(/^..3/), "should have a record with '3' in CMUT field"
618
618
  expect(oddb_dat).to match(RegExpDesitin), "should have Desitin"
619
- IO.readlines(dat_filename).each{ |line| check_article_IGM_format(line) }
619
+ IO.readlines(dat_filename).each{ |line| check_article_IGM_format(line, 0) }
620
620
  m = /.+DIAPHIN Trocke.*7680555610041.+/.match(oddb_dat)
621
621
  expect(m[0].size).to eq 97 # size of IGM 1 record
622
622
  expect(m[0][74]).to eq '3'
@@ -918,7 +918,7 @@ if RUN_ALL
918
918
  expect(oddb_dat).to match(/^..2/), "should have a record with '2' in CMUT field"
919
919
  expect(oddb_dat).to match(/^..3/), "should have a record with '3' in CMUT field"
920
920
  expect(oddb_dat).to match(RegExpDesitin), "should have Desitin"
921
- IO.readlines(dat_filename).each{ |line| check_article_IGM_format(line) }
921
+ IO.readlines(dat_filename).each{ |line| check_article_IGM_format(line, 0) }
922
922
  # oddb_dat.should match(/^..1/), "should have a record with '1' in CMUT field" # we have no
923
923
  end
924
924
  end
@@ -940,7 +940,7 @@ if RUN_ALL
940
940
  expect(File.exists?(dat_filename)).to eq true
941
941
  oddb_dat = IO.read(dat_filename)
942
942
  oddb_dat_lines = IO.readlines(dat_filename)
943
- IO.readlines(dat_filename).each{ |line| check_article_IGM_format(line, 891, true) }
943
+ IO.readlines(dat_filename).each{ |line| check_article_IGM_format(line, 892, true) }
944
944
  end
945
945
  end
946
946
  end
data/spec/cli_spec.rb CHANGED
@@ -181,9 +181,10 @@ describe Oddb2xml::Cli do
181
181
  end
182
182
  it 'should create the needed files' do
183
183
  expect(@cli_output).to match(/\sPharma\s/)
184
+ expect(File.exists?(File.join(Oddb2xml::Downloads, 'transfer.zip'))).to eq true
185
+ expect(File.exists?(File.join(Oddb2xml::WorkDir, 'transfer.zip'))).to eq false
184
186
  expected = [
185
187
  'duplicate_ean13_from_zur_rose.txt',
186
- 'transfer.zip',
187
188
  'oddb.dat',
188
189
  ].each{ |file|
189
190
  expect(File.exists?(File.join(Oddb2xml::WorkDir, file))).to eq true
@@ -0,0 +1,41 @@
1
+ 1130020209ERYTHROCIN i.v. Trockensub 1000 mg Amp 004137005995300B080160076802025804752
2
+ 1120020244FERRO-GRADUMET Depottabl 30 Stk 000896001380300C060710076803164401152
3
+ 1120020273KENDURAL Depottabl 30 Stk 000496000000100C060710076803536601632
4
+ 1130020646SELSUN Shampoo Susp 60 ml 000911001650300D100400076801723304142
5
+ 1130020652SELSUN Shampoo Susp (alt) 120 ml 001576002430300D100400076801723306812
6
+ 1130021806EAU PRECIEUSE D�pensier L�s 375 ml 001220001870300D100600040123461177062
7
+ 1125822801EPIMINERAL Paste 20 g 0043200060004000000000000000000000001
8
+ 1125822801EPIMINERAL Paste 20 g 0043200060004000000000000000000000001
9
+ 1125574740ADCETRIS Trockensub 50 mg Durchstf 369513394945101A000000076806213200102
10
+ 1120055805TENSOPLAST Kompressionsbinde 5cmx4.5m 0000000015001000000000040428090182881
11
+ 1125822801EPIMINERAL Paste 20 g 0043200060004000000000000000000000001
12
+ 1120055834TENSOPLAST Kompressionsbinde 10cmx4.5m 0000000025001000000000040428090184931
13
+ 1125822801EPIMINERAL Paste 20 g 0043200060004000000000000000000000001
14
+ 1125822801EPIMINERAL Paste 20 g 0043200060004000000000000000000000001
15
+ 1120058502TUBEGAZE Verband weiss Nr 01 20m Finger Zehen 0000000014201000000000076116004410131
16
+ 1120058519TUBEGAZE Verband weiss Nr 12 20m Finger gross 0000000017001000000000076116004410201
17
+ 1120058525TUBEGAZE Verband weiss Nr 34 20m Arm Fuss 0000000023201000000000076116004410371
18
+ 1122731179HIRUDOID Creme 3 mg/g 40 g 000477000880100D020820076801610505832
19
+ 1130020646SELSUN Shampoo Susp 60 ml 000911001650300D100400076801723304142
20
+ 1120177804ANCOPIR Inj L�s 5 Amp 2 ml 000337000795100B070240076802848601442
21
+ 1120020244FERRO-GRADUMET Depottabl 30 Stk 000896001380300C060710076803164401152
22
+ 1130598003SOFRADEX Gtt Auric 8 ml 000718001545300B120130076803169501572
23
+ 1130023722LANSOYL Gel 225 g 001054001625200D040811076803247501902
24
+ 1120020273KENDURAL Depottabl 30 Stk 000496000000100C060710076803536601632
25
+ 1133603779CARBADERM Creme Tb 300 ml 001622002770300D101000076804033304592
26
+ 11216999473TC Filmtabl 150 mg 60 Stk 017201020530100A080300076805366201372
27
+ 1122465312ZYVOXID Filmtabl 600 mg 10 Stk 084173094135100A080190076805555800542
28
+ 1125819012LEVETIRACETAM DESITIN Mini Filmtab 250 mg 30 Stk 001349002780100B000000076806206900842
29
+ 1121323751MAGNESIUMCHLORID Braun 0.5 molar 10ml Amp 5 Stk 001497002750300B050320076804588202022
30
+ 1125822801EPIMINERAL Paste 20 g 0043200060004000000000000000000000001
31
+ 1125822801EPIMINERAL Paste 20 g 0043200060004000000000000000000000001
32
+ 1120850684LIDOCAIN Streuli 1% 20 mg/2ml 10 Amp 2 ml 000556000975300B010220076803001501052
33
+ 1120935914ROCEPHIN 500 mg i.v. c Solv Durchstf 5 Stk 006084008160100A080130076804462505922
34
+ 1125822801EPIMINERAL Paste 20 g 0043200060004000000000000000000000001
35
+ 1130216094W TROPFEN liq 11.5 g 000658001080201D100700076801659801142
36
+ 1125822801EPIMINERAL Paste 20 g 0043200060004000000000000000000000001
37
+ 1122497134CAVERJECT DC Trockensub 20 mcg Fertspr 2 Stk 003496005420100A059900076805567400752
38
+ 1122134986NAROPIN Inj L�s 0.2 % 100ml Polybag 5 Stk 008275010690300B010220076805401510092
39
+ 1125822801EPIMINERAL Paste 20 g 0043200060004000000000000000000000001
40
+ 1121699999HUMALOG Inj L�s 100 IE/ml Durchstf 10 ml 003040005130101B070610076805329001962
41
+ 1125822801EPIMINERAL Paste 20 g 0043200060004000000000000000000000001
Binary file
@@ -262,6 +262,9 @@ end
262
262
  expect(File.exist?('oddb_orphan.xls')).to eq(false)
263
263
  end
264
264
  end
265
+ it 'should not save into the download directory' do
266
+ expect(File.exist?(File.join(Oddb2xml::Downloads, 'oddb_orphan.xls'))).to eq(false)
267
+ end
265
268
  end
266
269
  end
267
270
  context 'package' do
@@ -270,15 +273,16 @@ end
270
273
  VCR.insert_cassette('oddb2xml', :tag => :swissmedic, :exclusive => false)
271
274
  common_before
272
275
  @downloader = Oddb2xml::SwissmedicDownloader.new(:package)
276
+ @bin = @downloader.download
273
277
  end
274
278
  after(:each) do common_after end
275
279
  context 'download_by for package xls' do
276
- let(:bin) {
277
- @downloader.download
278
- }
279
280
  it 'should return valid Binary-String' do
280
- expect(bin).to be_a String
281
- expect(bin.bytes).not_to be nil
281
+ expect(@bin).to be_a String
282
+ expect(@bin.bytes).not_to be nil
283
+ end
284
+ it 'should save into the download directory' do
285
+ expect(File.exist?(File.join(Oddb2xml::Downloads, 'swissmedic_package.xlsx'))).to eq(true)
282
286
  end
283
287
  end
284
288
  end
@@ -305,6 +309,7 @@ describe Oddb2xml::EphaDownloader do
305
309
  VCR.insert_cassette('oddb2xml', :tag => :epha)
306
310
  @downloader = Oddb2xml::EphaDownloader.new
307
311
  common_before
312
+ @downloader.download
308
313
  end
309
314
  after(:all) do
310
315
  common_after
@@ -321,8 +326,10 @@ describe Oddb2xml::EphaDownloader do
321
326
  expect(csv.bytes).not_to be nil
322
327
  end
323
328
  it 'should clean up current directory' do
324
- expect { csv }.not_to raise_error
325
- # File.exist?('epha_interactions.csv').should eq(false)
329
+ File.exist?('epha_interactions.csv').should eq(false)
330
+ end
331
+ it 'should save under download' do
332
+ expect(File.exist?(File.join(Oddb2xml::Downloads, 'epha_interactions.csv'))).to eq(true)
326
333
  end
327
334
  end
328
335
  end
@@ -413,6 +420,7 @@ describe Oddb2xml::MigelDownloader do
413
420
  @downloader = Oddb2xml::MigelDownloader.new
414
421
  VCR.insert_cassette('oddb2xml', :tag => :migel)
415
422
  common_before
423
+ @downloader.download
416
424
  end
417
425
  after(:each) do common_after end
418
426
 
@@ -436,12 +444,10 @@ describe Oddb2xml::ZurroseDownloader do
436
444
  before(:each) do
437
445
  VCR.configure do |c|
438
446
  c.before_record(:zurrose) do |i|
439
- if /zurrose/i.match(i.request.uri)
447
+ if /pillbox/i.match(i.request.uri)
440
448
  puts "#{Time.now}: #{__LINE__}: URI was #{i.request.uri}"
441
- lines = i.response.body.clone.split("\n")
442
- to_add = lines[0..5]
443
- Oddb2xml::GTINS_DRUGS.each{ |ean| to_add << lines.find{ |line| line.index(ean.to_s) || /EPIMINERAL/i.match(line) } }
444
- i.response.body = to_add.compact.join("\n")
449
+ tmp_zip = File.join(Oddb2xml::SpecData, 'vcr', 'transfer.zip')
450
+ i.response.body = IO.binread(tmp_zip)
445
451
  i.response.headers['Content-Length'] = i.response.body.size
446
452
  end
447
453
  end
@@ -449,6 +455,7 @@ describe Oddb2xml::ZurroseDownloader do
449
455
  VCR.insert_cassette('oddb2xml', :tag => :zurrose)
450
456
  @downloader = Oddb2xml::ZurroseDownloader.new
451
457
  common_before
458
+ @downloader.download
452
459
  end
453
460
  after(:each) do common_after end
454
461
 
@@ -463,6 +470,11 @@ describe Oddb2xml::ZurroseDownloader do
463
470
  expect { dat }.not_to raise_error
464
471
  expect(File.exist?('transfer.dat')).to eq(false)
465
472
  expect(File.exist?('oddb2xml_zurrose_transfer.dat')).to eq(false)
473
+ expect(File.exist?('transfer.zip')).to eq(false)
474
+ end
475
+ it 'should save into the download directory' do
476
+ expect(File.exist?(File.join(Oddb2xml::Downloads, 'transfer.zip'))).to eq(true)
477
+ expect(File.exist?(File.join(Oddb2xml::Downloads, 'transfer.dat'))).to eq(true)
466
478
  end
467
479
  end
468
480
  end
@@ -475,26 +487,32 @@ describe Oddb2xml::MedregbmDownloader do
475
487
  c.before_record(:medreg) do |i|
476
488
  if /medregbm.admin.ch/i.match(i.request.uri)
477
489
  puts "#{Time.now}: #{__LINE__}: URI was #{i.request.uri} containing #{i.response.body.size/(1024*1024)} MB "
478
- medreg_dir = File.join(Oddb2xml::WorkDir, 'medreg')
479
- FileUtils.makedirs(medreg_dir)
480
- xlsx_name = File.join(medreg_dir, /ListBetrieb/.match(i.request.uri) ? 'Betriebe.xlsx' : 'Personen.xlsx')
481
- File.open(xlsx_name, 'wb+') { |f| f.write(i.response.body) }
482
- puts "#{Time.now}: Openening saved #{xlsx_name} (#{File.size(xlsx_name)} bytes) will take some time. URI was #{i.request.uri}"
483
- workbook = RubyXL::Parser.parse(xlsx_name)
484
- worksheet = workbook[0]
485
- idx = 1; to_delete = []
486
- while (worksheet.sheet_data[idx])
487
- idx += 1
488
- next unless worksheet.sheet_data[idx-1][0]
489
- to_delete << (idx-1) unless Oddb2xml::GTINS_MEDREG.index(worksheet.sheet_data[idx-1][0].value.to_i)
490
- end
491
- if to_delete.size > 0
492
- puts "#{Time.now}: Deleting #{to_delete.size} of the #{idx} items will take some time"
493
- to_delete.reverse.each{ |row_id| worksheet.delete_row(row_id) }
494
- workbook.write(xlsx_name)
495
- i.response.body = IO.binread(xlsx_name)
490
+ begin
491
+ medreg_dir = File.join(Oddb2xml::WorkDir, 'medreg')
492
+ FileUtils.makedirs(medreg_dir)
493
+ xlsx_name = File.join(medreg_dir, /ListBetrieb/.match(i.request.uri) ? 'Betriebe.xlsx' : 'Personen.xlsx')
494
+ File.open(xlsx_name, 'wb+') { |f| f.write(i.response.body) }
495
+ puts "#{Time.now}: Openening saved #{xlsx_name} (#{File.size(xlsx_name)} bytes) will take some time. URI was #{i.request.uri}"
496
+ workbook = RubyXL::Parser.parse(xlsx_name)
497
+ worksheet = workbook[0]
498
+ idx = 1; to_delete = []
499
+ while (worksheet.sheet_data[idx])
500
+ idx += 1
501
+ next unless worksheet.sheet_data[idx-1][0]
502
+ to_delete << (idx-1) unless Oddb2xml::GTINS_MEDREG.index(worksheet.sheet_data[idx-1][0].value.to_i)
503
+ end
504
+ if to_delete.size > 0
505
+ puts "#{Time.now}: Deleting #{to_delete.size} of the #{idx} items will take some time"
506
+ to_delete.reverse.each{ |row_id| worksheet.delete_row(row_id) }
507
+ workbook.write(xlsx_name)
508
+ i.response.body = IO.binread(xlsx_name)
509
+ i.response.headers['Content-Length'] = i.response.body.size
510
+ puts "#{Time.now}: response.body is now #{i.response.body.size/(1024*1024)} MB long. #{xlsx_name} was #{File.size(xlsx_name)}"
511
+ end
512
+ rescue
513
+ puts "Creating empty content, as I am unable to parse the XLSX file"
514
+ i.response.body = ""
496
515
  i.response.headers['Content-Length'] = i.response.body.size
497
- puts "#{Time.now}: response.body is now #{i.response.body.size/(1024*1024)} MB long. #{xlsx_name} was #{File.size(xlsx_name)}"
498
516
  end
499
517
  end
500
518
  end
@@ -508,6 +526,7 @@ describe Oddb2xml::MedregbmDownloader do
508
526
  VCR.eject_cassette
509
527
  VCR.insert_cassette('oddb2xml', :tag => :medreg)
510
528
  @downloader = Oddb2xml::MedregbmDownloader.new(:company)
529
+ @downloader.download
511
530
  end
512
531
  after(:each) do common_after end
513
532
  it_behaves_like 'any downloader'
@@ -578,6 +597,7 @@ describe Oddb2xml::SwissmedicInfoDownloader do
578
597
  VCR.insert_cassette('oddb2xml', :tag => :swissmedicInfo)
579
598
  common_before
580
599
  @downloader = Oddb2xml::SwissmedicInfoDownloader.new
600
+ @downloader.download
581
601
  end
582
602
  after(:all) do common_after end
583
603
  it_behaves_like 'any downloader'
@@ -596,6 +616,9 @@ describe Oddb2xml::SwissmedicInfoDownloader do
596
616
  expect { xml }.not_to raise_error
597
617
  expect(File.exist?('swissmedic_info.zip')).to eq(false)
598
618
  end
619
+ it 'should save into the download directory' do
620
+ expect(File.exist?(File.join(Oddb2xml::Downloads, 'swissmedic_info.zip'))).to eq(true)
621
+ end
599
622
  end
600
623
  end
601
624