oddb2xml 2.7.1 → 2.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +1 -1
- data/.standard.yml +2 -0
- data/Gemfile +3 -3
- data/History.txt +8 -0
- data/README.md +1 -1
- data/Rakefile +24 -23
- data/bin/check_artikelstamm +11 -11
- data/bin/compare_v5 +23 -23
- data/bin/oddb2xml +14 -13
- data/lib/oddb2xml.rb +1 -1
- data/lib/oddb2xml/builder.rb +1070 -1038
- data/lib/oddb2xml/calc.rb +232 -233
- data/lib/oddb2xml/chapter_70_hack.rb +38 -32
- data/lib/oddb2xml/cli.rb +252 -236
- data/lib/oddb2xml/compare.rb +70 -59
- data/lib/oddb2xml/compositions_syntax.rb +448 -430
- data/lib/oddb2xml/compressor.rb +20 -20
- data/lib/oddb2xml/downloader.rb +153 -127
- data/lib/oddb2xml/extractor.rb +302 -289
- data/lib/oddb2xml/options.rb +34 -35
- data/lib/oddb2xml/parslet_compositions.rb +263 -269
- data/lib/oddb2xml/semantic_check.rb +39 -33
- data/lib/oddb2xml/util.rb +163 -163
- data/lib/oddb2xml/version.rb +1 -1
- data/lib/oddb2xml/xml_definitions.rb +32 -33
- data/oddb2xml.gemspec +31 -32
- data/spec/artikelstamm_spec.rb +111 -110
- data/spec/builder_spec.rb +489 -505
- data/spec/calc_spec.rb +552 -593
- data/spec/check_artikelstamm_spec.rb +26 -26
- data/spec/cli_spec.rb +173 -174
- data/spec/compare_spec.rb +9 -11
- data/spec/composition_syntax_spec.rb +390 -409
- data/spec/compressor_spec.rb +48 -48
- data/spec/data/transfer.dat +1 -0
- data/spec/data_helper.rb +47 -49
- data/spec/downloader_spec.rb +247 -260
- data/spec/extractor_spec.rb +171 -159
- data/spec/galenic_spec.rb +233 -256
- data/spec/options_spec.rb +116 -119
- data/spec/parslet_spec.rb +833 -861
- data/spec/spec_helper.rb +154 -153
- data/test_options.rb +39 -42
- data/tools/win_fetch_cacerts.rb +2 -3
- metadata +19 -3
data/spec/compressor_spec.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
@compressor.contents << File.join(Oddb2xml::SpecCompressor,
|
8
|
-
@compressor.contents << File.join(Oddb2xml::SpecCompressor,
|
9
|
-
@compressor.contents << File.join(Oddb2xml::SpecCompressor,
|
10
|
-
@compressor.contents << File.join(Oddb2xml::SpecCompressor,
|
11
|
-
|
12
|
-
@compressor.
|
13
|
-
expect(@compressor.finalize!).not_to be nil
|
3
|
+
shared_examples_for "any compressor" do
|
4
|
+
it "should create compress file" do
|
5
|
+
@compressor.contents << File.join(Oddb2xml::SpecCompressor, "oddb_article.xml")
|
6
|
+
@compressor.contents << File.join(Oddb2xml::SpecCompressor, "oddb_product.xml")
|
7
|
+
@compressor.contents << File.join(Oddb2xml::SpecCompressor, "oddb_substance.xml")
|
8
|
+
@compressor.contents << File.join(Oddb2xml::SpecCompressor, "oddb_limitation.xml")
|
9
|
+
@compressor.contents << File.join(Oddb2xml::SpecCompressor, "oddb_fi.xml")
|
10
|
+
@compressor.contents << File.join(Oddb2xml::SpecCompressor, "oddb_fi_product.xml")
|
11
|
+
%(
|
12
|
+
expect{@compressor.finalize!}.not_to be nil
|
14
13
|
compress_file = @compressor.instance_variable_get(:@compress_file)
|
15
|
-
expect(File.
|
14
|
+
expect(File.exist?(compress_file)).to eq(true)
|
16
15
|
@compressor = nil
|
16
|
+
)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -22,96 +22,96 @@ describe Oddb2xml::Compressor do
|
|
22
22
|
cleanup_compressor
|
23
23
|
if @compress_file
|
24
24
|
compress_file = @compressor.instance_variable_get(:@compress_file)
|
25
|
-
FileUtils.rm_f(compress_file, :
|
25
|
+
FileUtils.rm_f(compress_file, verbose: true)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
after(:all) do
|
29
29
|
cleanup_compressor
|
30
30
|
end
|
31
|
-
context
|
32
|
-
context
|
31
|
+
context "at initialize" do
|
32
|
+
context " argment is given" do
|
33
33
|
before(:each) do
|
34
34
|
cleanup_directories_before_run
|
35
35
|
@compressor = Oddb2xml::Compressor.new
|
36
36
|
end
|
37
|
-
it
|
37
|
+
it "should have empty contents as array" do
|
38
38
|
expect(@compressor.contents).to be_a Array
|
39
39
|
expect(@compressor.contents).to be_empty
|
40
40
|
end
|
41
|
-
it
|
42
|
-
expect(@compressor.instance_variable_get(:@compress_file))
|
43
|
-
to match(/oddb_xml_\d{2}.\d{2}.\d{4}_\d{2}.\d{2}.tar\.gz/)
|
41
|
+
it "should have formated filename with datetime" do
|
42
|
+
expect(@compressor.instance_variable_get(:@compress_file))
|
43
|
+
.to match(/oddb_xml_\d{2}.\d{2}.\d{4}_\d{2}.\d{2}.tar\.gz/)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
context "when swiss prefix is given" do
|
47
47
|
before(:each) do
|
48
48
|
cleanup_directories_before_run
|
49
|
-
@compressor = Oddb2xml::Compressor.new(
|
49
|
+
@compressor = Oddb2xml::Compressor.new("swiss", {compress_ext: "tar.gz"})
|
50
50
|
end
|
51
|
-
it
|
52
|
-
expect(@compressor.instance_variable_get(:@compress_file))
|
53
|
-
to match(/swiss_xml_\d{2}.\d{2}.\d{4}_\d{2}.\d{2}.tar\.gz/)
|
51
|
+
it "should have formated filename with datetime" do
|
52
|
+
expect(@compressor.instance_variable_get(:@compress_file))
|
53
|
+
.to match(/swiss_xml_\d{2}.\d{2}.\d{4}_\d{2}.\d{2}.tar\.gz/)
|
54
54
|
end
|
55
55
|
end
|
56
56
|
context "when tar.gz ext is given" do
|
57
57
|
before(:each) do
|
58
58
|
cleanup_directories_before_run
|
59
|
-
@compressor = Oddb2xml::Compressor.new(
|
59
|
+
@compressor = Oddb2xml::Compressor.new("oddb", {compress_ext: "tar.gz"})
|
60
60
|
end
|
61
|
-
it
|
62
|
-
expect(@compressor.instance_variable_get(:@compress_file))
|
63
|
-
to match(/oddb_xml_\d{2}.\d{2}.\d{4}_\d{2}.\d{2}.tar\.gz/)
|
61
|
+
it "should have formated filename with datetime" do
|
62
|
+
expect(@compressor.instance_variable_get(:@compress_file))
|
63
|
+
.to match(/oddb_xml_\d{2}.\d{2}.\d{4}_\d{2}.\d{2}.tar\.gz/)
|
64
64
|
end
|
65
65
|
end
|
66
66
|
context "when zip ext is given" do
|
67
67
|
before(:each) do
|
68
68
|
cleanup_directories_before_run
|
69
|
-
@compressor = Oddb2xml::Compressor.new(
|
69
|
+
@compressor = Oddb2xml::Compressor.new("oddb", {compress_ext: "zip"})
|
70
70
|
end
|
71
|
-
it
|
72
|
-
expect(@compressor.instance_variable_get(:@compress_file))
|
73
|
-
to match(/oddb_xml_\d{2}.\d{2}.\d{4}_\d{2}.\d{2}.zip/)
|
71
|
+
it "should have formated filename with datetime" do
|
72
|
+
expect(@compressor.instance_variable_get(:@compress_file))
|
73
|
+
.to match(/oddb_xml_\d{2}.\d{2}.\d{4}_\d{2}.\d{2}.zip/)
|
74
74
|
end
|
75
75
|
end
|
76
76
|
end
|
77
|
-
context
|
78
|
-
context
|
77
|
+
context "when finalize! is called" do
|
78
|
+
context "unexpectedly" do
|
79
79
|
before(:each) do
|
80
80
|
cleanup_directories_before_run
|
81
|
-
@
|
81
|
+
@saved_dir = Dir.pwd
|
82
82
|
Dir.chdir Oddb2xml::SpecCompressor
|
83
83
|
@compressor = Oddb2xml::Compressor.new
|
84
84
|
end
|
85
85
|
after(:each) do
|
86
|
-
Dir.chdir @
|
86
|
+
Dir.chdir @saved_dir if @saved_dir && File.directory?(@saved_dir)
|
87
87
|
end
|
88
|
-
it
|
88
|
+
it "should fail with no contents" do
|
89
89
|
expect(@compressor.finalize!).to eq(false)
|
90
90
|
end
|
91
|
-
it
|
92
|
-
@compressor.contents <<
|
93
|
-
expect
|
91
|
+
it "should fail with invalid file" do
|
92
|
+
@compressor.contents << "../invalid_file"
|
93
|
+
expect { @compressor.finalize! }.to raise_error(RuntimeError)
|
94
94
|
end
|
95
95
|
end
|
96
|
-
context
|
97
|
-
context
|
96
|
+
context "successfully" do
|
97
|
+
context "with tar.gz" do
|
98
98
|
before(:each) do
|
99
99
|
cleanup_directories_before_run
|
100
100
|
@compressor = Oddb2xml::Compressor.new
|
101
101
|
end
|
102
|
-
it_behaves_like
|
102
|
+
it_behaves_like "any compressor"
|
103
103
|
end
|
104
|
-
context
|
104
|
+
context "with zip" do
|
105
105
|
before(:each) do
|
106
106
|
cleanup_directories_before_run
|
107
|
-
@
|
107
|
+
@saved_dir = Dir.pwd
|
108
108
|
Dir.chdir Oddb2xml::SpecCompressor
|
109
|
-
@compressor = Oddb2xml::Compressor.new(
|
109
|
+
@compressor = Oddb2xml::Compressor.new("oddb", {compress_ext: "zip"})
|
110
110
|
end
|
111
111
|
after(:each) do
|
112
|
-
Dir.chdir @
|
112
|
+
Dir.chdir @saved_dir if @saved_dir && File.directory?(@saved_dir)
|
113
113
|
end
|
114
|
-
it_behaves_like
|
114
|
+
it_behaves_like "any compressor"
|
115
115
|
end
|
116
116
|
end
|
117
117
|
end
|
data/spec/data/transfer.dat
CHANGED
@@ -69,5 +69,6 @@
|
|
69
69
|
1122069562EINF ARZNEI Urtinktur 1-10g/ml 0010040013401000000000025000005884712
|
70
70
|
1122069639EINF ARZNEI Ceres Urtinktur spez 20ml 0023440031301000000000025000005885322
|
71
71
|
1122069622EINF ARZNEI Ceres Urtinktur 20ml 0018870025201000000000025000005885252
|
72
|
+
1130361821SEROCYTOL Kolon Supp 3 Stk 002275003960401B080700076800027800132
|
72
73
|
1131770177VARILRIX Trockensub c Solv (alt) Fertspr 0.5 ml 004768006650101B080800076800058500102
|
73
74
|
1127766692VARILRIX Trockensub c Solv Fertspr 0.5 ml 004767006650101B080800076800058500342
|
data/spec/data_helper.rb
CHANGED
@@ -1,47 +1,47 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
$:.unshift File.join(File.dirname(__FILE__))
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
module Oddb2xml
|
5
|
-
# Small helper script to see, whether all files are correctly filled
|
6
|
-
def
|
5
|
+
# Small helper script to see, whether all files are correctly filled
|
6
|
+
def self.fill
|
7
7
|
start_keys = [
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
]
|
36
|
-
|
37
|
-
gtins = GTINS_DRUGS + [ FERRO_GRADUMET_GTIN,
|
38
|
-
HIRUDOID_GTIN,LANSOYL_GTIN, LEVETIRACETAM_GTIN,
|
39
|
-
SOFRADEX_GTIN, THREE_TC_GTIN, ZYVOXID_GTIN]
|
40
|
-
gtins.each{|gtin| Oddb2xml.check_gtin(gtin)}
|
8
|
+
1125822801,
|
9
|
+
1125830700,
|
10
|
+
1122465312,
|
11
|
+
1120020209,
|
12
|
+
1120020244,
|
13
|
+
1130020646,
|
14
|
+
1120020652,
|
15
|
+
1130021806,
|
16
|
+
1130021976,
|
17
|
+
1130023722,
|
18
|
+
1130027447,
|
19
|
+
1130028470,
|
20
|
+
1135366964,
|
21
|
+
1122871437,
|
22
|
+
1122871443,
|
23
|
+
1122871466,
|
24
|
+
1122871472,
|
25
|
+
1132867163,
|
26
|
+
1138110429,
|
27
|
+
1130598003,
|
28
|
+
1125565072,
|
29
|
+
1126000923,
|
30
|
+
1128111222,
|
31
|
+
1128111718,
|
32
|
+
1128807890,
|
33
|
+
1117199565,
|
34
|
+
1128111611
|
35
|
+
]
|
41
36
|
|
42
|
-
|
43
|
-
|
44
|
-
|
37
|
+
gtins = GTINS_DRUGS + [FERRO_GRADUMET_GTIN,
|
38
|
+
HIRUDOID_GTIN, LANSOYL_GTIN, LEVETIRACETAM_GTIN,
|
39
|
+
SOFRADEX_GTIN, THREE_TC_GTIN, ZYVOXID_GTIN]
|
40
|
+
gtins.each { |gtin| Oddb2xml.check_gtin(gtin) }
|
41
|
+
|
42
|
+
ENV["LANG"] = "de_CH.ISO-8859"
|
43
|
+
outfile = "spec/data/transfer.dat"
|
44
|
+
FileUtils.rm_f(outfile, verbose: true)
|
45
45
|
start_keys.each do |key|
|
46
46
|
cmd = "egrep '^#{key}' downloads/transfer.dat >> #{outfile}"
|
47
47
|
system(cmd)
|
@@ -50,23 +50,21 @@ module Oddb2xml
|
|
50
50
|
gtins.each do |key|
|
51
51
|
cmd = "grep #{key} downloads/transfer.dat >> #{outfile}"
|
52
52
|
system(cmd)
|
53
|
-
iksnrs << key.to_s[4..8] if /^7680/i.match(key.to_s)
|
53
|
+
iksnrs << key.to_s[4..8] if /^7680/i.match?(key.to_s)
|
54
54
|
end
|
55
55
|
puts "Created #{outfile} #{File.size(outfile)} bytes"
|
56
|
-
puts "Used IKSNRS are #{iksnrs.sort.uniq.join(
|
56
|
+
puts "Used IKSNRS are #{iksnrs.sort.uniq.join(" ")}"
|
57
57
|
end
|
58
|
-
|
59
|
-
def
|
58
|
+
|
59
|
+
def self.check_gtin(gtin)
|
60
60
|
files = `grep -l #{gtin} downloads/*.xml`.split("\n")
|
61
61
|
files.each do |file|
|
62
|
-
short = File.join(SpecData,File.basename(file))
|
63
|
-
|
64
|
-
|
65
|
-
puts "Could not find #{gtin} in #{short}" unless
|
62
|
+
short = File.join(SpecData, File.basename(file))
|
63
|
+
nr_matches = 0
|
64
|
+
nr_matches = `grep -c #{gtin} #{short}`.to_i if File.exist?(short)
|
65
|
+
puts "Could not find #{gtin} in #{short}" unless nr_matches > 0
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
70
|
Oddb2xml.fill
|
71
|
-
|
72
|
-
|
data/spec/downloader_spec.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
|
2
|
-
require 'spec_helper'
|
1
|
+
require "spec_helper"
|
3
2
|
require "rexml/document"
|
4
3
|
|
5
4
|
VCR.eject_cassette # we use insert/eject around each example
|
6
5
|
|
7
6
|
# not used but, as I still don't know how to generate
|
8
|
-
def filter_aips_xml(filename=
|
9
|
-
puts "File #{filename} exists? #{File.
|
10
|
-
|
7
|
+
def filter_aips_xml(filename = "AipsDownload_ng.xml", ids_to_keep = [55558, 61848])
|
8
|
+
puts "File #{filename} exists? #{File.exist?(filename)}"
|
9
|
+
if $VERBOSE
|
10
|
+
puts %(<?xml version="1.0" encoding="utf-8"?>
|
11
11
|
<medicalInformations>
|
12
12
|
<medicalInformation type="fi" version="5" lang="de" safetyRelevant="false" informationUpdate="07.2008">
|
13
13
|
<title>Zyvoxid®</title>
|
@@ -16,37 +16,36 @@ def filter_aips_xml(filename='AipsDownload_ng.xml', ids_to_keep = [55558, 61848]
|
|
16
16
|
<substances>Linezolid</substances>
|
17
17
|
<authNrs>55558, 55559, 55560</authNrs>
|
18
18
|
)
|
19
|
+
end
|
19
20
|
@xml = IO.read(filename)
|
20
|
-
ausgabe = File.open(
|
21
|
+
ausgabe = File.open("tst.out", "w+")
|
21
22
|
data = {}
|
22
|
-
result = MedicalInformationsContent.parse(@xml.sub(
|
23
|
+
result = MedicalInformationsContent.parse(@xml.sub(STRIP_FOR_SAX_MACHINE, ""), lazy: true)
|
23
24
|
result.medicalInformation.each do |pac|
|
24
25
|
lang = pac.lang.to_s
|
25
|
-
next unless
|
26
|
+
next unless /de|fr/.match?(lang)
|
26
27
|
item = {}
|
27
|
-
|
28
|
-
pac.authNrs.split(/[, ]+/).each{
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
break
|
28
|
+
keep_it = false
|
29
|
+
pac.authNrs.split(/[, ]+/).each { |id|
|
30
|
+
if ids_to_keep.index(id.to_i)
|
31
|
+
data[[lang, id.to_i]] = pac
|
32
|
+
keep_it = true
|
33
|
+
ausgabe.puts
|
34
|
+
break
|
35
35
|
end
|
36
36
|
}
|
37
|
-
html = Nokogiri::HTML.fragment(pac.content.force_encoding(
|
37
|
+
html = Nokogiri::HTML.fragment(pac.content.force_encoding("UTF-8"))
|
38
38
|
item[:paragraph] = html
|
39
|
-
numbers =
|
39
|
+
numbers = /(\d{5})[,\s]*(\d{5})?|(\d{5})[,\s]*(\d{5})?[,\s]*(\d{5})?/.match(html)
|
40
40
|
if numbers
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
puts "Must keep #{keepIt} #{pac.authNrs}"
|
41
|
+
[$1, $2, $3].compact.each { |id|
|
42
|
+
if ids_to_keep.index(id.to_i)
|
43
|
+
data[[lang, id.to_i]] = pac
|
44
|
+
keep_it = true
|
45
|
+
break
|
46
|
+
end
|
47
|
+
}
|
48
|
+
puts "Must keep #{keep_it} #{pac.authNrs}"
|
50
49
|
end
|
51
50
|
end
|
52
51
|
puts data.size
|
@@ -54,43 +53,32 @@ def filter_aips_xml(filename='AipsDownload_ng.xml', ids_to_keep = [55558, 61848]
|
|
54
53
|
end
|
55
54
|
|
56
55
|
XML_VERSION_1_0 = /xml\sversion=["']1.0["']/
|
57
|
-
PREP_XML =
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
expect {
|
62
|
-
Array.new(3).map do
|
63
|
-
Thread.new do
|
64
|
-
expect(@downloader.send(:retrievable?)).to be(true)
|
65
|
-
end
|
66
|
-
end.map(&:join)
|
67
|
-
}.to change {
|
68
|
-
@downloader.instance_variable_get(:@retry_times)
|
69
|
-
}.from(3).to(0)
|
70
|
-
end if false # as vcr does not support threads for the moment
|
56
|
+
PREP_XML = "Preparations.xml"
|
57
|
+
|
58
|
+
shared_examples_for "any downloader" do
|
59
|
+
# nothing at the moment
|
71
60
|
end
|
72
61
|
|
73
62
|
def common_before
|
74
|
-
@
|
63
|
+
@saved_dir = Dir.pwd
|
75
64
|
cleanup_directories_before_run
|
76
|
-
FileUtils.makedirs(Oddb2xml::
|
77
|
-
Dir.chdir(Oddb2xml::
|
65
|
+
FileUtils.makedirs(Oddb2xml::WORK_DIR)
|
66
|
+
Dir.chdir(Oddb2xml::WORK_DIR)
|
78
67
|
WebMock.enable!
|
79
|
-
{
|
80
|
-
}.each do |url, file|
|
68
|
+
{"https://raw.githubusercontent.com/zdavatz/oddb2xml_files/master/interactions_de_utf8.csv" => "epha_interactions.csv"}.each do |url, file|
|
81
69
|
inhalt = File.read(File.join(Oddb2xml::SpecData, file))
|
82
|
-
stub_request(:get,url).to_return(body: inhalt)
|
70
|
+
stub_request(:get, url).to_return(body: inhalt)
|
83
71
|
end
|
84
72
|
end
|
85
73
|
|
86
74
|
def common_after
|
87
|
-
Dir.chdir(@
|
75
|
+
Dir.chdir(@saved_dir) if @saved_dir && File.directory?(@saved_dir)
|
88
76
|
VCR.eject_cassette
|
89
|
-
vcr_file = File.expand_path(File.join(Oddb2xml::SpecData,
|
90
|
-
puts "Pretty-printing #{vcr_file} exists? #{File.
|
91
|
-
vcr_file_new = vcr_file.sub(
|
77
|
+
vcr_file = File.expand_path(File.join(Oddb2xml::SpecData, "..", "fixtures", "vcr_cassettes", "oddb2xml.json"))
|
78
|
+
puts "Pretty-printing #{vcr_file} exists? #{File.exist?(vcr_file)}" if $VERBOSE
|
79
|
+
vcr_file_new = vcr_file.sub(".json", ".new")
|
92
80
|
cmd = "cat #{vcr_file} | python -mjson.tool > #{vcr_file_new}"
|
93
|
-
|
81
|
+
system(cmd)
|
94
82
|
FileUtils.mv(vcr_file_new, vcr_file)
|
95
83
|
end
|
96
84
|
|
@@ -106,87 +94,85 @@ def zip_files(zipfile_name, input_filenames)
|
|
106
94
|
end
|
107
95
|
|
108
96
|
# Unzips into a specific directory
|
109
|
-
def unzip_files(zipfile_name, directory=Dir.pwd)
|
110
|
-
|
97
|
+
def unzip_files(zipfile_name, directory = Dir.pwd)
|
98
|
+
saved_dir = Dir.pwd
|
111
99
|
FileUtils.makedirs(directory)
|
112
100
|
Dir.chdir(directory)
|
113
101
|
Zip::File.open(zipfile_name) do |zip_file|
|
114
102
|
# Handle entries one by one
|
115
103
|
zip_file.each do |entry|
|
116
104
|
# Extract to file/directory/symlink
|
117
|
-
puts "downloader_spec.rb: Extracting #{entry.name} exists? #{File.
|
118
|
-
FileUtils.rm_f(entry.name, :
|
105
|
+
puts "downloader_spec.rb: Extracting #{entry.name} exists? #{File.exist?(entry.name)} into #{directory}"
|
106
|
+
FileUtils.rm_f(entry.name, verbose: true) if File.exist?(entry.name)
|
119
107
|
entry.extract(entry.name)
|
120
108
|
end
|
121
109
|
end
|
122
110
|
ensure
|
123
|
-
Dir.chdir(
|
111
|
+
Dir.chdir(saved_dir)
|
124
112
|
end
|
125
113
|
|
126
|
-
|
127
114
|
describe Oddb2xml::RefdataDownloader do
|
128
115
|
include ServerMockHelper
|
129
116
|
before(:all) do
|
130
117
|
VCR.eject_cassette
|
131
118
|
VCR.configure do |c|
|
132
119
|
c.before_record(:Refdata_DE) do |i|
|
133
|
-
if
|
134
|
-
puts "#{Time.now}: #{__LINE__}: Parsing response.body (#{i.response.body.size/(1024*1024)} MB ) will take some time. URI was #{i.request.uri}"
|
120
|
+
if !/WSDL$/.match(i.request.uri) && /refdatabase.refdata.ch\/Service/.match(i.request.uri) && (i.response.body.size > 1024 * 1024)
|
121
|
+
puts "#{Time.now}: #{__LINE__}: Parsing response.body (#{i.response.body.size / (1024 * 1024)} MB ) will take some time. URI was #{i.request.uri}"
|
135
122
|
doc = REXML::Document.new(i.response.body)
|
136
123
|
items = doc.root.children.first.elements.first
|
137
|
-
|
138
|
-
puts "#{Time.now}: #{__LINE__}: Removing most of the #{
|
139
|
-
|
140
|
-
items.elements.each{
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
items.delete x unless x.elements['GTIN'] and Oddb2xml::GTINS_DRUGS.index(x.elements['GTIN'].text)
|
124
|
+
nr_items = doc.root.children.first.elements.first.elements.size
|
125
|
+
puts "#{Time.now}: #{__LINE__}: Removing most of the #{nr_items} items will take some time"
|
126
|
+
nr_searched = 0
|
127
|
+
items.elements.each { |x|
|
128
|
+
nr_searched += 1
|
129
|
+
puts "#{Time.now}: #{__LINE__}: nr_searched #{nr_searched}/#{nr_items}" if nr_searched % 1000 == 0
|
130
|
+
items.delete x unless x.elements["GTIN"] && Oddb2xml::GTINS_DRUGS.index(x.elements["GTIN"].text)
|
145
131
|
}
|
146
132
|
i.response.body = doc.to_s
|
147
|
-
puts "#{Time.now}: response.body is now #{i.response.body.size/(1024*1024)} MB long"
|
148
|
-
i.response.headers[
|
133
|
+
puts "#{Time.now}: response.body is now #{i.response.body.size / (1024 * 1024)} MB long"
|
134
|
+
i.response.headers["Content-Length"] = i.response.body.size
|
149
135
|
end
|
150
136
|
end
|
151
137
|
end
|
152
|
-
VCR.insert_cassette(
|
138
|
+
VCR.insert_cassette("oddb2xml", tag: :Refdata_DE)
|
153
139
|
common_before
|
154
140
|
end
|
155
141
|
after(:all) do
|
156
142
|
common_after
|
157
143
|
end
|
158
|
-
context
|
144
|
+
context "Pharma" do
|
159
145
|
before(:all) do
|
160
146
|
@downloader = Oddb2xml::RefdataDownloader.new({}, :pharma)
|
161
147
|
@xml = @downloader.download
|
162
148
|
end
|
163
|
-
it_behaves_like
|
164
|
-
context
|
165
|
-
it
|
149
|
+
it_behaves_like "any downloader"
|
150
|
+
context "when download_by is called" do
|
151
|
+
it "should parse response hash to xml" do
|
166
152
|
expect(@xml).to be_a String
|
167
153
|
expect(@xml.length).not_to eq(0)
|
168
154
|
expect(@xml).to match(XML_VERSION_1_0)
|
169
155
|
end
|
170
|
-
it
|
156
|
+
it "should return valid xml" do
|
171
157
|
expect(@xml).to match(/PHAR/)
|
172
158
|
expect(@xml).to match(/ITEM/)
|
173
159
|
end
|
174
160
|
end
|
175
161
|
end
|
176
162
|
|
177
|
-
context
|
178
|
-
it_behaves_like
|
163
|
+
context "NonPharma" do
|
164
|
+
it_behaves_like "any downloader"
|
179
165
|
before(:all) do
|
180
166
|
@downloader = Oddb2xml::RefdataDownloader.new({}, :nonpharma)
|
181
167
|
@xml = @downloader.download
|
182
168
|
end
|
183
|
-
context
|
184
|
-
it
|
169
|
+
context "when download_by is " do
|
170
|
+
it "should parse response hash to xml" do
|
185
171
|
expect(@xml).to be_a String
|
186
172
|
expect(@xml.length).not_to eq(0)
|
187
173
|
expect(@xml).to match(XML_VERSION_1_0)
|
188
174
|
end
|
189
|
-
it
|
175
|
+
it "should return valid xml" do
|
190
176
|
expect(@xml).to match(/NONPHAR/)
|
191
177
|
expect(@xml).to match(/ITEM/)
|
192
178
|
end
|
@@ -196,40 +182,45 @@ end
|
|
196
182
|
|
197
183
|
def cleanPackungenXlsx(info)
|
198
184
|
m = /dokumente\/liste/i.match(info.request.uri)
|
199
|
-
puts "#{Time.now}: #{__LINE__} SwissmedicDownloader #{info.request.uri} #{m[1]} (#{info.response.body.size/(1024*1024)} MB )."
|
185
|
+
puts "#{Time.now}: #{__LINE__} SwissmedicDownloader #{info.request.uri} #{m[1]} (#{info.response.body.size / (1024 * 1024)} MB )."
|
200
186
|
return unless m
|
201
187
|
name = nil
|
202
|
-
name =
|
203
|
-
name =
|
204
|
-
swissmedic_dir = File.join(Oddb2xml::
|
188
|
+
name = "packungen" if /zugelasseneverpackungen/.match?(info.request.uri)
|
189
|
+
name = "orphan" if /zugelasseneverpackungen/.match?(info.request.uri)
|
190
|
+
swissmedic_dir = File.join(Oddb2xml::WORK_DIR, "swissmedic")
|
205
191
|
FileUtils.makedirs(swissmedic_dir)
|
206
|
-
xlsx_name = File.join(swissmedic_dir, name +
|
207
|
-
if /Packungen/i.match(xlsx_name)
|
208
|
-
FileUtils.rm(xlsx_name, :
|
209
|
-
File.open(xlsx_name,
|
210
|
-
FileUtils.cp(xlsx_name, File.join(Oddb2xml::SpecData,
|
192
|
+
xlsx_name = File.join(swissmedic_dir, name + ".xlsx")
|
193
|
+
if /Packungen/i.match?(xlsx_name)
|
194
|
+
FileUtils.rm(xlsx_name, verbose: false) if File.exist?(xlsx_name)
|
195
|
+
File.open(xlsx_name, "wb+") { |f| f.write(info.response.body) }
|
196
|
+
FileUtils.cp(xlsx_name, File.join(Oddb2xml::SpecData, "swissmedic_package_downloaded.xlsx"), verbose: true, preserve: true)
|
211
197
|
puts "#{Time.now}: #{__LINE__}: Openening saved #{xlsx_name} (#{File.size(xlsx_name)} bytes) will take some time. URI was #{info.request.uri}"
|
212
198
|
workbook = RubyXL::Parser.parse(xlsx_name)
|
213
199
|
worksheet = workbook[0]
|
214
200
|
drugs = []
|
215
|
-
Oddb2xml::GTINS_DRUGS.each
|
216
|
-
|
201
|
+
Oddb2xml::GTINS_DRUGS.each do |x|
|
202
|
+
next unless x.to_s.size == 13
|
203
|
+
drugs << [x.to_s[4..8].to_i, x.to_s[9..11].to_i]
|
204
|
+
end
|
205
|
+
idx = 6
|
206
|
+
to_delete = []
|
217
207
|
puts "#{Time.now}: Finding items to delete will take some time"
|
218
|
-
while
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
208
|
+
while worksheet.sheet_data[idx]
|
209
|
+
idx += 1
|
210
|
+
next unless worksheet.sheet_data[idx - 1][Oddb2xml::COLUMNS_FEBRUARY_2019.keys.index(:iksnr)]
|
211
|
+
to_delete << (idx - 1) unless drugs.find { |x|
|
212
|
+
(x[0] == worksheet.sheet_data[idx - 1][Oddb2xml::COLUMNS_FEBRUARY_2019.keys.index(:iksnr)].value.to_i) &&
|
213
|
+
(x[1] == worksheet.sheet_data[idx - 1][Oddb2xml::COLUMNS_FEBRUARY_2019.keys.index(:ikscd)].value.to_i)
|
214
|
+
}
|
224
215
|
end
|
225
216
|
if to_delete.size > 0
|
226
217
|
puts "#{Time.now}: Deleting #{to_delete.size} of the #{idx} items will take some time"
|
227
|
-
to_delete.
|
218
|
+
to_delete.reverse_each { |row_id| worksheet.delete_row(row_id) }
|
228
219
|
workbook.write(xlsx_name)
|
229
|
-
FileUtils.cp(xlsx_name, File.join(Oddb2xml::SpecData,
|
220
|
+
FileUtils.cp(xlsx_name, File.join(Oddb2xml::SpecData, "swissmedic_package_shortened.xlsx"), verbose: true, preserve: true)
|
230
221
|
info.response.body = IO.binread(xlsx_name)
|
231
|
-
info.response.headers[
|
232
|
-
puts "#{Time.now}: response.body is now #{info.response.body.size/(1024*1024)} MB long. #{xlsx_name} was #{File.size(xlsx_name)}"
|
222
|
+
info.response.headers["Content-Length"] = info.response.body.size
|
223
|
+
puts "#{Time.now}: response.body is now #{info.response.body.size / (1024 * 1024)} MB long. #{xlsx_name} was #{File.size(xlsx_name)}"
|
233
224
|
end
|
234
225
|
end
|
235
226
|
end
|
@@ -240,79 +231,73 @@ describe Oddb2xml::SwissmedicDownloader do
|
|
240
231
|
mock_downloads
|
241
232
|
VCR.configure do |c|
|
242
233
|
c.before_record(:swissmedic) do |i|
|
243
|
-
|
244
|
-
info = i
|
245
|
-
begin
|
246
|
-
if i.response.headers['Content-Disposition'] and /www.swissmedic.ch/.match(i.request.uri) and i.response.body.size > 1024*1024
|
234
|
+
if i.response.headers["Content-Disposition"] && /www.swissmedic.ch/.match(i.request.uri) && (i.response.body.size > 1024 * 1024)
|
247
235
|
cleanPackungenXlsx(i)
|
248
236
|
end
|
249
|
-
|
250
|
-
|
251
|
-
|
237
|
+
rescue => error
|
238
|
+
puts error if $VERBOSE
|
239
|
+
# require "pry"; binding.pry
|
252
240
|
end
|
253
241
|
end
|
254
242
|
end
|
255
|
-
# 2015-06-10 18:54:40 UTC: SwissmedicDownloader attachment; filename="Zugelassene_Packungen_310515.xlsx" (785630 bytes). URI was https://www.swissmedic.ch/arzneimittel/00156/00221/00222/00230/index.html?download=NHzLpZeg7t,lnp6I0NTU042l2Z6ln1acy4Zn4Z2qZpnO2Yuq2Z6gpJCDdHx7hGym162epYbg2c_JjKbNoKSn6A--&lang=de
|
243
|
+
# 2015-06-10 18:54:40 UTC: SwissmedicDownloader attachment; filename="Zugelassene_Packungen_310515.xlsx" (785630 bytes). URI was https://www.swissmedic.ch/arzneimittel/00156/00221/00222/00230/index.html?download=NHzLpZeg7t,lnp6I0NTU042l2Z6ln1acy4Zn4Z2qZpnO2Yuq2Z6gpJCDdHx7hGym162epYbg2c_JjKbNoKSn6A--&lang=de
|
256
244
|
|
257
|
-
context
|
245
|
+
context "orphan" do
|
258
246
|
before(:each) do
|
259
247
|
VCR.configure do |c|
|
260
248
|
c.before_record(:swissmedic) do |i|
|
261
|
-
|
262
|
-
info = i
|
263
|
-
begin
|
264
|
-
if i.response.headers['Content-Disposition'] and /www.swissmedic.ch/.match(i.request.uri) and i.response.body.size > 1024*1024
|
249
|
+
if i.response.headers["Content-Disposition"] && /www.swissmedic.ch/.match(i.request.uri) && (i.response.body.size > 1024 * 1024)
|
265
250
|
cleanPackungenXlsx(i)
|
266
251
|
end
|
267
|
-
|
268
|
-
|
269
|
-
|
252
|
+
rescue => error
|
253
|
+
puts error if $VERBOSE
|
254
|
+
# require "pry"; binding.pry
|
270
255
|
end
|
271
256
|
end
|
272
257
|
VCR.eject_cassette
|
273
|
-
VCR.insert_cassette(
|
258
|
+
VCR.insert_cassette("oddb2xml", tag: :swissmedic, exclusive: false)
|
274
259
|
common_before
|
275
260
|
@downloader = Oddb2xml::SwissmedicDownloader.new(:orphan)
|
276
261
|
end
|
277
|
-
after(:each)
|
278
|
-
it_behaves_like
|
279
|
-
context
|
262
|
+
after(:each) { common_after }
|
263
|
+
it_behaves_like "any downloader"
|
264
|
+
context "download_by for orphan xls" do
|
280
265
|
let(:bin) {
|
281
266
|
@downloader.download
|
282
267
|
}
|
283
|
-
it
|
268
|
+
it "should return valid Binary-String" do
|
284
269
|
# unless [:orphan, :package].index(@downloader.type)
|
285
|
-
|
286
|
-
|
270
|
+
expect(bin).to be_a String
|
271
|
+
expect(bin.bytes).not_to be nil
|
287
272
|
# end
|
288
273
|
end
|
289
|
-
it
|
274
|
+
it "should clean up current directory" do
|
290
275
|
unless [:orphan, :package].index(@downloader.type)
|
291
276
|
expect { bin }.not_to raise_error
|
292
|
-
expect(File.exist?(
|
277
|
+
expect(File.exist?("oddb_orphan.xls")).to eq(false)
|
293
278
|
end
|
294
279
|
end
|
295
|
-
it
|
296
|
-
expect(File.exist?(File.join(Oddb2xml::
|
280
|
+
it "should not save into the download directory" do
|
281
|
+
expect(File.exist?(File.join(Oddb2xml::DOWNLOADS, "oddb_orphan.xls"))).to eq(false)
|
297
282
|
end
|
298
283
|
end
|
299
284
|
end
|
300
|
-
context
|
285
|
+
context "package" do
|
301
286
|
before(:each) do
|
302
287
|
VCR.eject_cassette
|
303
|
-
VCR.insert_cassette(
|
288
|
+
VCR.insert_cassette("oddb2xml", tag: :swissmedic, exclusive: false)
|
304
289
|
common_before
|
305
290
|
@downloader = Oddb2xml::SwissmedicDownloader.new(:package)
|
306
291
|
@bin = @downloader.download
|
307
292
|
end
|
308
|
-
after(:each)
|
309
|
-
context
|
310
|
-
it
|
293
|
+
after(:each) { common_after }
|
294
|
+
context "download_by for package xls" do
|
295
|
+
it "should return valid Binary-String" do
|
311
296
|
expect(@bin).to be_a String
|
312
297
|
expect(@bin.bytes).not_to be nil
|
313
298
|
end
|
314
|
-
it
|
315
|
-
expect(File.exist?(File.join(Oddb2xml::
|
299
|
+
it "should save into the download directory" do
|
300
|
+
expect(File.exist?(File.join(Oddb2xml::DOWNLOADS, "swissmedic_package.xlsx"))).to eq(true)
|
316
301
|
end
|
317
302
|
end
|
318
303
|
end
|
@@ -327,59 +312,59 @@ describe Oddb2xml::EphaDownloader do
|
|
327
312
|
Oddb2xml.add_epha_changes_for_ATC(1, 3, force_run: true)
|
328
313
|
@csv = @downloader.download
|
329
314
|
}
|
330
|
-
expect(File.exist?(File.join(Oddb2xml::
|
315
|
+
expect(File.exist?(File.join(Oddb2xml::DOWNLOADS, "epha_interactions.csv"))).to eq(true)
|
331
316
|
end
|
332
317
|
after(:all) do
|
333
318
|
common_after
|
334
319
|
end
|
335
320
|
|
336
|
-
it_behaves_like
|
321
|
+
it_behaves_like "any downloader"
|
337
322
|
|
338
|
-
context
|
339
|
-
let(:csv) { @csv
|
340
|
-
it
|
323
|
+
context "when download is called" do
|
324
|
+
let(:csv) { @csv }
|
325
|
+
it "should read csv as String" do
|
341
326
|
expect(csv).to be_a String
|
342
327
|
expect(csv.bytes).not_to be nil
|
343
328
|
end
|
344
|
-
it
|
345
|
-
expect(File.exist?(
|
329
|
+
it "should clean up current directory" do
|
330
|
+
expect(File.exist?("epha_interactions.csv")).to eq(false)
|
346
331
|
end
|
347
|
-
it
|
348
|
-
expect(File.exist?(File.join(Oddb2xml::
|
332
|
+
it "should save under download" do
|
333
|
+
expect(File.exist?(File.join(Oddb2xml::DOWNLOADS, "epha_interactions.csv"))).to eq(true)
|
349
334
|
end
|
350
335
|
end
|
351
336
|
end
|
352
337
|
|
353
338
|
describe Oddb2xml::BagXmlDownloader do
|
354
339
|
include ServerMockHelper
|
355
|
-
before(:all)
|
340
|
+
before(:all) { VCR.eject_cassette }
|
356
341
|
before(:all) {
|
357
342
|
VCR.configure do |c|
|
358
343
|
c.before_record(:bag_xml) do |i|
|
359
|
-
if i.response.headers[
|
360
|
-
bag_dir = File.join(Oddb2xml::
|
361
|
-
FileUtils.makedirs(Oddb2xml::
|
362
|
-
tmp_zip = File.join(Oddb2xml::
|
363
|
-
File.open(tmp_zip,
|
344
|
+
if i.response.headers["Content-Disposition"] && /XMLPublications.zip/.match(i.request.uri)
|
345
|
+
bag_dir = File.join(Oddb2xml::WORK_DIR, "bag")
|
346
|
+
FileUtils.makedirs(Oddb2xml::WORK_DIR)
|
347
|
+
tmp_zip = File.join(Oddb2xml::WORK_DIR, "XMLPublications.zip")
|
348
|
+
File.open(tmp_zip, "wb+") { |f| f.write(i.response.body) }
|
364
349
|
unzip_files(tmp_zip, bag_dir)
|
365
350
|
bag_tmp = File.join(bag_dir, PREP_XML)
|
366
351
|
puts "#{Time.now}: #{__LINE__}: Parsing #{File.size(bag_tmp)} (#{File.size(bag_tmp)} bytes) will take some time. URI was #{i.request.uri}"
|
367
352
|
doc = REXML::Document.new(File.read(bag_tmp))
|
368
353
|
items = doc.root.elements
|
369
354
|
puts "#{Time.now}: Removing most of the #{items.size} items will take some time"
|
370
|
-
items.each{ |x| items.delete x unless
|
371
|
-
File.open(bag_tmp,
|
355
|
+
items.each { |x| items.delete x unless Oddb2xml::GTINS_DRUGS.index(x.elements["Packs/Pack/GTIN"].text); }
|
356
|
+
File.open(bag_tmp, "wb+") { |f| f.write(doc.to_s.gsub(/\n\s+\n/, "\n")) }
|
372
357
|
puts "Saved #{bag_tmp} (#{File.size(tmp_zip)} bytes)"
|
373
358
|
zip_files(tmp_zip, Dir.glob("#{bag_dir}/*"))
|
374
359
|
puts "Saved #{tmp_zip} (#{File.size(tmp_zip)} bytes)"
|
375
360
|
i.response.body = IO.binread(tmp_zip)
|
376
|
-
i.response.headers[
|
377
|
-
puts "#{Time.now}: response.body is now #{i.response.body.size/(1024*1024)} MB long. #{tmp_zip} was #{File.size(tmp_zip)}"
|
361
|
+
i.response.headers["Content-Length"] = i.response.body.size
|
362
|
+
puts "#{Time.now}: response.body is now #{i.response.body.size / (1024 * 1024)} MB long. #{tmp_zip} was #{File.size(tmp_zip)}"
|
378
363
|
end
|
379
364
|
end
|
380
365
|
end
|
381
|
-
|
382
|
-
|
366
|
+
VCR.eject_cassette
|
367
|
+
VCR.use_cassette("oddb2xml", tag: :bag_xml) do
|
383
368
|
@downloader = Oddb2xml::BagXmlDownloader.new
|
384
369
|
end
|
385
370
|
common_before
|
@@ -388,19 +373,19 @@ describe Oddb2xml::BagXmlDownloader do
|
|
388
373
|
common_after
|
389
374
|
end
|
390
375
|
|
391
|
-
it_behaves_like
|
392
|
-
context
|
376
|
+
it_behaves_like "any downloader"
|
377
|
+
context "when download is called" do
|
393
378
|
let(:xml) {
|
394
379
|
VCR.eject_cassette
|
395
|
-
VCR.use_cassette(
|
380
|
+
VCR.use_cassette("oddb2xml", tag: :bag_xml) do
|
396
381
|
@downloader.download
|
397
382
|
end
|
398
383
|
}
|
399
|
-
it
|
384
|
+
it "should parse zip to string" do
|
400
385
|
expect(xml).to be_a String
|
401
386
|
expect(xml.length).not_to eq(0)
|
402
387
|
end
|
403
|
-
it
|
388
|
+
it "should return valid xml" do
|
404
389
|
expect(xml).to match(XML_VERSION_1_0)
|
405
390
|
expect(xml).to match(/Preparations/)
|
406
391
|
expect(xml).to match(/DescriptionDe/)
|
@@ -410,174 +395,177 @@ end
|
|
410
395
|
|
411
396
|
describe Oddb2xml::LppvDownloader do
|
412
397
|
include ServerMockHelper
|
413
|
-
before(:all)
|
398
|
+
before(:all) { VCR.eject_cassette }
|
414
399
|
before(:all) do
|
415
|
-
VCR.insert_cassette(
|
400
|
+
VCR.insert_cassette("oddb2xml", tag: :lppv)
|
416
401
|
common_before
|
417
402
|
@downloader = Oddb2xml::LppvDownloader.new
|
418
403
|
@text = @downloader.download
|
419
404
|
end
|
420
|
-
after(:each)
|
405
|
+
after(:each) { common_after }
|
421
406
|
|
422
|
-
it_behaves_like
|
423
|
-
context
|
407
|
+
it_behaves_like "any downloader"
|
408
|
+
context "when download is called" do
|
424
409
|
let(:txt) { @downloader.download }
|
425
|
-
it
|
410
|
+
it "should read txt as String" do
|
426
411
|
expect(@text).to be_a String
|
427
412
|
expect(@text.bytes).not_to be nil
|
428
413
|
end
|
429
414
|
end
|
430
415
|
end
|
431
416
|
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
after(:each) do common_after end
|
442
|
-
|
443
|
-
it_behaves_like 'any downloader'
|
444
|
-
context 'when download is called' do
|
445
|
-
let(:bin) { @downloader.download }
|
446
|
-
it 'should read xls as Binary-String' do
|
447
|
-
expect(bin).to be_a String
|
448
|
-
expect(bin.bytes).not_to be nil
|
417
|
+
unless SKIP_MIGEL_DOWNLOADER
|
418
|
+
describe Oddb2xml::MigelDownloader do
|
419
|
+
include ServerMockHelper
|
420
|
+
before(:all) { VCR.eject_cassette }
|
421
|
+
before(:each) do
|
422
|
+
@downloader = Oddb2xml::MigelDownloader.new
|
423
|
+
VCR.insert_cassette("oddb2xml", tag: :migel)
|
424
|
+
common_before
|
425
|
+
@downloader.download
|
449
426
|
end
|
450
|
-
|
451
|
-
|
452
|
-
|
427
|
+
after(:each) { common_after }
|
428
|
+
|
429
|
+
it_behaves_like "any downloader"
|
430
|
+
context "when download is called" do
|
431
|
+
let(:bin) { @downloader.download }
|
432
|
+
it "should read xls as Binary-String" do
|
433
|
+
expect(bin).to be_a String
|
434
|
+
expect(bin.bytes).not_to be nil
|
435
|
+
end
|
436
|
+
it "should clean up current directory" do
|
437
|
+
expect { bin }.not_to raise_error
|
438
|
+
expect(File.exist?("oddb2xml_files_nonpharma.txt")).to eq(false)
|
439
|
+
end
|
453
440
|
end
|
454
441
|
end
|
455
|
-
end
|
442
|
+
end
|
456
443
|
|
457
444
|
describe Oddb2xml::ZurroseDownloader do
|
458
445
|
include ServerMockHelper
|
459
|
-
before(:all)
|
446
|
+
before(:all) { VCR.eject_cassette }
|
460
447
|
before(:each) do
|
461
448
|
VCR.configure do |c|
|
462
449
|
c.before_record(:zurrose) do |i|
|
463
|
-
if /pillbox/i.match(i.request.uri)
|
450
|
+
if /pillbox/i.match?(i.request.uri)
|
464
451
|
puts "#{Time.now}: #{__LINE__}: URI was #{i.request.uri}"
|
465
|
-
tmp_zip = File.join(Oddb2xml::SpecData,
|
452
|
+
tmp_zip = File.join(Oddb2xml::SpecData, "vcr", "transfer.zip")
|
466
453
|
i.response.body = IO.binread(tmp_zip)
|
467
|
-
i.response.headers[
|
454
|
+
i.response.headers["Content-Length"] = i.response.body.size
|
468
455
|
end
|
469
456
|
end
|
470
457
|
end
|
471
|
-
VCR.insert_cassette(
|
458
|
+
VCR.insert_cassette("oddb2xml", tag: :zurrose)
|
472
459
|
@downloader = Oddb2xml::ZurroseDownloader.new
|
473
460
|
common_before
|
474
461
|
@downloader.download
|
475
462
|
end
|
476
|
-
after(:each)
|
463
|
+
after(:each) { common_after }
|
477
464
|
|
478
|
-
it_behaves_like
|
479
|
-
context
|
465
|
+
it_behaves_like "any downloader"
|
466
|
+
context "when download is called" do
|
480
467
|
let(:dat) { @downloader.download }
|
481
|
-
it
|
468
|
+
it "should read dat as String" do
|
482
469
|
expect(dat).to be_a String
|
483
470
|
expect(dat.bytes).not_to be nil
|
484
471
|
end
|
485
|
-
it
|
472
|
+
it "should clean up current directory" do
|
486
473
|
expect { dat }.not_to raise_error
|
487
|
-
expect(File.exist?(
|
488
|
-
expect(File.exist?(
|
489
|
-
expect(File.exist?(
|
474
|
+
expect(File.exist?("transfer.dat")).to eq(false)
|
475
|
+
expect(File.exist?("oddb2xml_zurrose_transfer.dat")).to eq(false)
|
476
|
+
expect(File.exist?("transfer.zip")).to eq(false)
|
490
477
|
end
|
491
|
-
it
|
492
|
-
expect(File.exist?(File.join(Oddb2xml::
|
493
|
-
expect(File.exist?(File.join(Oddb2xml::
|
478
|
+
it "should save into the download directory" do
|
479
|
+
expect(File.exist?(File.join(Oddb2xml::DOWNLOADS, "transfer.zip"))).to eq(true)
|
480
|
+
expect(File.exist?(File.join(Oddb2xml::DOWNLOADS, "transfer.dat"))).to eq(true)
|
494
481
|
end
|
495
482
|
end
|
496
483
|
end
|
497
484
|
|
498
485
|
describe Oddb2xml::MedregbmDownloader do
|
499
486
|
include ServerMockHelper
|
500
|
-
before(:all)
|
487
|
+
before(:all) { VCR.eject_cassette }
|
501
488
|
before(:each) do
|
502
489
|
VCR.configure do |c|
|
503
490
|
c.before_record(:medreg) do |i|
|
504
|
-
if /medregbm.admin.ch/i.match(i.request.uri)
|
505
|
-
puts "#{Time.now}: #{__LINE__}: URI was #{i.request.uri} containing #{i.response.body.size/(1024*1024)} MB "
|
491
|
+
if /medregbm.admin.ch/i.match?(i.request.uri)
|
492
|
+
puts "#{Time.now}: #{__LINE__}: URI was #{i.request.uri} containing #{i.response.body.size / (1024 * 1024)} MB "
|
506
493
|
begin
|
507
|
-
medreg_dir = File.join(Oddb2xml::
|
494
|
+
medreg_dir = File.join(Oddb2xml::WORK_DIR, "medreg")
|
508
495
|
FileUtils.makedirs(medreg_dir)
|
509
|
-
xlsx_name = File.join(medreg_dir, /ListBetrieb/.match(i.request.uri) ?
|
510
|
-
File.open(xlsx_name,
|
496
|
+
xlsx_name = File.join(medreg_dir, /ListBetrieb/.match?(i.request.uri) ? "Betriebe.xlsx" : "Personen.xlsx")
|
497
|
+
File.open(xlsx_name, "wb+") { |f| f.write(i.response.body) }
|
511
498
|
puts "#{Time.now}: Openening saved #{xlsx_name} (#{File.size(xlsx_name)} bytes) will take some time. URI was #{i.request.uri}"
|
512
499
|
workbook = RubyXL::Parser.parse(xlsx_name)
|
513
500
|
worksheet = workbook[0]
|
514
|
-
idx = 1
|
515
|
-
|
501
|
+
idx = 1
|
502
|
+
to_delete = []
|
503
|
+
while worksheet.sheet_data[idx]
|
516
504
|
idx += 1
|
517
|
-
next unless worksheet.sheet_data[idx-1][0]
|
518
|
-
to_delete << (idx-1) unless Oddb2xml::GTINS_MEDREG.index(worksheet.sheet_data[idx-1][0].value.to_i)
|
505
|
+
next unless worksheet.sheet_data[idx - 1][0]
|
506
|
+
to_delete << (idx - 1) unless Oddb2xml::GTINS_MEDREG.index(worksheet.sheet_data[idx - 1][0].value.to_i)
|
519
507
|
end
|
520
508
|
if to_delete.size > 0
|
521
509
|
puts "#{Time.now}: Deleting #{to_delete.size} of the #{idx} items will take some time"
|
522
|
-
to_delete.
|
510
|
+
to_delete.reverse_each { |row_id| worksheet.delete_row(row_id) }
|
523
511
|
workbook.write(xlsx_name)
|
524
512
|
i.response.body = IO.binread(xlsx_name)
|
525
|
-
i.response.headers[
|
526
|
-
puts "#{Time.now}: response.body is now #{i.response.body.size/(1024*1024)} MB long. #{xlsx_name} was #{File.size(xlsx_name)}"
|
513
|
+
i.response.headers["Content-Length"] = i.response.body.size
|
514
|
+
puts "#{Time.now}: response.body is now #{i.response.body.size / (1024 * 1024)} MB long. #{xlsx_name} was #{File.size(xlsx_name)}"
|
527
515
|
end
|
528
516
|
rescue
|
529
517
|
puts "Creating empty content, as I am unable to parse the XLSX file"
|
530
518
|
i.response.body = ""
|
531
|
-
i.response.headers[
|
519
|
+
i.response.headers["Content-Length"] = i.response.body.size
|
532
520
|
end
|
533
521
|
end
|
534
522
|
end
|
535
523
|
end
|
536
524
|
common_before
|
537
525
|
end
|
538
|
-
after(:each)
|
526
|
+
after(:each) { common_after }
|
539
527
|
|
540
|
-
context
|
528
|
+
context "betrieb" do
|
541
529
|
before(:each) do
|
542
530
|
VCR.eject_cassette
|
543
|
-
VCR.insert_cassette(
|
531
|
+
VCR.insert_cassette("oddb2xml", tag: :medreg)
|
544
532
|
@downloader = Oddb2xml::MedregbmDownloader.new(:company)
|
545
533
|
@downloader.download
|
546
534
|
end
|
547
|
-
after(:each)
|
548
|
-
it_behaves_like
|
549
|
-
context
|
535
|
+
after(:each) { common_after }
|
536
|
+
it_behaves_like "any downloader"
|
537
|
+
context "download betrieb txt" do
|
550
538
|
let(:txt) { @downloader.download }
|
551
|
-
it
|
539
|
+
it "should return valid String" do
|
552
540
|
expect(txt).to be_a String
|
553
541
|
expect(txt.bytes).not_to be nil
|
554
542
|
end
|
555
|
-
it
|
543
|
+
it "should clean up current directory" do
|
556
544
|
expect { txt }.not_to raise_error
|
557
|
-
expect(File.exist?(
|
545
|
+
expect(File.exist?("oddb_company.xls")).to eq(false)
|
558
546
|
end
|
559
547
|
end
|
560
548
|
end
|
561
549
|
|
562
|
-
context
|
550
|
+
context "person" do
|
563
551
|
before(:each) do
|
564
552
|
VCR.eject_cassette
|
565
|
-
VCR.insert_cassette(
|
553
|
+
VCR.insert_cassette("oddb2xml", tag: :medreg)
|
566
554
|
@downloader = Oddb2xml::MedregbmDownloader.new(:person)
|
567
555
|
end
|
568
|
-
after(:each)
|
569
|
-
context
|
556
|
+
after(:each) { common_after }
|
557
|
+
context "download person txt" do
|
570
558
|
let(:txt) {
|
571
559
|
# this downloads a xlsx file (2.5MB), where we should keep only the first few lines
|
572
560
|
@downloader.download
|
573
561
|
}
|
574
|
-
it
|
562
|
+
it "should return valid String" do
|
575
563
|
expect(txt).to be_a String
|
576
564
|
expect(txt.bytes).not_to be nil
|
577
565
|
end
|
578
|
-
it
|
566
|
+
it "should clean up current directory" do
|
579
567
|
expect { txt }.not_to raise_error
|
580
|
-
expect(File.exist?(
|
568
|
+
expect(File.exist?("oddb_person.xls")).to eq(false)
|
581
569
|
end
|
582
570
|
end
|
583
571
|
end
|
@@ -588,49 +576,48 @@ describe Oddb2xml::SwissmedicInfoDownloader do
|
|
588
576
|
before(:all) do
|
589
577
|
VCR.configure do |c|
|
590
578
|
c.before_record(:swissmedicInfo) do |i|
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
579
|
+
puts "#{Time.now}: #{__LINE__}: URI was #{i.request.uri} returning #{i.response.body.size / (1024 * 1024)} MB"
|
580
|
+
if i.response.headers["Content-Disposition"]
|
581
|
+
m = /filename=([^\d]+)/.match(i.response.headers["Content-Disposition"][0])
|
582
|
+
if m
|
583
|
+
name = m[1].chomp("_")
|
584
|
+
if /AipsDownload/i.match?(name)
|
585
|
+
# we replace this by manually reduced xml file from spec/data
|
586
|
+
# As we only use to create the fachinfo, we don't need many elements
|
587
|
+
tmp_zip = File.join(Oddb2xml::SpecData, "AipsDownload.zip")
|
588
|
+
i.response.body = IO.binread(tmp_zip)
|
589
|
+
i.response.headers["Content-Length"] = i.response.body.size
|
590
|
+
puts "#{Time.now}: #{__LINE__}: response.body is now #{i.response.body.size / (1024 * 1024)} MB long. #{tmp_zip} was #{File.size(tmp_zip)}"
|
591
|
+
end
|
603
592
|
end
|
604
593
|
end
|
605
594
|
end
|
606
595
|
end
|
607
|
-
end
|
608
596
|
VCR.eject_cassette
|
609
|
-
VCR.insert_cassette(
|
597
|
+
VCR.insert_cassette("oddb2xml", tag: :swissmedicInfo)
|
610
598
|
common_before
|
611
599
|
@downloader = Oddb2xml::SwissmedicInfoDownloader.new
|
612
600
|
@downloader.download
|
613
601
|
end
|
614
|
-
after(:all)
|
615
|
-
it_behaves_like
|
616
|
-
context
|
617
|
-
let(:xml) { @downloader.download
|
618
|
-
it
|
602
|
+
after(:all) { common_after }
|
603
|
+
it_behaves_like "any downloader"
|
604
|
+
context "when download is called" do
|
605
|
+
let(:xml) { @downloader.download }
|
606
|
+
it "should parse zip to String" do
|
619
607
|
expect(xml).to be_a String
|
620
608
|
expect(xml.length).not_to eq(0)
|
621
609
|
end
|
622
|
-
it
|
610
|
+
it "should return valid xml" do
|
623
611
|
expect(xml).to match(XML_VERSION_1_0)
|
624
612
|
expect(xml).to match(/medicalInformations/)
|
625
613
|
expect(xml).to match(/content/)
|
626
614
|
end
|
627
|
-
it
|
615
|
+
it "should clean up current directory" do
|
628
616
|
expect { xml }.not_to raise_error
|
629
|
-
expect(File.exist?(
|
617
|
+
expect(File.exist?("swissmedic_info.zip")).to eq(false)
|
630
618
|
end
|
631
|
-
it
|
632
|
-
expect(File.exist?(File.join(Oddb2xml::
|
619
|
+
it "should save into the download directory" do
|
620
|
+
expect(File.exist?(File.join(Oddb2xml::DOWNLOADS, "swissmedic_info.zip"))).to eq(true)
|
633
621
|
end
|
634
622
|
end
|
635
623
|
end
|
636
|
-
|