oddb2xml 1.7.9 → 1.8.0
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/Gemfile.lock +1 -1
- data/README.md +7 -0
- data/Rakefile +19 -1
- data/bin/oddb2xml +10 -5
- data/lib/oddb2xml/builder.rb +68 -23
- data/lib/oddb2xml/cli.rb +1 -1
- data/lib/oddb2xml/downloader.rb +2 -0
- data/lib/oddb2xml/util.rb +7 -1
- data/lib/oddb2xml/version.rb +1 -1
- data/spec/builder_spec.rb +88 -12
- data/spec/data/swissindex_pharma.xml +14 -0
- data/spec/data/swissmedic_orphan.xlsx +0 -0
- data/spec/data/zurrose_transfer.dat +1 -0
- data/spec/extractor_spec.rb +2 -2
- data/spec/spec_helper.rb +3 -2
- data/test_options.rb +42 -0
- metadata +5 -4
- data/spec/data/swissmedic_orphans.xls +0 -0
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -74,6 +74,7 @@ $ oddb2xml -t md # => md_article.xml, md_product.xml, md_
|
|
74
74
|
$ oddb2xml -a nonpharma -t md -c tar.gz # => md_xml_dd.mm.yyyy_hh.mm.tar.gz
|
75
75
|
$ oddb2xml -f dat # => oddb.dat
|
76
76
|
$ oddb2xml -f dat -a nonpharma # => oddb_with_migel.dat
|
77
|
+
$ oddb2xml -e # => oddb_article.xml
|
77
78
|
```
|
78
79
|
|
79
80
|
output.
|
@@ -253,3 +254,9 @@ You can also run
|
|
253
254
|
* tools/win_fetch_cacerts.rb
|
254
255
|
|
255
256
|
for your currently open Terminal to download and set the Certificate.
|
257
|
+
|
258
|
+
|
259
|
+
## Testing
|
260
|
+
|
261
|
+
* Calling rake spec runs spec tests.
|
262
|
+
* Calling rake test installs the gems and runs oddb2xml with the most commonly used combinations. All output is placed under under ausgabe/<timestamp>. These files should be manually compared to the ones generated by the last release to check for possible problems.
|
data/Rakefile
CHANGED
@@ -4,10 +4,28 @@ lib = File.expand_path('../lib', __FILE__)
|
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
5
|
require 'oddb2xml/version'
|
6
6
|
require "bundler/gem_tasks"
|
7
|
+
require 'rspec/core/rake_task'
|
8
|
+
|
9
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
10
|
|
8
11
|
# dependencies are now declared in oddb2xml.gemspec
|
9
12
|
|
10
13
|
desc 'Offer a gem task like hoe'
|
11
14
|
task :gem => :build do
|
12
15
|
Rake::Task[:build].invoke
|
13
|
-
end
|
16
|
+
end
|
17
|
+
|
18
|
+
task :spec => :clean
|
19
|
+
|
20
|
+
desc 'Run oddb2xml with all commonly used combinations'
|
21
|
+
task :test => [:clean, :spec, :gem] do
|
22
|
+
system("./test_options.rb 2>&1 | tee test_options.log")
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'rake/clean'
|
26
|
+
CLEAN.include FileList['*.xls*']
|
27
|
+
CLEAN.include FileList['*.xml*']
|
28
|
+
CLEAN.include FileList['*.dat*']
|
29
|
+
CLEAN.include FileList['ruby*.tmp']
|
30
|
+
CLEAN.include FileList['data/download']
|
31
|
+
CLEAN.include FileList['duplicate_ean13_from_zur_rose.txt']
|
data/bin/oddb2xml
CHANGED
@@ -28,8 +28,9 @@ Usage:
|
|
28
28
|
-x N, --context=N context N {product|address}. product is default.
|
29
29
|
|
30
30
|
For debugging purposes
|
31
|
-
--skip-download skips downloading files it the file is already under data/
|
32
|
-
Downloaded files are saved under data/
|
31
|
+
--skip-download skips downloading files it the file is already under data/download.
|
32
|
+
Downloaded files are saved under data/download
|
33
|
+
--log log important actions
|
33
34
|
-h, --help Show this help message.
|
34
35
|
EOS
|
35
36
|
end
|
@@ -46,7 +47,8 @@ opts = {
|
|
46
47
|
:debug => false,
|
47
48
|
:ean14 => false,
|
48
49
|
:skip_download=> false,
|
49
|
-
|
50
|
+
:log => false,
|
51
|
+
}
|
50
52
|
|
51
53
|
parser.on('-a v', '--append v', /^nonpharma$/) {|v| opts[:nonpharma] = true }
|
52
54
|
parser.on('-c v', '--compress v', /^tar\.gz|zip$/){|v| opts[:compress_ext] = v }
|
@@ -60,7 +62,8 @@ parser.on('-i v', '--include v', /^ean14$/) {|v| opts[:ean14] = true }
|
|
60
62
|
parser.on('-t v', '--tag-suffix v', /^[A-z0-9]*$/i) {|v| opts[:tag_suffix] = v.upcase }
|
61
63
|
parser.on('-x v', '--context v', /^addr(ess)*$/i){|v| opts[:address] = true }
|
62
64
|
parser.on('-p v', '--price v', /^zurrose$/) {|v| opts[:price] = v.intern }
|
63
|
-
parser.on('--skip-download')
|
65
|
+
parser.on('--skip-download') {|v| opts[:skip_download] = true }
|
66
|
+
parser.on('--log') {|v| opts[:log] = :true }
|
64
67
|
parser.on_tail('-h', '--help') { puts help; exit }
|
65
68
|
|
66
69
|
args = ARGV.dup
|
@@ -78,6 +81,7 @@ if path = args.first
|
|
78
81
|
opts[:transfer_dat] = path
|
79
82
|
end
|
80
83
|
|
84
|
+
startTime = Time.now
|
81
85
|
ui = Oddb2xml::Cli.new(opts)
|
82
86
|
begin
|
83
87
|
if opts[:format] == :xml
|
@@ -95,4 +99,5 @@ then you will not see anymore warnings
|
|
95
99
|
rescue Interrupt
|
96
100
|
exit
|
97
101
|
end
|
98
|
-
|
102
|
+
diff = (Time.now-startTime).to_i
|
103
|
+
puts "#{Time.now}: #{__LINE__} done. Took #{diff} seconds"; $stdout.sync
|
data/lib/oddb2xml/builder.rb
CHANGED
@@ -44,6 +44,7 @@ module Oddb2xml
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
def to_xml(subject=nil)
|
47
|
+
Oddb2xml.log "to_xml subject #{subject ? subject.to_s : @subject.to_s} for #{self.class}"
|
47
48
|
if subject
|
48
49
|
self.send('build_' + subject.to_s)
|
49
50
|
elsif @subject
|
@@ -51,6 +52,7 @@ module Oddb2xml
|
|
51
52
|
end
|
52
53
|
end
|
53
54
|
def to_dat(subject=nil)
|
55
|
+
Oddb2xml.log "to_dat subject #{subject ? subject.to_s : @subject.to_s} for #{self.class}"
|
54
56
|
if subject
|
55
57
|
self.send('build_' + subject.to_s)
|
56
58
|
elsif @subject
|
@@ -61,6 +63,7 @@ module Oddb2xml
|
|
61
63
|
def prepare_articles(reset=false)
|
62
64
|
@articles = nil if reset
|
63
65
|
unless @articles
|
66
|
+
Oddb2xml.log("prepare_articles starting with #{@articles ? @articles.size : 'no'} articles")
|
64
67
|
@articles = [] # base is 'DE'
|
65
68
|
@index['DE'].each_pair do |phar, indices|
|
66
69
|
obj = {
|
@@ -98,34 +101,59 @@ module Oddb2xml
|
|
98
101
|
end
|
99
102
|
@articles << obj
|
100
103
|
end
|
104
|
+
nrAdded = 0
|
101
105
|
if @options[:extended]
|
102
|
-
|
106
|
+
Oddb2xml.log("prepare_articles prepare_local_index")
|
107
|
+
local_index = {}
|
108
|
+
%w[de fr].each { |lang| local_index[lang] = {} }
|
109
|
+
%w[de fr].each {
|
110
|
+
|lang|
|
111
|
+
@articles.each{|article|
|
112
|
+
ean = article[lang.intern][0][:ean]
|
113
|
+
next if ean == nil or ean.to_i == 0
|
114
|
+
local_index[lang][ean] = article
|
115
|
+
}
|
116
|
+
}
|
117
|
+
Oddb2xml.log("prepare_articles extended")
|
103
118
|
@prices.each{
|
104
119
|
|ean13, info|
|
105
|
-
|
120
|
+
obj = {}
|
121
|
+
found = false
|
106
122
|
%w[de fr].each do |lang|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
123
|
+
# existing = @articles.find{|art| art[lang.intern] and art[lang.intern][0][:ean] == ean13 }
|
124
|
+
existing = local_index[lang][ean13]
|
125
|
+
if existing
|
126
|
+
found = true
|
127
|
+
existing[:price] = info[:price]
|
128
|
+
existing[:pub_price] = info[:pub_price]
|
129
|
+
else
|
130
|
+
entry = {
|
131
|
+
:desc => info[:description],
|
132
|
+
:status => 'I', # or it will not be emitted in the dat
|
133
|
+
:atc_code => '',
|
134
|
+
:ean => ean13,
|
135
|
+
:lang => lang.capitalize,
|
136
|
+
:pharmacode => info[:pharmacode],
|
137
|
+
:price => info[:price],
|
138
|
+
:pub_price => info[:pub_price],
|
139
|
+
:type => info[:type],
|
140
|
+
}
|
141
|
+
obj[lang.intern] = [entry]
|
142
|
+
@index[lang.upcase][ean13] = entry
|
143
|
+
end
|
144
|
+
end
|
145
|
+
unless found
|
146
|
+
@articles << obj
|
147
|
+
nrAdded += 1
|
148
|
+
end
|
149
|
+
}
|
120
150
|
end
|
121
|
-
nrAdded += 1
|
122
|
-
@articles << obj
|
123
|
-
}
|
124
|
-
end
|
125
151
|
end
|
152
|
+
Oddb2xml.log("prepare_articles done. Added #{nrAdded} prices. Total #{@articles.size}")
|
126
153
|
end
|
127
154
|
def prepare_substances
|
128
155
|
unless @substances
|
156
|
+
Oddb2xml.log("prepare_substances from #{@items.size} items")
|
129
157
|
@substances = []
|
130
158
|
@items.values.uniq.each do |seq|
|
131
159
|
next unless seq[:substances]
|
@@ -135,10 +163,13 @@ module Oddb2xml
|
|
135
163
|
end
|
136
164
|
@substances.uniq!
|
137
165
|
@substances.sort!
|
166
|
+
Oddb2xml.log("prepare_substances done. Total #{@substances.size} from #{@items.size} items")
|
167
|
+
exit 2 if @options[:extended] and @substances.size == 0
|
138
168
|
end
|
139
169
|
end
|
140
170
|
def prepare_limitations
|
141
171
|
unless @limitations
|
172
|
+
Oddb2xml.log("prepare_limitations from #{@items.size} items")
|
142
173
|
limitations = []
|
143
174
|
@items.values.uniq.each do |seq|
|
144
175
|
next unless seq[:packages]
|
@@ -150,6 +181,7 @@ module Oddb2xml
|
|
150
181
|
# limitation.xml needs all duplicate entries by this keys.
|
151
182
|
limitations.uniq! {|lim| lim[:id] + lim[:code] + lim[:type] }
|
152
183
|
@limitations = limitations.sort_by {|lim| lim[:code] }
|
184
|
+
Oddb2xml.log("prepare_limitations done. Total #{@limitations.size} from #{@items.size} items")
|
153
185
|
end
|
154
186
|
end
|
155
187
|
def prepare_interactions
|
@@ -231,7 +263,9 @@ module Oddb2xml
|
|
231
263
|
'PROD_DATE' => datetime,
|
232
264
|
'VALID_DATE' => datetime
|
233
265
|
) {
|
234
|
-
@substances.
|
266
|
+
Oddb2xml.log "build_substance #{@substances.size} substances"
|
267
|
+
exit 2 if @options[:extended] and @substances.size == 0
|
268
|
+
@substances.each_with_index do |sub_name, i|
|
235
269
|
xml.SB('DT' => '') {
|
236
270
|
xml.SUBNO((i + 1).to_i)
|
237
271
|
#xml.NAMD
|
@@ -252,6 +286,7 @@ module Oddb2xml
|
|
252
286
|
end
|
253
287
|
def build_limitation
|
254
288
|
prepare_limitations
|
289
|
+
Oddb2xml.log "build_limitation #{@limitations.size} limitations"
|
255
290
|
_builder = Nokogiri::XML::Builder.new(:encoding => 'utf-8') do |xml|
|
256
291
|
xml.doc.tag_suffix = @tag_suffix
|
257
292
|
datetime = Time.new.strftime('%FT%T%z')
|
@@ -263,7 +298,7 @@ module Oddb2xml
|
|
263
298
|
'PROD_DATE' => datetime,
|
264
299
|
'VALID_DATE' => datetime
|
265
300
|
) {
|
266
|
-
|
301
|
+
@limitations.each do |lim|
|
267
302
|
xml.LIM('DT' => '') {
|
268
303
|
case lim[:key]
|
269
304
|
when :swissmedic_number8
|
@@ -310,6 +345,7 @@ module Oddb2xml
|
|
310
345
|
'PROD_DATE' => datetime,
|
311
346
|
'VALID_DATE' => datetime
|
312
347
|
) {
|
348
|
+
Oddb2xml.log "build_interaction #{@interactions.size} interactions"
|
313
349
|
@interactions.sort_by{|ix| ix[:ixno] }.each do |ix|
|
314
350
|
xml.IX('DT' => '') {
|
315
351
|
xml.IXNO ix[:ixno]
|
@@ -360,6 +396,7 @@ module Oddb2xml
|
|
360
396
|
end
|
361
397
|
def build_code
|
362
398
|
prepare_codes
|
399
|
+
Oddb2xml.log "build_code #{@codes.size} codes"
|
363
400
|
_builder = Nokogiri::XML::Builder.new(:encoding => 'utf-8') do |xml|
|
364
401
|
xml.doc.tag_suffix = @tag_suffix
|
365
402
|
datetime = Time.new.strftime('%FT%T%z')
|
@@ -399,6 +436,7 @@ module Oddb2xml
|
|
399
436
|
prepare_products
|
400
437
|
prepare_interactions
|
401
438
|
prepare_codes
|
439
|
+
Oddb2xml.log "build_product #{@products.size} products"
|
402
440
|
_builder = Nokogiri::XML::Builder.new(:encoding => 'utf-8') do |xml|
|
403
441
|
xml.doc.tag_suffix = @tag_suffix
|
404
442
|
datetime = Time.new.strftime('%FT%T%z')
|
@@ -551,6 +589,8 @@ module Oddb2xml
|
|
551
589
|
def build_article
|
552
590
|
prepare_limitations
|
553
591
|
prepare_articles
|
592
|
+
idx = 0
|
593
|
+
Oddb2xml.log "build_article #{idx} of #{@articles.size} articles"
|
554
594
|
_builder = Nokogiri::XML::Builder.new(:encoding => 'utf-8') do |xml|
|
555
595
|
xml.doc.tag_suffix = @tag_suffix
|
556
596
|
datetime = Time.new.strftime('%FT%T%z')
|
@@ -563,8 +603,10 @@ module Oddb2xml
|
|
563
603
|
'VALID_DATE' => datetime
|
564
604
|
) {
|
565
605
|
@articles.each do |obj|
|
566
|
-
|
567
|
-
|
606
|
+
idx += 1
|
607
|
+
Oddb2xml.log "build_article #{idx} of #{@articles.size} articles" if idx % 500 == 0
|
608
|
+
obj[:de].each_with_index do |de_idx, i|
|
609
|
+
fr_idx = obj[:fr][i] # swissindex FR
|
568
610
|
pac,no8 = nil,de_idx[:ean][4..11] # BAG-XML(SL/LS)
|
569
611
|
ppac = nil # Packungen
|
570
612
|
ean = de_idx[:ean]
|
@@ -743,6 +785,7 @@ module Oddb2xml
|
|
743
785
|
}
|
744
786
|
}
|
745
787
|
end
|
788
|
+
Oddb2xml.log "build_article. Done #{idx} of #{@articles.size} articles"
|
746
789
|
_builder.to_xml
|
747
790
|
end
|
748
791
|
def build_fi
|
@@ -834,6 +877,7 @@ module Oddb2xml
|
|
834
877
|
_builder.to_xml
|
835
878
|
end
|
836
879
|
def build_company
|
880
|
+
Oddb2xml.log "build_company #{@companies.size} companies"
|
837
881
|
_builder = Nokogiri::XML::Builder.new(:encoding => 'utf-8') do |xml|
|
838
882
|
xml.doc.tag_suffix = @tag_suffix
|
839
883
|
datetime = Time.new.strftime('%FT%T%z')
|
@@ -870,6 +914,7 @@ module Oddb2xml
|
|
870
914
|
_builder.to_xml
|
871
915
|
end
|
872
916
|
def build_person
|
917
|
+
Oddb2xml.log "build_person #{@people.size} persons"
|
873
918
|
_builder = Nokogiri::XML::Builder.new(:encoding => 'utf-8') do |xml|
|
874
919
|
xml.doc.tag_suffix = @tag_suffix
|
875
920
|
datetime = Time.new.strftime('%FT%T%z')
|
data/lib/oddb2xml/cli.rb
CHANGED
@@ -238,8 +238,8 @@ module Oddb2xml
|
|
238
238
|
xml = downloader.download
|
239
239
|
@mutex.synchronize do
|
240
240
|
hsh = ZurroseExtractor.new(xml, @options[:extended]).to_hash
|
241
|
-
@items = hsh if @options[:extended]
|
242
241
|
@prices = hsh
|
242
|
+
Oddb2xml.log("zurrose added #{@prices.size} prices")
|
243
243
|
end
|
244
244
|
end
|
245
245
|
when :index
|
data/lib/oddb2xml/downloader.rb
CHANGED
@@ -8,6 +8,7 @@ module Oddb2xml
|
|
8
8
|
module DownloadMethod
|
9
9
|
private
|
10
10
|
def download_as(file, option='r')
|
11
|
+
Oddb2xml.log "download_as file #{file} from #{@url}"
|
11
12
|
data = nil
|
12
13
|
if Oddb2xml.skip_download(file)
|
13
14
|
io = File.open(file, option)
|
@@ -36,6 +37,7 @@ module Oddb2xml
|
|
36
37
|
@url = url
|
37
38
|
@retry_times = 3
|
38
39
|
HTTPI.log = false # disable httpi warning
|
40
|
+
Oddb2xml.log "Downloader from #{@url} for #{self.class}"
|
39
41
|
init
|
40
42
|
end
|
41
43
|
def init
|
data/lib/oddb2xml/util.rb
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
module Oddb2xml
|
2
2
|
Backup = "#{Dir.pwd}/data/download"
|
3
3
|
@options = {}
|
4
|
-
|
4
|
+
|
5
|
+
def Oddb2xml.log(msg)
|
6
|
+
return unless @options[:log]
|
7
|
+
$stdout.puts "#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}: #{msg}"
|
8
|
+
$stdout.flush
|
9
|
+
end
|
10
|
+
|
5
11
|
def Oddb2xml.save_options(options)
|
6
12
|
@options = options
|
7
13
|
end
|
data/lib/oddb2xml/version.rb
CHANGED
data/spec/builder_spec.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
|
+
require "rexml/document"
|
5
|
+
include REXML
|
4
6
|
|
5
7
|
module Kernel
|
6
8
|
def capture(stream)
|
@@ -27,6 +29,7 @@ describe Oddb2xml::Builder do
|
|
27
29
|
setup_server_mocks
|
28
30
|
setup_swiss_index_server_mock(types = ['NonPharma', 'Pharma'])
|
29
31
|
end
|
32
|
+
if true
|
30
33
|
context 'should handle BAG-articles with and without pharmacode' do
|
31
34
|
it {
|
32
35
|
dat = File.read(File.expand_path('../data/Preparation.xml', __FILE__))
|
@@ -41,42 +44,42 @@ describe Oddb2xml::Builder do
|
|
41
44
|
let(:cli) do
|
42
45
|
opts = {}
|
43
46
|
Oddb2xml::Cli.new(opts)
|
44
|
-
end
|
47
|
+
end
|
45
48
|
it 'should generate a valid oddb_product.xml' do
|
46
49
|
res = capture(:stdout){ cli.run }
|
47
50
|
res.should match(/products/)
|
48
51
|
article_filename = File.expand_path(File.join(File.dirname(__FILE__), '..', 'oddb_article.xml'))
|
49
|
-
File.exists?(article_filename).should be_true
|
52
|
+
File.exists?(article_filename).should be_true
|
50
53
|
article_xml = IO.read(article_filename)
|
51
54
|
product_filename = File.expand_path(File.join(File.dirname(__FILE__), '..', 'oddb_product.xml'))
|
52
55
|
File.exists?(product_filename).should be_true
|
53
56
|
unless /1\.8\.7/.match(RUBY_VERSION)
|
54
57
|
product_xml = IO.read(product_filename)
|
55
|
-
article_xml.should match(/3TC/)
|
58
|
+
article_xml.should match(/3TC/)
|
56
59
|
article_xml.should match(/<PHAR>1699947</)
|
57
|
-
article_xml.should match(/<SMNO>53662013</)
|
58
|
-
article_xml.should match(/<DSCRD>3TC Filmtabl 150 mg</)
|
59
|
-
article_xml.should match(/<COMPNO>7601001392175</)
|
60
|
+
article_xml.should match(/<SMNO>53662013</)
|
61
|
+
article_xml.should match(/<DSCRD>3TC Filmtabl 150 mg</)
|
62
|
+
article_xml.should match(/<COMPNO>7601001392175</)
|
60
63
|
article_xml.should match(/<BC>7680536620137</)
|
61
64
|
article_xml.should match(/<VDAT>01.10.2011</)
|
62
65
|
article_xml.should match(/<PTYP>PEXF</)
|
63
66
|
article_xml.should match(/<PRICE>164.55</)
|
64
67
|
article_xml.should match(/<PTYP>PPUB</)
|
65
68
|
article_xml.should match(/<PRICE>205.3</)
|
66
|
-
|
67
|
-
article_xml.should match(/Levetiracetam DESITIN/i) #
|
69
|
+
|
70
|
+
article_xml.should match(/Levetiracetam DESITIN/i) #
|
68
71
|
article_xml.should match(/7680536620137/) # Pharmacode
|
69
|
-
article_xml.should match(/<PRICE>13.49</)
|
70
|
-
article_xml.should match(/<PRICE>27.8</)
|
72
|
+
article_xml.should match(/<PRICE>13.49</)
|
73
|
+
article_xml.should match(/<PRICE>27.8</)
|
71
74
|
|
72
75
|
product_xml.should match(/3TC/)
|
73
76
|
product_xml.should match(/7680620690084/) # Levetiracetam DESITIN
|
74
|
-
article_xml.scan(/<ART DT=/).size.should eq(
|
77
|
+
article_xml.scan(/<ART DT=/).size.should eq(3) # we should find two articles
|
75
78
|
article_xml.should match(/<PHAR>5819012</)
|
76
79
|
article_xml.should match(/<DSCRD>LEVETIRACETAM DESITIN Filmtabl 250 mg/)
|
77
80
|
article_xml.should match(/<COMPNO>7601001320451</)
|
78
81
|
end
|
79
|
-
end
|
82
|
+
end
|
80
83
|
end
|
81
84
|
|
82
85
|
context 'when -a nonpharma -f dat is given' do
|
@@ -99,5 +102,78 @@ describe Oddb2xml::Builder do
|
|
99
102
|
it "pending should match EAN of Desitin. returns 0 at the moment"
|
100
103
|
|
101
104
|
end
|
105
|
+
end
|
106
|
+
context 'when option -e is given' do
|
107
|
+
let(:cli) do
|
108
|
+
opts = {
|
109
|
+
:extended => :true,
|
110
|
+
:nonpharma => :true,
|
111
|
+
:price => :zurrose,
|
112
|
+
}
|
113
|
+
Oddb2xml::Cli.new(opts)
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'should emit correct data when called with -e (extended)' do
|
117
|
+
res = capture(:stdout){ cli.run }
|
118
|
+
res.should match(/products/)
|
119
|
+
article_filename = File.expand_path(File.join(File.dirname(__FILE__), '..', 'oddb_article.xml'))
|
120
|
+
File.exists?(article_filename).should be_true
|
121
|
+
article_xml = IO.read(article_filename)
|
122
|
+
product_filename = File.expand_path(File.join(File.dirname(__FILE__), '..', 'oddb_product.xml'))
|
123
|
+
File.exists?(product_filename).should be_true
|
124
|
+
|
125
|
+
# check substances
|
126
|
+
doc = REXML::Document.new File.new(File.join(File.dirname(__FILE__), '..', 'oddb_substance.xml'))
|
127
|
+
names = XPath.match( doc, "//NAML" )
|
128
|
+
names.size.should == 2
|
129
|
+
names.find_all{|x| x.text.match('Lamivudinum') }.size.should == 1
|
130
|
+
|
131
|
+
# check interactions
|
132
|
+
doc = REXML::Document.new File.new(File.join(File.dirname(__FILE__), '..', 'oddb_interaction.xml'))
|
133
|
+
titles = XPath.match( doc, "//TITD" )
|
134
|
+
titles.size.should == 2
|
135
|
+
titles.find_all{|x| x.text.match('Keine Interaktion') }.size.should == 1
|
136
|
+
titles.find_all{|x| x.text.match('Erhöhtes Risiko für Myopathie und Rhabdomyolyse') }.size.should == 1
|
137
|
+
|
138
|
+
unless /1\.8\.7/.match(RUBY_VERSION)
|
139
|
+
# check articles
|
140
|
+
article_xml.should match(/3TC/)
|
141
|
+
article_xml.should match(/<PHAR>1699947</)
|
142
|
+
article_xml.should match(/<SMNO>53662013</)
|
143
|
+
article_xml.should match(/<DSCRD>3TC Filmtabl 150 mg</)
|
144
|
+
article_xml.should match(/<COMPNO>7601001392175</)
|
145
|
+
article_xml.should match(/<BC>7680536620137</)
|
146
|
+
article_xml.should match(/<VDAT>01.10.2011</)
|
147
|
+
article_xml.should match(/<PTYP>PEXF</)
|
148
|
+
article_xml.should match(/<PRICE>164.55</)
|
149
|
+
article_xml.should match(/<PTYP>PPUB</)
|
150
|
+
article_xml.should match(/<PRICE>205.3</)
|
151
|
+
|
152
|
+
article_xml.should match(/Levetiracetam DESITIN/i) #
|
153
|
+
article_xml.should match(/7680536620137/) # Pharmacode
|
154
|
+
article_xml.should match(/<PRICE>13.49</)
|
155
|
+
article_xml.should match(/<PRICE>27.8</)
|
156
|
+
article_xml.scan(/<ART DT=/).size.should eq(60) # we should find some articles
|
157
|
+
article_xml.should match(/<PHAR>5819012</)
|
158
|
+
article_xml.should match(/<DSCRD>LEVETIRACETAM DESITIN Filmtabl 250 mg/)
|
159
|
+
article_xml.should match(/<COMPNO>7601001320451</)
|
160
|
+
|
161
|
+
# check products
|
162
|
+
product_xml = IO.read(product_filename)
|
163
|
+
product_xml.should match(/3TC/)
|
164
|
+
product_xml.should match(/7680620690084/) # Levetiracetam DESITIN
|
165
|
+
|
166
|
+
# check ZYVOXID in article
|
167
|
+
article_xml.should match(/7680555580054/) # ZYVOXID
|
168
|
+
article_xml.should match(/ZYVOXID/i)
|
169
|
+
|
170
|
+
product_xml.should match(/7680555580054/) # ZYVOXID
|
171
|
+
product_xml.should_not match(/ZYVOXID/i)
|
172
|
+
doc = REXML::Document.new File.new article_filename
|
173
|
+
dscrds = XPath.match( doc, "//DSCRD" )
|
174
|
+
dscrds.find_all{|x| x.text.match('ZYVOXID Filmtabl 600 mg') }.size.should == 1
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
102
178
|
end
|
103
179
|
|
@@ -33,6 +33,20 @@
|
|
33
33
|
<GLN>7601001320451</GLN>
|
34
34
|
</COMP>
|
35
35
|
</ITEM>
|
36
|
+
<ITEM DT="2013-06-22T00:00:00">
|
37
|
+
<GTIN>7680555580054</GTIN>
|
38
|
+
<PHAR>2465312</PHAR>
|
39
|
+
<STATUS>A</STATUS>
|
40
|
+
<STDATE>2002-01-16T00:00:00</STDATE>
|
41
|
+
<LANG>DE</LANG>
|
42
|
+
<DSCR>ZYVOXID Filmtabl 600 mg</DSCR>
|
43
|
+
<ADDSCR>10 Stk</ADDSCR>
|
44
|
+
<ATC>J01XX08</ATC>
|
45
|
+
<COMP>
|
46
|
+
<NAME>Pfizer AG</NAME>
|
47
|
+
<GLN>7601001010604</GLN>
|
48
|
+
</COMP>
|
49
|
+
</ITEM>
|
36
50
|
<RESULT>
|
37
51
|
<OK_ERROR>OK</OK_ERROR>
|
38
52
|
<NBR_RECORD>2</NBR_RECORD>
|
Binary file
|
@@ -1,3 +1,4 @@
|
|
1
|
+
1122465312ZYVOXID Filmtabl 600 mg 10 Stk 096114108275100A080190076805555800542
|
1
2
|
1120020209ERYTRHOCIN I.V. Trockensub Fl 1g 001518002010300B080160000000000000002
|
2
3
|
1120020244FERRO-GRADUMET Depottabl 30 Stk 000895001090300C060710076803164401152
|
3
4
|
1120020273KENDURAL Depottabl 30 Stk 000492000840100C060710076803536601632
|
data/spec/extractor_spec.rb
CHANGED
@@ -90,10 +90,10 @@ describe Oddb2xml::SwissmedicInfoExtractor do
|
|
90
90
|
end
|
91
91
|
context 'can parse swissmedic_orphans.xls' do
|
92
92
|
it {
|
93
|
-
filename = File.join(File.dirname(__FILE__), 'data/
|
93
|
+
filename = File.join(File.dirname(__FILE__), 'data/swissmedic_orphan.xlsx')
|
94
94
|
expect(File.exists?(filename)).to eq(true), "File #{filename} must exists"
|
95
95
|
@packs = Oddb2xml::SwissmedicExtractor.new(filename, :orphan).to_arry
|
96
|
-
expect(@packs.size).to eq(
|
96
|
+
expect(@packs.size).to eq(79)
|
97
97
|
expect(@packs.first).to eq("62132")
|
98
98
|
expect(@packs[7]).to eq("00687")
|
99
99
|
}
|
data/spec/spec_helper.rb
CHANGED
@@ -26,6 +26,7 @@ module ServerMockHelper
|
|
26
26
|
setup_lppv_server_mock
|
27
27
|
setup_migel_server_mock
|
28
28
|
setup_medregbm_server_mock
|
29
|
+
setup_zurrose_server_mock
|
29
30
|
end
|
30
31
|
def setup_bag_xml_server_mock
|
31
32
|
# zip
|
@@ -93,8 +94,8 @@ module ServerMockHelper
|
|
93
94
|
:body => stub_response)
|
94
95
|
# xls
|
95
96
|
if type == :orphans
|
96
|
-
stub_xls_url = "http://#{host}" + urls[:xls] + "/
|
97
|
-
stub_response = File.read(File.expand_path("../data/
|
97
|
+
stub_xls_url = "http://#{host}" + urls[:xls] + "/swissmedic_orphan.xlsx"
|
98
|
+
stub_response = File.read(File.expand_path("../data/swissmedic_orphan.xlsx", __FILE__))
|
98
99
|
else
|
99
100
|
stub_xls_url = "http://#{host}" + urls[:xls] + "/swissmedic_#{type.to_s}.xlsx"
|
100
101
|
stub_response = 'no_such_file'
|
data/test_options.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Helper script to test all common usageas of oddb2xml
|
3
|
+
# - runs rake install to install the gem
|
4
|
+
# - Creates an output directory ausgabe/time_stamp
|
5
|
+
# - runs all commands (and add ---skip-download)
|
6
|
+
# - saveds output and data/download to ausgabe/time_stamp
|
7
|
+
|
8
|
+
|
9
|
+
require 'fileutils'
|
10
|
+
|
11
|
+
def test_one_call(cmd)
|
12
|
+
dest = File.join(Ausgabe, cmd.gsub(/[ -]/, '_'))
|
13
|
+
cmd.sub!('oddb2xml', 'oddb2xml --skip-download --log')
|
14
|
+
files = (Dir.glob('%.xls*') + Dir.glob('*.dat*') + Dir.glob('*.xml'))
|
15
|
+
FileUtils.rm(files, :verbose => true)
|
16
|
+
puts "#{Time.now}: Running cmd #{cmd}"
|
17
|
+
startTime = Time.now
|
18
|
+
res = system(cmd)
|
19
|
+
endTime = Time.now
|
20
|
+
diffSeconds = (endTime - startTime).to_i
|
21
|
+
duration = "#{Time.now}: Took #{sprintf('%3d', diffSeconds)} seconds for"
|
22
|
+
puts "#{duration} success #{res} for #{cmd}"
|
23
|
+
exit 2 unless res
|
24
|
+
FileUtils.makedirs(dest)
|
25
|
+
FileUtils.cp_r('data/download', dest, :preserve => true, :verbose => true) if Dir.glob(Ausgabe).size > 0
|
26
|
+
FileUtils.cp(Dir.glob('*.dat'), dest, :preserve => true, :verbose => true) if Dir.glob('*.dat').size > 0
|
27
|
+
FileUtils.cp(Dir.glob('*.xml'), dest, :preserve => true, :verbose => true) if Dir.glob('*.xml').size > 0
|
28
|
+
FileUtils.cp(Dir.glob('*.gz'), dest, :preserve => true, :verbose => true) if Dir.glob('*.gz').size > 0
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
system("rake install") # build and install our gem first
|
33
|
+
Ausgabe = File.join(Dir.pwd, 'ausgabe', Time.now.strftime('%Y.%m.%d-%H:%M'))
|
34
|
+
FileUtils.makedirs(Ausgabe)
|
35
|
+
test_one_call('oddb2xml -x address')
|
36
|
+
test_one_call('oddb2xml -f dat')
|
37
|
+
test_one_call('oddb2xml -f xml')
|
38
|
+
test_one_call('oddb2xml -f dat -a nonpharma')
|
39
|
+
test_one_call('oddb2xml -t md')
|
40
|
+
test_one_call('oddb2xml -a nonpharma -t md -c tar.gz')
|
41
|
+
test_one_call('oddb2xml -a nonpharma')
|
42
|
+
test_one_call('oddb2xml -e') # take hours, therefor at the end
|
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.
|
4
|
+
version: 1.8.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-04-
|
12
|
+
date: 2014-04-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rubyzip
|
@@ -264,8 +264,8 @@ files:
|
|
264
264
|
- spec/data/swissmedic_info.html
|
265
265
|
- spec/data/swissmedic_info.zip
|
266
266
|
- spec/data/swissmedic_info_2.html
|
267
|
+
- spec/data/swissmedic_orphan.xlsx
|
267
268
|
- spec/data/swissmedic_orphans.html
|
268
|
-
- spec/data/swissmedic_orphans.xls
|
269
269
|
- spec/data/swissmedic_packages.html
|
270
270
|
- spec/data/swissmedic_packages.xls
|
271
271
|
- spec/data/swissmedic_packages.xlsx
|
@@ -276,6 +276,7 @@ files:
|
|
276
276
|
- spec/downloader_spec.rb
|
277
277
|
- spec/extractor_spec.rb
|
278
278
|
- spec/spec_helper.rb
|
279
|
+
- test_options.rb
|
279
280
|
- tools/cacert.pem
|
280
281
|
- tools/set.bat
|
281
282
|
- tools/win_fetch_cacerts.rb
|
@@ -338,8 +339,8 @@ test_files:
|
|
338
339
|
- spec/data/swissmedic_info.html
|
339
340
|
- spec/data/swissmedic_info.zip
|
340
341
|
- spec/data/swissmedic_info_2.html
|
342
|
+
- spec/data/swissmedic_orphan.xlsx
|
341
343
|
- spec/data/swissmedic_orphans.html
|
342
|
-
- spec/data/swissmedic_orphans.xls
|
343
344
|
- spec/data/swissmedic_packages.html
|
344
345
|
- spec/data/swissmedic_packages.xls
|
345
346
|
- spec/data/swissmedic_packages.xlsx
|
Binary file
|