Class: OddbPrevalence

Inherits:
Object show all
Includes:
ODBA::Persistable, ODDB::Failsafe
Defined in:
src/util/oddbapp.rb,
test/stub/oddbapp.rb

Constant Summary

RESULT_SIZE_LIMIT =
250
ODBA_EXCLUDE_VARS =
[
  "@atc_chooser", "@bean_counter", "@sorted_fachinfos", "@sorted_feedbacks",
  "@sorted_minifis",
]
ODBA_SERIALIZABLE =
[ '@currency_rates', '@rss_updates' ]
@@iks_or_ean =
/(?:\d{4})?(\d{5})(?:\d{4})?/u

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from ODDB::Failsafe

#failsafe

Constructor Details

- (OddbPrevalence) initialize

A new instance of OddbPrevalence



53
54
55
56
# File 'src/util/oddbapp.rb', line 53

def initialize
  init
  @last_medication_update ||= Time.now()
end

Instance Attribute Details

- (Object) accepted_orphans (readonly)

Returns the value of attribute accepted_orphans



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

def accepted_orphans
  @accepted_orphans
end

- (Object) address_suggestions

Returns the value of attribute address_suggestions



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

def address_suggestions
  @address_suggestions
end

- (Object) analysis_groups

Returns the value of attribute analysis_groups



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

def analysis_groups
  @analysis_groups
end

- (Object) atc_chooser (readonly)

Returns the value of attribute atc_chooser



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

def atc_chooser
  @atc_chooser
end

- (Object) atc_classes

Returns the value of attribute atc_classes



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

def atc_classes
  @atc_classes
end

- (Object) commercial_forms

Returns the value of attribute commercial_forms



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

def commercial_forms
  @commercial_forms
end

- (Object) companies

Returns the value of attribute companies



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

def companies
  @companies
end

- (Object) doctors

Returns the value of attribute doctors



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

def doctors
  @doctors
end

- (Object) fachinfos

Returns the value of attribute fachinfos



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

def fachinfos
  @fachinfos
end

- (Object) feedbacks

Returns the value of attribute feedbacks



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

def feedbacks
  @feedbacks
end

- (Object) galenic_forms

Returns the value of attribute galenic_forms



7
8
9
# File 'test/stub/oddbapp.rb', line 7

def galenic_forms
  @galenic_forms
end

- (Object) galenic_groups

Returns the value of attribute galenic_groups



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

def galenic_groups
  @galenic_groups
end

- (Object) generic_groups

Returns the value of attribute generic_groups



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

def generic_groups
  @generic_groups
end

- (Object) hospitals

Returns the value of attribute hospitals



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

def hospitals
  @hospitals
end

- (Object) incomplete_registrations

Returns the value of attribute incomplete_registrations



9
10
11
# File 'test/stub/oddbapp.rb', line 9

def incomplete_registrations
  @incomplete_registrations
end

- (Object) indication_index (readonly)

Returns the value of attribute indication_index



12
13
14
# File 'test/stub/oddbapp.rb', line 12

def indication_index
  @indication_index
end

- (Object) indications

Returns the value of attribute indications



656
657
658
# File 'src/util/oddbapp.rb', line 656

def indications
  @indications.values
end

- (Object) indices_therapeutici

Returns the value of attribute indices_therapeutici



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

def indices_therapeutici
  @indices_therapeutici
end

- (Object) invoices

Returns the value of attribute invoices



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

def invoices
  @invoices
end

- (Object) last_medication_update

Returns the value of attribute last_medication_update



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

def last_medication_update
  @last_medication_update
end

- (Object) last_update

Returns the value of attribute last_update



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

def last_update
  @last_update
end

- (Object) log_groups

Returns the value of attribute log_groups



9
10
11
# File 'test/stub/oddbapp.rb', line 9

def log_groups
  @log_groups
end

- (Object) migel_groups

Returns the value of attribute migel_groups



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

def migel_groups
  @migel_groups
end

- (Object) minifis

Returns the value of attribute minifis



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

def minifis
  @minifis
end

- (Object) narcotics

Returns the value of attribute narcotics



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

def narcotics
  @narcotics
end

- (Object) notification_logger (readonly)

Returns the value of attribute notification_logger



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

def notification_logger
  @notification_logger
end

- (Object) orphaned_fachinfos

Returns the value of attribute orphaned_fachinfos



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

def orphaned_fachinfos
  @orphaned_fachinfos
end

- (Object) orphaned_patinfos

Returns the value of attribute orphaned_patinfos



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

def orphaned_patinfos
  @orphaned_patinfos
end

- (Object) patinfos

Returns the value of attribute patinfos



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

def patinfos
  @patinfos
end

- (Object) patinfos_deprived_sequences (readonly)

Returns the value of attribute patinfos_deprived_sequences



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

def patinfos_deprived_sequences
  @patinfos_deprived_sequences
end

- (Object) registrations

Returns the value of attribute registrations



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

def registrations
  @registrations
end

- (Object) rss_updates (readonly)

Returns the value of attribute rss_updates



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

def rss_updates
  @rss_updates
end

- (Object) sequence_index (readonly)

Returns the value of attribute sequence_index



12
13
14
# File 'test/stub/oddbapp.rb', line 12

def sequence_index
  @sequence_index
end

- (Object) slates

Returns the value of attribute slates



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

def slates
  @slates
end

- (Object) soundex_substances(name)



1081
1082
1083
1084
1085
1086
# File 'src/util/oddbapp.rb', line 1081

def soundex_substances(name)
  parts = ODDB::Text::Soundex.prepare(name).split(/\s+/u)
  soundex = ODDB::Text::Soundex.soundex(parts)
  key = soundex.join(' ')
  ODBA.cache.retrieve_from_index("substance_soundex_index", key)
end

- (Object) sponsors=(value) (writeonly)

Sets the attribute sponsors

Parameters:

  • value

    the value to set the attribute sponsors to.



14
15
16
# File 'test/stub/oddbapp.rb', line 14

def sponsors=(value)
  @sponsors = value
end

- (Object) substance_index

Returns the value of attribute substance_index



12
13
14
# File 'test/stub/oddbapp.rb', line 12

def substance_index
  @substance_index
end

- (Object) substances

Returns the value of attribute substances



1128
1129
1130
# File 'src/util/oddbapp.rb', line 1128

def substances
  @substances.values
end

- (Object) users

Returns the value of attribute users



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

def users
  @users
end

Instance Method Details

- (Object) _clean_odba_stubs_array(array)



143
144
145
146
147
148
# File 'src/util/oddbapp.rb', line 143

def _clean_odba_stubs_array(array)
  if(array.any? { |val| val.odba_instance.nil? })
    array.delete_if { |val| val.odba_instance.nil? }
    array.odba_store
  end
end

- (Object) _clean_odba_stubs_hash(hash)



137
138
139
140
141
142
# File 'src/util/oddbapp.rb', line 137

def _clean_odba_stubs_hash(hash)
  if(hash.values.any? { |val| val.odba_instance.nil? })
    hash.delete_if { |key, val| val.odba_instance.nil? }
    hash.odba_store
  end
end

- (Object) _company_by_name(name, ngram_cutoff = nil, filter = nil)



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'src/util/oddbapp.rb', line 228

def _company_by_name(name, ngram_cutoff=nil, filter=nil)
  namedown = name.to_s.downcase
  if filter
    namedown.gsub! filter, ''
  end
  @companies.each_value { |company|
    name = company.name.to_s.downcase
    if filter
      name.gsub! filter, ''
    end
    if name == namedown \
      || (ngram_cutoff \
          && ODDB::Util::NGramSimilarity.compare(name, namedown) > ngram_cutoff)
      return company
    end
  }
  nil
end

- (Object) _search_exact_classified_result(sequences, type = :unknown, result = nil)



1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
# File 'src/util/oddbapp.rb', line 1019

def _search_exact_classified_result(sequences, type=:unknown, result=nil)
  atc_classes = {}
  sequences.each { |seq|
    code = (atc = seq.atc_class) ? atc.code : 'n.n'
    new_atc = atc_classes.fetch(code) { 
      atc_class = ODDB::AtcClass.new(code)
      atc_class.descriptions = atc.descriptions unless(atc.nil?)
      atc_classes.store(code, atc_class)
    }
    new_atc.sequences.push(seq)
  }
  result ||= ODDB::SearchResult.new
  result.search_type = type
  result.atc_classes = atc_classes.values
  result
end

- (Object) active_fachinfos



158
159
160
161
162
163
164
165
166
# File 'src/util/oddbapp.rb', line 158

def active_fachinfos
  active = {}
  @registrations.each_value { |reg|
    if(reg.active? && reg.fachinfo)
      active.store(reg.pointer, 1)
    end
  }
  active
end

- (Object) active_pdf_patinfos



167
168
169
170
171
172
173
174
175
# File 'src/util/oddbapp.rb', line 167

def active_pdf_patinfos
  active = {}
  each_sequence { |seq|
    if(str = seq.active_patinfo)
      active.store(str, 1)
    end
  }
  active
end

- (Object) address_suggestion(oid)



176
177
178
# File 'src/util/oddbapp.rb', line 176

def address_suggestion(oid)
  @address_suggestions[oid.to_i]
end

- (Object) admin(oid)



150
151
152
# File 'src/util/oddbapp.rb', line 150

def admin(oid)
  @users[oid.to_i]
end

- (Object) admin_subsystem



153
154
155
156
157
# File 'src/util/oddbapp.rb', line 153

def admin_subsystem
  ODBA.cache.fetch_named('admin', self) {
    ODDB::Admin::Subsystem.new
  }
end

- (Object) all_soundex_substances

public :rebuild_indices



17
18
19
# File 'test/stub/oddbapp.rb', line 17

def all_soundex_substances
  @soundex_substances
end

- (Object) analysis_count



442
443
444
# File 'src/util/oddbapp.rb', line 442

def analysis_count
  @analysis_count ||= analysis_positions.size
end

- (Object) analysis_group(grpcd)



179
180
181
# File 'src/util/oddbapp.rb', line 179

def analysis_group(grpcd)
  @analysis_groups[grpcd]
end

- (Object) analysis_positions



182
183
184
185
186
# File 'src/util/oddbapp.rb', line 182

def analysis_positions
  @analysis_groups.values.inject([]) { |memo, group| 
    memo.concat(group.positions.values)
  }
end

- (Object) atc_class(code)



190
191
192
# File 'src/util/oddbapp.rb', line 190

def atc_class(code)
  @atc_classes[code]
end

- (Object) atc_ddd_count



193
194
195
# File 'src/util/oddbapp.rb', line 193

def atc_ddd_count
  @atc_ddd_count ||= count_atc_ddd()
end

- (Object) atcless_sequences



187
188
189
# File 'src/util/oddbapp.rb', line 187

def atcless_sequences
  ODBA.cache.retrieve_from_index('atcless', 'true')
end

- (Object) clean_invoices



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'src/util/oddbapp.rb', line 196

def clean_invoices
  @invoices.delete_if { |oid, invoice| invoice.odba_instance.nil? }
  deletables = @invoices.values.select { |invoice|
    invoice.deletable?
  }
  unless(deletables.empty?)
    deletables.each { |invoice|
=begin # replaced by Yus
      if((ptr = invoice.user_pointer) \
        && (user = ptr.resolve(self)) \
        && user.respond_to?(:remove_invoice))
        user.remove_invoice(invoice) 
      end
=end


      delete(invoice.pointer)
    }
    @invoices.odba_isolated_store
  end
end

- (Object) clean_odba_stubs



123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'src/util/oddbapp.rb', line 123

def clean_odba_stubs
  _clean_odba_stubs_hash(@substances)
  @substances.each_value { |sub| _clean_odba_stubs_array(sub.sequences) }
  _clean_odba_stubs_hash(@atc_classes)
  @atc_classes.each_value { |atc| _clean_odba_stubs_array(atc.sequences) }
  _clean_odba_stubs_hash(@registrations)
  @registrations.each_value { |reg|
    _clean_odba_stubs_hash(reg.sequences)
    reg.sequences.each_value { |seq|
      _clean_odba_stubs_hash(seq.packages)
      _clean_odba_stubs_array(seq.active_agents)
    }
  }
end

- (Object) commercial_form(oid)



215
216
217
# File 'src/util/oddbapp.rb', line 215

def commercial_form(oid)
  @commercial_forms[oid.to_i]
end

- (Object) commercial_form_by_name(name)



218
219
220
# File 'src/util/oddbapp.rb', line 218

def commercial_form_by_name(name)
  ODDB::CommercialForm.find_by_name(name)
end

- (Object) company(oid)



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

def company(oid)
  @companies[oid.to_i]
end

- (Object) company_by_name(name, ngram_cutoff = nil)



224
225
226
227
# File 'src/util/oddbapp.rb', line 224

def company_by_name(name, ngram_cutoff=nil)
  _company_by_name(name, ngram_cutoff) \
    || _company_by_name(name, ngram_cutoff, /\s*(ag|gmbh|sa)\b/i)
end

- (Object) company_count



246
247
248
# File 'src/util/oddbapp.rb', line 246

def company_count
  @company_count ||= @companies.size
end

- (Object) config(*args)



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'src/util/oddbapp.rb', line 249

def config(*args)
  if(@config.nil?)
    @config = ODDB::Config.new
    @config.pointer = ODDB::Persistence::Pointer.new(:config)
    self.odba_store
  end
  hook = @config
  args.each { |arg|
    conf = hook.send(arg)
    if(conf.nil?)
      conf = hook.send("create_#{arg}")
      conf.pointer = hook.pointer + arg
      hook.odba_store
    end
    hook = conf
  }
  hook
end

- (Object) count_atc_ddd



267
268
269
270
271
272
# File 'src/util/oddbapp.rb', line 267

def count_atc_ddd
  @atc_classes.values.inject(0) { |inj, atc|
    inj += 1 if(atc.has_ddd?)
    inj
  }
end

- (Object) count_limitation_texts



273
274
275
276
277
# File 'src/util/oddbapp.rb', line 273

def count_limitation_texts
  @registrations.values.inject(0) { |inj,reg|     
    inj + reg.limitation_text_count
  }
end

- (Object) count_packages



278
279
280
281
282
# File 'src/util/oddbapp.rb', line 278

def count_packages
  @registrations.values.inject(0) { |inj, reg|
    inj + reg.active_package_count
  }
end

- (Object) count_patinfos



283
284
285
# File 'src/util/oddbapp.rb', line 283

def count_patinfos
  @patinfos.size + active_pdf_patinfos.size
end

- (Object) count_recent_registrations



286
287
288
289
290
291
292
293
294
295
# File 'src/util/oddbapp.rb', line 286

def count_recent_registrations
  if((grp = log_group(:swissmedic) || log_group(:swissmedic_journal)) \
     && (log = grp.latest))
    log.change_flags.select { |ptr, flags|
      flags.include?(:new)
    }.size
  else 
    0
  end
end

- (Object) count_vaccines



296
297
298
299
300
301
302
303
# File 'src/util/oddbapp.rb', line 296

def count_vaccines
  @registrations.values.inject(0) { |inj, reg|
    if(reg.vaccine)
      inj += reg.active_package_count
    end
    inj
  }
end

- (Object) create(pointer)

prevalence-methods ################################



95
96
97
98
99
100
101
102
103
# File 'src/util/oddbapp.rb', line 95

def create(pointer)
  @last_update = Time.now()
  failsafe {
    if(item = pointer.issue_create(self))
      updated(item)
      item
    end
  }
end

- (Object) create_address_suggestion



368
369
370
371
# File 'src/util/oddbapp.rb', line 368

def create_address_suggestion
  address = ODDB::AddressSuggestion.new
  @address_suggestions.store(address.oid, address) 
end

- (Object) create_analysis_group(groupcd)



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

def create_analysis_group(groupcd)
  group = ODDB::Analysis::Group.new(groupcd)
  @analysis_groups.store(groupcd, group)
end

- (Object) create_atc_class(atc_class)



314
315
316
317
318
# File 'src/util/oddbapp.rb', line 314

def create_atc_class(atc_class)
  atc = ODDB::AtcClass.new(atc_class)
  @atc_chooser.add_offspring(ODDB::AtcNode.new(atc))
  @atc_classes.store(atc_class, atc)
end

- (Object) create_commercial_form



319
320
321
322
# File 'src/util/oddbapp.rb', line 319

def create_commercial_form
  form = ODDB::CommercialForm.new
  @commercial_forms.store(form.oid, form)
end

- (Object) create_company



323
324
325
326
# File 'src/util/oddbapp.rb', line 323

def create_company
  company = ODDB::Company.new
  @companies.store(company.oid, company)
end

- (Object) create_cyp450(cyp_id)



336
337
338
339
# File 'src/util/oddbapp.rb', line 336

def create_cyp450(cyp_id)
  cyp450 = ODDB::CyP450.new(cyp_id)
  @cyp450s.store(cyp_id, cyp450)
end

- (Object) create_doctor



327
328
329
330
331
# File 'src/util/oddbapp.rb', line 327

def create_doctor
  doctor = ODDB::Doctor.new
  @doctors ||= {}
  @doctors.store(doctor.oid, doctor)
end

- (Object) create_fachinfo



340
341
342
343
# File 'src/util/oddbapp.rb', line 340

def create_fachinfo
  fachinfo = ODDB::Fachinfo.new
  @fachinfos.store(fachinfo.oid, fachinfo)
end

- (Object) create_feedback



344
345
346
347
# File 'src/util/oddbapp.rb', line 344

def create_feedback
   = ODDB::.new
  @feedbacks.store(.oid, ) 
end

- (Object) create_galenic_group



348
349
350
351
# File 'src/util/oddbapp.rb', line 348

def create_galenic_group
  galenic_group = ODDB::GalenicGroup.new
  @galenic_groups.store(galenic_group.oid, galenic_group)
end

- (Object) create_generic_group(package_pointer)



352
353
354
# File 'src/util/oddbapp.rb', line 352

def create_generic_group(package_pointer)
  @generic_groups.store(package_pointer, ODDB::GenericGroup.new)
end

- (Object) create_hospital(ean13)



332
333
334
335
# File 'src/util/oddbapp.rb', line 332

def create_hospital(ean13)
  hospital = ODDB::Hospital.new(ean13)
  @hospitals.store(ean13, hospital)
end

- (Object) create_index_therapeuticus(code)



355
356
357
358
359
# File 'src/util/oddbapp.rb', line 355

def create_index_therapeuticus(code)
  code = code.to_s
  it = ODDB::IndexTherapeuticus.new(code)
  @indices_therapeutici.store(code, it)
end

- (Object) create_indication



360
361
362
363
# File 'src/util/oddbapp.rb', line 360

def create_indication
  indication = ODDB::Indication.new
  @indications.store(indication.oid, indication)
end

- (Object) create_invoice



364
365
366
367
# File 'src/util/oddbapp.rb', line 364

def create_invoice
  invoice = ODDB::Invoice.new
  @invoices.store(invoice.oid, invoice)
end

- (Object) create_log_group(key)



372
373
374
# File 'src/util/oddbapp.rb', line 372

def create_log_group(key)
  @log_groups[key] ||= ODDB::LogGroup.new(key)
end

- (Object) create_migel_group(groupcd)



438
439
440
441
# File 'src/util/oddbapp.rb', line 438

def create_migel_group(groupcd)
  migel = ODDB::Migel::Group.new(groupcd)
  @migel_groups.store(groupcd, migel)
end

- (Object) create_minifi



375
376
377
378
# File 'src/util/oddbapp.rb', line 375

def create_minifi
  minifi = ODDB::MiniFi.new
  @minifis.store(minifi.oid, minifi)
end

- (Object) create_narcotic



379
380
381
382
# File 'src/util/oddbapp.rb', line 379

def create_narcotic
  narc = ODDB::Narcotic.new
  @narcotics.store(narc.oid, narc)
end

- (Object) create_orphaned_fachinfo



383
384
385
386
387
# File 'src/util/oddbapp.rb', line 383

def create_orphaned_fachinfo
  @orphaned_fachinfos ||= {}
  orphan = ODDB::OrphanedTextInfo.new
  @orphaned_fachinfos.store(orphan.oid, orphan)
end

- (Object) create_orphaned_patinfo



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

def create_orphaned_patinfo
  orphan = ODDB::OrphanedTextInfo.new
  @orphaned_patinfos.store(orphan.oid, orphan)
end

- (Object) create_patinfo



392
393
394
395
# File 'src/util/oddbapp.rb', line 392

def create_patinfo
  patinfo = ODDB::Patinfo.new
  @patinfos.store(patinfo.oid, patinfo)
end

- (Object) create_poweruser



396
397
398
399
# File 'src/util/oddbapp.rb', line 396

def create_poweruser
  user = ODDB::PowerUser.new
  @users.store(user.oid, user)
end

- (Object) create_registration(iksnr)



400
401
402
403
404
405
406
# File 'src/util/oddbapp.rb', line 400

def create_registration(iksnr)
  unless @registrations.include?(iksnr)
    reg = ODDB::Registration.new(iksnr)
    @registrations.store(iksnr, reg)
    reg
  end
end

- (Object) create_slate(name)



407
408
409
410
# File 'src/util/oddbapp.rb', line 407

def create_slate(name)
  slate = ODDB::Slate.new(name)
  @slates.store(name, slate)
end

- (Object) create_sponsor(flavor)



411
412
413
414
# File 'src/util/oddbapp.rb', line 411

def create_sponsor(flavor)
   = ODDB::.new
  @sponsors.store(flavor, )
end

- (Object) create_substance(key = nil)



415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
# File 'src/util/oddbapp.rb', line 415

def create_substance(key=nil)
  if(!key.nil? && (subs = substance(key)))
    subs
  else
    subs = ODDB::Substance.new
    unless(key.nil?)
      values = {
        'lt' =>  key,
      }
      diff = subs.diff(values, self)
      subs.update_values(diff)
    end
    @substances.store(subs.oid, subs)
  end
end

- (Object) create_user



430
431
432
433
434
# File 'src/util/oddbapp.rb', line 430

def create_user
  @users ||= {}
  user = ODDB::CompanyUser.new
  @users.store(user.oid, user)
end

- (Object) currencies



435
436
437
# File 'src/util/oddbapp.rb', line 435

def currencies
  @currency_rates.keys.sort
end

- (Object) cyp450(id)



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

def cyp450(id)
  @cyp450s[id]
end

- (Object) cyp450s



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

def cyp450s
  @cyp450s.values
end

- (Object) delete(pointer)



104
105
106
107
108
109
110
111
112
# File 'src/util/oddbapp.rb', line 104

def delete(pointer)
  @last_update = Time.now()
  failsafe(ODDB::Persistence::UninitializedPathError) {
    if(item = pointer.resolve(self))
      updated(item)
    end
    pointer.issue_delete(self)
  }
end

- (Object) delete_address_suggestion(oid)



445
446
447
448
449
450
# File 'src/util/oddbapp.rb', line 445

def delete_address_suggestion(oid)
  if(sug = @address_suggestions.delete(oid))
    @address_suggestions.odba_isolated_store
    sug
  end
end

- (Object) delete_atc_class(atccode)



451
452
453
454
455
456
457
458
# File 'src/util/oddbapp.rb', line 451

def delete_atc_class(atccode)
  atc = @atc_classes[atccode]
  @atc_chooser.delete(atccode)
  if(@atc_classes.delete(atccode))
    @atc_classes.odba_isolated_store
  end
  atc
end

- (Object) delete_commercial_form(oid)



465
466
467
468
469
470
# File 'src/util/oddbapp.rb', line 465

def delete_commercial_form(oid)
  if(form = @commercial_forms.delete(oid))
    @commercial_forms.odba_isolated_store
    form
  end
end

- (Object) delete_company(oid)



471
472
473
474
475
476
# File 'src/util/oddbapp.rb', line 471

def delete_company(oid)
  if(comp = @companies.delete(oid))
    @companies.odba_isolated_store
    comp
  end
end

- (Object) delete_cyp450(cyp_id)



459
460
461
462
463
464
# File 'src/util/oddbapp.rb', line 459

def delete_cyp450(cyp_id)
  if(cyp = @cyp450s.delete(cyp_id))
    @cyp450s.odba_isolated_store
    cyp
  end
end

- (Object) delete_doctor(oid)



477
478
479
480
481
482
# File 'src/util/oddbapp.rb', line 477

def delete_doctor(oid)
  if(doc = @doctors.delete(oid.to_i))
    @doctors.odba_isolated_store
    doc
  end
end

- (Object) delete_fachinfo(oid)



483
484
485
486
487
488
# File 'src/util/oddbapp.rb', line 483

def delete_fachinfo(oid)
  if(fi = @fachinfos.delete(oid))
    @fachinfos.odba_isolated_store
    fi
  end
end

- (Object) delete_galenic_group(oid)



489
490
491
492
493
494
495
496
497
498
# File 'src/util/oddbapp.rb', line 489

def delete_galenic_group(oid)
  group = galenic_group(oid)
  unless (group.nil? || group.empty?)
    raise 'e_nonempty_galenic_group'
  end
  if(grp = @galenic_groups.delete(oid.to_i))
    @galenic_groups.odba_isolated_store
    grp
  end
end

- (Object) delete_index_therapeuticus(code)



499
500
501
502
503
504
505
# File 'src/util/oddbapp.rb', line 499

def delete_index_therapeuticus(code)
  code = code.to_s
  if(it = @indices_therapeutici.delete(code))
    @indices_therapeutici.odba_isolated_store
    it
  end
end

- (Object) delete_indication(oid)



506
507
508
509
510
511
# File 'src/util/oddbapp.rb', line 506

def delete_indication(oid)
  if(ind = @indications.delete(oid))
    @indications.odba_isolated_store
    ind
  end
end

- (Object) delete_invoice(oid)



512
513
514
515
516
517
# File 'src/util/oddbapp.rb', line 512

def delete_invoice(oid)
  if(inv = @invoices.delete(oid))
    @invoices.odba_isolated_store
    inv
  end
end

- (Object) delete_migel_group(code)



518
519
520
521
522
523
# File 'src/util/oddbapp.rb', line 518

def delete_migel_group(code)
  if(grp = @migel_groups[code])
    @migel_groups.odba_isolated_store
    grp
  end
end

- (Object) delete_minifi(oid)



524
525
526
527
528
529
# File 'src/util/oddbapp.rb', line 524

def delete_minifi(oid)
  if(minifi = @minifis.delete(oid.to_i))
    @minifis.odba_isolated_store
    minifi
  end
end

- (Object) delete_orphaned_fachinfo(oid)



530
531
532
533
534
535
# File 'src/util/oddbapp.rb', line 530

def delete_orphaned_fachinfo(oid)
  if(fi = @orphaned_fachinfos.delete(oid.to_i))
    @orphaned_fachinfos.odba_isolated_store
    fi
  end
end

- (Object) delete_orphaned_patinfo(oid)



536
537
538
539
540
541
# File 'src/util/oddbapp.rb', line 536

def delete_orphaned_patinfo(oid)
  if(pi = @orphaned_patinfos.delete(oid.to_i))
    @orphaned_patinfos.odba_isolated_store
    pi
  end
end

- (Object) delete_patinfo(oid)



542
543
544
545
546
547
# File 'src/util/oddbapp.rb', line 542

def delete_patinfo(oid)
  if(fi = @patinfos.delete(oid))
    @patinfos.odba_isolated_store
    fi
  end
end

- (Object) delete_registration(iksnr)



548
549
550
551
552
553
# File 'src/util/oddbapp.rb', line 548

def delete_registration(iksnr)
  if(reg = @registrations.delete(iksnr))
    @registrations.odba_isolated_store
    reg
  end
end

- (Object) delete_substance(key)



554
555
556
557
558
559
560
561
562
563
564
565
# File 'src/util/oddbapp.rb', line 554

def delete_substance(key)
  substance = nil
  if(key.to_i.to_s == key.to_s)
    substance = @substances.delete(key.to_i)
  else
    substance = @substances.delete(key.to_s.downcase)
  end
  if(substance)
    @substances.odba_isolated_store
    substance
  end
end

- (Object) doctor(oid)



566
567
568
# File 'src/util/oddbapp.rb', line 566

def doctor(oid)
  @doctors[oid.to_i]
end

- (Object) doctor_by_origin(origin_db, origin_id)



578
579
580
581
582
583
584
585
586
# File 'src/util/oddbapp.rb', line 578

def doctor_by_origin(origin_db, origin_id)
  # values.each instead of each_value for testing
  @doctors.values.each { |doctor|
    if(doctor.record_match?(origin_db, origin_id))
      return doctor
    end
  }
  nil
end

- (Object) doctor_count



575
576
577
# File 'src/util/oddbapp.rb', line 575

def doctor_count
  @doctor_count ||= @doctors.size
end

- (Object) each_atc_class(&block)



587
588
589
# File 'src/util/oddbapp.rb', line 587

def each_atc_class(&block)
  @atc_classes.each_value(&block)
end

- (Object) each_galenic_form(&block)



590
591
592
593
594
# File 'src/util/oddbapp.rb', line 590

def each_galenic_form(&block)
  @galenic_groups.each_value { |galgroup|
    galgroup.each_galenic_form(&block)
  }
end

- (Object) each_migel_product(&block)



595
596
597
598
599
600
601
# File 'src/util/oddbapp.rb', line 595

def each_migel_product(&block)
  @migel_groups.each_value { |group| 
    group.subgroups.each_value { |subgr|
      subgr.products.each_value(&block)
    }
  }
end

- (Object) each_package(&block)



602
603
604
605
606
# File 'src/util/oddbapp.rb', line 602

def each_package(&block)
  @registrations.each_value { |reg|
    reg.each_package(&block)
  }
end

- (Object) each_sequence(&block)



607
608
609
610
611
# File 'src/util/oddbapp.rb', line 607

def each_sequence(&block)
  @registrations.each_value { |reg|
    reg.each_sequence(&block)
  }
end

- (Object) execute_command(command)



612
613
614
# File 'src/util/oddbapp.rb', line 612

def execute_command(command)
  command.execute(self)
end

- (Object) fachinfo(oid)



615
616
617
# File 'src/util/oddbapp.rb', line 615

def fachinfo(oid)
  @fachinfos[oid.to_i]
end

- (Object) fachinfo_count



618
619
620
# File 'src/util/oddbapp.rb', line 618

def fachinfo_count
  @fachinfos.size
end

- (Object) fachinfos_by_name(name, lang)



621
622
623
624
625
626
627
# File 'src/util/oddbapp.rb', line 621

def fachinfos_by_name(name, lang)
  if(lang.to_s != "fr") 
    lang = "de"
  end
  ODBA.cache.retrieve_from_index("fachinfo_name_#{lang}", 
    name)
end

- (Object) feedback(id)



628
629
630
# File 'src/util/oddbapp.rb', line 628

def (id)
  @feedbacks[id.to_i]
end

- (Object) galenic_form(name)



631
632
633
634
635
# File 'src/util/oddbapp.rb', line 631

def galenic_form(name)
  @galenic_groups.values.collect { |galenic_group|
    galenic_group.get_galenic_form(name)
  }.compact.first
end

- (Object) galenic_group(oid)



636
637
638
# File 'src/util/oddbapp.rb', line 636

def galenic_group(oid)
  @galenic_groups[oid.to_i]
end

- (Object) generate_dictionaries



1235
1236
1237
1238
# File 'src/util/oddbapp.rb', line 1235

def generate_dictionaries
  generate_french_dictionary
  generate_german_dictionary
end

- (Object) generate_dictionary(language, locale)



1229
1230
1231
1232
1233
1234
# File 'src/util/oddbapp.rb', line 1229

def generate_dictionary(language, locale)
  ODBA.storage.remove_dictionary(language)
  base = File.expand_path("../../ext/fulltext/data/dicts/#{language}", 
    File.dirname(__FILE__))
  ODBA.storage.generate_dictionary(language, locale, base)
end

- (Object) generate_french_dictionary



1239
1240
1241
# File 'src/util/oddbapp.rb', line 1239

def generate_french_dictionary
  generate_dictionary('french', 'fr_FR@euro')
end

- (Object) generate_german_dictionary



1242
1243
1244
# File 'src/util/oddbapp.rb', line 1242

def generate_german_dictionary
  generate_dictionary('german', 'de_DE@euro')
end

- (Object) generic_group(package_pointer)



639
640
641
# File 'src/util/oddbapp.rb', line 639

def generic_group(package_pointer)
  @generic_groups[package_pointer]
end

- (Object) get_currency_rate(symbol)



642
643
644
# File 'src/util/oddbapp.rb', line 642

def get_currency_rate(symbol)
  ODDB::Currency.rate('CHF', symbol)
end

- (Object) hospital(ean13)



569
570
571
# File 'src/util/oddbapp.rb', line 569

def hospital(ean13)
  @hospitals[ean13]
end

- (Object) hospital_count



572
573
574
# File 'src/util/oddbapp.rb', line 572

def hospital_count
  @hospitals.size
end

- (Object) index_therapeuticus(code)



645
646
647
# File 'src/util/oddbapp.rb', line 645

def index_therapeuticus(code)
  @indices_therapeutici[code.to_s]
end

- (Object) indication(oid)



648
649
650
# File 'src/util/oddbapp.rb', line 648

def indication(oid)
  @indications[oid.to_i]
end

- (Object) indication_by_text(text)



651
652
653
654
655
# File 'src/util/oddbapp.rb', line 651

def indication_by_text(text)
  @indications.values.select { |indication|
    indication.has_description?(text)
  }.first
end

- (Object) init



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'src/util/oddbapp.rb', line 57

def init
  create_unknown_galenic_group()
  @accepted_orphans ||= {}
  @address_suggestions ||= {}
  @analysis_groups ||= {}
  @atc_classes ||= {}
  @commercial_forms ||= {}
  @companies ||= {}
  @currency_rates ||= {}
  @cyp450s ||= {}
  @doctors ||= {}
  @fachinfos ||= {}
  @feedbacks ||= {}
  @galenic_forms ||= []
  @galenic_groups ||= []
  @generic_groups ||= {}
  @hospitals ||= {}
  @indications ||= {}
  @indices_therapeutici ||= {}
  @invoices ||= {}
  @log_groups ||= {}
  @migel_groups ||= {}
  @minifis ||= {}
  @narcotics ||= {}
  @notification_logger ||= ODDB::NotificationLogger.new
  @orphaned_fachinfos ||= {}
  @orphaned_patinfos ||= {}
  @patinfos ||= {}
  @patinfos_deprived_sequences ||= []
  @registrations ||= {}
  @rss_updates ||= {}
  @slates ||= {}
  @sponsors ||= {}
  @substances ||= {}
  #recount()
  rebuild_atc_chooser()
end

- (Object) invoice(oid)



659
660
661
662
# File 'src/util/oddbapp.rb', line 659

def invoice(oid)
  @invoices ||= {}
  @invoices[oid.to_i]
end

- (Object) limitation_text_count



663
664
665
# File 'src/util/oddbapp.rb', line 663

def limitation_text_count
  @limitation_text_count ||= count_limitation_texts()
end

- (Object) log_group(key)



666
667
668
# File 'src/util/oddbapp.rb', line 666

def log_group(key)
  @log_groups[key]
end

- (Object) migel_count



669
670
671
# File 'src/util/oddbapp.rb', line 669

def migel_count
  @migel_count ||= migel_products.size  
end

- (Object) migel_group(groupcd)



672
673
674
# File 'src/util/oddbapp.rb', line 672

def migel_group(groupcd)
  @migel_groups[groupcd]
end

- (Object) migel_product(code)



675
676
677
678
679
680
681
# File 'src/util/oddbapp.rb', line 675

def migel_product(code)
  parts = code.split('.', 3)
  migel_group(parts[0]).subgroup(parts[1]).product(parts[2])
rescue NoMethodError
  # invalid migel_code
  nil
end

- (Object) migel_products



682
683
684
685
686
687
688
689
690
# File 'src/util/oddbapp.rb', line 682

def migel_products
  products = []
  @migel_groups.each_value { |group| 
    group.subgroups.each_value { |subgr|
      products.concat(subgr.products.values)
    }
  }
  products
end

- (Object) minifi(oid)



691
692
693
# File 'src/util/oddbapp.rb', line 691

def minifi(oid)
  @minifis[oid.to_i]
end

- (Object) narcotic(odba_id)



694
695
696
# File 'src/util/oddbapp.rb', line 694

def narcotic(odba_id)
  @narcotics[odba_id.to_i]
end

- (Object) narcotic_by_casrn(casrn)



697
698
699
700
701
# File 'src/util/oddbapp.rb', line 697

def narcotic_by_casrn(casrn)
  unless(casrn.nil?)
    @narcotics.values.find do |narc| narc.casrn == casrn end
  end
end

- (Object) narcotic_by_smcd(smcd)



702
703
704
705
706
# File 'src/util/oddbapp.rb', line 702

def narcotic_by_smcd(smcd)
  unless(smcd.nil?)
    @narcotics.values.find do |narc| narc.swissmedic_codes.include?(smcd) end
  end
end

- (Object) narcotics_count



707
708
709
# File 'src/util/oddbapp.rb', line 707

def narcotics_count
  @narcotics.size
end

- (Object) orphaned_fachinfo(oid)



710
711
712
# File 'src/util/oddbapp.rb', line 710

def orphaned_fachinfo(oid)
  @orphaned_fachinfos[oid.to_i]
end

- (Object) orphaned_patinfo(oid)



713
714
715
# File 'src/util/oddbapp.rb', line 713

def orphaned_patinfo(oid)
  @orphaned_patinfos[oid.to_i]
end

- (Object) package(pcode)



716
717
718
# File 'src/util/oddbapp.rb', line 716

def package(pcode)
  ODDB::Package.find_by_pharmacode(pcode.to_s.gsub(/^0+/u, ''))
end

- (Object) package_by_ikskey(ikskey)



719
720
721
722
723
724
725
726
# File 'src/util/oddbapp.rb', line 719

def package_by_ikskey(ikskey)
  ikskey = ikskey.to_s
  iksnr = "%05i" % ikskey[-8..-4].to_i
  ikscd = ikskey[-3..-1]
  if reg = registration(iksnr)
    reg.package ikscd
  end
end

- (Object) package_count



727
728
729
# File 'src/util/oddbapp.rb', line 727

def package_count
  @package_count ||= count_packages()
end

- (Object) packages



730
731
732
733
734
# File 'src/util/oddbapp.rb', line 730

def packages
  @registrations.inject([]) { |pacs, (iksnr,reg)| 
    pacs.concat(reg.packages)
  }
end

- (Object) patinfo(oid)



735
736
737
# File 'src/util/oddbapp.rb', line 735

def patinfo(oid)
  @patinfos[oid.to_i]
end

- (Object) patinfo_count



738
739
740
# File 'src/util/oddbapp.rb', line 738

def patinfo_count
  @patinfo_count ||= count_patinfos()
end

- (Object) poweruser(oid)



741
742
743
# File 'src/util/oddbapp.rb', line 741

def poweruser(oid)
  @users[oid.to_i]
end

- (Object) rebuild_atc_chooser



744
745
746
747
748
749
750
# File 'src/util/oddbapp.rb', line 744

def rebuild_atc_chooser
  chooser = ODDB::AtcNode.new(nil)
  @atc_classes.sort.each { |key, atc| 
    chooser.add_offspring(ODDB::AtcNode.new(atc))
  }
  @atc_chooser = chooser
end

- (Object) rebuild_indices(name = nil, &block)

indices



1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
# File 'src/util/oddbapp.rb', line 1179

def rebuild_indices(name=nil, &block)
  ODBA.cache.indices.size
  begin
    start = Time.now
    path = File.expand_path("../../etc/index_definitions.yaml", 
      File.dirname(__FILE__))
    FileUtils.mkdir_p(File.dirname(path))
    file = File.open(path)
    YAML.load_documents(file) { |index_definition|
      doit = if(name)
               name.match(index_definition.index_name)
             elsif(block)
               block.call(index_definition)
             else
               true
             end
      if(doit)
        index_start = Time.now
        begin
          puts "dropping: #{index_definition.index_name}"
          ODBA.cache.drop_index(index_definition.index_name)
        rescue StandardError => e
          puts e.message
        end
        puts "creating: #{index_definition.index_name}"
        ODBA.cache.create_index(index_definition, ODDB)
        begin 
          puts "filling: #{index_definition.index_name}"
          puts index_definition.init_source
          source = instance_eval(index_definition.init_source)
          puts "source.size: #{source.size}"
          ODBA.cache.fill_index(index_definition.index_name, 
            source)
        rescue StandardError => e
          puts e.class
          puts e.message
          puts e.backtrace
        end
        puts "finished in #{(Time.now - index_start) / 60.0} min"
      end
    }
    puts "all Indices Created in total: #{(Time.now - start) / 3600.0} h"
  rescue StandardError => e
    puts "INDEX CREATION ERROR:"
    puts e.message
    puts e.backtrace
  ensure
    file.close
  end
end

- (Object) recent_registration_count



751
752
753
# File 'src/util/oddbapp.rb', line 751

def recent_registration_count
  @recent_registration_count ||= count_recent_registrations()
end

- (Object) recount



754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
# File 'src/util/oddbapp.rb', line 754

def recount
  again = true
  if(@bean_counter.is_a?(Thread) && @bean_counter.status)
    return again = true
  end
  @bean_counter = Thread.new {
    while(again)
      again = false
      @analysis_count = analysis_positions.size
      @atc_ddd_count = count_atc_ddd()
      @doctor_count = @doctors.size
      @company_count = @companies.size
      @substance_count = @substances.size
      @limitation_text_count = count_limitation_texts()
      @migel_count = migel_products.size
      @package_count = count_packages()
      @patinfo_count = count_patinfos()
      @recent_registration_count = count_recent_registrations()
      @vaccine_count = count_vaccines()
      self.odba_isolated_store
    end
  }
end

- (Object) refactor_addresses



783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
# File 'src/util/oddbapp.rb', line 783

def refactor_addresses
  # 3 Iterationen 
  puts "refactoring doctors"
  $stdout.flush
  @doctors.each_value { |doc| 
    doc.refactor_addresses 
    doc.odba_store
  }
  puts "refactoring hospitals"
  $stdout.flush
  @hospitals.each_value { |spi| 
    spi.refactor_addresses 
    spi.odba_store
  }
  puts "refactoring companies"
  $stdout.flush
  @companies.each_value { |comp| 
    comp.refactor_addresses 
    comp.odba_store
  }
  puts "finished refactoring addresses"
  $stdout.flush
end

- (Object) registration(registration_id)



777
778
779
# File 'src/util/oddbapp.rb', line 777

def registration(registration_id)
  @registrations[registration_id]
end

- (Object) resolve(pointer)



780
781
782
# File 'src/util/oddbapp.rb', line 780

def resolve(pointer)
  pointer.resolve(self)
end

- (Object) search_analysis(key, lang)



806
807
808
809
810
811
# File 'src/util/oddbapp.rb', line 806

def search_analysis(key, lang)
  if(lang == 'en')
    lang = 'de'
  end
  ODBA.cache.retrieve_from_index("analysis_index_#{lang}", key)
end

- (Object) search_analysis_alphabetical(query, lang)



812
813
814
815
816
817
818
# File 'src/util/oddbapp.rb', line 812

def search_analysis_alphabetical(query, lang)
  if(lang == 'en')
    lang = 'de'
  end
  index_name = "analysis_alphabetical_index_#{lang}"
  ODBA.cache.retrieve_from_index(index_name, query)
end

- (Object) search_by_atc(key)



909
910
911
# File 'src/util/oddbapp.rb', line 909

def search_by_atc(key)
  ODBA.cache.retrieve_from_index('atc_index', key.dup)
end

- (Object) search_by_company(key)



912
913
914
915
916
917
918
919
920
# File 'src/util/oddbapp.rb', line 912

def search_by_company(key)
  result = ODDB::SearchResult.new
  result.error_limit = RESULT_SIZE_LIMIT
  atcs = ODBA.cache.retrieve_from_index('atc_index_company', key.dup, result)
  filtered = atcs.collect { |atc|
    atc.company_filter_search(key.dup)
  }
  filtered.flatten.compact.uniq
end

- (Object) search_by_indication(key, lang, result)



921
922
923
924
925
926
927
928
929
930
931
# File 'src/util/oddbapp.rb', line 921

def search_by_indication(key, lang, result)
  if(lang.to_s != "fr") 
    lang = "de"
  end
  atcs = ODBA.cache.\
    retrieve_from_index("fachinfo_index_#{lang}", key.dup, result)
  atcs += ODBA.cache.\
    retrieve_from_index("indication_index_atc_#{lang}",
    key.dup, result)
  atcs.uniq
end

- (Object) search_by_interaction(key, lang)



935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
# File 'src/util/oddbapp.rb', line 935

def search_by_interaction(key, lang)
  result = ODDB::SearchResult.new
  result.error_limit = RESULT_SIZE_LIMIT
  if(lang.to_s != "fr") 
    lang = "de"
  end
  sequences = ODBA.cache.retrieve_from_index("interactions_index_#{lang}", 
                                             key, result)
  key = key.downcase
  sequences.reject! { |seq| 
    ODDB.search_terms(seq.search_terms, :downcase => true).include?(key) \
      || seq.substances.any? { |sub|
      sub.search_keys.any? { |skey| skey.downcase.include?(key) }
    }
  }
  _search_exact_classified_result(sequences, :interaction, result)
end

- (Object) search_by_sequence(key, result = nil)



932
933
934
# File 'src/util/oddbapp.rb', line 932

def search_by_sequence(key, result=nil)
  ODBA.cache.retrieve_from_index('sequence_index_atc', key.dup, result)
end

- (Object) search_by_substance(key)



952
953
954
# File 'src/util/oddbapp.rb', line 952

def search_by_substance(key)
  ODBA.cache.retrieve_from_index('substance_index_atc', key.dup)
end

- (Object) search_by_unwanted_effect(key, lang)



955
956
957
958
959
960
961
962
963
# File 'src/util/oddbapp.rb', line 955

def search_by_unwanted_effect(key, lang)
  result = ODDB::SearchResult.new
  if(lang.to_s != "fr") 
    lang = "de"
  end
  sequences = ODBA.cache.retrieve_from_index("unwanted_effects_index_#{lang}", 
                                             key, result)
  _search_exact_classified_result(sequences, :unwanted_effect, result)
end

- (Object) search_companies(key)



967
968
969
# File 'src/util/oddbapp.rb', line 967

def search_companies(key)
  ODBA.cache.retrieve_from_index("company_index", key)
end

- (Object) search_doctors(key)



964
965
966
# File 'src/util/oddbapp.rb', line 964

def search_doctors(key)
  ODBA.cache.retrieve_from_index("doctor_index", key)
end

- (Object) search_exact_company(query)



970
971
972
973
974
975
# File 'src/util/oddbapp.rb', line 970

def search_exact_company(query)
  result = ODDB::SearchResult.new
  result.search_type = :company
  result.atc_classes = search_by_company(query)
  result
end

- (Object) search_exact_indication(query, lang)



976
977
978
979
980
981
982
# File 'src/util/oddbapp.rb', line 976

def search_exact_indication(query, lang)
  result = ODDB::SearchResult.new
  result.exact = true
  result.search_type = :indication
  result.atc_classes = search_by_indication(query, lang, result)
  result
end

- (Object) search_exact_sequence(query)



1010
1011
1012
1013
# File 'src/util/oddbapp.rb', line 1010

def search_exact_sequence(query)
  sequences = search_sequences(query)
  _search_exact_classified_result(sequences, :sequence)
end

- (Object) search_exact_substance(query)



1014
1015
1016
1017
1018
# File 'src/util/oddbapp.rb', line 1014

def search_exact_substance(query)
  sequences = ODBA.cache.\
    retrieve_from_index('substance_index_sequence', query)
  _search_exact_classified_result(sequences, :substance)
end

- (Object) search_hospitals(key)



1035
1036
1037
# File 'src/util/oddbapp.rb', line 1035

def search_hospitals(key)
  ODBA.cache.retrieve_from_index("hospital_index", key)
end

- (Object) search_indications(query)



1038
1039
1040
# File 'src/util/oddbapp.rb', line 1038

def search_indications(query)
  ODBA.cache.retrieve_from_index("indication_index", query)
end

- (Object) search_interactions(query)



1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
# File 'src/util/oddbapp.rb', line 1041

def search_interactions(query)
  result = ODBA.cache.retrieve_from_index("sequence_index_substance", query)
  if(subs = substance(query, false))
    result.unshift(subs)
  end
  if(result.empty?)
    result = soundex_substances(query)
  end
  result
end

- (Object) search_migel_alphabetical(query, lang)



983
984
985
986
987
988
989
# File 'src/util/oddbapp.rb', line 983

def search_migel_alphabetical(query, lang)
  if(lang.to_s != "fr") 
    lang = "de"
  end
  index_name = "migel_index_#{lang}"
  ODBA.cache.retrieve_from_index(index_name, query)
end

- (Object) search_migel_products(query, lang)



990
991
992
993
994
995
996
# File 'src/util/oddbapp.rb', line 990

def search_migel_products(query, lang)
  if(lang.to_s != "fr") 
    lang = "de"
  end
  index_name = "migel_fulltext_index_#{lang}"
  ODBA.cache.retrieve_from_index(index_name, query)
end

- (Object) search_narcotics(query, lang)



997
998
999
1000
1001
1002
1003
# File 'src/util/oddbapp.rb', line 997

def search_narcotics(query, lang)
  if(lang.to_s != "fr") 
    lang = "de"
  end
  index_name = "narcotics_#{lang}"
  ODBA.cache.retrieve_from_index(index_name, query)
end

- (Object) search_oddb(query, lang)



820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
# File 'src/util/oddbapp.rb', line 820

def search_oddb(query, lang)
  # current search_order:
  # 1. atcless
  # 2. iksnr or ean13
  # 3. atc-code
  # 4. exact word in sequence name
  # 5. company-name
  # 6. substance
  # 7. indication
  # 8. sequence
  result = ODDB::SearchResult.new
  result.exact = true
  result.search_query = query
  # atcless
  if(query == 'atcless')
    atc = ODDB::AtcClass.new('n.n.')
    atc.sequences = atcless_sequences
    atc.instance_eval {
      alias :active_packages :packages
    }
    result.atc_classes = [atc]
    result.search_type = :atcless
    return result
  end
  # iksnr or ean13
  if(match = @@iks_or_ean.match(query))
    iksnr = match[1]
    if(reg = registration(iksnr))
      atc = ODDB::AtcClass.new('n.n.')
      atc.sequences = reg.sequences.values
      result.atc_classes = [atc]
      result.search_type = :iksnr
      return result
    end
  end
  # pharmacode
  if(match = /^\d{6,}$/u.match(query))
    if(pac = package(query))
      atc = ODDB::AtcClass.new('n.n.')
      seq = ODDB::Sequence.new(pac.sequence.seqnr)
      seq.registration = pac.registration
      seq.packages.store pac.ikscd, pac
      atc.sequences = [seq]
      result.atc_classes = [atc]
      result.search_type = :pharmacode
      return result
    end
  end
  key = query.to_s.downcase
  # atc-code
  atcs = search_by_atc(key)
  result.search_type = :atc
  result.error_limit = RESULT_SIZE_LIMIT
  # exact word in sequence name
  if(atcs.empty?)
    atcs = search_by_sequence(key, result)
    result.search_type = :sequence
  end
  # company-name
  if(atcs.empty?)
    atcs = search_by_company(key)
    result.search_type = :company
  end
  # substance
  if(atcs.empty?)
    atcs = search_by_substance(key)
    result.search_type = :substance
  end
  # indication
  if(atcs.empty?)
    atcs = search_by_indication(key, lang, result)
    result.search_type = :indication
  end
  # sequence
  if(atcs.empty?)
    atcs = search_by_sequence(key)
    result.search_type = :sequence
  end
  result.atc_classes = atcs
  # interaction
  if(atcs.empty?)
    result = search_by_interaction(key, lang)
  end
  # unwanted effects
  if(result.atc_classes.empty?)
    result = search_by_unwanted_effect(key, lang)
  end
  result
end

- (Object) search_patinfos(query)



1004
1005
1006
# File 'src/util/oddbapp.rb', line 1004

def search_patinfos(query)
  ODBA.cache.retrieve_from_index('sequence_patinfos', query)
end

- (Object) search_sequences(query, chk_all_words = true)



1051
1052
1053
1054
# File 'src/util/oddbapp.rb', line 1051

def search_sequences(query, chk_all_words=true)
  index = (chk_all_words) ? 'sequence_index' : 'sequence_index_exact'
  ODBA.cache.retrieve_from_index(index, query)
end

- (Object) search_single_substance(key)



1055
1056
1057
1058
1059
1060
1061
1062
# File 'src/util/oddbapp.rb', line 1055

def search_single_substance(key)
  result = ODDB::SearchResult.new
  result.exact = true
  key = ODDB.search_term(key)
  ODBA.cache.retrieve_from_index("substance_index", key, result).find { |sub|
    sub.same_as? key
  }
end

- (Object) search_substances(query)



1063
1064
1065
1066
1067
1068
1069
# File 'src/util/oddbapp.rb', line 1063

def search_substances(query)
  if(subs = substance(query))
    [subs]
  else
    soundex_substances(query)
  end
end

- (Object) search_vaccines(query)



1007
1008
1009
# File 'src/util/oddbapp.rb', line 1007

def search_vaccines(query)
  ODBA.cache.retrieve_from_index('sequence_vaccine', query)
end

- (Object) sequences



1070
1071
1072
1073
1074
# File 'src/util/oddbapp.rb', line 1070

def sequences
  @registrations.values.inject([]) { |seq, reg| 
    seq.concat(reg.sequences.values)
  }
end

- (Object) set_currency_rate(symbol, value)



1075
1076
1077
# File 'src/util/oddbapp.rb', line 1075

def set_currency_rate(symbol, value)
  @currency_rates.store(symbol, value)
end

- (Object) slate(name)



1078
1079
1080
# File 'src/util/oddbapp.rb', line 1078

def slate(name)
  @slates[name]
end

- (Object) sorted_fachinfos



1087
1088
1089
1090
# File 'src/util/oddbapp.rb', line 1087

def sorted_fachinfos
  @sorted_fachinfos ||= @fachinfos.values.select { |fi| 
    fi.revision }.sort_by { |fi| fi.revision }.reverse
end

- (Object) sorted_feedbacks



1091
1092
1093
# File 'src/util/oddbapp.rb', line 1091

def sorted_feedbacks
  @sorted_feedbacks ||= @feedbacks.values.sort_by { |fb| fb.time }.reverse
end

- (Object) sorted_minifis



1094
1095
1096
1097
1098
# File 'src/util/oddbapp.rb', line 1094

def sorted_minifis
  @sorted_minifis ||= @minifis.values.sort_by { |minifi| 
    [ -minifi.publication_date.year, 
      -minifi.publication_date.month, minifi.name] }
end

- (Object) sorted_patented_registrations



1099
1100
1101
1102
1103
# File 'src/util/oddbapp.rb', line 1099

def sorted_patented_registrations
  @registrations.values.select { |reg|
    (pat = reg.patent) && pat.expiry_date #_protected?
  }.sort_by { |reg| reg.patent.expiry_date }
end


1104
1105
1106
# File 'src/util/oddbapp.rb', line 1104

def (flavor)
  @sponsors[flavor.to_s]
end

- (Object) substance(key, neurotic = false)



1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
# File 'src/util/oddbapp.rb', line 1107

def substance(key, neurotic=false)
  if(key.to_i.to_s == key.to_s)
    @substances[key.to_i]
  elsif(substance = search_single_substance(key))
    substance
  elsif neurotic
    @substances.values.find { |subs|
      subs.same_as?(key)
    }
  end
end

- (Object) substance_by_connection_key(connection_key)



1118
1119
1120
1121
1122
# File 'src/util/oddbapp.rb', line 1118

def substance_by_connection_key(connection_key)
  @substances.values.select { |substance|
    substance.has_connection_key?(connection_key)
  }.first
end

- (Object) substance_by_smcd(smcd)



1123
1124
1125
1126
1127
# File 'src/util/oddbapp.rb', line 1123

def substance_by_smcd(smcd)
  @substances.values.select { |sub|
    sub.swissmedic_code == smcd
  }.first
end

- (Object) substance_count



1131
1132
1133
# File 'src/util/oddbapp.rb', line 1131

def substance_count
  @substance_count ||= @substances.size
end

- (Object) unique_atc_class(substance)



1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
# File 'src/util/oddbapp.rb', line 1160

def unique_atc_class(substance)
 atc_array = search_by_substance(substance)
=begin ## this is much too unstable, completely wrong assignment is 
     ## probable!
 if(atc_array.size > 1)
   atc_array = atc_array.select { |atc|
     atc.substances.size == 1
   }
 end
=end


 if(atc_array.size == 1)
   atc_array.first
 end
end

- (Object) update(pointer, values, origin = nil)



113
114
115
116
117
118
119
120
121
122
# File 'src/util/oddbapp.rb', line 113

def update(pointer, values, origin=nil)
  #puts [__FILE__,__LINE__,"update(#{pointer}, #{values})"].join(':')
  @last_update = Time.now()
  item = nil
  failsafe(ODDB::Persistence::UninitializedPathError, nil) {
    item = pointer.issue_update(self, values, origin)
    updated(item) unless(item.nil?)
  }
  item
end

- (Object) updated(item)



1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
# File 'src/util/oddbapp.rb', line 1134

def updated(item)
  case item
  when ODDB::Registration, ODDB::Sequence, ODDB::Package, ODDB::AtcClass
    @last_medication_update = @@today
    odba_isolated_store
  when ODDB::LimitationText, ODDB::AtcClass::DDD
  when ODDB::Substance
    @substances.each_value { |subs|
      if(!subs.is_effective_form? && subs.effective_form == item)
        subs.odba_isolated_store
      end
    }
  when ODDB::Fachinfo, ODDB::FachinfoDocument
    @sorted_fachinfos = nil
  when ODDB::
    @sorted_feedbacks = nil
  when ODDB::MiniFi
    @sorted_minifis = nil
  end
end

- (Object) user(oid)



1154
1155
1156
# File 'src/util/oddbapp.rb', line 1154

def user(oid)
  @users[oid]
end

- (Object) user_by_email(email)



1157
1158
1159
# File 'src/util/oddbapp.rb', line 1157

def user_by_email()
  @users.values.find { |user| user.unique_email ==  }
end

- (Object) vaccine_count



1174
1175
1176
# File 'src/util/oddbapp.rb', line 1174

def vaccine_count
  @vaccine_count ||= count_vaccines()
end