Class: ODDB::Updater

Inherits:
Object show all
Includes:
ODDB::Util::Schedule
Defined in:
src/util/updater.rb

Constant Summary

RECIPIENTS =

Recipients for all Update-Logs go here…

[]
LOG_RECIPIENTS =
{
  # :powerlink         =>  [], ## Disabled 2.3.2009, there are no Powerlink-Users at the current time
  :passthru            =>  [],  
}
LOG_FILES =
{
  :powerlink       => 'Powerlink-Statistics',
  #:passthru       => 'Banner-Clicks',
}
SPONSORS =
{
  :generika =>  'Exklusiv-Sponsoring Generika.cc',
  :gcc      => 'Exklusiv-Sponsoring ODDB.org',
}

Instance Method Summary (collapse)

Methods included from ODDB::Util::Schedule

#run_on_monthday, #run_on_weekday

Constructor Details

- (Updater) initialize(app)

A new instance of Updater



45
46
47
48
# File 'src/util/updater.rb', line 45

def initialize(app)
  @app = app
  @smj_updated = false
end

Instance Method Details

- (Object) _logfile_stats(date)



160
161
162
163
164
# File 'src/util/updater.rb', line 160

def _logfile_stats(date)
  self::class::LOG_FILES.each { |name, subj|
    mail_logfile(name, date, subj)
  }
end

- (Object) export_competition_xls(company, db_path = nil)



49
50
51
52
53
54
55
56
57
58
59
# File 'src/util/updater.rb', line 49

def export_competition_xls(company, db_path=nil)
  subj = "Generika-Preisvergleich #{company.name}"
  wrap_update(XlsExportPlugin, subj) {
    plug = Exporter.new(@app).export_competition_xls(company, db_path)
    log = Log.new(@@today)
    log.update_values(log_info(plug))
    log.notify(subj)
  }
  plug = XlsExportPlugin.new(@app)
  path = plug.export_competition(company)
end

- (Object) export_competition_xlss(db_path = nil)



60
61
62
63
64
65
66
# File 'src/util/updater.rb', line 60

def export_competition_xlss(db_path=nil)
  @app.companies.each_value { |comp|
    if(comp.competition_email)
      export_competition_xls(comp, db_path)
    end
  }
end

- (Object) export_generics_xls(date = @@today)



97
98
99
100
101
102
103
104
105
106
# File 'src/util/updater.rb', line 97

def export_generics_xls(date = @@today)
  subj = 'Generikaliste'
  wrap_update(XlsExportPlugin, subj) {
    plug = XlsExportPlugin.new(@app)
    plug.export_generics
    log = Log.new(date)
    log.update_values(log_info(plug))
    log.notify(subj)
  }
end

- (Object) export_index_therapeuticus_csv(date = @@today)



67
68
69
70
71
72
73
74
75
76
# File 'src/util/updater.rb', line 67

def export_index_therapeuticus_csv(date = @@today)
  subj = 'index_therapeuticus.csv'
  wrap_update(CsvExportPlugin, subj) {
    plug = CsvExportPlugin.new(@app)
    plug.export_index_therapeuticus
    log = Log.new(date)
    log.update_values(log_info(plug))
    log.notify(subj)
  }
end

- (Object) export_oddb2_csv(date = @@today)



87
88
89
90
91
92
93
94
95
96
# File 'src/util/updater.rb', line 87

def export_oddb2_csv(date = @@today)
  subj = 'oddb2.csv'
  wrap_update(CsvExportPlugin, subj) {
    plug = CsvExportPlugin.new(@app)
    plug.export_drugs_extended
    log = Log.new(date)
    log.update_values(log_info(plug))
    log.notify(subj)
  }
end

- (Object) export_oddb_csv(date = @@today)



77
78
79
80
81
82
83
84
85
86
# File 'src/util/updater.rb', line 77

def export_oddb_csv(date = @@today)
  subj = 'oddb.csv'
  wrap_update(CsvExportPlugin, subj) {
    plug = CsvExportPlugin.new(@app)
    plug.export_drugs
    log = Log.new(date)
    log.update_values(log_info(plug))
    log.notify(subj)
  }
end

- (Object) export_ouwerkerk(date = @@today)



117
118
119
120
121
122
123
124
125
126
# File 'src/util/updater.rb', line 117

def export_ouwerkerk(date = @@today)
  subj = 'Med-Drugs' 
  wrap_update(OuwerkerkPlugin, subj) {
    plug = Exporter.new(@app).export_swissdrug_xls date, 
                                                   :remove_newlines => true
    log = Log.new(date)
    log.update_values(log_info(plug))
    log.notify(subj)
  }
end

- (Object) export_patents_xls(date = @@today)



107
108
109
110
111
112
113
114
115
116
# File 'src/util/updater.rb', line 107

def export_patents_xls(date = @@today)
  subj = 'Export patents.xls'
  wrap_update(XlsExportPlugin, subj) {
    plug = XlsExportPlugin.new(@app)
    plug.export_patents
    log = Log.new(date)
    log.update_values(log_info(plug))
    log.notify(subj)
  }
end

- (Object) log_info(plugin, method = :log_info)



127
128
129
130
131
132
133
134
135
# File 'src/util/updater.rb', line 127

def log_info(plugin, method=:log_info)
  hash = plugin.send(method)
  hash[:recipients] = if(rcp = hash[:recipients])
    rcp + recipients
  else
    recipients
  end
  hash
end

- (Object) logfile_stats



153
154
155
156
157
158
159
# File 'src/util/updater.rb', line 153

def logfile_stats
  date = @@today << 1
  if(date.day == 1)
    _logfile_stats(date)
    mail_sponsor_logs(date)
  end
end

- (Object) mail_logfile(name, date, subj, emails = nil)



136
137
138
139
140
141
142
143
144
145
# File 'src/util/updater.rb', line 136

def mail_logfile(name, date, subj, emails=nil)
  report = LogFile.read(name, date)
  unless report.empty?
    log = Log.new(date)
    log.report = report
    mails = (emails || self::class::LOG_RECIPIENTS[name] || [])
    log.recipients = recipients + mails
    log.notify(subj)
  end
end

- (Object) mail_sponsor_logs(date = @@today)



146
147
148
149
150
151
152
# File 'src/util/updater.rb', line 146

def mail_sponsor_logs(date=@@today)
  self::class::SPONSORS.each { |name, subj|
    if  = @app.(name)
      mail_logfile("sponsor_#{name}", date, subj, .emails)
    end
  }
end

- (Object) recipients



165
166
167
# File 'src/util/updater.rb', line 165

def recipients
  self.class::RECIPIENTS
end

- (Object) reconsider_bsv(opts = {})



168
# File 'src/util/updater.rb', line 168

def reconsider_bsv opts={}

- (Object) run



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'src/util/updater.rb', line 201

def run
  logfile_stats
  if(update_swissmedic)
    update_swissmedic_followers
  end
  update_swissmedicjournal
  update_vaccines

  return_value_update_bsv = update_bsv
  LogFile.append('oddb/debug', " return_value_update_bsv=" + return_value_update_bsv.inspect.to_s, Time.now)

  #if(update_bsv)
  if(return_value_update_bsv)
    update_bsv_followers
  end
  update_narcotics
  run_on_monthday(1) {
    update_interactions 
  }
end

- (Object) run_random



221
222
223
# File 'src/util/updater.rb', line 221

def run_random
  update_fachinfo
end

- (Object) update_analysis(path, lang)



224
225
226
227
228
229
230
231
# File 'src/util/updater.rb', line 224

def update_analysis(path, lang)
  klass = AnalysisPlugin
  subj = 'Analysis'
  wrap_update(klass, subj) {
    plug = klass.new(@app)
    plug.update(path, lang) 
  }
end

- (Object) update_bsv



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
# File 'src/util/updater.rb', line 232

def update_bsv
    
  LogFile.append('oddb/debug', " getin update_bsv", Time.now)

  logs_pointer = Persistence::Pointer.new([:log_group, :bsv_sl])
  logs = @app.create(logs_pointer)
  this_month = Date.new(@@today.year, @@today.month)
  if (latest = logs.newest_date) && latest > this_month
    this_month = latest
  end
  klass = BsvXmlPlugin
  plug = klass.new(@app)
  subj = 'SL-Update (XML)'
        return_value_plug_update = nil
  wrap_update(klass, subj) { 

    return_value_plug_update = plug.update
    LogFile.append('oddb/debug', " return_value_BsvXmlPlugin.update = " + return_value_plug_update.inspect.to_s, Time.now)

    #if plug.update
    if return_value_plug_update
      log_notify_bsv(plug, this_month, subj)
    end
  }
        return return_value_plug_update
end

- (Object) update_bsv_followers



258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'src/util/updater.rb', line 258

def update_bsv_followers

  LogFile.append('oddb/debug', " getin update_bsv_followers", Time.now)

  update_trade_status
  update_medwin_packages
  update_lppv
  update_price_feeds
  export_oddb_csv
  # export_oddb2_csv # Disabled 4.1.2010
  export_ouwerkerk
  export_generics_xls
  export_competition_xlss
end

- (Object) update_comarketing



272
273
274
# File 'src/util/updater.rb', line 272

def update_comarketing
  update_immediate(CoMarketingPlugin, 'Co-Marketing')
end

- (Object) update_company_textinfos(*companies)



275
276
277
278
279
# File 'src/util/updater.rb', line 275

def update_company_textinfos *companies
  update_notify_simple TextInfoPlugin,
                       "Fach- und Patienteninfo '#{companies.join(', ')}'",
                       :import_company, [companies]
end

- (Object) update_doctors



285
286
287
# File 'src/util/updater.rb', line 285

def update_doctors
  update_simple(Doctors::DoctorPlugin, 'Doctors')
end

- (Object) update_fachinfo(*iksnrs)



288
289
290
291
292
293
294
# File 'src/util/updater.rb', line 288

def update_fachinfo(*iksnrs)
  if iksnrs.empty?
    update_textinfo_news
  else
    update_textinfos *iksnrs
  end
end

- (Object) update_hospitals



295
296
297
# File 'src/util/updater.rb', line 295

def update_hospitals
  update_simple(HospitalPlugin, 'Hospitals')
end

- (Object) update_interactions



298
299
300
# File 'src/util/updater.rb', line 298

def update_interactions
  update_simple(Interaction::InteractionPlugin, 'Interaktionen')
end

- (Object) update_lppv



301
302
303
# File 'src/util/updater.rb', line 301

def update_lppv
  update_immediate(LppvPlugin, 'Lppv prices')
end

- (Object) update_medwin_companies



304
305
306
# File 'src/util/updater.rb', line 304

def update_medwin_companies
  update_simple(MedwinCompanyPlugin, 'Medwin-Companies')
end

- (Object) update_medwin_packages



307
308
309
# File 'src/util/updater.rb', line 307

def update_medwin_packages
  update_simple(MedwinPackagePlugin, 'Medwin-Packages')
end

- (Object) update_migel



316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# File 'src/util/updater.rb', line 316

def update_migel
  klass = MiGeLPlugin
  subj = 'MiGeL'
  status_report = "MiGeL is now up to date"
  wrap_update(klass, subj) {
    plug = klass.new(@app)
    [:de, :fr, :it].each { |lang|
      path = File.expand_path("../../data/csv/migel_#{lang}.csv", 
        File.dirname(__FILE__))
      plug.update(path, lang)
    }
    plug.prune_old_revisions
    status_report
  }
end

- (Object) update_narcotics



331
332
333
# File 'src/util/updater.rb', line 331

def update_narcotics
  update_notify_simple(NarcoticPlugin, 'Narcotics')
end

- (Object) update_price_feeds(month = @@today)



310
311
312
# File 'src/util/updater.rb', line 310

def update_price_feeds(month = @@today)
  RssPlugin.new(@app).update_price_feeds(month)
end

- (Object) update_swissmedic(*args)



334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
# File 'src/util/updater.rb', line 334

def update_swissmedic(*args)
  logs_pointer = Persistence::Pointer.new([:log_group, :swissmedic])
  logs = @app.create(logs_pointer)
  klass = SwissmedicPlugin
  plug = klass.new(@app)
  return_value_plug_update = nil
  wrap_update(klass, "swissmedic") { 
    #if(plug.update(*args))
    if(return_value_plug_update = plug.update(*args))
      month = @@today << 1
      pointer = logs.pointer + [:log, Date.new(month.year, month.month)]
      log = @app.update(pointer.creator, log_info(plug))
      log.notify('Swissmedic XLS')
    end
  }
  return return_value_plug_update
end

- (Object) update_swissmedic_followers



351
352
353
354
355
356
357
358
359
360
361
362
363
# File 'src/util/updater.rb', line 351

def update_swissmedic_followers
  update_trade_status
  update_medwin_packages
  reconsider_bsv :new_log => true
  update_comarketing
  update_swissreg_news
  update_lppv
  update_medwin_companies
  exporter = Exporter.new(@app)
  exporter.export_generics_xls
  export_patents_xls
  exporter.mail_swissmedic_notifications
end

- (Object) update_swissmedicjournal



364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
# File 'src/util/updater.rb', line 364

def update_swissmedicjournal
  logs_pointer = Persistence::Pointer.new([:log_group, :swissmedic_journal])
  logs = @app.create(logs_pointer)
  # The first issue of SwissmedicJournal is 2002,1
  latest = logs.newest_date || Date.new(2002,4) 
  latest_swissmedic = @app.log_group(:swissmedic).newest_date
  success = true
  while(latest < @@today && latest <= latest_swissmedic && success)
    latest = latest >> 1
    klass = SwissmedicJournalPlugin
    plug = klass.new(@app)
    wrap_update(klass, "swissmedic-journal") { 
      success = false
      success = plug.update(latest)
    }
    if(success)
      pointer = logs.pointer + [:log, latest.dup]
      log = @app.update(pointer.creator, log_info(plug))
      log.notify('Swissmedic-Journal')
      @smj_updated = latest
    end
  end
  @smj_updated
end

- (Object) update_swissreg



388
389
390
# File 'src/util/updater.rb', line 388

def update_swissreg
  update_immediate(SwissregPlugin, 'Patents')
end

- (Object) update_swissreg_news



391
392
393
# File 'src/util/updater.rb', line 391

def update_swissreg_news
  update_immediate(SwissregPlugin, 'Patents', :update_news)
end

- (Object) update_textinfo_news



280
281
282
283
284
# File 'src/util/updater.rb', line 280

def update_textinfo_news
  update_notify_simple TextInfoPlugin,
                       "Fach- und Patienteninfo News",
                       :import_news
end

- (Object) update_textinfos(*iksnrs)



394
395
396
397
398
# File 'src/util/updater.rb', line 394

def update_textinfos *iksnrs
  update_notify_simple TextInfoPlugin,
                       "Fach- und Patienteninfo '#{iksnrs.join(', ')}'",
                       :import_fulltext, [iksnrs]
end

- (Object) update_trade_status



313
314
315
# File 'src/util/updater.rb', line 313

def update_trade_status
  update_immediate(MedwinPackagePlugin, 'Trade-Status', :update_trade_status)
end

- (Object) update_vaccines



399
400
401
# File 'src/util/updater.rb', line 399

def update_vaccines
  update_notify_simple(VaccinePlugin, 'blutprodukte')
end

- (Object) update_whocc



402
403
404
# File 'src/util/updater.rb', line 402

def update_whocc
  update_notify_simple WhoPlugin, "WHO-Update", :import
end