oddb2xml 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -12
- data/History.txt +8 -0
- data/Manifest.txt +5 -0
- data/lib/oddb2xml/builder.rb +220 -36
- data/lib/oddb2xml/cli.rb +39 -18
- data/lib/oddb2xml/downloader.rb +76 -41
- data/lib/oddb2xml/extractor.rb +24 -0
- data/lib/oddb2xml/version.rb +1 -1
- data/oddb2xml.gemspec +30 -0
- data/spec/cli_spec.rb +67 -4
- data/spec/compressor_spec.rb +2 -0
- data/spec/data/epha_interactions.csv +3 -0
- data/spec/data/oddb_fi.xml +0 -0
- data/spec/data/oddb_fi_product.xml +0 -0
- data/spec/data/swissmedic_info.html +3 -1
- data/spec/data/swissmedic_info.zip +0 -0
- data/spec/data/swissmedic_info_2.html +13 -0
- data/spec/downloader_spec.rb +79 -25
- data/spec/spec_helper.rb +39 -10
- metadata +11 -6
data/Gemfile
CHANGED
data/History.txt
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
=== 1.1.3 / 09.01.2013
|
2
|
+
|
3
|
+
* Add interaction.xml and code.xml output
|
4
|
+
* Update to check option fi
|
5
|
+
* Improve using of memory at file reading for mswin
|
6
|
+
* Add oddb_fi_product.xml output to fi option
|
7
|
+
* Restore Gemfile to use gemspec file
|
8
|
+
|
1
9
|
=== 1.1.2 / 08.01.2013
|
2
10
|
|
3
11
|
* Update Gemfile for development
|
data/Manifest.txt
CHANGED
@@ -14,11 +14,15 @@ lib/oddb2xml/compressor.rb
|
|
14
14
|
lib/oddb2xml/downloader.rb
|
15
15
|
lib/oddb2xml/extractor.rb
|
16
16
|
lib/oddb2xml/version.rb
|
17
|
+
oddb2xml.gemspec
|
17
18
|
spec/builder_spec.rb
|
18
19
|
spec/cli_spec.rb
|
19
20
|
spec/compressor_spec.rb
|
20
21
|
spec/data/XMLPublications.zip
|
22
|
+
spec/data/epha_interactions.csv
|
21
23
|
spec/data/oddb_article.xml
|
24
|
+
spec/data/oddb_fi.xml
|
25
|
+
spec/data/oddb_fi_product.xml
|
22
26
|
spec/data/oddb_limitation.xml
|
23
27
|
spec/data/oddb_product.xml
|
24
28
|
spec/data/oddb_substance.xml
|
@@ -29,6 +33,7 @@ spec/data/swissmedic_fridges.html
|
|
29
33
|
spec/data/swissmedic_fridges.xls
|
30
34
|
spec/data/swissmedic_info.html
|
31
35
|
spec/data/swissmedic_info.zip
|
36
|
+
spec/data/swissmedic_info_2.html
|
32
37
|
spec/data/swissmedic_orphans.html
|
33
38
|
spec/data/swissmedic_orphans.xls
|
34
39
|
spec/data/wsdl.xml
|
data/lib/oddb2xml/builder.rb
CHANGED
@@ -17,14 +17,17 @@ end
|
|
17
17
|
|
18
18
|
module Oddb2xml
|
19
19
|
class Builder
|
20
|
-
attr_accessor :subject, :index, :items,
|
20
|
+
attr_accessor :subject, :index, :items,
|
21
|
+
:actions,
|
21
22
|
:orphans, :fridges,
|
23
|
+
:infos,
|
22
24
|
:tag_suffix
|
23
25
|
def initialize
|
24
26
|
@subject = nil
|
25
27
|
@index = {}
|
26
28
|
@items = {}
|
27
29
|
@infos = {}
|
30
|
+
@actions = []
|
28
31
|
@orphans = []
|
29
32
|
@fridges = []
|
30
33
|
@tag_suffix = nil
|
@@ -40,6 +43,21 @@ module Oddb2xml
|
|
40
43
|
end
|
41
44
|
end
|
42
45
|
private
|
46
|
+
def prepare_articles
|
47
|
+
unless @articles
|
48
|
+
@articles = [] # base is 'DE'
|
49
|
+
@index['DE'].each_pair do |pharmacode, index|
|
50
|
+
object = {
|
51
|
+
:de => index,
|
52
|
+
:fr => @index['FR'][pharmacode],
|
53
|
+
}
|
54
|
+
if seq = @items[pharmacode]
|
55
|
+
object[:seq] = seq
|
56
|
+
end
|
57
|
+
@articles << object
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
43
61
|
def prepare_substances
|
44
62
|
unless @substances
|
45
63
|
@substances = []
|
@@ -64,6 +82,45 @@ module Oddb2xml
|
|
64
82
|
@limitations.sort_by!{|lim| lim[:code] }
|
65
83
|
end
|
66
84
|
end
|
85
|
+
def prepare_interactions
|
86
|
+
unless @interactions
|
87
|
+
@interactions = []
|
88
|
+
@actions.each do |act|
|
89
|
+
@interactions << act
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
def prepare_codes
|
94
|
+
unless @codes
|
95
|
+
@codes = {
|
96
|
+
'X' => {:int => 11, :txt => 'Kontraindiziert'},
|
97
|
+
'E' => {:int => 12, :txt => 'Kontraindiziert'},
|
98
|
+
'D' => {:int => 13, :txt => 'Kombination meiden'},
|
99
|
+
'C' => {:int => 14, :txt => 'Monitorisieren'},
|
100
|
+
'B' => {:int => 15, :txt => 'Vorsichtsmassnahmen'},
|
101
|
+
'A' => {:int => 16, :txt => 'keine Massnahmen'}
|
102
|
+
}
|
103
|
+
end
|
104
|
+
end
|
105
|
+
def prepare_products
|
106
|
+
unless @products
|
107
|
+
# merge company info from swissINDEX
|
108
|
+
@products = []
|
109
|
+
@products = @items.values.uniq.map do |seq|
|
110
|
+
%w[de fr].each do |lang|
|
111
|
+
name_key = "company_name_#{lang}".intern
|
112
|
+
seq[name_key] = ''
|
113
|
+
if pharmacode = seq[:pharmacodes].first
|
114
|
+
indices = @index[lang.upcase]
|
115
|
+
if index = indices[pharmacode]
|
116
|
+
seq[name_key] = index[:company_name]
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
seq
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
67
124
|
def build_substance
|
68
125
|
prepare_substances
|
69
126
|
_builder = Nokogiri::XML::Builder.new(:encoding => 'utf-8') do |xml|
|
@@ -133,23 +190,109 @@ module Oddb2xml
|
|
133
190
|
end
|
134
191
|
_builder.to_xml
|
135
192
|
end
|
136
|
-
def
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
193
|
+
def build_interaction
|
194
|
+
prepare_interactions
|
195
|
+
prepare_codes
|
196
|
+
_builder = Nokogiri::XML::Builder.new(:encoding => 'utf-8') do |xml|
|
197
|
+
xml.doc.tag_suffix = @tag_suffix
|
198
|
+
datetime = Time.new.strftime('%FT%T.%7N%z')
|
199
|
+
xml.INTERACTION(
|
200
|
+
'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema',
|
201
|
+
'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
|
202
|
+
'xmlns' => 'http://wiki.oddb.org/wiki.php?pagename=Swissmedic.Datendeklaration',
|
203
|
+
'CREATION_DATETIME' => datetime,
|
204
|
+
'PROD_DATE' => datetime,
|
205
|
+
'VALID_DATE' => datetime,
|
206
|
+
) {
|
207
|
+
@interactions.sort_by{|ix| ix[:ixno] }.each do |ix|
|
208
|
+
xml.IX('DT' => '') {
|
209
|
+
xml.IXNO ix[:ixno]
|
210
|
+
#xml.TITD
|
211
|
+
#xml.TITF
|
212
|
+
xml.GRP1D ix[:atc1]
|
213
|
+
#xml.GRP1F
|
214
|
+
xml.GRP2D ix[:atc2]
|
215
|
+
#xml.GRP2F
|
216
|
+
xml.EFFD ix[:effect]
|
217
|
+
#xml.EFFF
|
218
|
+
if dict = @codes[ix[:grad].upcase]
|
219
|
+
xml.RLV dict[:int]
|
220
|
+
xml.RLVD dict[:txt]
|
221
|
+
#xml.RLVF
|
222
|
+
end
|
223
|
+
#xml.EFFTXTD
|
224
|
+
#xml.EFFTXTF
|
225
|
+
xml.MECHD ix[:mechanism]
|
226
|
+
#xml.MECHF
|
227
|
+
xml.MEASD ix[:measures]
|
228
|
+
#xml.MEASF
|
229
|
+
#xml.REMD
|
230
|
+
#xml.REMF
|
231
|
+
#xml.LIT
|
232
|
+
xml.DEL false
|
233
|
+
#xml.IXMCH {
|
234
|
+
# xml.TYP
|
235
|
+
# xml.TYPD
|
236
|
+
# xml.TYPF
|
237
|
+
# xml.CD
|
238
|
+
# xml.CDD
|
239
|
+
# xml.CDF
|
240
|
+
# xml.TXTD
|
241
|
+
# xml.TXTF
|
242
|
+
#}
|
243
|
+
}
|
149
244
|
end
|
150
|
-
|
151
|
-
|
245
|
+
xml.RESULT {
|
246
|
+
xml.OK_ERROR 'OK'
|
247
|
+
xml.NBR_RECORD @interactions.length.to_s
|
248
|
+
xml.ERROR_CODE ''
|
249
|
+
xml.MESSAGE ''
|
250
|
+
}
|
251
|
+
}
|
152
252
|
end
|
253
|
+
_builder.to_xml
|
254
|
+
end
|
255
|
+
def build_code
|
256
|
+
prepare_codes
|
257
|
+
_builder = Nokogiri::XML::Builder.new(:encoding => 'utf-8') do |xml|
|
258
|
+
xml.doc.tag_suffix = @tag_suffix
|
259
|
+
datetime = Time.new.strftime('%FT%T.%7N%z')
|
260
|
+
xml.CODE(
|
261
|
+
'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema',
|
262
|
+
'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
|
263
|
+
'xmlns' => 'http://wiki.oddb.org/wiki.php?pagename=Swissmedic.Datendeklaration',
|
264
|
+
'CREATION_DATETIME' => datetime,
|
265
|
+
'PROD_DATE' => datetime,
|
266
|
+
'VALID_DATE' => datetime,
|
267
|
+
) {
|
268
|
+
@codes.each_pair do |val, definition|
|
269
|
+
xml.CD('DT' => '') {
|
270
|
+
xml.CDTYP definition[:int]
|
271
|
+
xml.CDVAL val
|
272
|
+
xml.DSCRSD definition[:txt]
|
273
|
+
#xml.DSCRSF
|
274
|
+
#xml.DSCRMD
|
275
|
+
#xml.DSCRMF
|
276
|
+
#xml.DSCRD
|
277
|
+
#xml.DSCRF
|
278
|
+
xml.DEL false
|
279
|
+
}
|
280
|
+
end
|
281
|
+
xml.RESULT {
|
282
|
+
xml.OK_ERROR 'OK'
|
283
|
+
xml.NBR_RECORD @codes.keys.length
|
284
|
+
xml.ERROR_CODE ''
|
285
|
+
xml.MESSAGE ''
|
286
|
+
}
|
287
|
+
}
|
288
|
+
end
|
289
|
+
_builder.to_xml
|
290
|
+
end
|
291
|
+
def build_product
|
292
|
+
prepare_substances
|
293
|
+
prepare_products
|
294
|
+
prepare_interactions
|
295
|
+
prepare_codes
|
153
296
|
_builder = Nokogiri::XML::Builder.new(:encoding => 'utf-8') do |xml|
|
154
297
|
xml.doc.tag_suffix = @tag_suffix
|
155
298
|
datetime = Time.new.strftime('%FT%T.%7N%z')
|
@@ -161,7 +304,7 @@ module Oddb2xml
|
|
161
304
|
'PROD_DATE' => datetime,
|
162
305
|
'VALID_DATE' => datetime,
|
163
306
|
) {
|
164
|
-
|
307
|
+
@products.each do |seq|
|
165
308
|
xml.PRD('DT' => '') {
|
166
309
|
xml.PRDNO seq[:product_key] unless seq[:product_key].empty?
|
167
310
|
%w[de fr].each do |l|
|
@@ -245,11 +388,15 @@ module Oddb2xml
|
|
245
388
|
#xml.WHK
|
246
389
|
}
|
247
390
|
end
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
391
|
+
@interactions.each do |ix|
|
392
|
+
if [ix[:act1], ix[:act2]].include?(seq[:atc_code])
|
393
|
+
xml.CPTIX {
|
394
|
+
xml.IXNO ix[:ixno]
|
395
|
+
#xml.GRP
|
396
|
+
xml.RLV @codes[ix[:grad]]
|
397
|
+
}
|
398
|
+
end
|
399
|
+
end
|
253
400
|
#xml.CPTROA {
|
254
401
|
#xml.SYSLOC
|
255
402
|
#xml.ROA
|
@@ -266,7 +413,7 @@ module Oddb2xml
|
|
266
413
|
end
|
267
414
|
xml.RESULT {
|
268
415
|
xml.OK_ERROR 'OK'
|
269
|
-
xml.NBR_RECORD
|
416
|
+
xml.NBR_RECORD @products.length.to_s
|
270
417
|
xml.ERROR_CODE ''
|
271
418
|
xml.MESSAGE ''
|
272
419
|
}
|
@@ -276,17 +423,7 @@ module Oddb2xml
|
|
276
423
|
end
|
277
424
|
def build_article
|
278
425
|
prepare_limitations
|
279
|
-
|
280
|
-
@index['DE'].each_pair do |pharmacode, index|
|
281
|
-
object = {
|
282
|
-
:de => index,
|
283
|
-
:fr => @index['FR'][pharmacode],
|
284
|
-
}
|
285
|
-
if seq = @items[pharmacode]
|
286
|
-
object[:seq] = seq
|
287
|
-
end
|
288
|
-
objects << object
|
289
|
-
end
|
426
|
+
prepare_articles
|
290
427
|
_builder = Nokogiri::XML::Builder.new(:encoding => 'utf-8') do |xml|
|
291
428
|
xml.doc.tag_suffix = @tag_suffix
|
292
429
|
datetime = Time.new.strftime('%FT%T.%7N%z')
|
@@ -298,7 +435,7 @@ module Oddb2xml
|
|
298
435
|
'PROD_DATE' => datetime,
|
299
436
|
'VALID_DATE' => datetime,
|
300
437
|
) {
|
301
|
-
|
438
|
+
@articles.each do |obj|
|
302
439
|
de_pac = obj[:de] # swiss index DE (base)
|
303
440
|
fr_pac = obj[:fr] # swiss index FR
|
304
441
|
bg_pac = nil # BAG XML (additional data)
|
@@ -440,7 +577,7 @@ module Oddb2xml
|
|
440
577
|
end
|
441
578
|
xml.RESULT {
|
442
579
|
xml.OK_ERROR 'OK'
|
443
|
-
xml.NBR_RECORD
|
580
|
+
xml.NBR_RECORD @articles.length.to_s
|
444
581
|
xml.ERROR_CODE ''
|
445
582
|
xml.MESSAGE ''
|
446
583
|
}
|
@@ -490,5 +627,52 @@ module Oddb2xml
|
|
490
627
|
end
|
491
628
|
_builder.to_xml
|
492
629
|
end
|
630
|
+
def build_fi_product
|
631
|
+
prepare_products
|
632
|
+
_builder = Nokogiri::XML::Builder.new(:encoding => 'utf-8') do |xml|
|
633
|
+
xml.doc.tag_suffix = @tag_suffix
|
634
|
+
datetime = Time.new.strftime('%FT%T.%7N%z')
|
635
|
+
xml.KOMPENDIUM_PRODUCT(
|
636
|
+
'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema',
|
637
|
+
'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
|
638
|
+
'xmlns' => 'http://wiki.oddb.org/wiki.php?pagename=Swissmedic.Datendeklaration',
|
639
|
+
'CREATION_DATETIME' => datetime,
|
640
|
+
'PROD_DATE' => datetime,
|
641
|
+
'VALID_DATE' => datetime,
|
642
|
+
) {
|
643
|
+
length = 0
|
644
|
+
%w[de fr].each do |lang|
|
645
|
+
info_index = {}
|
646
|
+
@infos[lang].each_with_index do |info, i|
|
647
|
+
info_index[info[:monid]] = i
|
648
|
+
end
|
649
|
+
# prod
|
650
|
+
@products.each do |seq|
|
651
|
+
seq[:packages].values.each do |pac|
|
652
|
+
if pac[:swissmedic_number] =~ /(\d{5})(\d{3})/
|
653
|
+
number = $1.to_s
|
654
|
+
if i = info_index[number]
|
655
|
+
length += 1
|
656
|
+
xml.KP('DT' => '') {
|
657
|
+
xml.MONID @infos[lang][i][:monid]
|
658
|
+
xml.PRDNO seq[:product_key] unless seq[:product_key].empty?
|
659
|
+
# as orphans ?
|
660
|
+
xml.DEL @orphans.include?(number) ? true : false
|
661
|
+
}
|
662
|
+
end
|
663
|
+
end
|
664
|
+
end
|
665
|
+
end
|
666
|
+
end
|
667
|
+
xml.RESULT {
|
668
|
+
xml.OK_ERROR 'OK'
|
669
|
+
xml.NBR_RECORD length
|
670
|
+
xml.ERROR_CODE ''
|
671
|
+
xml.MESSAGE ''
|
672
|
+
}
|
673
|
+
}
|
674
|
+
end
|
675
|
+
_builder.to_xml
|
676
|
+
end
|
493
677
|
end
|
494
678
|
end
|
data/lib/oddb2xml/cli.rb
CHANGED
@@ -9,39 +9,51 @@ require 'oddb2xml/compressor'
|
|
9
9
|
module Oddb2xml
|
10
10
|
class Cli
|
11
11
|
SUBJECTS = %w[product article]
|
12
|
-
ADDITIONS = %w[substance limitation]
|
13
|
-
OPTIONALS = %w[fi]
|
12
|
+
ADDITIONS = %w[substance limitation interaction code]
|
13
|
+
OPTIONALS = %w[fi fi_product]
|
14
14
|
LANGUAGES = %w[DE FR] # EN does not exist
|
15
15
|
def initialize(args)
|
16
16
|
@options = args
|
17
17
|
@mutex = Mutex.new
|
18
18
|
@items = {} # Items from Preparations.xml in BAG
|
19
19
|
@index = {} # Base index from swissINDEX
|
20
|
-
@infos = {} # FI from SwissmedicInfo
|
21
|
-
@
|
22
|
-
@
|
20
|
+
@infos = {} # [option] FI from SwissmedicInfo
|
21
|
+
@actions = [] # [addition] interactions from epha
|
22
|
+
@orphans = [] # [addition] Orphaned drugs from Swissmedic xls
|
23
|
+
@fridges = [] # [addition] ReFridge drugs from Swissmedic xls
|
23
24
|
LANGUAGES.each do |lang|
|
24
25
|
@index[lang] = {}
|
25
26
|
end
|
26
27
|
end
|
27
28
|
def run
|
28
29
|
threads = []
|
29
|
-
# swissmedic
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
30
|
+
# swissmedic-info
|
31
|
+
if @options[:fi]
|
32
|
+
threads << Thread.new do
|
33
|
+
downloader = SwissmedicInfoDownloader.new
|
34
|
+
xml = downloader.download
|
35
|
+
@mutex.synchronize do
|
36
|
+
hsh = SwissmedicInfoExtractor.new(xml).to_hash
|
37
|
+
@infos = hsh
|
38
|
+
end
|
36
39
|
end
|
37
40
|
end
|
41
|
+
# swissmedic
|
38
42
|
[:orphans, :fridges].each do |type|
|
39
43
|
threads << Thread.new do
|
40
|
-
downloader = SwissmedicDownloader.new
|
41
|
-
io = downloader.
|
44
|
+
downloader = SwissmedicDownloader.new(type)
|
45
|
+
io = downloader.download
|
42
46
|
self.instance_variable_set("@#{type.to_s}", SwissmedicExtractor.new(io, type).to_arry)
|
43
47
|
end
|
44
48
|
end
|
49
|
+
# epha
|
50
|
+
threads << Thread.new do
|
51
|
+
downloader = EphaDownloader.new
|
52
|
+
io = downloader.download
|
53
|
+
@mutex.synchronize do
|
54
|
+
@actions = EphaExtractor.new(io).to_hash
|
55
|
+
end
|
56
|
+
end
|
45
57
|
# bag
|
46
58
|
threads << Thread.new do
|
47
59
|
downloader = BagXmlDownloader.new
|
@@ -55,8 +67,8 @@ module Oddb2xml
|
|
55
67
|
# swissindex
|
56
68
|
types.each do |type|
|
57
69
|
threads << Thread.new do
|
58
|
-
downloader = SwissIndexDownloader.new(type)
|
59
|
-
xml = downloader.
|
70
|
+
downloader = SwissIndexDownloader.new(type, lang)
|
71
|
+
xml = downloader.download
|
60
72
|
@mutex.synchronize do
|
61
73
|
hsh = SwissIndexExtractor.new(xml, type).to_hash
|
62
74
|
@index[lang][type] = hsh
|
@@ -85,8 +97,12 @@ module Oddb2xml
|
|
85
97
|
builder.index = index
|
86
98
|
builder.items = @items
|
87
99
|
# additions
|
88
|
-
|
89
|
-
|
100
|
+
%w[actions orphans fridges].each do |addition|
|
101
|
+
builder.send("#{addition}=".intern, self.instance_variable_get("@#{addition}"))
|
102
|
+
end
|
103
|
+
#builder.actions = @actions
|
104
|
+
#builder.orphans = @orphans
|
105
|
+
#builder.fridges = @fridges
|
90
106
|
# optionals
|
91
107
|
builder.infos = @infos
|
92
108
|
builder.tag_suffix = @options[:tag_suffix]
|
@@ -115,6 +131,11 @@ module Oddb2xml
|
|
115
131
|
def files
|
116
132
|
unless @_files
|
117
133
|
@_files = {}
|
134
|
+
##
|
135
|
+
# building order
|
136
|
+
# 1. addtions
|
137
|
+
# 2. subjects
|
138
|
+
# 3. optionals
|
118
139
|
_files = (ADDITIONS + SUBJECTS)
|
119
140
|
_files += OPTIONALS if @options[:fi]
|
120
141
|
_files.each do|sbj|
|
data/lib/oddb2xml/downloader.rb
CHANGED
@@ -13,7 +13,11 @@ module Oddb2xml
|
|
13
13
|
init
|
14
14
|
end
|
15
15
|
def init
|
16
|
-
|
16
|
+
@agent = Mechanize.new
|
17
|
+
@agent.user_agent = 'Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20100101 Firefox/16.0'
|
18
|
+
@agent.redirect_ok = true
|
19
|
+
@agent.redirection_limit = 5
|
20
|
+
@agent.follow_meta_refresh = true
|
17
21
|
end
|
18
22
|
protected
|
19
23
|
def retrievable?
|
@@ -25,23 +29,39 @@ module Oddb2xml
|
|
25
29
|
false
|
26
30
|
end
|
27
31
|
end
|
32
|
+
def read_xml_form_zip(target, zipfile)
|
33
|
+
xml = ''
|
34
|
+
if RUBY_PLATFORM =~ /mswin/i # for memory error
|
35
|
+
Zip::ZipFile.foreach(zipfile) do |entry|
|
36
|
+
if entry.name =~ target
|
37
|
+
entry.get_input_stream do |io|
|
38
|
+
while line = io.gets
|
39
|
+
xml << line
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
else
|
45
|
+
Zip::ZipFile.foreach(zipfile) do |entry|
|
46
|
+
if entry.name =~ target
|
47
|
+
entry.get_input_stream { |io| xml = io.read }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
xml
|
52
|
+
end
|
28
53
|
end
|
29
54
|
class BagXmlDownloader < Downloader
|
30
55
|
def init
|
56
|
+
super
|
31
57
|
@url ||= 'http://bag.e-mediat.net/SL2007.Web.External/File.axd?file=XMLPublications.zip'
|
32
58
|
end
|
33
59
|
def download
|
34
60
|
file = 'XMLPublications.zip'
|
35
61
|
begin
|
36
|
-
response =
|
62
|
+
response = @agent.get(@url)
|
37
63
|
response.save_as file
|
38
|
-
|
39
|
-
Zip::ZipFile.foreach(file) do |entry|
|
40
|
-
if entry.name =~ /^Preparation/iu
|
41
|
-
entry.get_input_stream{ |io| xml = io.read }
|
42
|
-
end
|
43
|
-
end
|
44
|
-
return xml
|
64
|
+
return read_xml_form_zip(/^Preparation/iu, file)
|
45
65
|
rescue Timeout::Error
|
46
66
|
retrievable? ? retry : raise
|
47
67
|
ensure
|
@@ -52,33 +72,33 @@ module Oddb2xml
|
|
52
72
|
end
|
53
73
|
end
|
54
74
|
class SwissIndexDownloader < Downloader
|
55
|
-
def initialize(type=:pharma)
|
75
|
+
def initialize(type=:pharma, lang='DE')
|
56
76
|
@type = (type == :pharma ? 'Pharma' : 'NonPharma')
|
77
|
+
@lang = lang
|
57
78
|
url = "https://index.ws.e-mediat.net/Swissindex/#{@type}/ws_#{@type}_V101.asmx?WSDL"
|
58
79
|
super(url)
|
59
80
|
end
|
60
81
|
def init
|
61
|
-
|
82
|
+
config = {
|
62
83
|
:log_level => :info,
|
63
84
|
:log => false, # $stdout
|
64
85
|
:raise_errors => true,
|
65
86
|
:ssl_verify_mode => :none,
|
66
87
|
:wsdl => @url
|
67
88
|
}
|
89
|
+
@client = Savon::Client.new(config)
|
68
90
|
end
|
69
|
-
def
|
70
|
-
client = Savon::Client.new(@config)
|
91
|
+
def download
|
71
92
|
begin
|
72
|
-
type = @type
|
73
93
|
soap = <<XML
|
74
94
|
<?xml version="1.0" encoding="utf-8"?>
|
75
95
|
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
|
76
96
|
<soap:Body>
|
77
|
-
<lang xmlns="http://swissindex.e-mediat.net/Swissindex#{type}_out_V101">#{lang}</lang>
|
97
|
+
<lang xmlns="http://swissindex.e-mediat.net/Swissindex#{@type}_out_V101">#{@lang}</lang>
|
78
98
|
</soap:Body>
|
79
99
|
</soap:Envelope>
|
80
100
|
XML
|
81
|
-
response = client.call(:download_all, :xml => soap)
|
101
|
+
response = @client.call(:download_all, :xml => soap)
|
82
102
|
if response.success?
|
83
103
|
if xml = response.to_xml
|
84
104
|
return xml
|
@@ -95,25 +115,26 @@ XML
|
|
95
115
|
end
|
96
116
|
end
|
97
117
|
class SwissmedicDownloader < Downloader
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
def download_by(index=:orphans)
|
102
|
-
case index
|
118
|
+
def initialize(type=:orphans)
|
119
|
+
@type = type
|
120
|
+
case @type
|
103
121
|
when :orphans
|
104
|
-
|
105
|
-
xpath =
|
122
|
+
action = "daten/00081/index.html?lang=de"
|
123
|
+
@xpath = "//div[@id='sprungmarke0_4']//a[@title='Humanarzneimittel']"
|
106
124
|
when :fridges
|
107
|
-
|
108
|
-
xpath =
|
125
|
+
action = "daten/00080/00254/index.html?lang=de"
|
126
|
+
@xpath = "//table[@class='swmTableFlex']//a[@title='B3.1.35-d.xls']"
|
109
127
|
end
|
110
|
-
|
128
|
+
url = "http://www.swissmedic.ch/#{action}"
|
129
|
+
super(url)
|
130
|
+
end
|
131
|
+
def download
|
132
|
+
file = "swissmedic_#{@type}.xls"
|
111
133
|
begin
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
response = agent.get(url)
|
134
|
+
page = @agent.get(@url)
|
135
|
+
if link_node = page.search(@xpath).first
|
136
|
+
link = Mechanize::Page::Link.new(link_node, @agent, page)
|
137
|
+
response = link.click
|
117
138
|
response.save_as file
|
118
139
|
end
|
119
140
|
return File.open(file, 'rb')
|
@@ -128,15 +149,15 @@ XML
|
|
128
149
|
end
|
129
150
|
class SwissmedicInfoDownloader < Downloader
|
130
151
|
def init
|
152
|
+
super
|
153
|
+
@agent.ignore_bad_chunking = true
|
131
154
|
@url ||= "http://download.swissmedicinfo.ch/Accept.aspx?ReturnUrl=%2f"
|
132
155
|
end
|
133
156
|
def download
|
134
157
|
file = "swissmedic_info.zip"
|
135
158
|
begin
|
136
159
|
response = nil
|
137
|
-
|
138
|
-
agent.ignore_bad_chunking = true
|
139
|
-
if home = agent.get(@url)
|
160
|
+
if home = @agent.get(@url)
|
140
161
|
form = home.form_with(:id => 'Form1')
|
141
162
|
bttn = form.button_with(:name => 'ctl00$MainContent$btnOK')
|
142
163
|
if page = form.submit(bttn)
|
@@ -148,13 +169,7 @@ XML
|
|
148
169
|
if response
|
149
170
|
response.save_as file
|
150
171
|
end
|
151
|
-
|
152
|
-
Zip::ZipFile.foreach(file) do |entry|
|
153
|
-
if entry.name =~ /^AipsDownload_/iu
|
154
|
-
entry.get_input_stream{ |io| xml = io.read }
|
155
|
-
end
|
156
|
-
end
|
157
|
-
return xml
|
172
|
+
return read_xml_form_zip(/^AipsDownload_/iu, file)
|
158
173
|
rescue Timeout::Error
|
159
174
|
retrievable? ? retry : raise
|
160
175
|
rescue NoMethodError => e
|
@@ -166,4 +181,24 @@ XML
|
|
166
181
|
end
|
167
182
|
end
|
168
183
|
end
|
184
|
+
class EphaDownloader < Downloader
|
185
|
+
def init
|
186
|
+
super
|
187
|
+
@url ||= 'http://community.epha.ch/interactions_de_utf8.csv'
|
188
|
+
end
|
189
|
+
def download
|
190
|
+
file = "epha_interactions.csv"
|
191
|
+
begin
|
192
|
+
response = @agent.get(@url)
|
193
|
+
response.save_as file
|
194
|
+
return File.open(file, 'r')
|
195
|
+
rescue Timeout::Error
|
196
|
+
retrievable? ? retry : raise
|
197
|
+
ensure
|
198
|
+
if File.exists? file
|
199
|
+
File.unlink file
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
169
204
|
end
|
data/lib/oddb2xml/extractor.rb
CHANGED
@@ -200,4 +200,28 @@ module Oddb2xml
|
|
200
200
|
data
|
201
201
|
end
|
202
202
|
end
|
203
|
+
class EphaExtractor < Extractor
|
204
|
+
def initialize(io)
|
205
|
+
@io = io
|
206
|
+
end
|
207
|
+
def to_hash
|
208
|
+
data = []
|
209
|
+
ixno = 0
|
210
|
+
while line = @io.gets
|
211
|
+
next if line =~ /^ATC1;Name1;ATC2;Name2;/
|
212
|
+
row = line.chomp.gsub("\"", '').split(';')
|
213
|
+
ixno += 1
|
214
|
+
action = {}
|
215
|
+
action[:ixno] = ixno
|
216
|
+
action[:atc1] = row[0]
|
217
|
+
action[:atc2] = row[2]
|
218
|
+
action[:mechanism] = row[5]
|
219
|
+
action[:effect] = row[6]
|
220
|
+
action[:measures] = row[7]
|
221
|
+
action[:grad] = row[8]
|
222
|
+
data << action
|
223
|
+
end
|
224
|
+
data
|
225
|
+
end
|
226
|
+
end
|
203
227
|
end
|
data/lib/oddb2xml/version.rb
CHANGED
data/oddb2xml.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'oddb2xml/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "oddb2xml"
|
8
|
+
gem.version = Oddb2xml::VERSION
|
9
|
+
gem.authors = [""]
|
10
|
+
gem.email = [""]
|
11
|
+
gem.description = %q{TODO: Write a gem description}
|
12
|
+
gem.summary = %q{TODO: Write a gem summary}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency 'rubyzip'
|
21
|
+
gem.add_dependency 'archive-tar-minitar'
|
22
|
+
gem.add_dependency 'mechanize'
|
23
|
+
gem.add_dependency 'nokogiri'
|
24
|
+
gem.add_dependency 'savon', '>= 2.0'
|
25
|
+
gem.add_dependency 'spreadsheet'
|
26
|
+
|
27
|
+
gem.add_development_dependency 'rspec'
|
28
|
+
gem.add_development_dependency 'webmock'
|
29
|
+
gem.add_development_dependency 'ZenTest'
|
30
|
+
end
|
data/spec/cli_spec.rb
CHANGED
@@ -32,6 +32,7 @@ describe Oddb2xml::Cli do
|
|
32
32
|
opts = {
|
33
33
|
:compress_ext => 'tar.gz',
|
34
34
|
:nonpharma => false,
|
35
|
+
:fi => false,
|
35
36
|
:tag_suffix => nil,
|
36
37
|
}
|
37
38
|
Oddb2xml::Cli.new(opts)
|
@@ -64,6 +65,7 @@ describe Oddb2xml::Cli do
|
|
64
65
|
opts = {
|
65
66
|
:compress_ext => 'zip',
|
66
67
|
:nonpharma => false,
|
68
|
+
:fi => false,
|
67
69
|
:tag_suffix => nil,
|
68
70
|
}
|
69
71
|
Oddb2xml::Cli.new(opts)
|
@@ -96,6 +98,7 @@ describe Oddb2xml::Cli do
|
|
96
98
|
opts = {
|
97
99
|
:compress_ext => nil,
|
98
100
|
:nonpharma => true,
|
101
|
+
:fi => false,
|
99
102
|
:tag_suffix => nil,
|
100
103
|
}
|
101
104
|
Oddb2xml::Cli.new(opts)
|
@@ -110,12 +113,20 @@ describe Oddb2xml::Cli do
|
|
110
113
|
Dir.glob('oddb_*.tar.gz').first.should be_nil
|
111
114
|
Dir.glob('oddb_*.zip').first.should be_nil
|
112
115
|
end
|
113
|
-
it 'should create
|
116
|
+
it 'should create xml files' do
|
114
117
|
$stdout.should_receive(:puts).with(/NonPharma/)
|
115
118
|
cli.run
|
119
|
+
expected = [
|
120
|
+
'oddb_product.xml',
|
121
|
+
'oddb_article.xml',
|
122
|
+
'oddb_limitation.xml',
|
123
|
+
'oddb_substance.xml',
|
124
|
+
'oddb_interaction.xml',
|
125
|
+
'oddb_code.xml'
|
126
|
+
].length
|
116
127
|
Dir.glob('oddb_*.xml').each do |file|
|
117
128
|
File.exists?(file).should be_true
|
118
|
-
end
|
129
|
+
end.to_a.length.should equal expected
|
119
130
|
end
|
120
131
|
after(:each) do
|
121
132
|
Dir.glob('oddb_*.xml').each do |file|
|
@@ -128,6 +139,7 @@ describe Oddb2xml::Cli do
|
|
128
139
|
opts = {
|
129
140
|
:compress_ext => nil,
|
130
141
|
:nonpharma => false,
|
142
|
+
:fi => false,
|
131
143
|
:tag_suffix => '_swiss'.upcase,
|
132
144
|
}
|
133
145
|
Oddb2xml::Cli.new(opts)
|
@@ -142,12 +154,20 @@ describe Oddb2xml::Cli do
|
|
142
154
|
Dir.glob('oddb_*.tar.gz').first.should be_nil
|
143
155
|
Dir.glob('oddb_*.zip').first.should be_nil
|
144
156
|
end
|
145
|
-
it 'should create
|
157
|
+
it 'should create xml files with prefix swiss_' do
|
146
158
|
$stdout.should_receive(:puts).with(/Pharma/)
|
147
159
|
cli.run
|
160
|
+
expected = [
|
161
|
+
'swiss_product.xml',
|
162
|
+
'swiss_article.xml',
|
163
|
+
'swiss_limitation.xml',
|
164
|
+
'swiss_substance.xml',
|
165
|
+
'swiss_interaction.xml',
|
166
|
+
'swiss_code.xml'
|
167
|
+
].length
|
148
168
|
Dir.glob('swiss_*.xml').each do |file|
|
149
169
|
File.exists?(file).should be_true
|
150
|
-
end
|
170
|
+
end.to_a.length.should equal expected
|
151
171
|
end
|
152
172
|
after(:each) do
|
153
173
|
Dir.glob('swiss_*.xml').each do |file|
|
@@ -155,4 +175,47 @@ describe Oddb2xml::Cli do
|
|
155
175
|
end
|
156
176
|
end
|
157
177
|
end
|
178
|
+
context 'when -o fi option is given' do
|
179
|
+
let(:cli) do
|
180
|
+
opts = {
|
181
|
+
:compress_ext => nil,
|
182
|
+
:nonpharma => false,
|
183
|
+
:fi => true,
|
184
|
+
:tag_suffix => nil,
|
185
|
+
}
|
186
|
+
Oddb2xml::Cli.new(opts)
|
187
|
+
end
|
188
|
+
it_behaves_like 'any interface'
|
189
|
+
it 'should have nonpharma option' do
|
190
|
+
cli.should have_option(:fi => true)
|
191
|
+
end
|
192
|
+
it 'should not create any compressed file' do
|
193
|
+
$stdout.should_receive(:puts).with(/Pharma/)
|
194
|
+
cli.run
|
195
|
+
Dir.glob('oddb_*.tar.gz').first.should be_nil
|
196
|
+
Dir.glob('oddb_*.zip').first.should be_nil
|
197
|
+
end
|
198
|
+
it 'should create xml files' do
|
199
|
+
$stdout.should_receive(:puts).with(/Pharma/)
|
200
|
+
cli.run
|
201
|
+
expected = [
|
202
|
+
'oddb_fi.xml',
|
203
|
+
'oddb_fi_product.xml',
|
204
|
+
'oddb_product.xml',
|
205
|
+
'oddb_article.xml',
|
206
|
+
'oddb_limitation.xml',
|
207
|
+
'oddb_substance.xml',
|
208
|
+
'oddb_interaction.xml',
|
209
|
+
'oddb_code.xml'
|
210
|
+
].length
|
211
|
+
Dir.glob('oddb_*.xml').each do |file|
|
212
|
+
File.exists?(file).should be_true
|
213
|
+
end.to_a.length.should equal expected
|
214
|
+
end
|
215
|
+
after(:each) do
|
216
|
+
Dir.glob('oddb_*.xml').each do |file|
|
217
|
+
File.unlink(file) if File.exists?(file)
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
158
221
|
end
|
data/spec/compressor_spec.rb
CHANGED
@@ -9,6 +9,8 @@ shared_examples_for 'any compressor' do
|
|
9
9
|
@compressor.contents << File.expand_path('../data/oddb_product.xml', __FILE__)
|
10
10
|
@compressor.contents << File.expand_path('../data/oddb_substance.xml', __FILE__)
|
11
11
|
@compressor.contents << File.expand_path('../data/oddb_limitation.xml', __FILE__)
|
12
|
+
@compressor.contents << File.expand_path('../data/oddb_fi.xml', __FILE__)
|
13
|
+
@compressor.contents << File.expand_path('../data/oddb_fi_product.xml', __FILE__)
|
12
14
|
@compressor.finalize!.should == true
|
13
15
|
compress_file = @compressor.instance_variable_get(:@compress_file)
|
14
16
|
File.exists?(compress_file).should == true
|
@@ -0,0 +1,3 @@
|
|
1
|
+
ATC1;Name1;ATC2;Name2;Info;Mechanismus;Effekt;Massnahmen;Grad
|
2
|
+
"N06AB06";"Sertralin";"M03BX02";"Tizanidin";"Keine Interaktion";"Tizanidin wird über CYP1A2 metabolisiert. Sertralin beeinflusst CYP1A2 jedoch nicht.";"Keine Interaktion.";"Die Kombination aus Sertralin und Tizanidin hat kein bekanntes Interaktionspotential.";"A"
|
3
|
+
"J05AE08";"Atazanavir";"C10AA05";"Atorvastatin";"Erhöhtes Risiko für Myopathie und Rhabdomyolyse";"Atazanavir hemmt CYP3A4 und darüber auch den Abbau von Atorvastatin, was zu erhöhten Plasmakonzentrationen von Atorvastatin führt..";"Aufgrund der Inhibition von CYP3A4 durch Atazanavir kann die Atorvastatinkonzentration im Plasma ansteigen, was mit einem erhöhten Risiko für Myopathie und Rhabdomyolyse einhergeht.";"Kombination nach Möglichkeit meiden und alternativ Statin wählen, welches nicht mit Atazanavir interagiert, wie z.B. Pravastatin. Ist nach Nutzen-Risiko-Abwägung die Kombination aus Atorvastatin und Atazanavir erforderlich, niedrige Atorvastatindosis (z.B. 10 mg/d) wählen und auf Zeichen der Myopathie und Rhabdomyolyse, wie Muskelschwäche, Muskelschmerzen, verfärbter Urin und CK-Anstieg, achten. Die Kombination aus Atazanavir und Ritonavir mit Atorvastatin ist kontraindiziert.";"D"
|
File without changes
|
File without changes
|
Binary file
|
data/spec/downloader_spec.rb
CHANGED
@@ -21,7 +21,7 @@ describe Oddb2xml::BagXmlDownloader do
|
|
21
21
|
include ServerMockHelper
|
22
22
|
before(:each) do
|
23
23
|
setup_bag_xml_server_mock
|
24
|
-
@downloader = Oddb2xml::BagXmlDownloader.new
|
24
|
+
@downloader = Oddb2xml::BagXmlDownloader.new
|
25
25
|
end
|
26
26
|
it_behaves_like 'any downloader'
|
27
27
|
context 'when download is called' do
|
@@ -47,13 +47,13 @@ describe Oddb2xml::SwissIndexDownloader do
|
|
47
47
|
before(:each) do
|
48
48
|
setup_swiss_index_server_mock
|
49
49
|
end
|
50
|
-
context 'Pharma' do
|
50
|
+
context 'Pharma with DE' do
|
51
51
|
before(:each) do
|
52
|
-
@downloader = Oddb2xml::SwissIndexDownloader.new(:pharma)
|
52
|
+
@downloader = Oddb2xml::SwissIndexDownloader.new(:pharma, 'DE')
|
53
53
|
end
|
54
54
|
it_behaves_like 'any downloader'
|
55
55
|
context 'when download_by is called with DE' do
|
56
|
-
let(:xml) { @downloader.
|
56
|
+
let(:xml) { @downloader.download }
|
57
57
|
it 'should parse response hash to xml' do
|
58
58
|
xml.should be_a String
|
59
59
|
xml.length.should_not == 0
|
@@ -65,13 +65,13 @@ describe Oddb2xml::SwissIndexDownloader do
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
68
|
-
context 'NonPharma' do
|
68
|
+
context 'NonPharma with FR' do
|
69
69
|
before(:each) do
|
70
|
-
@downloader = Oddb2xml::SwissIndexDownloader.new(:nonpharma)
|
70
|
+
@downloader = Oddb2xml::SwissIndexDownloader.new(:nonpharma, 'FR')
|
71
71
|
end
|
72
72
|
it_behaves_like 'any downloader'
|
73
|
-
context 'when download_by is called with
|
74
|
-
let(:xml) { @downloader.
|
73
|
+
context 'when download_by is called with FR' do
|
74
|
+
let(:xml) { @downloader.download }
|
75
75
|
it 'should parse response hash to xml' do
|
76
76
|
xml.should be_a String
|
77
77
|
xml.length.should_not == 0
|
@@ -83,36 +83,90 @@ describe Oddb2xml::SwissIndexDownloader do
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
end
|
86
|
+
end
|
86
87
|
|
87
88
|
describe Oddb2xml::SwissmedicDownloader do
|
89
|
+
include ServerMockHelper
|
90
|
+
context 'orphans' do
|
91
|
+
before(:each) do
|
92
|
+
setup_swissmedic_server_mock
|
93
|
+
@downloader = Oddb2xml::SwissmedicDownloader.new(:orphans)
|
94
|
+
end
|
95
|
+
it_behaves_like 'any downloader'
|
96
|
+
context 'download_by for orphans xls' do
|
97
|
+
let(:io) { @downloader.download }
|
98
|
+
it 'should return valid IO' do
|
99
|
+
io.should be_a IO
|
100
|
+
io.bytes.should_not nil
|
101
|
+
end
|
102
|
+
it 'should clean up current directory' do
|
103
|
+
io.should_not raise_error(Timeout::Error)
|
104
|
+
File.exist?('oddb_orphans.xls').should be(false)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
context 'fridges' do
|
109
|
+
before(:each) do
|
110
|
+
setup_swissmedic_server_mock
|
111
|
+
@downloader = Oddb2xml::SwissmedicDownloader.new(:fridges)
|
112
|
+
end
|
113
|
+
context 'download_by for fridges xls' do
|
114
|
+
let(:io) { @downloader.download }
|
115
|
+
it 'should return valid IO' do
|
116
|
+
io.should be_a IO
|
117
|
+
io.bytes.should_not nil
|
118
|
+
end
|
119
|
+
it 'should clean up current directory' do
|
120
|
+
io.should_not raise_error(Timeout::Error)
|
121
|
+
File.exist?('oddb_fridges.xls').should be(false)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe Oddb2xml::SwissmedicInfoDownloader do
|
88
128
|
include ServerMockHelper
|
89
129
|
before(:each) do
|
90
|
-
|
91
|
-
@downloader = Oddb2xml::
|
130
|
+
setup_swissmedic_info_server_mock
|
131
|
+
@downloader = Oddb2xml::SwissmedicInfoDownloader.new
|
92
132
|
end
|
93
133
|
it_behaves_like 'any downloader'
|
94
|
-
context '
|
95
|
-
let(:
|
96
|
-
it 'should
|
97
|
-
|
98
|
-
|
134
|
+
context 'when download is called' do
|
135
|
+
let(:xml) { @downloader.download }
|
136
|
+
it 'should parse zip to string' do
|
137
|
+
xml.should be_a String
|
138
|
+
xml.length.should_not == 0
|
139
|
+
end
|
140
|
+
it 'should return valid xml' do
|
141
|
+
xml.should =~ /xml\sversion="1.0"/
|
142
|
+
xml.should =~ /medicalInformations/
|
143
|
+
xml.should =~ /content/
|
99
144
|
end
|
100
145
|
it 'should clean up current directory' do
|
101
|
-
|
102
|
-
File.exist?('
|
146
|
+
xml.should_not raise_error(Timeout::Error)
|
147
|
+
File.exist?('swissmedic_info.zip').should be(false)
|
103
148
|
end
|
104
149
|
end
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
150
|
+
end
|
151
|
+
|
152
|
+
describe Oddb2xml::EphaDownloader do
|
153
|
+
include ServerMockHelper
|
154
|
+
before(:each) do
|
155
|
+
setup_epha_server_mock
|
156
|
+
@downloader = Oddb2xml::EphaDownloader.new
|
157
|
+
end
|
158
|
+
it_behaves_like 'any downloader'
|
159
|
+
context 'when download is called' do
|
160
|
+
let(:xml) { @downloader.download }
|
161
|
+
it 'should read csv to IO Object' do
|
162
|
+
xml.should be_a IO
|
163
|
+
xml.bytes.should_not nil
|
110
164
|
end
|
111
165
|
it 'should clean up current directory' do
|
112
|
-
|
113
|
-
File.exist?('
|
166
|
+
xml.should_not raise_error(Timeout::Error)
|
167
|
+
File.exist?('epha_interactions.csv').should be(false)
|
114
168
|
end
|
115
169
|
end
|
116
170
|
end
|
117
171
|
|
118
|
-
|
172
|
+
|
data/spec/spec_helper.rb
CHANGED
@@ -21,6 +21,7 @@ module ServerMockHelper
|
|
21
21
|
setup_swiss_index_server_mock
|
22
22
|
setup_swissmedic_server_mock
|
23
23
|
setup_swissmedic_info_server_mock
|
24
|
+
setup_epha_server_mock
|
24
25
|
end
|
25
26
|
def setup_bag_xml_server_mock
|
26
27
|
# zip
|
@@ -101,28 +102,56 @@ module ServerMockHelper
|
|
101
102
|
stub_html_url = "http://download.swissmedicinfo.ch/Accept.aspx?ReturnUrl=%2f"
|
102
103
|
stub_response = File.read(File.expand_path("../data/swissmedic_info.html", __FILE__))
|
103
104
|
stub_request(:get, stub_html_url).
|
104
|
-
with(
|
105
|
-
|
106
|
-
|
107
|
-
|
105
|
+
with(
|
106
|
+
:headers => {
|
107
|
+
'Accept' => '*/*',
|
108
|
+
'Host' => 'download.swissmedicinfo.ch',
|
109
|
+
}).
|
110
|
+
to_return(
|
111
|
+
:status => 200,
|
112
|
+
:headers => {'Content-Type' => 'text/html; charset=utf-8'},
|
113
|
+
:body => stub_response)
|
114
|
+
# html (dummy 2)
|
115
|
+
stub_html_url = 'http://download.swissmedicinfo.ch/Accept.aspx?ctl00$MainContent$btnOK=1'
|
116
|
+
stub_response = File.read(File.expand_path("../data/swissmedic_info_2.html", __FILE__))
|
117
|
+
stub_request(:get, stub_html_url).
|
118
|
+
with(
|
119
|
+
:headers => {
|
120
|
+
'Accept' => '*/*',
|
121
|
+
'Host' => 'download.swissmedicinfo.ch',
|
122
|
+
}).
|
108
123
|
to_return(
|
109
124
|
:status => 200,
|
110
125
|
:headers => {'Content-Type' => 'text/html; charset=utf-8'},
|
111
126
|
:body => stub_response)
|
112
127
|
# zip
|
113
|
-
stub_zip_url =
|
128
|
+
stub_zip_url = 'http://download.swissmedicinfo.ch/Accept.aspx?ctl00$MainContent$BtnYes=1'
|
114
129
|
stub_response = File.read(File.expand_path('../data/swissmedic_info.zip', __FILE__))
|
115
130
|
stub_request(:get, stub_zip_url).
|
131
|
+
with(
|
132
|
+
:headers => {
|
133
|
+
'Accept' => '*/*',
|
134
|
+
'Accept-Encoding' => 'gzip,deflate,identity',
|
135
|
+
'Host' => 'download.swissmedicinfo.ch',
|
136
|
+
}).
|
137
|
+
to_return(
|
138
|
+
:status => 200,
|
139
|
+
:headers => {'Content-Type' => 'application/zip; charset=utf-8'},
|
140
|
+
:body => stub_response)
|
141
|
+
end
|
142
|
+
def setup_epha_server_mock
|
143
|
+
# csv
|
144
|
+
stub_csv_url = 'http://community.epha.ch/interactions_de_utf8.csv'
|
145
|
+
stub_response = File.read(File.expand_path('../data/epha_interactions.csv', __FILE__))
|
146
|
+
stub_request(:get, stub_csv_url).
|
116
147
|
with(:headers => {
|
117
|
-
'Accept'
|
118
|
-
'
|
119
|
-
'Host' => 'download.swisssmedicinfo.ch',
|
148
|
+
'Accept' => '*/*',
|
149
|
+
'Host' => 'community.epha.ch',
|
120
150
|
}).
|
121
151
|
to_return(
|
122
152
|
:status => 200,
|
123
|
-
:headers => {'Content-Type' => '
|
153
|
+
:headers => {'Content-Type' => 'text/csv; charset=utf-8'},
|
124
154
|
:body => stub_response)
|
125
|
-
|
126
155
|
end
|
127
156
|
end
|
128
157
|
|
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.1.
|
4
|
+
version: 1.1.3
|
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-01-
|
12
|
+
date: 2013-01-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rdoc
|
16
|
-
requirement: &
|
16
|
+
requirement: &19096920 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.10'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *19096920
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: hoe
|
27
|
-
requirement: &
|
27
|
+
requirement: &19112720 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '2.13'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *19112720
|
36
36
|
description: ''
|
37
37
|
email:
|
38
38
|
- yasaka@ywesee.com, zdavatz@ywesee.com
|
@@ -59,11 +59,15 @@ files:
|
|
59
59
|
- lib/oddb2xml/downloader.rb
|
60
60
|
- lib/oddb2xml/extractor.rb
|
61
61
|
- lib/oddb2xml/version.rb
|
62
|
+
- oddb2xml.gemspec
|
62
63
|
- spec/builder_spec.rb
|
63
64
|
- spec/cli_spec.rb
|
64
65
|
- spec/compressor_spec.rb
|
65
66
|
- spec/data/XMLPublications.zip
|
67
|
+
- spec/data/epha_interactions.csv
|
66
68
|
- spec/data/oddb_article.xml
|
69
|
+
- spec/data/oddb_fi.xml
|
70
|
+
- spec/data/oddb_fi_product.xml
|
67
71
|
- spec/data/oddb_limitation.xml
|
68
72
|
- spec/data/oddb_product.xml
|
69
73
|
- spec/data/oddb_substance.xml
|
@@ -74,6 +78,7 @@ files:
|
|
74
78
|
- spec/data/swissmedic_fridges.xls
|
75
79
|
- spec/data/swissmedic_info.html
|
76
80
|
- spec/data/swissmedic_info.zip
|
81
|
+
- spec/data/swissmedic_info_2.html
|
77
82
|
- spec/data/swissmedic_orphans.html
|
78
83
|
- spec/data/swissmedic_orphans.xls
|
79
84
|
- spec/data/wsdl.xml
|