oddb2xml 2.6.7 → 2.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +40 -0
- data/.standard.yml +2 -0
- data/Elexis_Artikelstamm_v5.xsd +0 -3
- data/Gemfile +3 -3
- data/History.txt +30 -0
- data/README.md +1 -1
- data/Rakefile +24 -23
- data/bin/check_artikelstamm +11 -11
- data/bin/compare_v5 +23 -23
- data/bin/oddb2xml +14 -13
- data/lib/oddb2xml.rb +1 -1
- data/lib/oddb2xml/builder.rb +1077 -1039
- data/lib/oddb2xml/calc.rb +232 -233
- data/lib/oddb2xml/chapter_70_hack.rb +38 -32
- data/lib/oddb2xml/cli.rb +252 -233
- data/lib/oddb2xml/compare.rb +70 -59
- data/lib/oddb2xml/compositions_syntax.rb +448 -430
- data/lib/oddb2xml/compressor.rb +20 -20
- data/lib/oddb2xml/downloader.rb +155 -129
- data/lib/oddb2xml/extractor.rb +302 -296
- data/lib/oddb2xml/options.rb +34 -35
- data/lib/oddb2xml/parslet_compositions.rb +263 -265
- data/lib/oddb2xml/semantic_check.rb +39 -33
- data/lib/oddb2xml/util.rb +169 -159
- data/lib/oddb2xml/version.rb +1 -1
- data/lib/oddb2xml/xml_definitions.rb +32 -33
- data/oddb2xml.gemspec +32 -30
- data/spec/artikelstamm_spec.rb +139 -132
- data/spec/builder_spec.rb +495 -524
- data/spec/calc_spec.rb +552 -593
- data/spec/check_artikelstamm_spec.rb +26 -26
- data/spec/cli_spec.rb +182 -157
- data/spec/compare_spec.rb +9 -11
- data/spec/composition_syntax_spec.rb +390 -409
- data/spec/compressor_spec.rb +48 -48
- data/spec/data/Preparations.xml +139 -3
- data/spec/data/refdata_NonPharma.xml +0 -3
- data/spec/data/refdata_Pharma.xml +10 -25
- data/spec/data/swissmedic_package.xlsx +0 -0
- data/spec/data/transfer.dat +3 -1
- data/spec/data/varia_De.htm +2 -2
- data/spec/data_helper.rb +47 -49
- data/spec/downloader_spec.rb +247 -260
- data/spec/extractor_spec.rb +173 -165
- data/spec/galenic_spec.rb +233 -256
- data/spec/options_spec.rb +116 -119
- data/spec/parslet_spec.rb +833 -861
- data/spec/spec_helper.rb +154 -153
- data/test_options.rb +39 -42
- data/tools/win_fetch_cacerts.rb +2 -3
- metadata +49 -5
- data/.travis.yml +0 -30
@@ -1,14 +1,19 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require 'open-uri'
|
1
|
+
require "oddb2xml/extractor"
|
2
|
+
require "ox"
|
3
|
+
require "open-uri"
|
5
4
|
|
6
5
|
module Oddb2xml
|
7
6
|
class Chapter70xtractor < Extractor
|
8
|
-
def
|
7
|
+
def self.parse_td(elem)
|
9
8
|
begin
|
10
9
|
values = elem.is_a?(Array) ? elem : elem.values
|
11
|
-
res = values.flatten.collect{|x|
|
10
|
+
res = values.flatten.collect { |x|
|
11
|
+
if x.nil?
|
12
|
+
nil
|
13
|
+
else
|
14
|
+
x.is_a?(Hash) ? x.values : x.gsub(/\r\n/, "").strip
|
15
|
+
end
|
16
|
+
}
|
12
17
|
puts "parse_td returns: #{res}" if $VERBOSE
|
13
18
|
rescue => exc
|
14
19
|
puts "Unable to pars #{elem} #{exc}"
|
@@ -18,53 +23,54 @@ module Oddb2xml
|
|
18
23
|
res.flatten # .join("\t")
|
19
24
|
end
|
20
25
|
LIMITATIONS = {
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
26
|
+
"L" => "Kostenübernahme nur nach vorgängiger allergologischer Abklärung.",
|
27
|
+
"L1" => "Eine Flasche zu 20 ml Urtinktur einer bestimmten Pflanze pro Monat.",
|
28
|
+
"L1, L2" => "Eine Flasche zu 20 ml Urtinktur einer bestimmten Pflanze pro Monat. Für Aesculus, Carduus Marianus, Ginkgo, Hedera helix, Hypericum perforatum, Lavandula, Rosmarinus officinalis, Taraxacum officinale.",
|
29
|
+
"L3" => "Alle drei Monate wird eine Verordnung/Originalpackung pro Mittel vergütet."
|
25
30
|
}
|
26
31
|
def self.items
|
27
32
|
@@items
|
28
33
|
end
|
29
|
-
|
30
|
-
|
34
|
+
|
35
|
+
def self.parse(html_file = "http://www.spezialitaetenliste.ch/varia_De.htm")
|
36
|
+
data = Hash.new { |h, k| h[k] = [] }
|
31
37
|
Ox.default_options = {
|
32
|
-
|
33
|
-
|
34
|
-
|
38
|
+
mode: :generic,
|
39
|
+
effort: :tolerant,
|
40
|
+
smart: true
|
35
41
|
}
|
36
|
-
res = Ox.load(
|
42
|
+
res = Ox.load(Oddb2xml.uri_open(html_file).read, mode: :hash_no_attrs).values.first["body"]
|
37
43
|
result = []
|
38
44
|
idx = 0
|
39
45
|
@@items = {}
|
40
46
|
res.values.last.each do |item|
|
41
|
-
item.values.first.each do |
|
42
|
-
what =
|
47
|
+
item.values.first.each do |sub_elem|
|
48
|
+
what = Chapter70xtractor.parse_td(sub_elem)
|
43
49
|
idx += 1
|
44
50
|
puts "#{idx}: xx #{what}" if $VERBOSE
|
45
51
|
result << what
|
46
52
|
end
|
47
53
|
end
|
48
|
-
result2 = result.find_all{ |x| (x.is_a?(Array) && x.first.is_a?(String)) && x.first.to_i > 100}
|
54
|
+
result2 = result.find_all { |x| (x.is_a?(Array) && x.first.is_a?(String)) && x.first.to_i > 100 }
|
49
55
|
result2.each do |entry|
|
50
56
|
data = {}
|
51
57
|
pharma_code = entry.first
|
52
|
-
ean13 =
|
53
|
-
if entry[2].encoding.to_s.eql?(
|
54
|
-
|
58
|
+
ean13 = (Oddb2xml::FAKE_GTIN_START + pharma_code.to_s)
|
59
|
+
german = if entry[2].encoding.to_s.eql?("ASCII-8BIT")
|
60
|
+
CGI.unescape(entry[2].force_encoding("ISO-8859-1"))
|
55
61
|
else
|
56
|
-
|
62
|
+
entry[2]
|
57
63
|
end
|
58
64
|
@@items[ean13] = {
|
59
|
-
:
|
60
|
-
:
|
61
|
-
:
|
62
|
-
:
|
63
|
-
:
|
64
|
-
:
|
65
|
-
:
|
66
|
-
:
|
67
|
-
:
|
65
|
+
data_origin: "Chapter70",
|
66
|
+
line: entry.join(","),
|
67
|
+
ean13: ean13,
|
68
|
+
description: german,
|
69
|
+
quantity: entry[3],
|
70
|
+
pharmacode: pharma_code,
|
71
|
+
pub_price: entry[4],
|
72
|
+
limitation: entry[5],
|
73
|
+
type: :pharma
|
68
74
|
}
|
69
75
|
end
|
70
76
|
result2
|
data/lib/oddb2xml/cli.rb
CHANGED
@@ -1,25 +1,21 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require 'oddb2xml/util'
|
10
|
-
require 'rubyXL'
|
11
|
-
require 'date' # for today
|
1
|
+
require "oddb2xml/builder"
|
2
|
+
require "oddb2xml/downloader"
|
3
|
+
require "oddb2xml/extractor"
|
4
|
+
require "oddb2xml/compressor"
|
5
|
+
require "oddb2xml/options"
|
6
|
+
require "oddb2xml/util"
|
7
|
+
require "rubyXL"
|
8
|
+
require "date" # for today
|
12
9
|
|
13
10
|
module Oddb2xml
|
14
|
-
|
15
11
|
class Cli
|
16
12
|
attr_reader :options
|
17
|
-
SUBJECTS
|
13
|
+
SUBJECTS = %w[product article]
|
18
14
|
ADDITIONS = %w[substance limitation interaction code]
|
19
15
|
OPTIONALS = %w[fi fi_product]
|
20
16
|
def initialize(args)
|
21
17
|
@options = args
|
22
|
-
|
18
|
+
$stdout.puts "\nStarting cli with from #{caller(2..2).first} using #{@options}" if defined?(RSpec)
|
23
19
|
Oddb2xml.save_options(@options)
|
24
20
|
@mutex = Mutex.new
|
25
21
|
# product
|
@@ -28,21 +24,22 @@ module Oddb2xml
|
|
28
24
|
@lppvs = {} # lppv.txt from files repo
|
29
25
|
@infos = {} # [option] FI from SwissmedicInfo
|
30
26
|
@packs = {} # [option] Packungen from Swissmedic for dat
|
31
|
-
@infos_zur_rose
|
32
|
-
@migel
|
27
|
+
@infos_zur_rose = {} # [addition] infos_zur_rose and other infos from zurrose transfer.txt
|
28
|
+
@migel = {} # [addition] additional Non Pharma products from files repo
|
33
29
|
@actions = [] # [addition] interactions from epha
|
34
30
|
@orphan = [] # [addition] Orphaned drugs from Swissmedic xls
|
35
31
|
# addresses
|
36
32
|
@companies = [] # betrieb
|
37
|
-
@people
|
33
|
+
@people = [] # medizinalperson
|
38
34
|
@_message = false
|
39
35
|
end
|
36
|
+
|
40
37
|
def run
|
41
38
|
threads = []
|
42
|
-
|
43
|
-
files2rm = Dir.glob(File.join(
|
44
|
-
FileUtils.rm_f(files2rm, :
|
45
|
-
if @options[:calc]
|
39
|
+
start_time = Time.now
|
40
|
+
files2rm = Dir.glob(File.join(DOWNLOADS, "*"))
|
41
|
+
FileUtils.rm_f(files2rm, verbose: @options[:log]) if (files2rm.size > 0) && !Oddb2xml.skip_download?
|
42
|
+
if @options[:calc] && !(@options[:extended])
|
46
43
|
threads << download(:package) # swissmedic
|
47
44
|
elsif @options[:address]
|
48
45
|
[:company, :person].each do |type|
|
@@ -82,146 +79,157 @@ module Oddb2xml
|
|
82
79
|
end
|
83
80
|
build
|
84
81
|
if @options[:artikelstamm] && system("which xmllint")
|
85
|
-
elexis_v5_xsd = File.expand_path(File.join(__FILE__,
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
82
|
+
elexis_v5_xsd = File.expand_path(File.join(__FILE__, "..", "..", "..", "Elexis_Artikelstamm_v5.xsd"))
|
83
|
+
cmd = "xmllint --noout --schema #{elexis_v5_xsd} #{@the_files[:artikelstamm]}"
|
84
|
+
if system(cmd)
|
85
|
+
puts "Validatied #{@the_files[:artikelstamm]}"
|
86
|
+
else
|
87
|
+
puts "Validating failed using #{cmd}"
|
88
|
+
raise "Validating failed using #{cmd}"
|
89
|
+
end
|
93
90
|
end
|
94
91
|
compress if @options[:compress_ext]
|
95
92
|
res = report
|
96
|
-
|
97
|
-
if defined?(RSpec) &&
|
93
|
+
nr_secs = (Time.now - start_time).to_i
|
94
|
+
if defined?(RSpec) && nr_secs.to_i > 10 && ENV["TRAVIS"].to_s.empty?
|
95
|
+
puts "Took took long #{nr_secs} seconds"
|
96
|
+
# require "pry"; binding.pry;
|
97
|
+
end
|
98
98
|
res
|
99
99
|
end
|
100
|
+
|
100
101
|
private
|
102
|
+
|
101
103
|
def build
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
refdata.merge!(@refdata_types[type]) if @refdata_types[type]
|
115
|
-
end
|
116
|
-
builder.refdata = refdata
|
117
|
-
end
|
118
|
-
# common sources
|
119
|
-
builder.items = @items
|
120
|
-
builder.flags = @flags
|
121
|
-
builder.lppvs = @lppvs
|
122
|
-
# optional sources
|
123
|
-
builder.infos = @infos
|
124
|
-
builder.packs = @packs
|
125
|
-
# additional sources
|
126
|
-
%w[actions orphan migel infos_zur_rose].each do |addition|
|
127
|
-
builder.send("#{addition}=".intern, self.instance_variable_get("@#{addition}"))
|
104
|
+
@the_files = {"calc" => "oddb_calc.xml"} if @options[:calc] && !(@options[:extended] || @options[:artikelstamm])
|
105
|
+
builder = Builder.new(@options) do |builder|
|
106
|
+
if @options[:calc] && !(@options[:extended] || @options[:artikelstamm])
|
107
|
+
builder.packs = @packs
|
108
|
+
elsif @options[:address]
|
109
|
+
builder.companies = @companies
|
110
|
+
builder.people = @people
|
111
|
+
else # product
|
112
|
+
if @options[:format] != :dat
|
113
|
+
refdata = {}
|
114
|
+
types.each do |type|
|
115
|
+
refdata.merge!(@refdata_types[type]) if @refdata_types[type]
|
128
116
|
end
|
117
|
+
builder.refdata = refdata
|
118
|
+
end
|
119
|
+
# common sources
|
120
|
+
builder.items = @items
|
121
|
+
builder.flags = @flags
|
122
|
+
builder.lppvs = @lppvs
|
123
|
+
# optional sources
|
124
|
+
builder.infos = @infos
|
125
|
+
builder.packs = @packs
|
126
|
+
# additional sources
|
127
|
+
%w[actions orphan migel infos_zur_rose].each do |addition|
|
128
|
+
builder.send("#{addition}=".intern, instance_variable_get("@#{addition}"))
|
129
129
|
end
|
130
|
-
builder.tag_suffix = @options[:tag_suffix]
|
131
130
|
end
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
output << builder.to_dat
|
131
|
+
builder.tag_suffix = @options[:tag_suffix]
|
132
|
+
end
|
133
|
+
files.each_pair do |sbj, file|
|
134
|
+
builder.subject = sbj
|
135
|
+
output = ""
|
136
|
+
if !@options[:address] && (@options[:format] == :dat)
|
137
|
+
types.each do |type|
|
138
|
+
a_sby = (type == :pharma ? :dat : :with_migel_dat)
|
139
|
+
builder.refdata = @refdata_types[type]
|
140
|
+
builder.subject = a_sby
|
141
|
+
builder.ean14 = @options[:ean14]
|
142
|
+
if type == :nonpharma
|
143
|
+
output << "\n"
|
146
144
|
end
|
147
|
-
|
148
|
-
output = builder.to_xml
|
145
|
+
output << builder.to_dat
|
149
146
|
end
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
147
|
+
else
|
148
|
+
output = builder.to_xml
|
149
|
+
end
|
150
|
+
File.open(File.join(WORK_DIR, file), "w:utf-8") do |fh|
|
151
|
+
output.split("\n").each do |line|
|
152
|
+
if /.xml$/i.match?(file)
|
153
|
+
fh.puts(line)
|
154
|
+
else
|
155
|
+
fh.puts(Oddb2xml.convert_to_8859_1(line))
|
157
156
|
end
|
158
157
|
end
|
159
|
-
if @options[:calc]
|
160
|
-
FileUtils.cp(File.join(WorkDir, file), File.join(WorkDir, file.sub('.xml', '_'+Time.now.strftime("%d.%m.%Y_%H.%M")+'.xml')), :verbose => false)
|
161
|
-
end
|
162
158
|
end
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
end
|
159
|
+
if @options[:calc]
|
160
|
+
ext = File.extname(file)
|
161
|
+
dest = File.join(WORK_DIR, file.sub(ext, "_" + Time.now.strftime("%d.%m.%Y_%H.%M") + ext))
|
162
|
+
FileUtils.cp(File.join(WORK_DIR, file), dest, verbose: false)
|
168
163
|
end
|
169
|
-
raise Interrupt
|
170
164
|
end
|
165
|
+
rescue Interrupt
|
166
|
+
files.values.each do |file|
|
167
|
+
if File.exist? file
|
168
|
+
File.unlink(file) # we don't save it as it might be only partly downloaded
|
169
|
+
end
|
170
|
+
end
|
171
|
+
raise Interrupt
|
171
172
|
end
|
172
|
-
|
173
|
+
|
174
|
+
def download(what, type = nil)
|
173
175
|
case what
|
174
176
|
when :company, :person
|
175
|
-
var = (what == :company ?
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
)
|
184
|
-
|
185
|
-
|
186
|
-
|
177
|
+
var = (what == :company ? "companies" : "people")
|
178
|
+
# instead of Thread.new do
|
179
|
+
|
180
|
+
downloader = MedregbmDownloader.new(what)
|
181
|
+
str = downloader.download
|
182
|
+
Oddb2xml.log("SwissmedicInfoDownloader #{what} str #{str.size} bytes")
|
183
|
+
instance_variable_set(
|
184
|
+
"@#{var}".intern,
|
185
|
+
items = MedregbmExtractor.new(str, what).to_arry
|
186
|
+
)
|
187
|
+
Oddb2xml.log("MedregbmExtractor #{what} added #{items.size} fachinfo")
|
188
|
+
items
|
189
|
+
|
187
190
|
when :fachinfo
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
191
|
+
# instead of Thread.new do
|
192
|
+
|
193
|
+
downloader = SwissmedicInfoDownloader.new
|
194
|
+
xml = downloader.download
|
195
|
+
Oddb2xml.log("SwissmedicInfoDownloader #{var} xml #{xml.size} bytes")
|
196
|
+
@mutex.synchronize do
|
197
|
+
hsh = SwissmedicInfoExtractor.new(xml).to_hash
|
198
|
+
@infos = hsh
|
199
|
+
Oddb2xml.log("SwissmedicInfoExtractor added #{@infos.size} fachinfo")
|
200
|
+
@infos
|
198
201
|
end
|
202
|
+
|
199
203
|
when :orphan
|
200
204
|
var = what.to_s
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
)
|
209
|
-
|
210
|
-
|
211
|
-
|
205
|
+
# instead of Thread.new do
|
206
|
+
|
207
|
+
downloader = SwissmedicDownloader.new(what, @options)
|
208
|
+
bin = downloader.download
|
209
|
+
Oddb2xml.log("SwissmedicDownloader #{var} #{bin} #{File.size(bin)} bytes")
|
210
|
+
instance_variable_set(
|
211
|
+
"@#{var}",
|
212
|
+
items = SwissmedicExtractor.new(bin, what).to_arry
|
213
|
+
)
|
214
|
+
Oddb2xml.log("SwissmedicExtractor added #{items.size}")
|
215
|
+
items
|
216
|
+
|
212
217
|
when :interaction
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
218
|
+
# instead of Thread.new do
|
219
|
+
|
220
|
+
downloader = EphaDownloader.new
|
221
|
+
str = downloader.download
|
222
|
+
Oddb2xml.log("EphaDownloader str #{str.size} bytes")
|
223
|
+
@mutex.synchronize do
|
224
|
+
@actions = EphaExtractor.new(str).to_arry
|
225
|
+
Oddb2xml.log("EphaExtractor added #{@actions.size} interactions")
|
226
|
+
@actions
|
222
227
|
end
|
228
|
+
|
223
229
|
when :migel
|
224
|
-
|
230
|
+
# instead of Thread.new do
|
231
|
+
unless SKIP_MIGEL_DOWNLOADER
|
232
|
+
|
225
233
|
downloader = MigelDownloader.new
|
226
234
|
bin = downloader.download
|
227
235
|
Oddb2xml.log("MigelDownloader bin #{bin.size} bytes")
|
@@ -230,99 +238,107 @@ module Oddb2xml
|
|
230
238
|
Oddb2xml.log("MigelExtractor added #{@migel.size} migel items")
|
231
239
|
@migel
|
232
240
|
end
|
233
|
-
|
241
|
+
|
242
|
+
end
|
234
243
|
when :package
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
+
# instead of Thread.new do
|
245
|
+
|
246
|
+
downloader = SwissmedicDownloader.new(:package, @options)
|
247
|
+
bin = downloader.download
|
248
|
+
Oddb2xml.log("SwissmedicDownloader package #{bin} #{File.size(bin)} bytes")
|
249
|
+
@mutex.synchronize do
|
250
|
+
@packs = SwissmedicExtractor.new(bin, :package).to_hash
|
251
|
+
Oddb2xml.log("SwissmedicExtractor added #{@packs.size} packs from #{bin}")
|
252
|
+
@packs
|
244
253
|
end
|
254
|
+
|
245
255
|
when :lppv
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
256
|
+
# instead of Thread.new do
|
257
|
+
|
258
|
+
downloader = LppvDownloader.new
|
259
|
+
str = downloader.download
|
260
|
+
Oddb2xml.log("LppvDownloader str #{str.size} bytes")
|
261
|
+
@mutex.synchronize do
|
262
|
+
@lppvs = LppvExtractor.new(str).to_hash
|
263
|
+
Oddb2xml.log("LppvExtractor added #{@lppvs.size} lppvs")
|
264
|
+
@lppvs
|
255
265
|
end
|
266
|
+
|
256
267
|
when :bag
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
268
|
+
# instead of Thread.new do
|
269
|
+
|
270
|
+
downloader = BagXmlDownloader.new(@options)
|
271
|
+
xml = downloader.download
|
272
|
+
Oddb2xml.log("BagXmlDownloader xml #{xml.size} bytes")
|
273
|
+
@mutex.synchronize do
|
274
|
+
hsh = BagXmlExtractor.new(xml).to_hash
|
275
|
+
@items = hsh
|
276
|
+
Oddb2xml.log("BagXmlExtractor added #{@items.size} items.")
|
277
|
+
@items
|
267
278
|
end
|
279
|
+
|
268
280
|
when :zurrose
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
281
|
+
# instead of Thread.new do
|
282
|
+
|
283
|
+
downloader = ZurroseDownloader.new(@options, @options[:transfer_dat])
|
284
|
+
xml = downloader.download
|
285
|
+
Oddb2xml.log("ZurroseDownloader xml #{xml.size} bytes")
|
286
|
+
@mutex.synchronize do
|
287
|
+
hsh = ZurroseExtractor.new(xml, @options[:extended], @options[:artikelstamm]).to_hash
|
288
|
+
Oddb2xml.log("ZurroseExtractor added #{hsh.size} items from xml with #{xml.size} bytes")
|
289
|
+
@infos_zur_rose = hsh
|
278
290
|
end
|
291
|
+
|
279
292
|
when :refdata
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
unless @_message # hook only one exit
|
289
|
-
@_message = true
|
290
|
-
exit
|
291
|
-
end
|
292
|
-
end
|
293
|
-
end
|
293
|
+
# instead of Thread.new do
|
294
|
+
|
295
|
+
downloader = RefdataDownloader.new(@options, type)
|
296
|
+
begin
|
297
|
+
xml = downloader.download
|
298
|
+
Oddb2xml.log("RefdataDownloader #{type} xml #{xml.size} bytes")
|
299
|
+
xml
|
300
|
+
rescue SystemExit
|
294
301
|
@mutex.synchronize do
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
302
|
+
unless @_message # hook only one exit
|
303
|
+
@_message = true
|
304
|
+
exit
|
305
|
+
end
|
299
306
|
end
|
300
307
|
end
|
308
|
+
@mutex.synchronize do
|
309
|
+
hsh = RefdataExtractor.new(xml, type).to_hash
|
310
|
+
@refdata_types[type] = hsh
|
311
|
+
Oddb2xml.log("RefdataExtractor #{type} added #{hsh.size} keys now #{@refdata_types.keys} items from xml with #{xml.size} bytes")
|
312
|
+
@refdata_types[type]
|
313
|
+
end
|
314
|
+
|
301
315
|
end
|
302
316
|
end
|
317
|
+
|
303
318
|
def compress
|
304
319
|
compressor = Compressor.new(prefix, @options)
|
305
320
|
files.values.each do |file|
|
306
|
-
work_file = File.join(
|
307
|
-
if File.
|
321
|
+
work_file = File.join(WORK_DIR, file)
|
322
|
+
if File.exist?(work_file)
|
308
323
|
compressor.contents << work_file
|
309
324
|
end
|
310
325
|
end
|
311
326
|
compressor.finalize!
|
312
327
|
end
|
328
|
+
|
313
329
|
def files
|
314
|
-
unless @
|
315
|
-
@
|
316
|
-
@
|
330
|
+
unless @the_files
|
331
|
+
@the_files = {}
|
332
|
+
@the_files[:calc] = "oddb_calc.xml" if @options[:calc]
|
317
333
|
if @options[:artikelstamm]
|
318
|
-
@
|
334
|
+
@the_files[:artikelstamm] = "artikelstamm_#{Date.today.strftime("%d%m%Y")}_v5.xml"
|
319
335
|
elsif @options[:address]
|
320
|
-
@
|
321
|
-
@
|
336
|
+
@the_files[:company] = "#{prefix}_betrieb.xml"
|
337
|
+
@the_files[:person] = "#{prefix}_medizinalperson.xml"
|
322
338
|
elsif @options[:format] == :dat
|
323
|
-
@
|
339
|
+
@the_files[:dat] = "#{prefix}.dat"
|
324
340
|
if @options[:nonpharma] # into one file
|
325
|
-
@
|
341
|
+
@the_files[:dat] = "#{prefix}_with_migel.dat"
|
326
342
|
end
|
327
343
|
else # xml
|
328
344
|
##
|
@@ -330,18 +346,20 @@ module Oddb2xml
|
|
330
346
|
# 1. additions
|
331
347
|
# 2. subjects
|
332
348
|
# 3. optional SUBJECTS
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
@
|
349
|
+
the_files = (ADDITIONS + SUBJECTS)
|
350
|
+
the_files += OPTIONALS if @options[:fi]
|
351
|
+
the_files.each do |sbj|
|
352
|
+
@the_files[sbj] = "#{prefix}_#{sbj}.xml"
|
337
353
|
end
|
338
354
|
end
|
339
355
|
end
|
340
|
-
@
|
356
|
+
@the_files
|
341
357
|
end
|
358
|
+
|
342
359
|
def prefix
|
343
|
-
@_prefix ||= (@options[:tag_suffix] ||
|
360
|
+
@_prefix ||= (@options[:tag_suffix] || "oddb").gsub(/^_|_$/, "").downcase
|
344
361
|
end
|
362
|
+
|
345
363
|
def report
|
346
364
|
lines = []
|
347
365
|
if @options[:calc]
|
@@ -350,45 +368,46 @@ module Oddb2xml
|
|
350
368
|
lines << Calc.report_conversion
|
351
369
|
lines << ParseComposition.report
|
352
370
|
end
|
353
|
-
if
|
371
|
+
if @options[:artikelstamm]
|
354
372
|
lines << "Generated artikelstamm.xml for Elexis"
|
355
373
|
lines += Builder.articlestamm_v5_info_lines
|
374
|
+
elsif @options[:address]
|
375
|
+
{
|
376
|
+
"Betrieb" => :@companies,
|
377
|
+
"Person" => :@people
|
378
|
+
}.each do |type, var|
|
379
|
+
lines << sprintf(
|
380
|
+
"#{type} addresses: %i", instance_variable_get(var).length
|
381
|
+
)
|
382
|
+
end
|
356
383
|
else
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
indices = @refdata_types[type].values.flatten.length
|
384
|
+
types.each do |type|
|
385
|
+
if @refdata_types[type]
|
386
|
+
indices = @refdata_types[type].values.flatten.length
|
361
387
|
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
else
|
367
|
-
migel_xls = @migel.values.compact.select{|m| !m[:pharmacode]}.map{|m| m[:pharmacode] }
|
368
|
-
indices += (migel_xls - nonpharmas).length # ignore duplicates, null
|
369
|
-
end
|
370
|
-
lines << sprintf("\tNonPharma products: %i", indices)
|
388
|
+
if type == :nonpharma
|
389
|
+
nonpharmas = @refdata_types[type].keys
|
390
|
+
if SKIP_MIGEL_DOWNLOADER
|
391
|
+
indices + nonpharmas.length
|
371
392
|
else
|
372
|
-
|
393
|
+
migel_xls = @migel.values.compact.select { |m| !m[:pharmacode] }.map { |m| m[:pharmacode] }
|
394
|
+
indices += (migel_xls - nonpharmas).length # ignore duplicates, null
|
373
395
|
end
|
396
|
+
lines << sprintf("\tNonPharma products: %i", indices)
|
397
|
+
else
|
398
|
+
lines << sprintf("\tPharma products: %i", indices)
|
374
399
|
end
|
375
400
|
end
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
else
|
380
|
-
{
|
381
|
-
'Betrieb' => :@companies,
|
382
|
-
'Person' => :@people
|
383
|
-
}.each do |type, var|
|
384
|
-
lines << sprintf(
|
385
|
-
"#{type} addresses: %i", self.instance_variable_get(var).length)
|
386
|
-
end
|
401
|
+
end
|
402
|
+
if @options[:extended] || @options[:artikelstamm]
|
403
|
+
lines << sprintf("\tInformation items zur Rose: %i", @infos_zur_rose.length)
|
387
404
|
end
|
388
405
|
end
|
389
406
|
puts lines.join("\n")
|
390
407
|
end
|
391
|
-
|
408
|
+
|
409
|
+
# RefData
|
410
|
+
def types
|
392
411
|
@_types ||=
|
393
412
|
if @options[:nonpharma] || @options[:artikelstamm]
|
394
413
|
[:pharma, :nonpharma]
|