oddb2xml 1.3.8 → 1.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +6 -0
- data/Manifest.txt +3 -3
- data/README.md +1 -1
- data/bin/oddb2xml +6 -3
- data/lib/oddb2xml/builder.rb +75 -1
- data/lib/oddb2xml/cli.rb +84 -53
- data/lib/oddb2xml/downloader.rb +70 -91
- data/lib/oddb2xml/extractor.rb +68 -20
- data/lib/oddb2xml/version.rb +1 -1
- data/spec/cli_spec.rb +55 -6
- data/spec/data/medregbm_betrieb.txt +0 -0
- data/spec/data/medregbm_person.txt +0 -0
- data/spec/downloader_spec.rb +51 -12
- data/spec/spec_helper.rb +27 -0
- metadata +31 -29
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
|
@@ -19,17 +19,17 @@ spec/cli_spec.rb
|
|
|
19
19
|
spec/compressor_spec.rb
|
|
20
20
|
spec/data/XMLPublications.zip
|
|
21
21
|
spec/data/epha_interactions.csv
|
|
22
|
+
spec/data/medregbm_betrieb.txt
|
|
23
|
+
spec/data/medregbm_person.txt
|
|
22
24
|
spec/data/oddb2xml_files_bm_update.txt
|
|
23
25
|
spec/data/oddb2xml_files_lppv.txt
|
|
26
|
+
spec/data/oddb2xml_files_nonpharma.xls
|
|
24
27
|
spec/data/oddb_article.xml
|
|
25
28
|
spec/data/oddb_fi.xml
|
|
26
29
|
spec/data/oddb_fi_product.xml
|
|
27
30
|
spec/data/oddb_limitation.xml
|
|
28
31
|
spec/data/oddb_product.xml
|
|
29
32
|
spec/data/oddb_substance.xml
|
|
30
|
-
spec/data/oddb2xml_files_nonpharma.xls
|
|
31
|
-
spec/data/oddb2xml_files_lppv.txt
|
|
32
|
-
spec/data/oddb2xml_files_bm_update.txt
|
|
33
33
|
spec/data/swissindex.xml
|
|
34
34
|
spec/data/swissindex_nonpharma.xml
|
|
35
35
|
spec/data/swissindex_pharma.xml
|
data/README.md
CHANGED
|
@@ -229,7 +229,7 @@ You can confirm wit `ruby -ropenssl -e 'p OpenSSL::X509::DEFAULT_CERT_FILE'`.
|
|
|
229
229
|
3. Click "Advanced" Tab.
|
|
230
230
|
4. Click "Environment Variables" button.
|
|
231
231
|
5. Add set variable entry "SSL\_CERT\_FILE=%HOMEPATH%\cacert.pem"
|
|
232
|
-
* Variable name: SSL\
|
|
232
|
+
* Variable name: SSL\_CERT\_FILE
|
|
233
233
|
* Variable value: %HOMEPATH%\cacert.pem
|
|
234
234
|
* with "New..." button into upper are "User variables for xxx"
|
|
235
235
|
6. Do not remove this cacert.pem. All SSLv3 connections use this file.
|
data/bin/oddb2xml
CHANGED
|
@@ -17,21 +17,23 @@ Usage:
|
|
|
17
17
|
-c F, --compress=F Compress format F. {tar.gz|zip}
|
|
18
18
|
-f F, --format=F File format F, default is xml. {xml|dat}
|
|
19
19
|
If F is given, -o option is ignored.
|
|
20
|
-
-o O, --
|
|
20
|
+
-o O, --option=O Optional output. O, only 'fi' is available.
|
|
21
21
|
-i I, --include=I Include target option for 'dat' format. only 'ean14' is available.
|
|
22
22
|
'xml' format includes always ean14 records.
|
|
23
23
|
-t S, --tag-suffix=S XML tag suffix S. Default is none. [A-z0-9]
|
|
24
24
|
If S is given, it is also used as prefix of filename.
|
|
25
|
+
-x X, --context context for address (betrieb and person).
|
|
25
26
|
-h, --help Show this help message.
|
|
26
27
|
EOS
|
|
27
28
|
end
|
|
28
29
|
|
|
29
30
|
parser = OptionParser.new
|
|
30
31
|
opts = {
|
|
32
|
+
:fi => false,
|
|
33
|
+
:adr => false,
|
|
31
34
|
:nonpharma => false,
|
|
32
35
|
:compress_ext => nil,
|
|
33
36
|
:format => :xml,
|
|
34
|
-
:fi => false,
|
|
35
37
|
:tag_suffix => nil,
|
|
36
38
|
:debug => false,
|
|
37
39
|
:ean14 => false,
|
|
@@ -40,9 +42,10 @@ opts = {
|
|
|
40
42
|
parser.on('-a v', '--append v', /^nonpharma$/) {|v| opts[:nonpharma] = true }
|
|
41
43
|
parser.on('-c v', '--compress v', /^tar\.gz|zip$/){|v| opts[:compress_ext] = v }
|
|
42
44
|
parser.on('-f v', '--format v', /^xml|dat$/) {|v| opts[:format] = v.intern }
|
|
43
|
-
parser.on('-o v', '--
|
|
45
|
+
parser.on('-o v', '--option v', /^fi$/) {|v| opts[:fi] = true }
|
|
44
46
|
parser.on('-i v', '--include v', /^ean14$/) {|v| opts[:ean14] = true }
|
|
45
47
|
parser.on('-t v', '--tag-suffix v', /^[A-z0-9]*$/i) {|v| opts[:tag_suffix] = v.upcase }
|
|
48
|
+
parser.on('-x v', '--context v', /^addr(ess)*$/i){|v| opts[:address] = true }
|
|
46
49
|
#parser.on('--debug') {|v| opts[:debug] = true }
|
|
47
50
|
parser.on_tail('-h', '--help') { puts help; exit }
|
|
48
51
|
|
data/lib/oddb2xml/builder.rb
CHANGED
|
@@ -20,7 +20,8 @@ module Oddb2xml
|
|
|
20
20
|
attr_accessor :subject, :index, :items, :flags, :lppvs,
|
|
21
21
|
:actions, :migel, :orphans, :fridges,
|
|
22
22
|
:infos, :packs,
|
|
23
|
-
:ean14, :tag_suffix
|
|
23
|
+
:ean14, :tag_suffix,
|
|
24
|
+
:companies, :people
|
|
24
25
|
def initialize
|
|
25
26
|
@subject = nil
|
|
26
27
|
@index = {}
|
|
@@ -34,6 +35,8 @@ module Oddb2xml
|
|
|
34
35
|
@orphans = []
|
|
35
36
|
@fridges = []
|
|
36
37
|
@ean14 = true
|
|
38
|
+
@companies = {}
|
|
39
|
+
@people = {}
|
|
37
40
|
@tag_suffix = nil
|
|
38
41
|
if block_given?
|
|
39
42
|
yield self
|
|
@@ -766,6 +769,77 @@ module Oddb2xml
|
|
|
766
769
|
end
|
|
767
770
|
_builder.to_xml
|
|
768
771
|
end
|
|
772
|
+
def build_company
|
|
773
|
+
_builder = Nokogiri::XML::Builder.new(:encoding => 'utf-8') do |xml|
|
|
774
|
+
xml.doc.tag_suffix = @tag_suffix
|
|
775
|
+
datetime = Time.new.strftime('%FT%T.%7N%z')
|
|
776
|
+
xml.Betriebe(
|
|
777
|
+
'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema',
|
|
778
|
+
'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
|
|
779
|
+
'xmlns' => 'http://wiki.oddb.org/wiki.php?pagename=Swissmedic.Datendeklaration',
|
|
780
|
+
'CREATION_DATETIME' => datetime,
|
|
781
|
+
'VALID_DATE' => datetime,
|
|
782
|
+
) {
|
|
783
|
+
@companies.each_pair do |ean, c|
|
|
784
|
+
xml.Betrieb('DT' => '') {
|
|
785
|
+
xml.GLN_Betrieb ean unless ean.empty?
|
|
786
|
+
xml.Betriebsname_1 c[:name_1] unless c[:name_1].empty?
|
|
787
|
+
xml.Betriebsname_2 c[:name_2] unless c[:name_2].empty?
|
|
788
|
+
xml.Strasse c[:address] unless c[:address].empty?
|
|
789
|
+
xml.Nummer c[:number] unless c[:number].empty?
|
|
790
|
+
xml.PLZ c[:post] unless c[:post].empty?
|
|
791
|
+
xml.Ort c[:place] unless c[:place].empty?
|
|
792
|
+
xml.Bewilligungskanton c[:region] unless c[:region].empty?
|
|
793
|
+
xml.Land c[:country] unless c[:country].empty?
|
|
794
|
+
xml.Betriebstyp c[:type] unless c[:type].empty?
|
|
795
|
+
xml.BTM_Berechtigung c[:authorization] unless c[:authorization].empty?
|
|
796
|
+
}
|
|
797
|
+
end
|
|
798
|
+
xml.RESULT {
|
|
799
|
+
xml.OK_ERROR 'OK'
|
|
800
|
+
xml.NBR_RECORD @companies.values.length
|
|
801
|
+
xml.ERROR_CODE ''
|
|
802
|
+
xml.MESSAGE ''
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
end
|
|
806
|
+
_builder.to_xml
|
|
807
|
+
end
|
|
808
|
+
def build_person
|
|
809
|
+
_builder = Nokogiri::XML::Builder.new(:encoding => 'utf-8') do |xml|
|
|
810
|
+
xml.doc.tag_suffix = @tag_suffix
|
|
811
|
+
datetime = Time.new.strftime('%FT%T.%7N%z')
|
|
812
|
+
xml.Personen(
|
|
813
|
+
'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema',
|
|
814
|
+
'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
|
|
815
|
+
'xmlns' => 'http://wiki.oddb.org/wiki.php?pagename=Swissmedic.Datendeklaration',
|
|
816
|
+
'CREATION_DATETIME' => datetime,
|
|
817
|
+
'VALID_DATE' => datetime,
|
|
818
|
+
) {
|
|
819
|
+
@people.each_pair do |ean, p|
|
|
820
|
+
xml.Person('DT' => '') {
|
|
821
|
+
xml.GLN_Person ean unless ean.empty?
|
|
822
|
+
xml.Name p[:last_name] unless p[:last_name].empty?
|
|
823
|
+
xml.Vorname p[:first_name] unless p[:first_name].empty?
|
|
824
|
+
xml.PLZ p[:post] unless p[:post].empty?
|
|
825
|
+
xml.Ort p[:place] unless p[:place].empty?
|
|
826
|
+
xml.Bewilligungskanton p[:region] unless p[:region].empty?
|
|
827
|
+
xml.Land p[:country] unless p[:country].empty?
|
|
828
|
+
xml.Bewilligung_Selbstdispensation p[:lincense] unless p[:license].empty?
|
|
829
|
+
xml.Diplom p[:certificate] unless p[:certificate].empty?
|
|
830
|
+
xml.BTM_Berechtigung p[:authorization] unless p[:authorization].empty?
|
|
831
|
+
}
|
|
832
|
+
end
|
|
833
|
+
xml.RESULT {
|
|
834
|
+
xml.OK_ERROR 'OK'
|
|
835
|
+
xml.NBR_RECORD @people.values.length
|
|
836
|
+
xml.ERROR_CODE ''
|
|
837
|
+
xml.MESSAGE ''
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
end
|
|
841
|
+
_builder.to_xml
|
|
842
|
+
end
|
|
769
843
|
|
|
770
844
|
### --- see oddb2tdat
|
|
771
845
|
def format_price(price_str, len=6, int_len=4, frac_len=2)
|
data/lib/oddb2xml/cli.rb
CHANGED
|
@@ -15,6 +15,7 @@ module Oddb2xml
|
|
|
15
15
|
def initialize(args)
|
|
16
16
|
@options = args
|
|
17
17
|
@mutex = Mutex.new
|
|
18
|
+
# product
|
|
18
19
|
@items = {} # Items from Preparations.xml in BAG
|
|
19
20
|
@index = {} # Base index from swissINDEX
|
|
20
21
|
@flags = {} # narcotics flag files repo
|
|
@@ -25,6 +26,9 @@ module Oddb2xml
|
|
|
25
26
|
@actions = [] # [addition] interactions from epha
|
|
26
27
|
@orphans = [] # [addition] Orphaned drugs from Swissmedic xls
|
|
27
28
|
@fridges = [] # [addition] ReFridge drugs from Swissmedic xls
|
|
29
|
+
# addres
|
|
30
|
+
@companies = {} # betrieb
|
|
31
|
+
@people = {} # medizinalperson
|
|
28
32
|
LANGUAGES.each do |lang|
|
|
29
33
|
@index[lang] = {}
|
|
30
34
|
end
|
|
@@ -32,25 +36,31 @@ module Oddb2xml
|
|
|
32
36
|
end
|
|
33
37
|
def run
|
|
34
38
|
threads = []
|
|
35
|
-
if @options[:
|
|
36
|
-
|
|
37
|
-
threads << download(
|
|
39
|
+
if @options[:address]
|
|
40
|
+
[:company, :person].each do |type|
|
|
41
|
+
threads << download(type) # medregbm.admin
|
|
38
42
|
end
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
else
|
|
44
|
+
if @options[:format] != :dat
|
|
45
|
+
if @options[:fi]
|
|
46
|
+
threads << download(:fachinfo) # swissmedic-info
|
|
47
|
+
end
|
|
48
|
+
[:orphan, :fridge].each do |type|
|
|
49
|
+
threads << download(type) # swissmedic
|
|
50
|
+
end
|
|
51
|
+
threads << download(:interaction) # epha
|
|
41
52
|
end
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
threads << download(:
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
threads << download(:index, type, lang) # swissindex
|
|
53
|
+
if @options[:nonpharma]
|
|
54
|
+
threads << download(:migel) # oddb2xml_files
|
|
55
|
+
end
|
|
56
|
+
threads << download(:package) # swissmedic
|
|
57
|
+
threads << download(:bm_update) # oddb2xml_files
|
|
58
|
+
threads << download(:lppv) # oddb2xml_files
|
|
59
|
+
threads << download(:bag) # bag.e-mediat
|
|
60
|
+
LANGUAGES.each do |lang|
|
|
61
|
+
types.each do |type|
|
|
62
|
+
threads << download(:index, type, lang) # swissindex
|
|
63
|
+
end
|
|
54
64
|
end
|
|
55
65
|
end
|
|
56
66
|
begin
|
|
@@ -75,32 +85,38 @@ module Oddb2xml
|
|
|
75
85
|
begin
|
|
76
86
|
files.each_pair do |sbj, file|
|
|
77
87
|
builder = Builder.new do |builder|
|
|
78
|
-
if @options[:
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
88
|
+
if @options[:address]
|
|
89
|
+
builder.subject = sbj
|
|
90
|
+
builder.companies = @companies
|
|
91
|
+
builder.people = @people
|
|
92
|
+
else # product
|
|
93
|
+
if @options[:format] != :dat
|
|
94
|
+
index = {}
|
|
95
|
+
LANGUAGES.each do |lang|
|
|
96
|
+
index[lang] = {} unless index[lang]
|
|
97
|
+
types.each do |type|
|
|
98
|
+
index[lang].merge!(@index[lang][type]) if @index[lang][type]
|
|
99
|
+
end
|
|
84
100
|
end
|
|
101
|
+
builder.index = index
|
|
102
|
+
builder.subject = sbj
|
|
103
|
+
end
|
|
104
|
+
# common sources
|
|
105
|
+
builder.items = @items
|
|
106
|
+
builder.flags = @flags
|
|
107
|
+
builder.lppvs = @lppvs
|
|
108
|
+
# optional sources
|
|
109
|
+
builder.infos = @infos
|
|
110
|
+
builder.packs = @packs
|
|
111
|
+
# additional sources
|
|
112
|
+
%w[actions orphans fridges migel].each do |addition|
|
|
113
|
+
builder.send("#{addition}=".intern, self.instance_variable_get("@#{addition}"))
|
|
85
114
|
end
|
|
86
|
-
builder.index = index
|
|
87
|
-
builder.subject = sbj
|
|
88
|
-
end
|
|
89
|
-
# common sources
|
|
90
|
-
builder.items = @items
|
|
91
|
-
builder.flags = @flags
|
|
92
|
-
builder.lppvs = @lppvs
|
|
93
|
-
# optional sources
|
|
94
|
-
builder.infos = @infos
|
|
95
|
-
builder.packs = @packs
|
|
96
|
-
# additional sources
|
|
97
|
-
%w[actions orphans fridges migel].each do |addition|
|
|
98
|
-
builder.send("#{addition}=".intern, self.instance_variable_get("@#{addition}"))
|
|
99
115
|
end
|
|
100
116
|
builder.tag_suffix = @options[:tag_suffix]
|
|
101
117
|
end
|
|
102
118
|
output = ''
|
|
103
|
-
if @options[:format] == :dat
|
|
119
|
+
if !@options[:address] and (@options[:format] == :dat)
|
|
104
120
|
types.each do |type|
|
|
105
121
|
index = {}
|
|
106
122
|
LANGUAGES.each do |lang|
|
|
@@ -131,6 +147,16 @@ module Oddb2xml
|
|
|
131
147
|
end
|
|
132
148
|
def download(what, type=nil, lang=nil)
|
|
133
149
|
case what
|
|
150
|
+
when :company, :person
|
|
151
|
+
var = (what == :company ? 'companies' : 'people')
|
|
152
|
+
Thread.new do
|
|
153
|
+
downloader = MedregbmDownloader.new(what)
|
|
154
|
+
str = downloader.download
|
|
155
|
+
self.instance_variable_set(
|
|
156
|
+
"@#{var}".intern,
|
|
157
|
+
MedregbmExtractor.new(str, what).to_hash
|
|
158
|
+
)
|
|
159
|
+
end
|
|
134
160
|
when :fachinfo
|
|
135
161
|
Thread.new do
|
|
136
162
|
downloader = SwissmedicInfoDownloader.new
|
|
@@ -141,13 +167,13 @@ module Oddb2xml
|
|
|
141
167
|
end
|
|
142
168
|
end
|
|
143
169
|
when :orphan, :fridge
|
|
144
|
-
|
|
170
|
+
var = what.to_s + 's'
|
|
145
171
|
Thread.new do
|
|
146
|
-
downloader = SwissmedicDownloader.new(
|
|
172
|
+
downloader = SwissmedicDownloader.new(what)
|
|
147
173
|
bin = downloader.download
|
|
148
174
|
self.instance_variable_set(
|
|
149
|
-
"@#{
|
|
150
|
-
SwissmedicExtractor.new(bin,
|
|
175
|
+
"@#{var}".intern,
|
|
176
|
+
SwissmedicExtractor.new(bin, what).to_arry
|
|
151
177
|
)
|
|
152
178
|
end
|
|
153
179
|
when :interaction
|
|
@@ -168,10 +194,10 @@ module Oddb2xml
|
|
|
168
194
|
end
|
|
169
195
|
when :package
|
|
170
196
|
Thread.new do
|
|
171
|
-
downloader = SwissmedicDownloader.new(:
|
|
197
|
+
downloader = SwissmedicDownloader.new(:package)
|
|
172
198
|
bin = downloader.download
|
|
173
199
|
@mutex.synchronize do
|
|
174
|
-
@packs = SwissmedicExtractor.new(bin, :
|
|
200
|
+
@packs = SwissmedicExtractor.new(bin, :package).to_hash
|
|
175
201
|
end
|
|
176
202
|
end
|
|
177
203
|
when :bm_update
|
|
@@ -231,7 +257,10 @@ module Oddb2xml
|
|
|
231
257
|
def files
|
|
232
258
|
unless @_files
|
|
233
259
|
@_files = {}
|
|
234
|
-
if @options[:
|
|
260
|
+
if @options[:address]
|
|
261
|
+
@_files[:company] = "#{prefix}_betrieb.xml"
|
|
262
|
+
@_files[:person] = "#{prefix}_medizinalperson.xml"
|
|
263
|
+
elsif @options[:format] == :dat
|
|
235
264
|
@_files[:dat] = "#{prefix}.dat"
|
|
236
265
|
if @options[:nonpharma] # into one file
|
|
237
266
|
@_files[:dat] = "#{prefix}_with_migel.dat"
|
|
@@ -255,18 +284,20 @@ module Oddb2xml
|
|
|
255
284
|
@_prefix ||= (@options[:tag_suffix] || 'oddb').gsub(/^_|_$/, '').downcase
|
|
256
285
|
end
|
|
257
286
|
def report
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
287
|
+
unless @options[:address]
|
|
288
|
+
lines = []
|
|
289
|
+
LANGUAGES.each do |lang|
|
|
290
|
+
lines << lang
|
|
291
|
+
types.each do |type|
|
|
292
|
+
key = (type == :nonpharma ? 'NonPharma' : 'Pharma')
|
|
293
|
+
if @index[lang][type]
|
|
294
|
+
lines << sprintf(
|
|
295
|
+
"\t#{key} products: %i", @index[lang][type].values.length)
|
|
296
|
+
end
|
|
266
297
|
end
|
|
267
298
|
end
|
|
299
|
+
puts lines.join("\n")
|
|
268
300
|
end
|
|
269
|
-
puts lines.join("\n")
|
|
270
301
|
end
|
|
271
302
|
def types # swissindex
|
|
272
303
|
@_types ||=
|
data/lib/oddb2xml/downloader.rb
CHANGED
|
@@ -5,6 +5,25 @@ require 'zip/zip'
|
|
|
5
5
|
require 'savon'
|
|
6
6
|
|
|
7
7
|
module Oddb2xml
|
|
8
|
+
module DownloadMethod
|
|
9
|
+
private
|
|
10
|
+
def download_as(file, option='r')
|
|
11
|
+
begin
|
|
12
|
+
response = @agent.get(@url)
|
|
13
|
+
response.save_as(file)
|
|
14
|
+
response = nil # win
|
|
15
|
+
io = File.open(file, option)
|
|
16
|
+
return io.read
|
|
17
|
+
rescue Timeout::Error
|
|
18
|
+
retrievable? ? retry : raise
|
|
19
|
+
ensure
|
|
20
|
+
io.close if io and !io.closed? # win
|
|
21
|
+
if File.exists?(file)
|
|
22
|
+
File.unlink(file)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
8
27
|
class Downloader
|
|
9
28
|
def initialize(options={}, url=nil)
|
|
10
29
|
@options = options
|
|
@@ -56,6 +75,53 @@ module Oddb2xml
|
|
|
56
75
|
xml
|
|
57
76
|
end
|
|
58
77
|
end
|
|
78
|
+
class MigelDownloader < Downloader
|
|
79
|
+
include DownloadMethod
|
|
80
|
+
def download
|
|
81
|
+
@url ||= 'https://github.com/zdavatz/oddb2xml_files/raw/master/NON-Pharma.xls'
|
|
82
|
+
download_as('oddb2xml_files_nonpharma.xls', 'rb')
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
class EphaDownloader < Downloader
|
|
86
|
+
include DownloadMethod
|
|
87
|
+
def download
|
|
88
|
+
@url ||= 'http://community.epha.ch/interactions_de_utf8.csv'
|
|
89
|
+
download_as('epha_interactions.csv', 'r')
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
class BMUpdateDownloader < Downloader
|
|
93
|
+
include DownloadMethod
|
|
94
|
+
def download
|
|
95
|
+
@url ||= 'https://raw.github.com/zdavatz/oddb2xml_files/master/BM_Update.txt'
|
|
96
|
+
download_as('oddb2xml_files_bm_update.txt', 'r')
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
class LppvDownloader < Downloader
|
|
100
|
+
include DownloadMethod
|
|
101
|
+
def download
|
|
102
|
+
@url ||= 'https://raw.github.com/zdavatz/oddb2xml_files/master/LPPV.txt'
|
|
103
|
+
download_as('oddb2xml_files_lppv.txt', 'r')
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
class MedregbmDownloader < Downloader
|
|
107
|
+
include DownloadMethod
|
|
108
|
+
def initialize(type=:company)
|
|
109
|
+
@type = type
|
|
110
|
+
case @type
|
|
111
|
+
when :company # betrieb
|
|
112
|
+
action = 'CreateExcelListBetriebs'
|
|
113
|
+
when :person # medizinalperson
|
|
114
|
+
action = 'CreateExcelListMedizinalPersons'
|
|
115
|
+
else
|
|
116
|
+
action = ''
|
|
117
|
+
end
|
|
118
|
+
url = "https://www.medregbm.admin.ch/Publikation/#{action}"
|
|
119
|
+
super({}, url)
|
|
120
|
+
end
|
|
121
|
+
def download
|
|
122
|
+
download_as("medregbm_#{@type.to_s}.txt", 'r:iso-8859-1:utf-8')
|
|
123
|
+
end
|
|
124
|
+
end
|
|
59
125
|
class BagXmlDownloader < Downloader
|
|
60
126
|
def init
|
|
61
127
|
super
|
|
@@ -131,16 +197,16 @@ XML
|
|
|
131
197
|
end
|
|
132
198
|
end
|
|
133
199
|
class SwissmedicDownloader < Downloader
|
|
134
|
-
def initialize(type=:
|
|
200
|
+
def initialize(type=:orphan)
|
|
135
201
|
@type = type
|
|
136
202
|
case @type
|
|
137
|
-
when :
|
|
203
|
+
when :orphan
|
|
138
204
|
action = "daten/00081/index.html?lang=de"
|
|
139
205
|
@xpath = "//div[@id='sprungmarke0_4']//a[@title='Humanarzneimittel']"
|
|
140
|
-
when :
|
|
206
|
+
when :fridge
|
|
141
207
|
action = "daten/00080/00254/index.html?lang=de"
|
|
142
208
|
@xpath = "//table[@class='swmTableFlex']//a[@title='B3.1.35-d.xls']"
|
|
143
|
-
when :
|
|
209
|
+
when :package
|
|
144
210
|
action = "daten/00080/00251/index.html?lang=de"
|
|
145
211
|
@xpath = "//div[@id='sprungmarke0_7']//a[@title='Excel-Version Zugelassene Verpackungen*']"
|
|
146
212
|
end
|
|
@@ -169,29 +235,6 @@ XML
|
|
|
169
235
|
end
|
|
170
236
|
end
|
|
171
237
|
end
|
|
172
|
-
class MigelDownloader < Downloader
|
|
173
|
-
def init
|
|
174
|
-
super
|
|
175
|
-
@url ||= 'https://github.com/zdavatz/oddb2xml_files/raw/master/NON-Pharma.xls'
|
|
176
|
-
end
|
|
177
|
-
def download
|
|
178
|
-
file = "oddb2xml_files_nonpharma.xls"
|
|
179
|
-
begin
|
|
180
|
-
response = @agent.get(@url)
|
|
181
|
-
response.save_as(file)
|
|
182
|
-
response = nil # win
|
|
183
|
-
io = File.open(file, 'rb')
|
|
184
|
-
return io.read
|
|
185
|
-
rescue Timeout::Error
|
|
186
|
-
retrievable? ? retry : raise
|
|
187
|
-
ensure
|
|
188
|
-
io.close if io and !io.closed? # win
|
|
189
|
-
if File.exists?(file)
|
|
190
|
-
File.unlink(file)
|
|
191
|
-
end
|
|
192
|
-
end
|
|
193
|
-
end
|
|
194
|
-
end
|
|
195
238
|
class SwissmedicInfoDownloader < Downloader
|
|
196
239
|
def init
|
|
197
240
|
super
|
|
@@ -235,68 +278,4 @@ XML
|
|
|
235
278
|
end
|
|
236
279
|
end
|
|
237
280
|
end
|
|
238
|
-
class EphaDownloader < Downloader
|
|
239
|
-
def init
|
|
240
|
-
super
|
|
241
|
-
@url ||= 'http://community.epha.ch/interactions_de_utf8.csv'
|
|
242
|
-
end
|
|
243
|
-
def download
|
|
244
|
-
file = "epha_interactions.csv"
|
|
245
|
-
begin
|
|
246
|
-
response = @agent.get(@url)
|
|
247
|
-
response.save_as(file)
|
|
248
|
-
response = nil # win
|
|
249
|
-
io = File.open(file, 'r')
|
|
250
|
-
return io.read
|
|
251
|
-
rescue Timeout::Error
|
|
252
|
-
retrievable? ? retry : raise
|
|
253
|
-
ensure
|
|
254
|
-
io.close if io and !io.closed? # win
|
|
255
|
-
if File.exists?(file)
|
|
256
|
-
File.unlink(file)
|
|
257
|
-
end
|
|
258
|
-
end
|
|
259
|
-
end
|
|
260
|
-
end
|
|
261
|
-
# txt filse
|
|
262
|
-
module TxtDownloadMethods
|
|
263
|
-
def download_as(file)
|
|
264
|
-
begin
|
|
265
|
-
response = @agent.get(@url)
|
|
266
|
-
response.save_as(file)
|
|
267
|
-
response = nil # win
|
|
268
|
-
io = File.open(file, 'r')
|
|
269
|
-
return io.read
|
|
270
|
-
rescue Timeout::Error
|
|
271
|
-
retrievable? ? retry : raise
|
|
272
|
-
ensure
|
|
273
|
-
io.close if io and !io.closed? # win
|
|
274
|
-
if File.exists?(file)
|
|
275
|
-
File.unlink(file)
|
|
276
|
-
end
|
|
277
|
-
end
|
|
278
|
-
end
|
|
279
|
-
end
|
|
280
|
-
class BMUpdateDownloader < Downloader
|
|
281
|
-
include TxtDownloadMethods
|
|
282
|
-
def init
|
|
283
|
-
super
|
|
284
|
-
@url ||= 'https://raw.github.com/zdavatz/oddb2xml_files/master/BM_Update.txt'
|
|
285
|
-
end
|
|
286
|
-
def download
|
|
287
|
-
file = 'oddb2xml_files_bm_update.txt'
|
|
288
|
-
download_as(file)
|
|
289
|
-
end
|
|
290
|
-
end
|
|
291
|
-
class LppvDownloader < Downloader
|
|
292
|
-
include TxtDownloadMethods
|
|
293
|
-
def init
|
|
294
|
-
super
|
|
295
|
-
@url ||= 'https://raw.github.com/zdavatz/oddb2xml_files/master/LPPV.txt'
|
|
296
|
-
end
|
|
297
|
-
def download
|
|
298
|
-
file = 'oddb2xml_files_lppv.txt'
|
|
299
|
-
download_as(file)
|
|
300
|
-
end
|
|
301
|
-
end
|
|
302
281
|
end
|
data/lib/oddb2xml/extractor.rb
CHANGED
|
@@ -5,12 +5,32 @@ require 'spreadsheet'
|
|
|
5
5
|
require 'stringio'
|
|
6
6
|
|
|
7
7
|
module Oddb2xml
|
|
8
|
+
module TxtExtractorMethods
|
|
9
|
+
def initialize(str)
|
|
10
|
+
@io = StringIO.new(str)
|
|
11
|
+
end
|
|
12
|
+
def to_hash
|
|
13
|
+
data = {}
|
|
14
|
+
while line = @io.gets
|
|
15
|
+
next unless line =~ /\d{13}/
|
|
16
|
+
ean = line.chomp.gsub("\"", '')
|
|
17
|
+
data[ean] = true
|
|
18
|
+
end
|
|
19
|
+
data
|
|
20
|
+
end
|
|
21
|
+
end
|
|
8
22
|
class Extractor
|
|
9
23
|
attr_accessor :xml
|
|
10
24
|
def initialize(xml)
|
|
11
25
|
@xml = xml
|
|
12
26
|
end
|
|
13
27
|
end
|
|
28
|
+
class BMUpdateExtractor < Extractor
|
|
29
|
+
include TxtExtractorMethods
|
|
30
|
+
end
|
|
31
|
+
class LppvExtractor < Extractor
|
|
32
|
+
include TxtExtractorMethods
|
|
33
|
+
end
|
|
14
34
|
class BagXmlExtractor < Extractor
|
|
15
35
|
def to_hash
|
|
16
36
|
data = {}
|
|
@@ -167,21 +187,21 @@ module Oddb2xml
|
|
|
167
187
|
class SwissmedicExtractor < Extractor
|
|
168
188
|
def initialize(bin, type)
|
|
169
189
|
io = StringIO.new(bin)
|
|
170
|
-
book = Spreadsheet.open(io)
|
|
190
|
+
book = Spreadsheet.open(io, 'rb')
|
|
171
191
|
@sheet = book.worksheet(0)
|
|
172
192
|
@type = type
|
|
173
193
|
end
|
|
174
194
|
def to_arry
|
|
175
195
|
data = []
|
|
176
196
|
case @type
|
|
177
|
-
when :
|
|
197
|
+
when :orphan
|
|
178
198
|
i = 1
|
|
179
199
|
@sheet.each do |row|
|
|
180
200
|
if number = extract_number(row, i)
|
|
181
201
|
data << number.to_s
|
|
182
202
|
end
|
|
183
203
|
end
|
|
184
|
-
when :
|
|
204
|
+
when :fridge
|
|
185
205
|
i,c = 1,7
|
|
186
206
|
@sheet.each do |row|
|
|
187
207
|
if number = extract_number(row, i) and row[c] and row[c].to_s == 'x'
|
|
@@ -194,7 +214,7 @@ module Oddb2xml
|
|
|
194
214
|
def to_hash # Packungen.xls
|
|
195
215
|
data = {}
|
|
196
216
|
case @type
|
|
197
|
-
when :
|
|
217
|
+
when :package
|
|
198
218
|
typ = 6 # Heilmittelcode
|
|
199
219
|
i_5,i_3 = 0,10 # :swissmedic_numbers
|
|
200
220
|
cat = 13 # :swissmedic_category
|
|
@@ -253,13 +273,13 @@ module Oddb2xml
|
|
|
253
273
|
class MigelExtractor < Extractor
|
|
254
274
|
def initialize(bin)
|
|
255
275
|
io = StringIO.new(bin)
|
|
256
|
-
book = Spreadsheet.open(io)
|
|
276
|
+
book = Spreadsheet.open(io, 'rb')
|
|
257
277
|
@sheet = book.worksheet(0)
|
|
258
278
|
end
|
|
259
279
|
def to_hash
|
|
260
280
|
data = {}
|
|
261
281
|
@sheet.each_with_index do |row, i|
|
|
262
|
-
next if i
|
|
282
|
+
next if i.zero?
|
|
263
283
|
phar = row[1].to_s
|
|
264
284
|
data[phar] = {
|
|
265
285
|
:ean => row[0].to_i.to_s,
|
|
@@ -328,25 +348,53 @@ module Oddb2xml
|
|
|
328
348
|
data
|
|
329
349
|
end
|
|
330
350
|
end
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
@
|
|
351
|
+
class MedregbmExtractor < Extractor
|
|
352
|
+
def initialize(str, type)
|
|
353
|
+
@io = StringIO.new(str)
|
|
354
|
+
@type = type
|
|
335
355
|
end
|
|
336
356
|
def to_hash
|
|
337
357
|
data = {}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
358
|
+
case @type
|
|
359
|
+
when :company
|
|
360
|
+
while line = @io.gets
|
|
361
|
+
row = line.chomp.split("\t")
|
|
362
|
+
next if row[0] =~ /^GLN/
|
|
363
|
+
gln = row[0].to_s
|
|
364
|
+
data[gln] = {
|
|
365
|
+
:gln => gln, #=> GLN Betrieb
|
|
366
|
+
:name_1 => row[1].to_s, #=> Betriebsname 1
|
|
367
|
+
:name_2 => row[2].to_s, #=> Betriebsname 2
|
|
368
|
+
:address => row[3].to_s, #=> Strasse
|
|
369
|
+
:number => row[4].to_s, #=> Nummer
|
|
370
|
+
:post => row[5].to_s, #=> PLZ
|
|
371
|
+
:place => row[6].to_s, #=> Ort
|
|
372
|
+
:region => row[7].to_s, #=> Bewilligungskanton
|
|
373
|
+
:country => row[8].to_s, #=> Land
|
|
374
|
+
:type => row[9].to_s, #=> Betriebstyp
|
|
375
|
+
:authorization => row[10].to_s, #=> BTM Berechtigung
|
|
376
|
+
}
|
|
377
|
+
end
|
|
378
|
+
when :person
|
|
379
|
+
while line = @io.gets
|
|
380
|
+
row = line.chomp.split("\t")
|
|
381
|
+
next if row[0] =~ /^GLN/
|
|
382
|
+
gln = row[0].to_s
|
|
383
|
+
data[gln] = {
|
|
384
|
+
:gln => gln, #=> GLN Person
|
|
385
|
+
:last_name => row[1].to_s, #=> Name
|
|
386
|
+
:first_name => row[2].to_s, #=> Vorname
|
|
387
|
+
:post => row[3].to_s, #=> PLZ
|
|
388
|
+
:place => row[4].to_s, #=> Ort
|
|
389
|
+
:region => row[5].to_s, #=> Bewilligungskanton
|
|
390
|
+
:country => row[6].to_s, #=> Land
|
|
391
|
+
:license => row[7].to_s, #=> Bewilligung Selbstdispensation
|
|
392
|
+
:certificate => row[8].to_s, #=> Diplom
|
|
393
|
+
:authorization => row[9].to_s, #=> BTM Berechtigung
|
|
394
|
+
}
|
|
395
|
+
end
|
|
342
396
|
end
|
|
343
397
|
data
|
|
344
398
|
end
|
|
345
399
|
end
|
|
346
|
-
class BMUpdateExtractor < Extractor
|
|
347
|
-
include TxtMethods
|
|
348
|
-
end
|
|
349
|
-
class LppvExtractor < Extractor
|
|
350
|
-
include TxtMethods
|
|
351
|
-
end
|
|
352
400
|
end
|
data/lib/oddb2xml/version.rb
CHANGED
data/spec/cli_spec.rb
CHANGED
|
@@ -14,7 +14,7 @@ RSpec::Matchers.define :have_option do |option|
|
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
shared_examples_for 'any interface' do
|
|
17
|
+
shared_examples_for 'any interface for product' do
|
|
18
18
|
it { cli.should respond_to(:run) }
|
|
19
19
|
it 'should run successfully' do
|
|
20
20
|
$stdout.should_receive(:puts).with(/products/)
|
|
@@ -22,6 +22,14 @@ shared_examples_for 'any interface' do
|
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
+
shared_examples_for 'any interface for address' do
|
|
26
|
+
it { cli.should respond_to(:run) }
|
|
27
|
+
it 'should run successfully' do
|
|
28
|
+
$stdout.should_not_receive(:puts) # no output
|
|
29
|
+
cli.run
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
25
33
|
describe Oddb2xml::Cli do
|
|
26
34
|
include ServerMockHelper
|
|
27
35
|
before(:each) do
|
|
@@ -33,11 +41,12 @@ describe Oddb2xml::Cli do
|
|
|
33
41
|
:compress_ext => 'tar.gz',
|
|
34
42
|
:nonpharma => false,
|
|
35
43
|
:fi => false,
|
|
44
|
+
:address => false,
|
|
36
45
|
:tag_suffix => nil,
|
|
37
46
|
}
|
|
38
47
|
Oddb2xml::Cli.new(opts)
|
|
39
48
|
end
|
|
40
|
-
it_behaves_like 'any interface'
|
|
49
|
+
it_behaves_like 'any interface for product'
|
|
41
50
|
it 'should have compress option' do
|
|
42
51
|
cli.should have_option(:compress_ext => 'tar.gz')
|
|
43
52
|
end
|
|
@@ -66,11 +75,12 @@ describe Oddb2xml::Cli do
|
|
|
66
75
|
:compress_ext => 'zip',
|
|
67
76
|
:nonpharma => false,
|
|
68
77
|
:fi => false,
|
|
78
|
+
:address => false,
|
|
69
79
|
:tag_suffix => nil,
|
|
70
80
|
}
|
|
71
81
|
Oddb2xml::Cli.new(opts)
|
|
72
82
|
end
|
|
73
|
-
it_behaves_like 'any interface'
|
|
83
|
+
it_behaves_like 'any interface for product'
|
|
74
84
|
it 'should have compress option' do
|
|
75
85
|
cli.should have_option(:compress_ext => 'zip')
|
|
76
86
|
end
|
|
@@ -99,11 +109,12 @@ describe Oddb2xml::Cli do
|
|
|
99
109
|
:compress_ext => nil,
|
|
100
110
|
:nonpharma => true,
|
|
101
111
|
:fi => false,
|
|
112
|
+
:address => false,
|
|
102
113
|
:tag_suffix => nil,
|
|
103
114
|
}
|
|
104
115
|
Oddb2xml::Cli.new(opts)
|
|
105
116
|
end
|
|
106
|
-
it_behaves_like 'any interface'
|
|
117
|
+
it_behaves_like 'any interface for product'
|
|
107
118
|
it 'should have nonpharma option' do
|
|
108
119
|
cli.should have_option(:nonpharma => true)
|
|
109
120
|
end
|
|
@@ -140,11 +151,12 @@ describe Oddb2xml::Cli do
|
|
|
140
151
|
:compress_ext => nil,
|
|
141
152
|
:nonpharma => false,
|
|
142
153
|
:fi => false,
|
|
154
|
+
:address => false,
|
|
143
155
|
:tag_suffix => '_swiss'.upcase,
|
|
144
156
|
}
|
|
145
157
|
Oddb2xml::Cli.new(opts)
|
|
146
158
|
end
|
|
147
|
-
it_behaves_like 'any interface'
|
|
159
|
+
it_behaves_like 'any interface for product'
|
|
148
160
|
it 'should have tag_suffix option' do
|
|
149
161
|
cli.should have_option(:tag_suffix=> '_SWISS')
|
|
150
162
|
end
|
|
@@ -181,11 +193,12 @@ describe Oddb2xml::Cli do
|
|
|
181
193
|
:compress_ext => nil,
|
|
182
194
|
:nonpharma => false,
|
|
183
195
|
:fi => true,
|
|
196
|
+
:address => false,
|
|
184
197
|
:tag_suffix => nil,
|
|
185
198
|
}
|
|
186
199
|
Oddb2xml::Cli.new(opts)
|
|
187
200
|
end
|
|
188
|
-
it_behaves_like 'any interface'
|
|
201
|
+
it_behaves_like 'any interface for product'
|
|
189
202
|
it 'should have nonpharma option' do
|
|
190
203
|
cli.should have_option(:fi => true)
|
|
191
204
|
end
|
|
@@ -218,4 +231,40 @@ describe Oddb2xml::Cli do
|
|
|
218
231
|
end
|
|
219
232
|
end
|
|
220
233
|
end
|
|
234
|
+
context 'when -x address option is given' do
|
|
235
|
+
let(:cli) do
|
|
236
|
+
opts = {
|
|
237
|
+
:compress_ext => nil,
|
|
238
|
+
:nonpharma => false,
|
|
239
|
+
:fi => false,
|
|
240
|
+
:address => true,
|
|
241
|
+
:tag_suffix => nil,
|
|
242
|
+
}
|
|
243
|
+
Oddb2xml::Cli.new(opts)
|
|
244
|
+
end
|
|
245
|
+
it_behaves_like 'any interface for address'
|
|
246
|
+
it 'should have address option' do
|
|
247
|
+
cli.should have_option(:address=> true)
|
|
248
|
+
end
|
|
249
|
+
it 'should not create any compressed file' do
|
|
250
|
+
cli.run
|
|
251
|
+
Dir.glob('oddb_*.tar.gz').first.should be_nil
|
|
252
|
+
Dir.glob('oddb_*.zip').first.should be_nil
|
|
253
|
+
end
|
|
254
|
+
it 'should create xml files' do
|
|
255
|
+
cli.run
|
|
256
|
+
expected = [
|
|
257
|
+
'oddb_betrieb.xml',
|
|
258
|
+
'oddb_medizinalperson.xml',
|
|
259
|
+
].length
|
|
260
|
+
Dir.glob('oddb_*.xml').each do |file|
|
|
261
|
+
File.exists?(file).should be_true
|
|
262
|
+
end.to_a.length.should equal expected
|
|
263
|
+
end
|
|
264
|
+
after(:each) do
|
|
265
|
+
Dir.glob('oddb_*.xml').each do |file|
|
|
266
|
+
File.unlink(file) if File.exists?(file)
|
|
267
|
+
end
|
|
268
|
+
end
|
|
269
|
+
end
|
|
221
270
|
end
|
|
File without changes
|
|
File without changes
|
data/spec/downloader_spec.rb
CHANGED
|
@@ -87,13 +87,13 @@ end
|
|
|
87
87
|
|
|
88
88
|
describe Oddb2xml::SwissmedicDownloader do
|
|
89
89
|
include ServerMockHelper
|
|
90
|
-
context '
|
|
90
|
+
context 'orphan' do
|
|
91
91
|
before(:each) do
|
|
92
92
|
setup_swissmedic_server_mock
|
|
93
|
-
@downloader = Oddb2xml::SwissmedicDownloader.new(:
|
|
93
|
+
@downloader = Oddb2xml::SwissmedicDownloader.new(:orphan)
|
|
94
94
|
end
|
|
95
95
|
it_behaves_like 'any downloader'
|
|
96
|
-
context 'download_by for
|
|
96
|
+
context 'download_by for orphan xls' do
|
|
97
97
|
let(:bin) { @downloader.download }
|
|
98
98
|
it 'should return valid Binary-String' do
|
|
99
99
|
bin.should be_a String
|
|
@@ -101,16 +101,16 @@ describe Oddb2xml::SwissmedicDownloader do
|
|
|
101
101
|
end
|
|
102
102
|
it 'should clean up current directory' do
|
|
103
103
|
bin.should_not raise_error(Timeout::Error)
|
|
104
|
-
File.exist?('
|
|
104
|
+
File.exist?('oddb_orphan.xls').should be(false)
|
|
105
105
|
end
|
|
106
106
|
end
|
|
107
107
|
end
|
|
108
|
-
context '
|
|
108
|
+
context 'fridge' do
|
|
109
109
|
before(:each) do
|
|
110
110
|
setup_swissmedic_server_mock
|
|
111
|
-
@downloader = Oddb2xml::SwissmedicDownloader.new(:
|
|
111
|
+
@downloader = Oddb2xml::SwissmedicDownloader.new(:fridge)
|
|
112
112
|
end
|
|
113
|
-
context 'download_by for
|
|
113
|
+
context 'download_by for fridge xls' do
|
|
114
114
|
let(:bin) { @downloader.download }
|
|
115
115
|
it 'should return valid Binary-String' do
|
|
116
116
|
bin.should be_a String
|
|
@@ -118,16 +118,16 @@ describe Oddb2xml::SwissmedicDownloader do
|
|
|
118
118
|
end
|
|
119
119
|
it 'should clean up current directory' do
|
|
120
120
|
bin.should_not raise_error(Timeout::Error)
|
|
121
|
-
File.exist?('
|
|
121
|
+
File.exist?('oddb_fridge.xls').should be(false)
|
|
122
122
|
end
|
|
123
123
|
end
|
|
124
124
|
end
|
|
125
|
-
context '
|
|
125
|
+
context 'package' do
|
|
126
126
|
before(:each) do
|
|
127
127
|
setup_swissmedic_server_mock
|
|
128
|
-
@downloader = Oddb2xml::SwissmedicDownloader.new(:
|
|
128
|
+
@downloader = Oddb2xml::SwissmedicDownloader.new(:package)
|
|
129
129
|
end
|
|
130
|
-
context 'download_by for
|
|
130
|
+
context 'download_by for package xls' do
|
|
131
131
|
let(:bin) { @downloader.download }
|
|
132
132
|
it 'should return valid Binary-String' do
|
|
133
133
|
bin.should be_a String
|
|
@@ -135,7 +135,7 @@ describe Oddb2xml::SwissmedicDownloader do
|
|
|
135
135
|
end
|
|
136
136
|
it 'should clean up current directory' do
|
|
137
137
|
bin.should_not raise_error(Timeout::Error)
|
|
138
|
-
File.exist?('
|
|
138
|
+
File.exist?('oddb_package.xls').should be(false)
|
|
139
139
|
end
|
|
140
140
|
end
|
|
141
141
|
end
|
|
@@ -245,3 +245,42 @@ describe Oddb2xml::MigelDownloader do
|
|
|
245
245
|
end
|
|
246
246
|
end
|
|
247
247
|
end
|
|
248
|
+
|
|
249
|
+
describe Oddb2xml::MedregbmDownloader do
|
|
250
|
+
include ServerMockHelper
|
|
251
|
+
context 'betrieb' do
|
|
252
|
+
before(:each) do
|
|
253
|
+
setup_medregbm_server_mock
|
|
254
|
+
@downloader = Oddb2xml::MedregbmDownloader.new(:company)
|
|
255
|
+
end
|
|
256
|
+
it_behaves_like 'any downloader'
|
|
257
|
+
context 'download betrieb txt' do
|
|
258
|
+
let(:txt) { @downloader.download }
|
|
259
|
+
it 'should return valid String' do
|
|
260
|
+
txt.should be_a String
|
|
261
|
+
txt.bytes.should_not nil
|
|
262
|
+
end
|
|
263
|
+
it 'should clean up current directory' do
|
|
264
|
+
txt.should_not raise_error(Timeout::Error)
|
|
265
|
+
File.exist?('oddb_company.xls').should be(false)
|
|
266
|
+
end
|
|
267
|
+
end
|
|
268
|
+
end
|
|
269
|
+
context 'person' do
|
|
270
|
+
before(:each) do
|
|
271
|
+
setup_medregbm_server_mock
|
|
272
|
+
@downloader = Oddb2xml::MedregbmDownloader.new(:person)
|
|
273
|
+
end
|
|
274
|
+
context 'download person txt' do
|
|
275
|
+
let(:txt) { @downloader.download }
|
|
276
|
+
it 'should return valid String' do
|
|
277
|
+
txt.should be_a String
|
|
278
|
+
txt.bytes.should_not nil
|
|
279
|
+
end
|
|
280
|
+
it 'should clean up current directory' do
|
|
281
|
+
txt.should_not raise_error(Timeout::Error)
|
|
282
|
+
File.exist?('oddb_person.xls').should be(false)
|
|
283
|
+
end
|
|
284
|
+
end
|
|
285
|
+
end
|
|
286
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -25,6 +25,7 @@ module ServerMockHelper
|
|
|
25
25
|
setup_bm_update_server_mock
|
|
26
26
|
setup_lppv_server_mock
|
|
27
27
|
setup_migel_server_mock
|
|
28
|
+
setup_medregbm_server_mock
|
|
28
29
|
end
|
|
29
30
|
def setup_bag_xml_server_mock
|
|
30
31
|
# zip
|
|
@@ -199,6 +200,32 @@ module ServerMockHelper
|
|
|
199
200
|
:headers => {'Content-Type' => 'application/octet-stream; charset=utf-8'},
|
|
200
201
|
:body => stub_response)
|
|
201
202
|
end
|
|
203
|
+
def setup_medregbm_server_mock
|
|
204
|
+
# txt betrieb
|
|
205
|
+
stub_txt_url = 'https://www.medregbm.admin.ch/Publikation/CreateExcelListBetriebs'
|
|
206
|
+
stub_response = File.read(File.expand_path('../data/medregbm_betrieb.txt', __FILE__))
|
|
207
|
+
stub_request(:get, stub_txt_url).
|
|
208
|
+
with(:headers => {
|
|
209
|
+
'Accept' => '*/*',
|
|
210
|
+
'Host' => 'www.medregbm.admin.ch',
|
|
211
|
+
}).
|
|
212
|
+
to_return(
|
|
213
|
+
:status => 200,
|
|
214
|
+
:headers => {'Content-Type' => 'text/plain; charset=utf-8'},
|
|
215
|
+
:body => stub_response)
|
|
216
|
+
stub_txt_url = 'https://www.medregbm.admin.ch/Publikation/CreateExcelListMedizinalPersons'
|
|
217
|
+
# txt person
|
|
218
|
+
stub_response = File.read(File.expand_path('../data/medregbm_person.txt', __FILE__))
|
|
219
|
+
stub_request(:get, stub_txt_url).
|
|
220
|
+
with(:headers => {
|
|
221
|
+
'Accept' => '*/*',
|
|
222
|
+
'Host' => 'www.medregbm.admin.ch',
|
|
223
|
+
}).
|
|
224
|
+
to_return(
|
|
225
|
+
:status => 200,
|
|
226
|
+
:headers => {'Content-Type' => 'text/plain; charset=utf-8'},
|
|
227
|
+
:body => stub_response)
|
|
228
|
+
end
|
|
202
229
|
end
|
|
203
230
|
|
|
204
231
|
RSpec.configure do |config|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: oddb2xml
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.3.
|
|
4
|
+
version: 1.3.9
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,11 +9,11 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2013-02-
|
|
12
|
+
date: 2013-02-14 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rubyzip
|
|
16
|
-
requirement: &
|
|
16
|
+
requirement: &19384600 !ruby/object:Gem::Requirement
|
|
17
17
|
none: false
|
|
18
18
|
requirements:
|
|
19
19
|
- - ! '>='
|
|
@@ -21,10 +21,10 @@ dependencies:
|
|
|
21
21
|
version: '0'
|
|
22
22
|
type: :runtime
|
|
23
23
|
prerelease: false
|
|
24
|
-
version_requirements: *
|
|
24
|
+
version_requirements: *19384600
|
|
25
25
|
- !ruby/object:Gem::Dependency
|
|
26
26
|
name: archive-tar-minitar
|
|
27
|
-
requirement: &
|
|
27
|
+
requirement: &19384140 !ruby/object:Gem::Requirement
|
|
28
28
|
none: false
|
|
29
29
|
requirements:
|
|
30
30
|
- - ! '>='
|
|
@@ -32,10 +32,10 @@ dependencies:
|
|
|
32
32
|
version: '0'
|
|
33
33
|
type: :runtime
|
|
34
34
|
prerelease: false
|
|
35
|
-
version_requirements: *
|
|
35
|
+
version_requirements: *19384140
|
|
36
36
|
- !ruby/object:Gem::Dependency
|
|
37
37
|
name: mechanize
|
|
38
|
-
requirement: &
|
|
38
|
+
requirement: &19383700 !ruby/object:Gem::Requirement
|
|
39
39
|
none: false
|
|
40
40
|
requirements:
|
|
41
41
|
- - ! '>='
|
|
@@ -43,10 +43,10 @@ dependencies:
|
|
|
43
43
|
version: '0'
|
|
44
44
|
type: :runtime
|
|
45
45
|
prerelease: false
|
|
46
|
-
version_requirements: *
|
|
46
|
+
version_requirements: *19383700
|
|
47
47
|
- !ruby/object:Gem::Dependency
|
|
48
48
|
name: nokogiri
|
|
49
|
-
requirement: &
|
|
49
|
+
requirement: &19383200 !ruby/object:Gem::Requirement
|
|
50
50
|
none: false
|
|
51
51
|
requirements:
|
|
52
52
|
- - ! '>='
|
|
@@ -54,10 +54,10 @@ dependencies:
|
|
|
54
54
|
version: '0'
|
|
55
55
|
type: :runtime
|
|
56
56
|
prerelease: false
|
|
57
|
-
version_requirements: *
|
|
57
|
+
version_requirements: *19383200
|
|
58
58
|
- !ruby/object:Gem::Dependency
|
|
59
59
|
name: savon
|
|
60
|
-
requirement: &
|
|
60
|
+
requirement: &19382620 !ruby/object:Gem::Requirement
|
|
61
61
|
none: false
|
|
62
62
|
requirements:
|
|
63
63
|
- - ! '>='
|
|
@@ -65,10 +65,10 @@ dependencies:
|
|
|
65
65
|
version: '2.0'
|
|
66
66
|
type: :runtime
|
|
67
67
|
prerelease: false
|
|
68
|
-
version_requirements: *
|
|
68
|
+
version_requirements: *19382620
|
|
69
69
|
- !ruby/object:Gem::Dependency
|
|
70
70
|
name: spreadsheet
|
|
71
|
-
requirement: &
|
|
71
|
+
requirement: &19255580 !ruby/object:Gem::Requirement
|
|
72
72
|
none: false
|
|
73
73
|
requirements:
|
|
74
74
|
- - ! '>='
|
|
@@ -76,10 +76,10 @@ dependencies:
|
|
|
76
76
|
version: '0'
|
|
77
77
|
type: :runtime
|
|
78
78
|
prerelease: false
|
|
79
|
-
version_requirements: *
|
|
79
|
+
version_requirements: *19255580
|
|
80
80
|
- !ruby/object:Gem::Dependency
|
|
81
81
|
name: rspec
|
|
82
|
-
requirement: &
|
|
82
|
+
requirement: &19254720 !ruby/object:Gem::Requirement
|
|
83
83
|
none: false
|
|
84
84
|
requirements:
|
|
85
85
|
- - ! '>='
|
|
@@ -87,10 +87,10 @@ dependencies:
|
|
|
87
87
|
version: '0'
|
|
88
88
|
type: :development
|
|
89
89
|
prerelease: false
|
|
90
|
-
version_requirements: *
|
|
90
|
+
version_requirements: *19254720
|
|
91
91
|
- !ruby/object:Gem::Dependency
|
|
92
92
|
name: webmock
|
|
93
|
-
requirement: &
|
|
93
|
+
requirement: &19253480 !ruby/object:Gem::Requirement
|
|
94
94
|
none: false
|
|
95
95
|
requirements:
|
|
96
96
|
- - ! '>='
|
|
@@ -98,10 +98,10 @@ dependencies:
|
|
|
98
98
|
version: '0'
|
|
99
99
|
type: :development
|
|
100
100
|
prerelease: false
|
|
101
|
-
version_requirements: *
|
|
101
|
+
version_requirements: *19253480
|
|
102
102
|
- !ruby/object:Gem::Dependency
|
|
103
103
|
name: ZenTest
|
|
104
|
-
requirement: &
|
|
104
|
+
requirement: &19252640 !ruby/object:Gem::Requirement
|
|
105
105
|
none: false
|
|
106
106
|
requirements:
|
|
107
107
|
- - ! '>='
|
|
@@ -109,10 +109,10 @@ dependencies:
|
|
|
109
109
|
version: '0'
|
|
110
110
|
type: :development
|
|
111
111
|
prerelease: false
|
|
112
|
-
version_requirements: *
|
|
112
|
+
version_requirements: *19252640
|
|
113
113
|
- !ruby/object:Gem::Dependency
|
|
114
114
|
name: hoe
|
|
115
|
-
requirement: &
|
|
115
|
+
requirement: &19251860 !ruby/object:Gem::Requirement
|
|
116
116
|
none: false
|
|
117
117
|
requirements:
|
|
118
118
|
- - ! '>='
|
|
@@ -120,10 +120,10 @@ dependencies:
|
|
|
120
120
|
version: '3.4'
|
|
121
121
|
type: :development
|
|
122
122
|
prerelease: false
|
|
123
|
-
version_requirements: *
|
|
123
|
+
version_requirements: *19251860
|
|
124
124
|
- !ruby/object:Gem::Dependency
|
|
125
125
|
name: rdoc
|
|
126
|
-
requirement: &
|
|
126
|
+
requirement: &19250720 !ruby/object:Gem::Requirement
|
|
127
127
|
none: false
|
|
128
128
|
requirements:
|
|
129
129
|
- - ! '>='
|
|
@@ -131,10 +131,10 @@ dependencies:
|
|
|
131
131
|
version: '0'
|
|
132
132
|
type: :development
|
|
133
133
|
prerelease: false
|
|
134
|
-
version_requirements: *
|
|
134
|
+
version_requirements: *19250720
|
|
135
135
|
- !ruby/object:Gem::Dependency
|
|
136
136
|
name: rdoc
|
|
137
|
-
requirement: &
|
|
137
|
+
requirement: &19247520 !ruby/object:Gem::Requirement
|
|
138
138
|
none: false
|
|
139
139
|
requirements:
|
|
140
140
|
- - ~>
|
|
@@ -142,10 +142,10 @@ dependencies:
|
|
|
142
142
|
version: '3.10'
|
|
143
143
|
type: :development
|
|
144
144
|
prerelease: false
|
|
145
|
-
version_requirements: *
|
|
145
|
+
version_requirements: *19247520
|
|
146
146
|
- !ruby/object:Gem::Dependency
|
|
147
147
|
name: hoe
|
|
148
|
-
requirement: &
|
|
148
|
+
requirement: &19246620 !ruby/object:Gem::Requirement
|
|
149
149
|
none: false
|
|
150
150
|
requirements:
|
|
151
151
|
- - ~>
|
|
@@ -153,7 +153,7 @@ dependencies:
|
|
|
153
153
|
version: '2.13'
|
|
154
154
|
type: :development
|
|
155
155
|
prerelease: false
|
|
156
|
-
version_requirements: *
|
|
156
|
+
version_requirements: *19246620
|
|
157
157
|
description: oddb2xml creates xml files using swissINDEX, BAG-XML and Swissmedic.
|
|
158
158
|
email: yasaka@ywesee.com, zdavatz@ywesee.com
|
|
159
159
|
executables:
|
|
@@ -184,15 +184,17 @@ files:
|
|
|
184
184
|
- spec/compressor_spec.rb
|
|
185
185
|
- spec/data/XMLPublications.zip
|
|
186
186
|
- spec/data/epha_interactions.csv
|
|
187
|
+
- spec/data/medregbm_betrieb.txt
|
|
188
|
+
- spec/data/medregbm_person.txt
|
|
187
189
|
- spec/data/oddb2xml_files_bm_update.txt
|
|
188
190
|
- spec/data/oddb2xml_files_lppv.txt
|
|
191
|
+
- spec/data/oddb2xml_files_nonpharma.xls
|
|
189
192
|
- spec/data/oddb_article.xml
|
|
190
193
|
- spec/data/oddb_fi.xml
|
|
191
194
|
- spec/data/oddb_fi_product.xml
|
|
192
195
|
- spec/data/oddb_limitation.xml
|
|
193
196
|
- spec/data/oddb_product.xml
|
|
194
197
|
- spec/data/oddb_substance.xml
|
|
195
|
-
- spec/data/oddb2xml_files_nonpharma.xls
|
|
196
198
|
- spec/data/swissindex.xml
|
|
197
199
|
- spec/data/swissindex_nonpharma.xml
|
|
198
200
|
- spec/data/swissindex_pharma.xml
|