Class: TestOuwerkerkPlugin

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
test/test_plugin/ouwerkerk.rb

Defined Under Namespace

Classes: StubApp, StubCompany, StubDose, StubLogGroup, StubPackage, StubPointer, StubRegistration, StubSequence

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



76
77
78
79
80
81
82
83
84
# File 'test/test_plugin/ouwerkerk.rb', line 76

def setup
  @app = StubApp.new
  @plugin = ODDB::OuwerkerkPlugin.new(@app)
  @atc_class = ODDB::AtcClass.new('A01BC23')
  @galform = ODDB::GalenicForm.new
  @galform.update_values({:fr => 'Tabletten'})
  @indication = ODDB::Indication.new
  @indication.update_values({:de => 'Placebo'})
end

- (Object) teardown



85
86
87
88
89
90
# File 'test/test_plugin/ouwerkerk.rb', line 85

def teardown
  if(File.exists? @plugin.file_path)
    FileUtils.rm_f(@plugin.file_path)
  end
  ODBA.storage = nil
end

- (Object) test_export_package



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'test/test_plugin/ouwerkerk.rb', line 100

def test_export_package
  pointer = ODDB::Persistence::Pointer.new([:reg, 1],[:seq, 2],[:pac, 3])
  pack = StubPackage.new
  pack.pointer = pointer
  pack.ikscd = '032'
  pack.ikscat = 'A'
  pack.size = "100 Tabletten"
  pack.price_exfactory = 12.34
  pack.price_public = 56.78
  flags = [:new]
  row = @plugin.export_package(pack, [flags], {pointer.to_s => [:price]})
  expected = [
    [:new,:price], nil, '032', nil, nil, nil, nil, nil, nil, nil, 'A', nil, 
    nil, "100 Tabletten", nil, nil, 12.34, 56.78, nil, nil, nil, nil, 
    nil, nil, 'keine'
  ]
  assert_equal(expected, row)
  pack.sl_entry = Object.new
  row = @plugin.export_package(pack, [flags], {pointer.to_s => [:price]})
  expected = [
    [:new,:price], nil, '032', nil, nil, nil, nil, nil, nil, nil, 'A', nil, 
    nil, "100 Tabletten", nil, nil, 12.34, 56.78, nil, nil, nil, nil, 
    nil, nil, 'SL'
  ]
  assert_equal(expected, row)
end

- (Object) test_export_registration



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'test/test_plugin/ouwerkerk.rb', line 166

def test_export_registration
  pack1 = StubPackage.new
  pack1.pointer = :foo
  pack1.ikscd = '032'
  pack1.ikscat = 'A'
  pack1.size = "100 Tabletten"
  pack1.price_exfactory = 12.34
  pack1.price_public = 56.78
  pack2 = StubPackage.new
  pack2.pointer = :bar
  pack2.ikscd = '064'
  pack2.ikscat = 'B'
  pack2.size = "200 Kapseln"
  pack2.price_exfactory = 43.21
  pack2.price_public = 87.65
  seq = StubSequence.new
  seq.packages = {'032' =>  pack1, '064' => pack2}
  seq.galenic_form = @galform
  seq.seqnr = '01'
  seq.name = 'Ponstan, Tabletten'
  seq.dose = StubDose.new(150, 'mg')
  seq.active_agents = [:foo, :bar, :baz]
  seq.atc_class = @atc_class
  reg = StubRegistration.new
  reg.sequences = {'01' => seq}
  reg.iksnr = '98765'
  reg.indication = @indication
  reg.export_flag = 'Export'
  reg.company = StubCompany.new('Pfizer', 'www.pfizer.ch')
  flags = [:productname, :address]
  rows = @plugin.export_registration(reg, [flags], {'foo' => [:price]})
  expected = [
    [
      [:productname, :address, :price], '98765', '032', '01', 'Ponstan, Tabletten', nil, 'Placebo', 
      'Export', 150, 'mg', 'A', 3, 'Pfizer', "100 Tabletten", "Tabletten", 
      nil, 12.34, 56.78, nil, 'www.pfizer.ch', nil, 'A01BC23', nil, nil, 'keine'
    ],
    [
      [:productname,:address], '98765', '064', '01', 'Ponstan, Tabletten', nil, 'Placebo', 
      'Export', 150, 'mg', 'B', 3, 'Pfizer', "200 Kapseln", "Tabletten", 
      nil, 43.21, 87.65, nil, 'www.pfizer.ch', nil, 'A01BC23', nil, nil, 'keine'
    ],
  ]
  assert([expected, expected.reverse].include?(rows), 
    "expected\n<#{expected.inspect}>\nbut was\n<#{rows.inspect}>")
end

- (Object) test_export_registrations



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# File 'test/test_plugin/ouwerkerk.rb', line 212

def test_export_registrations
  # Combine Swissmedic and BSV Updates but only Packages from BSV
  pack1 = StubPackage.new
  pack1.pointer = :foo
  pack1.ikscd = '032'
  pack1.ikscat = 'A'
  pack1.size = "100 Tabletten"
  pack1.price_exfactory = 12.34
  pack1.price_public = 56.78
  pack2 = StubPackage.new
  pack2.pointer = :bar
  pack2.ikscd = '064'
  pack2.ikscat = 'B'
  pack2.size = "200 Kapseln"
  pack2.price_exfactory = 43.21
  pack2.price_public = 87.65
  seq = StubSequence.new
  seq.packages = {'032' =>  pack1, '064' => pack2}
  seq.galenic_form = @galform
  seq.seqnr = '01'
  seq.name = 'Ponstan, Tabletten'
  seq.dose = StubDose.new(150, 'mg')
  seq.active_agents = [:foo, :bar, :baz]
  seq.atc_class = @atc_class
  reg = StubRegistration.new
  reg.sequences = {'01' => seq}
  reg.iksnr = '98765'
  reg.indication = @indication
  reg.export_flag = 'Export'
  reg.company = StubCompany.new('Pfizer', 'www.pfizer.ch')
  log = StubLogGroup.new
  pointer = StubPointer.new
  pointer.reg = reg
  flags = [:productname, :address]
  log.change_flags = {pointer => flags}
  pack3 = StubPackage.new
  pack3.ikscd = '007'
  pack3.ikscat = 'C'
  pack3.size = "7 cl"
  pack3.price_exfactory = 7.00 
  pack3.price_public = 70.00
  pack4 = StubPackage.new
  seq2 = StubSequence.new
  seq2.packages = {'007'  => pack3, '008' => pack4}
  seq2.galenic_form = @galform
  seq2.seqnr = '02'
  seq2.name = 'Vodka Martini Dry, shaken - not stirred'
  seq2.dose = StubDose.new(7, 'cl')
  seq2.active_agents = ['Vodka', 'Vermouth', 'Lemon Zest']
  seq2.atc_class = @atc_class
  reg2 = StubRegistration.new
  reg2.sequences = {'02' => seq2}
  reg2.iksnr = '12007'
  reg2.indication = @indication
  reg2.export_flag = nil
  reg2.company = StubCompany.new('Her Majesty\'s Secret Service', nil)
  bsv = StubLogGroup.new
  bsv_pointer = StubPointer.new
  pack3.pointer = bsv_pointer
  bsv_pointer.reg = reg2
  flags = [:price]
  bsv.change_flags = {bsv_pointer => flags}
  @app.log_groups = {
    :swissmedic => log, 
    :bsv_sl     => bsv,
  }
  rows = @plugin.export_registrations
  assert_equal(3, rows.size)
  expected = [
    [ "3,4", "98765", "032", "01", "Ponstan, Tabletten", nil, "Placebo",
      "Export", 150, "mg", "A", 3, "Pfizer", "100 Tabletten", "Tabletten",
      nil, 12.34, 56.78, nil, "www.pfizer.ch", nil, "A01BC23", nil, nil, 'keine' ], 
    [ "3,4", "98765", "064", "01", "Ponstan, Tabletten", nil, "Placebo",
      "Export", 150, "mg", "B", 3, "Pfizer", "200 Kapseln", "Tabletten", 
      nil, 43.21, 87.65, nil, "www.pfizer.ch", nil, "A01BC23", nil, nil, 'keine'], 
    [ "11", "12007", "007", "02", "Vodka Martini Dry, shaken - not stirred",
      nil, "Placebo", '', 7, "cl", "C", 3, "Her Majesty's Secret Service", 
      "7 cl", "Tabletten", nil, 7.00, 70.00, nil, nil, nil, "A01BC23", nil, nil, 'keine'], 
  ].sort
  assert_equal(expected.sort, rows.sort)
end

- (Object) test_export_sequence



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'test/test_plugin/ouwerkerk.rb', line 126

def test_export_sequence
  pack1 = StubPackage.new
  pack1.pointer = :foo
  pack1.ikscd = '032'
  pack1.ikscat = 'A'
  pack1.size = "100 Tabletten"
  pack1.price_exfactory = 12.34
  pack1.price_public = 56.78
  pack2 = StubPackage.new
  pack2.pointer = :bar
  pack2.ikscd = '064'
  pack2.ikscat = 'B'
  pack2.size = "200 Kapseln"
  pack2.price_exfactory = 43.21
  pack2.price_public = 87.65
  seq = StubSequence.new
  seq.packages = {'032' =>  pack1, '064' => pack2}
  seq.seqnr = '01'
  seq.galenic_form = @galform
  seq.name = 'Ponstan, Tabletten'
  seq.active_agents = [:foo, :bar, :baz]
  seq.dose = StubDose.new(150, 'mg')
  seq.atc_class = @atc_class
  flags = [:productname, :address]
  rows = @plugin.export_sequence(seq, [flags], {'foo' => [:price]})
  expected = [
    [
      [:productname,:address], nil, '064', '01', 'Ponstan, Tabletten', nil, nil, nil, 
      150, 'mg', 'B', 3, nil, "200 Kapseln", "Tabletten", nil, 43.21, 87.65,
      nil, nil, nil, 'A01BC23', nil, nil, 'keine'
    ],
    [
      [:productname,:address,:price], nil, '032', '01', 'Ponstan, Tabletten', nil, nil, nil, 
      150, 'mg', 'A', 3, nil, "100 Tabletten", "Tabletten", nil, 
      12.34, 56.78, nil, nil, nil, 'A01BC23', nil, nil, 'keine'
    ],
  ]
  assert([expected, expected.reverse].include?(rows), 
    "expected\n<#{expected.inspect}>\nbut was\n<#{rows.inspect}>")
end

- (Object) test_export_xls



293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'test/test_plugin/ouwerkerk.rb', line 293

def test_export_xls
  pack1 = StubPackage.new
  pack1.pointer = :foo
  pack1.ikscd = '032'
  pack1.ikscat = 'A'
  pack1.size = "100 Tabletten"
  pack1.price_exfactory = 1234
  pack1.price_public = 5678
  pack2 = StubPackage.new
  pack2.pointer = :bar
  pack2.ikscd = '064'
  pack2.ikscat = 'B'
  pack2.size = "200 Kapseln"
  pack2.price_exfactory = 4321
  pack2.price_public = 8765
  seq = StubSequence.new
  seq.packages = {'032' =>  pack1, '064' => pack2}
  seq.galenic_form = @galform
  seq.seqnr = '01'
  seq.name = 'Ponstan, Tabletten'
  seq.dose = StubDose.new(150, 'mg')
  seq.active_agents = [:foo, :bar, :baz]
  seq.atc_class = @atc_class
  reg = StubRegistration.new
  reg.sequences = {'01' => seq}
  reg.iksnr = '98765'
  reg.indication = @indication
  reg.export_flag = 'Export'
  reg.company = StubCompany.new('Pfizer', 'www.pfizer.ch')
  log = StubLogGroup.new
  pointer = StubPointer.new
  pointer.reg = reg
  flags = [:productname, :address]
  log.change_flags = {pointer => flags}
  log.date = Date.today
  bsvlog = StubLogGroup.new
  bsvlog.date = Date.today
  @app.log_groups = {
    :swissmedic_journal  => log, 
    :bsv_sl => bsvlog,
  }
  @plugin.export_xls
  assert(File.exists?(File.dirname(@plugin.file_path)))
  assert(File.exists?(@plugin.file_path))
end

- (Object) test_log_info



91
92
93
94
95
96
97
98
99
# File 'test/test_plugin/ouwerkerk.rb', line 91

def test_log_info
  log = StubLogGroup.new
  log.date = Date.today
  @plugin.smj = log
  info = @plugin.log_info
  [:files, :report, :change_flags, :recipients, :date_str].each { |key|
    assert(info.include?(key), "Missing '#{key}' in Log-Info")
  }
end