swissmedic-diff 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- swissmedic-diff (0.2.0)
4
+ swissmedic-diff (0.2.1)
5
5
  nokogiri
6
6
  rubyXL (= 3.3.1)
7
7
  rubyzip
@@ -12,14 +12,10 @@ GEM
12
12
  specs:
13
13
  ansi (1.5.0)
14
14
  builder (3.2.2)
15
+ byebug (4.0.5)
16
+ columnize (= 0.9.0)
15
17
  coderay (1.1.0)
16
18
  columnize (0.9.0)
17
- debugger (1.6.8)
18
- columnize (>= 0.3.1)
19
- debugger-linecache (~> 1.2.0)
20
- debugger-ruby_core_source (~> 1.3.5)
21
- debugger-linecache (1.2.0)
22
- debugger-ruby_core_source (1.3.8)
23
19
  hoe (3.13.1)
24
20
  rake (>= 0.8, < 11.0)
25
21
  method_source (0.8.2)
@@ -36,9 +32,12 @@ GEM
36
32
  coderay (~> 1.1.0)
37
33
  method_source (~> 0.8.1)
38
34
  slop (~> 3.4)
39
- pry-debugger (0.2.3)
40
- debugger (~> 1.3)
41
- pry (>= 0.9.10, < 0.11.0)
35
+ pry-byebug (3.1.0)
36
+ byebug (~> 4.0)
37
+ pry (~> 0.10)
38
+ pry-doc (0.8.0)
39
+ pry (~> 0.9)
40
+ yard (~> 0.8)
42
41
  rake (10.4.2)
43
42
  ruby-ole (1.2.11.8)
44
43
  ruby-progressbar (1.7.5)
@@ -49,6 +48,7 @@ GEM
49
48
  slop (3.6.0)
50
49
  spreadsheet (1.0.3)
51
50
  ruby-ole (>= 1.0)
51
+ yard (0.8.7.6)
52
52
 
53
53
  PLATFORMS
54
54
  ruby
@@ -57,7 +57,8 @@ DEPENDENCIES
57
57
  hoe
58
58
  minitest
59
59
  minitest-reporters
60
- pry-debugger
60
+ pry-byebug
61
+ pry-doc
61
62
  rake
62
63
  swissmedic-diff!
63
64
 
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ === 0.2.1 / 06.07.2015
2
+
3
+ * Fix problems comparing dates (using to_date.start)
4
+ * Assume nothing has changed when comparing nil with an emtpy string
5
+ * Revert nr of paramenters of diff method to previous version, to make oddb.org happy again
6
+
1
7
  === 0.2.0 / 03.07.2015
2
8
 
3
9
  * Abort if Swissmedic introduces incompatible header lines
data/lib/compatibility.rb CHANGED
@@ -21,23 +21,6 @@ module Spreadsheet
21
21
  end
22
22
  end
23
23
  end
24
- def Spreadsheet.date_cell(row, idx)
25
- if row.kind_of?(Spreadsheet::Excel::Row)
26
- row.at(idx) && row.date(idx)
27
- else
28
- data = row[idx]
29
- if data.is_a?(RubyXL::Cell)
30
- return data.value.respond_to?(:to_i) ? data.value.to_i : data.value
31
- return data.value if data.value.is_a?(DateTime)
32
- if data.value.class.to_s == 'DateTime'
33
- puts "data is_a RubyXL::Cell and value #{data.value.class} is_a? Date #{data.value.is_a?(Date)} DateTime #{data.value.is_a?(DateTime)}"
34
- return Date.new(1899,12,30)+data.to_date.value.to_i
35
- else
36
- return Date.new(1899,12,30)+data.value.to_i if data.is_a?(RubyXL::Cell)
37
- end
38
- end
39
- end
40
- end
41
24
  end
42
25
 
43
26
  module RubyXL
@@ -148,25 +148,25 @@ class SwissmedicDiff
148
148
  tbook = Spreadsheet.open(target)
149
149
  idx, prr, prp = nil
150
150
  multiples = {}
151
- latest_keys = get_column_indices(Spreadsheet.open(latest)).keys
152
- target_keys = get_column_indices(tbook).keys
151
+ @latest_keys = get_column_indices(Spreadsheet.open(latest)).keys
152
+ @target_keys = get_column_indices(tbook).keys
153
153
  each_valid_row(tbook) { |row|
154
- iksnr = cell(row, target_keys.index(:iksnr))
155
- seqnr = cell(row, target_keys.index(:seqnr))
156
- pacnr = cell(row, target_keys.index(:ikscd))
154
+ iksnr = cell(row, @target_keys.index(:iksnr))
155
+ seqnr = cell(row, @target_keys.index(:seqnr))
156
+ pacnr = cell(row, @target_keys.index(:ikscd))
157
157
  (multiples[iksnr] ||= {})
158
158
  if prr == iksnr && prp == pacnr
159
159
  idx += 1
160
160
  elsif previous = multiples[iksnr][pacnr]
161
161
  prr = iksnr
162
162
  prp = pacnr
163
- idx = previous[target_keys.size].to_i + 1
163
+ idx = previous[@target_keys.size].to_i + 1
164
164
  else
165
165
  prr = iksnr
166
166
  prp = pacnr
167
167
  idx = 0
168
168
  end
169
- row[target_keys.size] = idx
169
+ row[@target_keys.size] = idx
170
170
  (newest_rows[iksnr] ||= {})[pacnr] = row
171
171
  multiples[iksnr][pacnr] = row
172
172
  if(other = known_regs.delete([iksnr]))
@@ -176,12 +176,12 @@ class SwissmedicDiff
176
176
  end
177
177
  known_seqs.delete([iksnr, seqnr])
178
178
  if(other = known_pacs.delete([iksnr, pacnr, idx]))
179
- flags = rows_diff(row, target_keys, other, latest_keys, ignore)
179
+ flags = rows_diff(row, other, ignore)
180
180
  (changes[iksnr].concat flags).uniq!
181
181
  updates.push row unless flags.empty?
182
182
  else
183
- replacements.store [ iksnr, seqnr, cell(row, target_keys.index(:size)),
184
- cell(row, target_keys.index(:unit)) ], row
183
+ replacements.store [ iksnr, seqnr, cell(row, @target_keys.index(:size)),
184
+ cell(row, @target_keys.index(:unit)) ], row
185
185
  flags = changes[iksnr]
186
186
  flags.push(:sequence).uniq! unless(flags.include? :new)
187
187
  news.push row
@@ -189,8 +189,8 @@ class SwissmedicDiff
189
189
  }
190
190
  @diff.replacements = reps = {}
191
191
  known_pacs.each { |(iksnr, pacnr), row|
192
- key = [iksnr, '%02i' % cell(row, target_keys.index(:seqnr)).to_i,
193
- cell(row, target_keys.index(:size)), cell(row, target_keys.index(:unit))]
192
+ key = [iksnr, '%02i' % cell(row, @target_keys.index(:seqnr)).to_i,
193
+ cell(row, @target_keys.index(:size)), cell(row, @target_keys.index(:unit))]
194
194
  if(rep = replacements[key])
195
195
  changes[iksnr].push :replaced_package
196
196
  reps.store rep, pacnr
@@ -202,7 +202,7 @@ class SwissmedicDiff
202
202
  ## the keys in known_pacs don't include the sequence number (which
203
203
  # would prevent us from properly recognizing multi-sequence-Packages),
204
204
  # so we need complete the path to the package now
205
- key[1,0] = '%02i' % cell(row, target_keys.index(:seqnr)).to_i
205
+ key[1,0] = '%02i' % cell(row, @target_keys.index(:seqnr)).to_i
206
206
  key
207
207
  }
208
208
  @diff.sequence_deletions = known_seqs.keys
@@ -225,27 +225,27 @@ class SwissmedicDiff
225
225
  end
226
226
  def _known_data(latest, known_regs, known_seqs, known_pacs, newest_rows)
227
227
  lbook = Spreadsheet.open(latest)
228
+ @latest_keys = get_column_indices(lbook).keys
228
229
  idx, prr, prp = nil
229
230
  multiples = {}
230
- latest_keys = get_column_indices(lbook).keys
231
231
  each_valid_row(lbook) { |row|
232
- iksnr = cell(row, latest_keys.index(:iksnr))
233
- seqnr = cell(row, latest_keys.index(:seqnr))
234
- pacnr = cell(row, latest_keys.index(:ikscd))
232
+ iksnr = cell(row, @latest_keys.index(:iksnr))
233
+ seqnr = cell(row, @latest_keys.index(:seqnr))
234
+ pacnr = cell(row, @latest_keys.index(:ikscd))
235
235
  multiples[iksnr] ||= {}
236
236
  if prr == iksnr && prp == pacnr
237
237
  idx += 1
238
238
  elsif previous = multiples[iksnr][pacnr]
239
239
  prr = iksnr
240
240
  prp = pacnr
241
- idx = previous[latest_keys.size].to_i + 1
241
+ idx = previous[@latest_keys.size].to_i + 1
242
242
  else
243
243
  prr = iksnr
244
244
  prp = pacnr
245
245
  idx = 0
246
246
  end
247
247
  multiples[iksnr][pacnr] = row
248
- row[latest_keys.size] = idx
248
+ row[@latest_keys.size] = idx
249
249
  known_regs.store [iksnr], row
250
250
  known_seqs.store [iksnr, seqnr], row
251
251
  known_pacs.store [iksnr, pacnr, idx], row
@@ -257,15 +257,17 @@ class SwissmedicDiff
257
257
  row = rows.sort.first.last
258
258
  cell(row, COLUMNS_2014.keys.index(:name_base))
259
259
  end
260
- def rows_diff(row, row_keys, other, other_keys, ignore = [])
260
+ def rows_diff(row, other, ignore = [])
261
261
  flags = []
262
262
  COLUMNS_OLD.each_with_index {
263
263
  |key, idx|
264
264
  if !ignore.include?(key)
265
- left = _comparable(key, row, row_keys.index(key))
266
- right = _comparable(key, other, other_keys.index(key))
265
+ left = _comparable(key, row, @target_keys.index(key))
266
+ right = _comparable(key, other, @latest_keys.index(key))
267
+ next if left.is_a?(Date) and right.is_a?(Date) and left.start.eql?(right.start)
268
+ next if left.is_a?(String) and left.empty? and not right
269
+ next if right.is_a?(String) and right.empty? and not left
267
270
  if left != right
268
- puts "Pushing key #{key}: '#{left.inspect}' != '#{right.inspect}'" if $VERBOSE
269
271
  flags.push key
270
272
  end
271
273
  end
@@ -318,9 +320,9 @@ class SwissmedicDiff
318
320
  if cell = row[idx]
319
321
  case key
320
322
  when :registration_date, :expiry_date
321
- Spreadsheet.date_cell(row, idx)
323
+ row[idx].value.to_date
322
324
  when :seqnr
323
- sprintf "%02i", cell.to_i
325
+ sprintf "%02i", cell(row, idx).to_i
324
326
  else
325
327
  cell(row, idx).downcase.gsub(/\s+/, "")
326
328
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class SwissmedicDiff
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -23,10 +23,10 @@ module ODDB
23
23
  result = @diff.diff this_month, last_month, [:atc_class, :sequence_date]
24
24
  assert(result.changes.flatten.index('Zulassungs-Nummer') == nil, "Should not find Zulassungs-Nummer in changes")
25
25
  assert_equal(1, result.news.size)
26
- assert_equal(2, result.changes.size)
27
- assert_equal(1, result.updates.size)
26
+ assert_equal(1, result.changes.size)
27
+ assert_equal(0, result.updates.size)
28
28
  assert_equal(['65838'], result.news.collect{|x| x[0] if x[0] == '65838'})
29
- assert_equal({"65837"=>[:indication_sequence], "65838"=>[:new]}, result.changes)
29
+ assert_equal({"65838"=>[:new]}, result.changes)
30
30
  end
31
31
 
32
32
  def test_diff_wrong_header
@@ -37,21 +37,11 @@ module ODDB
37
37
  end
38
38
 
39
39
 
40
- def test_date_xlsx
41
- tbook = Spreadsheet.open(@january_2014)
42
- sheet = tbook.worksheet(0)
43
- assert_equal(nil, sheet.row(0)[8]) # sequence_date
44
- assert_equal(2010, sheet.row(4).date(8).year)
45
- assert_equal(26, sheet.row(4).date(8).day)
46
- assert_equal(26, Spreadsheet.date_cell(sheet.row(4), 8).day)
47
- assert_equal(2010, Spreadsheet.date_cell(sheet.row(4), 8).year)
48
- end
49
-
50
40
  def test_diff_xlsx_and_xlsx
51
41
  result = @diff.diff @february_2014, @january_2014, [:atc_class, :sequence_date]
52
42
  assert_equal 4, result.news.size
53
43
  expected = {
54
- "00277"=>[:name_base, :expiry_date, :indication_sequence],
44
+ "00277"=>[:name_base],
55
45
  "65040"=>[:sequence, :replaced_package],
56
46
  "60125"=>[:new],
57
47
  "61367"=>[:new],
@@ -106,14 +96,14 @@ module ODDB
106
96
  + 60125: Otriduo Schnupfen, Dosierspray
107
97
  + 61367: Hypericum-Mepha 250, Lactab
108
98
  - 00274: Cardio-Pulmo-Rénal Sérocytol, suppositoire
109
- > 00277: Coeur-Vaisseaux Sérocytol, Namensänderung; Namensänderung (Coeur-Vaisseaux Sérocytol, Namensänderung), Ablaufdatum der Zulassung (25.04.2020), Anwendungsgebiet Sequenz ()
99
+ > 00277: Coeur-Vaisseaux Sérocytol, Namensänderung; Namensänderung (Coeur-Vaisseaux Sérocytol, Namensänderung)
110
100
  > 00278: Colon Sérocytol, suppositoire; ATC-Code (J06AA)
111
101
  > 00279: Conjonctif Sérocytol, suppositoire; ATC-Code (D03AX04)
112
102
  > 65040: Panthoben, Salbe; Packungs-Nummer (001 -> 003)
113
103
  EOS
114
104
  assert_equal <<-EOS.strip, @diff.to_s(:name)
115
105
  - 00274: Cardio-Pulmo-Rénal Sérocytol, suppositoire
116
- > 00277: Coeur-Vaisseaux Sérocytol, Namensänderung; Namensänderung (Coeur-Vaisseaux Sérocytol, Namensänderung), Ablaufdatum der Zulassung (25.04.2020), Anwendungsgebiet Sequenz ()
106
+ > 00277: Coeur-Vaisseaux Sérocytol, Namensänderung; Namensänderung (Coeur-Vaisseaux Sérocytol, Namensänderung)
117
107
  > 00278: Colon Sérocytol, suppositoire; ATC-Code (J06AA)
118
108
  > 00279: Conjonctif Sérocytol, suppositoire; ATC-Code (D03AX04)
119
109
  + 61367: Hypericum-Mepha 250, Lactab
@@ -122,7 +112,7 @@ module ODDB
122
112
  EOS
123
113
  assert_equal <<-EOS.strip, @diff.to_s(:registration)
124
114
  - 00274: Cardio-Pulmo-Rénal Sérocytol, suppositoire
125
- > 00277: Coeur-Vaisseaux Sérocytol, Namensänderung; Namensänderung (Coeur-Vaisseaux Sérocytol, Namensänderung), Ablaufdatum der Zulassung (25.04.2020), Anwendungsgebiet Sequenz ()
115
+ > 00277: Coeur-Vaisseaux Sérocytol, Namensänderung; Namensänderung (Coeur-Vaisseaux Sérocytol, Namensänderung)
126
116
  > 00278: Colon Sérocytol, suppositoire; ATC-Code (J06AA)
127
117
  > 00279: Conjonctif Sérocytol, suppositoire; ATC-Code (D03AX04)
128
118
  + 60125: Otriduo Schnupfen, Dosierspray
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swissmedic-diff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
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: 2015-07-04 00:00:00.000000000 Z
12
+ date: 2015-07-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdoc
@@ -101,18 +101,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
101
101
  - - ! '>='
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
- segments:
105
- - 0
106
- hash: -1183980882964765712
107
104
  required_rubygems_version: !ruby/object:Gem::Requirement
108
105
  none: false
109
106
  requirements:
110
107
  - - ! '>='
111
108
  - !ruby/object:Gem::Version
112
109
  version: '0'
113
- segments:
114
- - 0
115
- hash: -1183980882964765712
116
110
  requirements: []
117
111
  rubyforge_project:
118
112
  rubygems_version: 1.8.23.2