Class: ODDB::Package

Inherits:
PackageCommon show all
Includes:
ODBA::Persistable, FeedbackObserver, OddbYaml
Defined in:
ext/export/src/oddb_yaml.rb,
src/model/package.rb,
test/test_model/package.rb,
test/test_plugin/bsv_xml.rb

Overview

< PackageCommon

Constant Summary

ODBA_SERIALIZABLE =
[ '@prices', '@ancestors', '@swissmedic_source' ]
EXPORT_PROPERTIES =
[ 
  '@ikscd',
  '@lppv',
  '@descr',
  '@ikscat',
  '@sl_entry',
  '@parts',
]

Constants included from OddbYaml

EXPORT_PROPERTIES, YAML_URI

Constants included from Persistence

ODBA_PREDEFINE_SERIALIZABLE

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from OddbYaml

#to_yaml_properties, #to_yaml_type

Methods included from FeedbackObserver

#add_feedback, #feedback, #remove_feedback

Methods inherited from PackageCommon

#<=>, #active?, #active_agents, #add_narcotic, #barcode, #commercial_forms, #company_name, #comparable?, #comparable_size, #comparables, #compositions, #create_part, #create_sl_entry, #ddd, #ddd_price, #delete_part, #delete_sl_entry, #dose, #fix_pointers, #generic_group_comparables, #good_result?, #has_generic?, #ikskey, #limitation, #limitation_text, #localized_name, #most_precise_dose, #name_with_size, #narcotic?, #part, #preview?, price_internal, #public?, registration_data, #remove_narcotic, sequence_data, #size, #substances

Methods included from PersistenceMethods

#data_origin, #data_origins, #diff, #init, #nil_if_empty, #parent, #pointer_descr, #structural_ancestors, #undiffable?, #update_values

Constructor Details

- (Package) initialize(ikscd)

A new instance of Package



304
305
306
307
# File 'src/model/package.rb', line 304

def initialize(ikscd)
  super
  @feedbacks = []
end

Instance Attribute Details

- (Object) ancestors

Returns the value of attribute ancestors



302
303
304
# File 'src/model/package.rb', line 302

def ancestors
  @ancestors
end

- (Object) medwin_ikscd

Returns the value of attribute medwin_ikscd



302
303
304
# File 'src/model/package.rb', line 302

def medwin_ikscd
  @medwin_ikscd
end

Instance Method Details

- (Object) adjust_types

- (Object) checkout



308
309
310
311
312
313
314
# File 'src/model/package.rb', line 308

def checkout
  super
  if(@feedbacks)
    @feedbacks.dup.each { |fb| fb.item = nil; fb.odba_store }
    @feedbacks.odba_delete
  end
end

- (Object) generic_group=(generic_group)



315
316
317
318
319
320
321
322
323
# File 'src/model/package.rb', line 315

def generic_group=(generic_group)
  unless(@generic_group.nil?)
    @generic_group.remove_package(self)
  end
  unless(generic_group.nil?)
    generic_group.add_package(self)
  end
  @generic_group = generic_group
end

- (Boolean) has_price?

Returns:

  • (Boolean)


324
325
326
# File 'src/model/package.rb', line 324

def has_price?
  prices.any? do |key, values| !values.empty? end
end

- (Boolean) has_price_history?

Returns:

  • (Boolean)


327
328
329
# File 'src/model/package.rb', line 327

def has_price_history?
  prices.any? do |key, values| values.size > 1 end
end

- (Object) price(type, ord_or_time = 0)



330
331
332
333
334
335
336
337
# File 'src/model/package.rb', line 330

def price(type, ord_or_time=0)
  candidates = (prices[type] ||= [])
  if(ord_or_time.is_a?(Time))
    candidates.find { |price| price.valid_from < ord_or_time }
  else
    candidates[ord_or_time.to_i]
  end
end

- (Object) price_exfactory(ord_or_time = 0)



338
339
340
# File 'src/model/package.rb', line 338

def price_exfactory(ord_or_time=0)
  price(:exfactory, ord_or_time)
end

- (Object) price_exfactory=(price)



341
342
343
344
345
# File 'src/model/package.rb', line 341

def price_exfactory=(price)
  return price_exfactory if(price == price_exfactory)
  (prices[:exfactory] ||= []).unshift(price)
  price
end

- (Object) price_public(ord_or_time = 0)



346
347
348
# File 'src/model/package.rb', line 346

def price_public(ord_or_time=0)
  price(:public, ord_or_time)
end

- (Object) price_public=(price)



349
350
351
352
353
# File 'src/model/package.rb', line 349

def price_public=(price)
  return price_public if(price == price_public)
  (prices[:public] ||= []).unshift(price)
  price
end

- (Object) prices



354
355
356
# File 'src/model/package.rb', line 354

def prices
  @prices ||= {}
end

- (Object) to_yaml(opts = {})



358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
# File 'ext/export/src/oddb_yaml.rb', line 358

def to_yaml( opts = {} )
  YAML::quick_emit( self.object_id, opts ) { |out|
    out.map( taguri ) { |map|
      if Thread.current[:export_prices]
        map.add('iksnr', self.iksnr)
        map.add('ikscd', self.ikscd)
        map.add('name', self.name)
        map.add('size', self.size)
        map.add('ean13', self.barcode.to_s)
        map.add('pharmacode', self.pharmacode)
        map.add('out_of_trade', !self.public?)
        map.add('prices', self.prices)
      else
        to_yaml_properties.each { |m|
          map.add( m[1..-1], instance_variable_get( m ) )
        }
        map.add('has_generic', self.has_generic?)
        map.add('ean13', self.barcode.to_s)
        map.add('price_exfactory', self.price_exfactory.to_f)
        map.add('price_public', self.price_public.to_f)
        map.add('pharmacode', self.pharmacode)
        map.add('narcotics', @narcotics.collect { |narc| narc.casrn})
        map.add('deductible', {'deductible_g' => 10, 'deductible_o' => 20 }[self.deductible.to_s])
      end
    }
  }
end