gtin2atc 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/History.txt +4 -0
- data/lib/gtin2atc/builder.rb +108 -112
- data/lib/gtin2atc/downloader.rb +3 -3
- data/lib/gtin2atc/options.rb +3 -0
- data/lib/gtin2atc/version.rb +1 -1
- data/spec/builder_spec.rb +21 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5fde24bd193bb317155d193187921c62d47b9694
|
4
|
+
data.tar.gz: eec181694b853f52ee99d275e276291655f72d24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adaabdf14c6ec0ea883e4969c9e94b0beb22e491843474323845911c81d2a7d796f418e8f99734f23d1a29618a4859be1e048dca01191941eceaaa56b1acf984
|
7
|
+
data.tar.gz: 106691a04f037e14f49725626a6a069830313922645c3ae09147995293f09512f857e2ad09eb917d2e64b63c9c4a37628d4424f7884b3013763086a3d57c701e
|
data/Gemfile.lock
CHANGED
data/History.txt
CHANGED
data/lib/gtin2atc/builder.rb
CHANGED
@@ -11,6 +11,7 @@ module Gtin2atc
|
|
11
11
|
def initialize(opts)
|
12
12
|
Util.set_logging(opts[:log])
|
13
13
|
@do_compare = opts[:compare]
|
14
|
+
@gen_reports = opts[:compare] and opts[:full]
|
14
15
|
Util.debug_msg "Builder: opts are #{opts} @do_compare is #{@do_compare}"
|
15
16
|
@data_swissmedic = {}
|
16
17
|
@data_bag = {}
|
@@ -55,7 +56,7 @@ module Gtin2atc
|
|
55
56
|
data
|
56
57
|
end
|
57
58
|
def swissindex_xml_extractor
|
58
|
-
@swissindex =
|
59
|
+
@swissindex = SwissindexDownloader.new
|
59
60
|
xml = @swissindex.download
|
60
61
|
Util.debug_msg "swissindex_xml_extractor xml is #{xml.size} bytes long"
|
61
62
|
data = {}
|
@@ -76,7 +77,7 @@ module Gtin2atc
|
|
76
77
|
end
|
77
78
|
def bag_xml_extractor
|
78
79
|
data = {}
|
79
|
-
@bag =
|
80
|
+
@bag = BagDownloader.new
|
80
81
|
xml = @bag.download
|
81
82
|
Util.debug_msg "bag_xml_extractor xml is #{xml.size} bytes long"
|
82
83
|
|
@@ -117,7 +118,7 @@ module Gtin2atc
|
|
117
118
|
end
|
118
119
|
end
|
119
120
|
end
|
120
|
-
msg = "
|
121
|
+
msg = "swissindex: Extracted #{gtins_to_parse.size} of #{@data_swissindex.size} items into #{output_name} for #{gtins_to_parse}"
|
121
122
|
Util.debug_msg(msg)
|
122
123
|
return unless @do_compare
|
123
124
|
@data_bag = bag_xml_extractor
|
@@ -128,7 +129,7 @@ module Gtin2atc
|
|
128
129
|
csvfile << [gtin, item[:atc_code], item[:description]]
|
129
130
|
end
|
130
131
|
end
|
131
|
-
Util.debug_msg "
|
132
|
+
Util.debug_msg "bag: Extracted #{gtins_to_parse.size} of #{@data_bag.size} items into #{output_name} for #{gtins_to_parse}"
|
132
133
|
@data_swissmedic = swissmedic_xls_extractor
|
133
134
|
output_name = File.join(Util.get_archive, 'gtin2atc_swissmedic.csv')
|
134
135
|
CSV.open(output_name,'w+') do |csvfile|
|
@@ -137,26 +138,26 @@ module Gtin2atc
|
|
137
138
|
csvfile << [gtin, item[:atc_code], item[:pharmacode], item[:description]]
|
138
139
|
end
|
139
140
|
end
|
140
|
-
Util.debug_msg "
|
141
|
+
Util.debug_msg "swissmedic: Extracted #{@data_swissmedic.size} items into #{output_name}"
|
141
142
|
check_bag
|
142
143
|
check_swissmedic
|
143
144
|
compare
|
144
145
|
end
|
145
146
|
# require 'pry';
|
146
147
|
def check_bag
|
147
|
-
matching_atc_codes =
|
148
|
+
matching_atc_codes = []
|
148
149
|
|
149
|
-
not_in_swissmedic =
|
150
|
-
match_in_swissmedic =
|
151
|
-
shorter_in_swissmedic =
|
152
|
-
longer_in_swissmedic =
|
153
|
-
different_atc_in_swissmedic =
|
150
|
+
not_in_swissmedic = []
|
151
|
+
match_in_swissmedic = []
|
152
|
+
shorter_in_swissmedic = []
|
153
|
+
longer_in_swissmedic = []
|
154
|
+
different_atc_in_swissmedic = []
|
154
155
|
|
155
|
-
not_in_swissindex =
|
156
|
-
match_in_swissindex =
|
157
|
-
shorter_in_swissindex =
|
158
|
-
longer_in_swissindex =
|
159
|
-
different_atc_in_swissindex =
|
156
|
+
not_in_swissindex = []
|
157
|
+
match_in_swissindex = []
|
158
|
+
shorter_in_swissindex = []
|
159
|
+
longer_in_swissindex = []
|
160
|
+
different_atc_in_swissindex = []
|
160
161
|
j = 0
|
161
162
|
@data_bag.each{
|
162
163
|
|gtin, item|
|
@@ -166,43 +167,32 @@ module Gtin2atc
|
|
166
167
|
if @data_swissmedic[gtin] and @data_swissindex[gtin] and
|
167
168
|
atc_code == @data_swissmedic[gtin][:atc_code] and
|
168
169
|
atc_code == @data_swissindex[gtin][:atc_code]
|
169
|
-
|
170
|
-
matching_atc_codes += 1
|
170
|
+
matching_atc_codes << "#{gtin}: matching_atc_codes swissindex #{item} #{@data_swissmedic[gtin][:atc_code]} and #{@data_swissindex[gtin][:atc_code]}"
|
171
171
|
next
|
172
172
|
end
|
173
173
|
|
174
174
|
if not @data_swissindex[gtin]
|
175
|
-
|
176
|
-
not_in_swissindex += 1
|
175
|
+
not_in_swissindex << "#{gtin}: Not in swissindex #{item}"
|
177
176
|
elsif atc_code == @data_swissindex[gtin][:atc_code]
|
178
|
-
|
179
|
-
match_in_swissindex += 1
|
177
|
+
match_in_swissindex << "swissindex #{gtin}: ATC code #{atc_code} matches swissindex #{@data_swissindex[gtin][:atc_code]}"
|
180
178
|
elsif atc_code.length < @data_swissindex[gtin][:atc_code].length
|
181
|
-
longer_in_swissindex
|
182
|
-
Util.debug_msg "SwissIndex #{gtin}: ATC code #{atc_code} longer in swissindex #{@data_swissindex[gtin][:atc_code]}"
|
179
|
+
longer_in_swissindex << "swissindex #{gtin}: ATC code #{atc_code} longer in swissindex #{@data_swissindex[gtin][:atc_code]}"
|
183
180
|
elsif atc_code.length > @data_swissindex[gtin][:atc_code].length
|
184
|
-
shorter_in_swissindex
|
185
|
-
Util.debug_msg "SwissIndex #{gtin}: ATC code #{atc_code} shorter in swissindex #{@data_swissindex[gtin][:atc_code]}"
|
181
|
+
shorter_in_swissindex << "swissindex #{gtin}: ATC code #{atc_code} shorter in swissindex #{@data_swissindex[gtin][:atc_code]}"
|
186
182
|
else
|
187
|
-
|
188
|
-
Util.debug_msg "SwissIndex #{gtin}: ATC code #{atc_code} differs from swissindex #{@data_swissindex[gtin][:atc_code]}"
|
183
|
+
matching_atc_codes << "swissindex #{gtin}: ATC code #{atc_code} differs from swissindex #{@data_swissindex[gtin][:atc_code]}"
|
189
184
|
end
|
190
185
|
|
191
|
-
if not
|
192
|
-
|
193
|
-
not_in_swissmedic += 1
|
186
|
+
if not @data_swissmedic[gtin]
|
187
|
+
not_in_swissmedic << "#{gtin}: Not in swissmedic #{item}"
|
194
188
|
elsif atc_code == @data_swissmedic[gtin][:atc_code]
|
195
|
-
|
196
|
-
match_in_swissmedic += 1
|
189
|
+
match_in_swissmedic << "swissmedic #{gtin}: ATC code #{atc_code} matches swissmedic #{@data_swissmedic[gtin][:atc_code]}"
|
197
190
|
elsif atc_code.length < @data_swissmedic[gtin][:atc_code].length
|
198
|
-
longer_in_swissmedic
|
199
|
-
Util.debug_msg "SwissMedic #{gtin}: ATC code #{atc_code} longer in swissmedic #{@data_swissmedic[gtin][:atc_code]}"
|
191
|
+
longer_in_swissmedic << "swissmedic #{gtin}: ATC code #{atc_code} longer in swissmedic #{@data_swissmedic[gtin][:atc_code]}"
|
200
192
|
elsif atc_code.length > @data_swissmedic[gtin][:atc_code].length
|
201
|
-
shorter_in_swissmedic
|
202
|
-
Util.debug_msg "SwissMedic #{gtin}: ATC code #{atc_code} shorter in swissmedic #{@data_swissmedic[gtin][:atc_code]}"
|
193
|
+
shorter_in_swissmedic << "swissmedic #{gtin}: ATC code #{atc_code} shorter in swissmedic #{@data_swissmedic[gtin][:atc_code]}"
|
203
194
|
else
|
204
|
-
different_atc_in_swissmedic
|
205
|
-
Util.debug_msg "SwissMedic #{gtin}: ATC code #{atc_code} differs from swissmedic #{@data_swissmedic[gtin][:atc_code]}"
|
195
|
+
different_atc_in_swissmedic << "swissmedic #{gtin}: ATC code #{atc_code} differs from swissmedic #{@data_swissmedic[gtin][:atc_code]}"
|
206
196
|
end
|
207
197
|
total1 = not_in_swissindex + match_in_swissindex + longer_in_swissindex + shorter_in_swissindex + different_atc_in_swissindex
|
208
198
|
total2 = not_in_swissmedic + match_in_swissmedic + longer_in_swissmedic + shorter_in_swissmedic + different_atc_in_swissmedic
|
@@ -210,132 +200,138 @@ module Gtin2atc
|
|
210
200
|
# binding.pry if j != (total2 + matching_atc_codes)
|
211
201
|
# Util.debug_msg "#{gtin}: j #{j} finished #{total1} #{total2} #{atc_code} matching_atc_codes #{matching_atc_codes}"
|
212
202
|
}
|
213
|
-
Util.info "Result of verifing data from
|
214
|
-
|
215
|
-
|
203
|
+
Util.info "Result of verifing data from bag (SL):
|
204
|
+
bag-data fetched from #{@bag.origin}.
|
205
|
+
bag had #{@data_bag.size} entries
|
216
206
|
#{@bag_entries_without_gtin.size} entries had no GTIN field
|
217
|
-
Not in
|
218
|
-
Not in
|
219
|
-
Comparing ATC-Codes between BAG and Swissmedic
|
220
|
-
#{sprintf("%6d", matching_atc_codes)} items had the same ATC code in BAG, SwissIndex and SwissMedic
|
221
|
-
#{sprintf("%6d", match_in_swissindex)} are the same in SwissMedic and BAG
|
222
|
-
#{sprintf("%6d", different_atc_in_swissmedic)} are different in SwissMedic and BAG
|
223
|
-
#{sprintf("%6d", shorter_in_swissmedic)} are shorter in SwissMedic than in BAG
|
224
|
-
#{sprintf("%6d", longer_in_swissindex)} are longer in SwissMedic than in BAG
|
225
|
-
Comparing ATC-Codes between BAG and Swissindex
|
226
|
-
#{sprintf("%6d", matching_atc_codes)} items had the same ATC code in BAG, SwissIndex and SwissMedic
|
227
|
-
#{sprintf("%6d", match_in_swissindex)} are the same in SwissIndex and BAG
|
228
|
-
#{sprintf("%6d", different_atc_in_swissindex)} are different in SwissMedic and BAG
|
229
|
-
#{sprintf("%6d", shorter_in_swissindex)} are shorter in SwissIndex than in BAG
|
230
|
-
#{sprintf("%6d", longer_in_swissindex)} are longer in SwissIndex than in BAG
|
207
|
+
Not in swissmedic #{not_in_swissmedic.size}
|
208
|
+
Not in swissindex #{not_in_swissindex.size}
|
231
209
|
"
|
210
|
+
Util.info "Comparing ATC-Codes between bag and swissmedic"
|
211
|
+
report('compare_bag_to_swissmedic', 'items had the same ATC code in bag, swissindex and swissmedic', matching_atc_codes)
|
212
|
+
report('compare_bag_to_swissmedic', 'are the same in swissmedic and bag', match_in_swissmedic)
|
213
|
+
report('compare_bag_to_swissmedic', 'are different in swissmedic and bag', different_atc_in_swissmedic)
|
214
|
+
report('compare_bag_to_swissmedic', 'are shorter in swissmedic than in bag', shorter_in_swissmedic)
|
215
|
+
report('compare_bag_to_swissmedic', 'are longer in swissmedic than in bag', longer_in_swissmedic)
|
216
|
+
|
217
|
+
Util.info "Comparing ATC-Codes between bag and swissindex"
|
218
|
+
report('compare_bag_to_swissindex', 'items had the same ATC code in bag, swissindex and swissmedic', matching_atc_codes)
|
219
|
+
report('compare_bag_to_swissindex', 'are the same in swissindex and bag', match_in_swissindex)
|
220
|
+
report('compare_bag_to_swissindex', 'are different in swissmedic and bag', different_atc_in_swissindex)
|
221
|
+
report('compare_bag_to_swissindex', 'are shorter in swissindex than in bag', shorter_in_swissindex)
|
222
|
+
report('compare_bag_to_swissindex', 'are longer in swissindex than in bag', longer_in_swissindex)
|
232
223
|
end
|
233
224
|
|
225
|
+
def report(topic, msg, details)
|
226
|
+
full_msg = "#{topic}: #{details.size} #{msg}"
|
227
|
+
Util.info " #{full_msg}"
|
228
|
+
return unless @gen_reports
|
229
|
+
File.open((full_msg+'.txt').gsub(/[: ,]+/, '_'), 'w+') {
|
230
|
+
|file|
|
231
|
+
file.puts full_msg
|
232
|
+
details.each{|detail| file.puts detail }
|
233
|
+
}
|
234
|
+
end
|
234
235
|
def check_swissmedic
|
235
|
-
matching =
|
236
|
-
not_in_bag =
|
237
|
-
not_in_swissindex =
|
238
|
-
matching_atc_codes =
|
239
|
-
shorter_in_swissmedic =
|
240
|
-
longer_in_swissindex =
|
241
|
-
different_atc =
|
236
|
+
matching = []
|
237
|
+
not_in_bag = []
|
238
|
+
not_in_swissindex = []
|
239
|
+
matching_atc_codes = []
|
240
|
+
shorter_in_swissmedic = []
|
241
|
+
longer_in_swissindex = []
|
242
|
+
different_atc = []
|
242
243
|
@data_swissmedic.each{
|
243
244
|
|gtin, item|
|
244
|
-
|
245
|
-
|
245
|
+
atc_code = item[:atc_code]
|
246
|
+
if @data_bag[gtin] and
|
247
|
+
@data_swissmedic[gtin] and
|
248
|
+
@data_bag[gtin] and
|
249
|
+
atc_code.eql?(@data_bag[gtin][1]) and
|
250
|
+
atc_code.eql?(@data_swissindex[gtin][1])
|
251
|
+
matching << "#{gtin} #{atc_code} #{@data_swissmedic[gtin][1]} match in bag, swissmedic and swissindex"
|
246
252
|
next
|
247
253
|
end
|
248
254
|
unless @data_swissindex[gtin]
|
249
|
-
|
250
|
-
not_in_swissindex += 1
|
255
|
+
not_in_swissindex << "Swissmedic #{gtin}: Not in swissindex #{item}"
|
251
256
|
next
|
252
257
|
end
|
253
258
|
if item[:atc_code] == @data_swissindex[gtin][:atc_code]
|
254
|
-
|
255
|
-
matching_atc_codes += 1
|
259
|
+
matching_atc_codes << "swissindex #{gtin}: ATC code #{item[:atc_code]} matches swissindex #{@data_swissindex[gtin][:atc_code]}"
|
256
260
|
elsif item[:atc_code].length < @data_swissindex[gtin][:atc_code].length
|
257
|
-
longer_in_swissindex
|
258
|
-
Util.debug_msg "SwissIndex #{gtin}: ATC code #{item[:atc_code]} longer in swissindex #{@data_swissindex[gtin][:atc_code]}"
|
261
|
+
longer_in_swissindex << "swissindex #{gtin}: ATC code #{item[:atc_code]} longer in swissindex #{@data_swissindex[gtin][:atc_code]}"
|
259
262
|
elsif item[:atc_code].length > @data_swissindex[gtin][:atc_code].length
|
260
|
-
shorter_in_swissmedic
|
261
|
-
Util.debug_msg "SwissIndex #{gtin}: ATC code #{item[:atc_code]} shorter in swissindex #{@data_swissindex[gtin][:atc_code]}"
|
263
|
+
shorter_in_swissmedic << "swissindex #{gtin}: ATC code #{item[:atc_code]} shorter in swissindex #{@data_swissindex[gtin][:atc_code]}"
|
262
264
|
else
|
263
|
-
different_atc
|
264
|
-
Util.debug_msg "SwissIndex #{gtin}: ATC code #{item[:atc_code]} differs from swissindex #{@data_swissindex[gtin][:atc_code]}"
|
265
|
+
different_atc << "swissindex #{gtin}: ATC code #{item[:atc_code]} differs from swissindex #{@data_swissindex[gtin][:atc_code]}"
|
265
266
|
end
|
266
267
|
unless @data_bag[gtin]
|
267
|
-
|
268
|
-
not_in_bag += 1
|
268
|
+
not_in_bag << "#{gtin}: Not in bag #{item}"
|
269
269
|
next
|
270
270
|
end
|
271
271
|
}
|
272
272
|
Util.info "Result of verifing data from swissmedic:
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
Matching #{matching} items.
|
277
|
-
Not in
|
278
|
-
Not in
|
279
|
-
Comparing ATC-Codes between
|
280
|
-
#{sprintf("%6d", matching_atc_codes)} match
|
281
|
-
#{sprintf("%6d", different_atc)} are different
|
282
|
-
#{sprintf("%6d", matching_atc_codes)} are the same in SwissIndex and SwissMedic
|
283
|
-
#{sprintf("%6d", shorter_in_swissmedic)} are shorter in SwissIndex
|
284
|
-
#{sprintf("%6d", longer_in_swissindex)} are longer in SwissIndex
|
273
|
+
swissmedic had #{@data_swissmedic.size} entries. Fetched from #{@swissmedic.origin}
|
274
|
+
swissindex #{@data_swissindex.size} entries. Fetched from #{@swissindex.origin}
|
275
|
+
bag #{@data_bag.size} entries. #{@bag_entries_without_gtin.size} entries had no GTIN field. Fetched from #{@bag.origin}
|
276
|
+
Matching #{matching.size} items.
|
277
|
+
Not in bag #{not_in_bag.size}
|
278
|
+
Not in swissindex #{not_in_swissindex.size}
|
279
|
+
Comparing ATC-Codes between swissmedic and swissindex
|
285
280
|
"
|
281
|
+
report('swissmedic', 'match in swissindex and swissmedic', matching_atc_codes)
|
282
|
+
report('swissmedic', 'are different in swissindex and swissmedic', different_atc)
|
283
|
+
report('swissmedic', 'are the same in swissindex and swissmedic', matching_atc_codes)
|
284
|
+
report('swissmedic', 'are shorter in swissindex', shorter_in_swissmedic)
|
285
|
+
report('swissmedic', 'are longer in swissindex', longer_in_swissindex)
|
286
286
|
end
|
287
287
|
|
288
288
|
def compare
|
289
289
|
all_gtin = @data_bag.merge(@data_swissindex).merge(@data_swissmedic).sort
|
290
|
-
matching_atc_codes =
|
291
|
-
not_in_bag =
|
292
|
-
not_in_swissmedic =
|
293
|
-
not_in_swissindex =
|
294
|
-
different_atc =
|
290
|
+
matching_atc_codes = []
|
291
|
+
not_in_bag = []
|
292
|
+
not_in_swissmedic = []
|
293
|
+
not_in_swissindex = []
|
294
|
+
different_atc = []
|
295
295
|
all_gtin.each{
|
296
296
|
|gtin, item|
|
297
297
|
if @data_bag[gtin] and @data_swissindex[gtin] and @data_swissmedic[gtin] and
|
298
298
|
@data_bag[gtin][:atc_code] == @data_swissindex[gtin][:atc_code] and
|
299
299
|
@data_bag[gtin][:atc_code] == @data_swissindex[gtin][:atc_code]
|
300
|
-
matching_atc_codes
|
300
|
+
matching_atc_codes << "#{gtin}: ATC-Code #{@data_bag[gtin][:atc_code]} matches in bag, swissmedic and swissindex"
|
301
301
|
next
|
302
302
|
end
|
303
303
|
unless @data_swissmedic[gtin]
|
304
|
-
|
305
|
-
not_in_swissmedic += 1
|
304
|
+
not_in_swissmedic << "#{gtin}: Not in swissmedic #{item}"
|
306
305
|
next
|
307
306
|
end
|
308
307
|
unless @data_swissindex[gtin]
|
309
|
-
|
310
|
-
not_in_swissindex += 1
|
308
|
+
not_in_swissindex << "#{gtin}: Not in swissindex #{item}"
|
311
309
|
next
|
312
310
|
end
|
313
311
|
unless @data_bag[gtin]
|
314
|
-
|
315
|
-
not_in_bag += 1
|
312
|
+
not_in_bag << "#{gtin}: Not in bag #{item}"
|
316
313
|
next
|
317
314
|
end
|
318
|
-
different_atc
|
319
|
-
Util.debug_msg "#{gtin}: ATC code differs BAG #{@data_bag[gtin][:atc_code]} swissindex #{@data_swissindex[gtin][:atc_code]}"
|
315
|
+
different_atc << "#{gtin}: ATC code differs bag #{@data_bag[gtin][:atc_code]} swissindex #{@data_swissindex[gtin][:atc_code]}"
|
320
316
|
}
|
321
317
|
Util.info "Comparing all GTIN-codes:
|
322
318
|
Found infos about #{all_gtin.size} entries
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
#{sprintf("%6d", matching_atc_codes)} items had the same ATC code in BAG, SwissIndex and SwissMedic
|
327
|
-
#{sprintf("%6d", not_in_bag)} not in BAG
|
328
|
-
#{sprintf("%6d", not_in_swissindex)} not in SwissIndex
|
329
|
-
#{sprintf("%6d", not_in_swissmedic)} not in SwissMedic
|
330
|
-
#{sprintf("%6d", different_atc)} ATC-Codes differed
|
319
|
+
bag #{@data_bag.size} entries. #{@bag_entries_without_gtin.size} entries had no GTIN field. Fetched from #{@bag.origin}
|
320
|
+
swissindex #{@data_swissindex.size} entries. Fetched from #{@swissindex.origin}
|
321
|
+
swissmedic #{@data_swissmedic.size} entries. Fetched from #{@swissmedic.origin}
|
331
322
|
"
|
323
|
+
report('compare_all_gtins', 'items had the same ATC code in bag, swissindex and swissmedic', matching_atc_codes)
|
324
|
+
report('compare_all_gtins', 'not in bag', not_in_bag)
|
325
|
+
report('compare_all_gtins', 'not in swissindex', not_in_swissindex)
|
326
|
+
report('compare_all_gtins', 'not in swissmedic', not_in_swissmedic)
|
327
|
+
report('compare_all_gtins', 'ATC-Codes differed', different_atc)
|
332
328
|
end
|
333
329
|
end
|
334
330
|
class Swissmedic
|
335
331
|
def Swissmedic.get_latest
|
336
332
|
Util.debug_msg 'test'
|
337
333
|
@index_url = 'https://www.swissmedic.ch/arzneimittel/00156/00221/00222/00230/index.html?lang=de'
|
338
|
-
Util.debug_msg("
|
334
|
+
Util.debug_msg("swissmedicPlugin @index_url #{@index_url}")
|
339
335
|
latest_name, target = Util.get_latest_and_dated_name('Packungen', '.xlsx')
|
340
336
|
if File.exist?(target)
|
341
337
|
Util.debug_msg "#{__FILE__}: #{__LINE__} skip writing #{target} as it already exists and is #{File.size(target)} bytes."
|
data/lib/gtin2atc/downloader.rb
CHANGED
@@ -115,7 +115,7 @@ module Gtin2atc
|
|
115
115
|
xml
|
116
116
|
end
|
117
117
|
end
|
118
|
-
class
|
118
|
+
class BagDownloader < Downloader
|
119
119
|
def init
|
120
120
|
super
|
121
121
|
@url ||= 'http://bag.e-mediat.net/SL2007.Web.External/File.axd?file=XMLPublications.zip'
|
@@ -125,7 +125,7 @@ module Gtin2atc
|
|
125
125
|
end
|
126
126
|
def download
|
127
127
|
file = File.join(WorkDir, 'XMLPublications.zip')
|
128
|
-
Gtin2atc.log "
|
128
|
+
Gtin2atc.log "BagDownloader #{__LINE__}: #{file} from #{@url}"
|
129
129
|
if File.exists?(file) and diff_hours = ((Time.now-File.ctime(file)).to_i/3600) and diff_hours < 24
|
130
130
|
Util.debug_msg "Skip download of #{file} as only #{diff_hours} hours old"
|
131
131
|
else
|
@@ -190,7 +190,7 @@ module Gtin2atc
|
|
190
190
|
end
|
191
191
|
end
|
192
192
|
|
193
|
-
class
|
193
|
+
class SwissindexDownloader < Downloader
|
194
194
|
def initialize(options={}, type=:pharma, lang='DE')
|
195
195
|
@type = (type == :pharma ? 'Pharma' : 'NonPharma')
|
196
196
|
@lang = lang
|
data/lib/gtin2atc/options.rb
CHANGED
@@ -9,6 +9,7 @@ module Gtin2atc
|
|
9
9
|
{
|
10
10
|
:log => false,
|
11
11
|
:compare => false,
|
12
|
+
:full => false,
|
12
13
|
}
|
13
14
|
end
|
14
15
|
def Options.help
|
@@ -25,6 +26,7 @@ Usage:
|
|
25
26
|
* BAG http://bag.e-mediat.net/SL2007.Web.External/File.axd?file=XMLPublications.zip
|
26
27
|
* SwissIndex e-mediat: http://swissindex.e-mediat.net/SwissindexPharma_out_V101
|
27
28
|
* or if the ATC_Code does not not match
|
29
|
+
-- full if --compare and --full given produce 15 detailed report files
|
28
30
|
-h, --help Show this help message.
|
29
31
|
EOS
|
30
32
|
end
|
@@ -33,6 +35,7 @@ EOS
|
|
33
35
|
@opts = Options.default_opts
|
34
36
|
@parser.on('--log') {|v| @opts[:log] = true }
|
35
37
|
@parser.on('--compare') {|v| @opts[:compare] = true }
|
38
|
+
@parser.on('--full') {|v| @opts[:full] = true }
|
36
39
|
@parser.on_tail('-h', '--help') { puts Options.help; exit }
|
37
40
|
end
|
38
41
|
end
|
data/lib/gtin2atc/version.rb
CHANGED
data/spec/builder_spec.rb
CHANGED
@@ -60,7 +60,7 @@ describe Gtin2atc::Builder do
|
|
60
60
|
it 'should produce more log output' do
|
61
61
|
@res = buildr_capture(:stdout){ cli.run }
|
62
62
|
@res.match(/swissindex_xml_extractor/).should_not == nil
|
63
|
-
@res.match(/
|
63
|
+
@res.match(/swissindex: Extracted/).should_not == nil
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
@@ -129,9 +129,9 @@ describe Gtin2atc::Builder do
|
|
129
129
|
[ /Found infos/,
|
130
130
|
/Fetched from/,
|
131
131
|
/Matching/,
|
132
|
-
/not in
|
133
|
-
/not in
|
134
|
-
/not in
|
132
|
+
/not in bag/,
|
133
|
+
/not in swissmedic/,
|
134
|
+
/not in swissindex/,
|
135
135
|
/ATC-Codes diff/,
|
136
136
|
].each {
|
137
137
|
|pattern|
|
@@ -144,4 +144,21 @@ describe Gtin2atc::Builder do
|
|
144
144
|
|
145
145
|
end
|
146
146
|
|
147
|
+
context 'when --compare --full is given' do
|
148
|
+
let(:cli) do
|
149
|
+
options = Gtin2atc::Options.new
|
150
|
+
options.parser.parse!('--compare --full'.split(' '))
|
151
|
+
Gtin2atc::Builder.new(options.opts)
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'should produce a many report files' do
|
155
|
+
@res = buildr_capture(:stdout){ cli.run }
|
156
|
+
Dir.glob(Gtin2atc::WorkDir + '/compare_all_gtins*.txt').size.should == 5
|
157
|
+
Dir.glob(Gtin2atc::WorkDir + '/swissmedic_*.txt').size.should == 5
|
158
|
+
Dir.glob(Gtin2atc::WorkDir + '/compare_bag_to_swissindex_*.txt').size.should == 5
|
159
|
+
Dir.glob(Gtin2atc::WorkDir + '/compare_bag_to_swissmedic_*.txt').size.should == 5
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|
163
|
+
|
147
164
|
end
|