Class: ODDB::Drugs::Package

Inherits:
Model
  • Object
show all
Defined in:
lib/oddb/export/yaml.rb,
lib/oddb/drugs/package.rb,
lib/oddb/persistence/odba/drugs/package.rb

Constant Summary

Constants included from OddbUri

OddbUri::YAML_URI

Instance Method Summary collapse

Methods inherited from Model

#__odba_delete__, #__odba_save__, _serializables, belongs_to, connections, connector, connectors, #data_origin, #data_origins, delegates, #delete, find_by_uid, has_many, is_coded, m10l_document, multilingual, #odba_serializables, #oid, on_delete, on_save, predicates, #save, #saved?, serializables, serialize, singular

Methods included from Yaml

append_features

Methods included from OddbUri

#to_yaml, #to_yaml_type

Instance Method Details

#__sequence_writer__Object



90
# File 'lib/oddb/drugs/package.rb', line 90

alias :__sequence_writer__ :sequence=

#_price_exfactory(country = 'DE') ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/oddb/drugs/package.rb', line 62

def _price_exfactory(country='DE')
  if((price = price(:public, country)) \
     && (code = code(:prescription)) && code.value)
    c = ODDB.config
    efp = (price - c.pharmacy_premium) * 100 /
      (100.0 + c.vat + c.pharmacy_percentage) 
    efp.type = :exfactory
    efp.country = country
    efp
  end
end

#_price_zuzahlung(country = 'DE') ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/oddb/drugs/package.rb', line 78

def _price_zuzahlung(country='DE')
  if(pp = price(:public, country))
    if pp <= 50
      Util::Money.five
    elsif pp <= 100
      pp * 0.1
    else
      Util::Money.ten
    end
  end
end

#cascading_name(language) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/oddb/drugs/package.rb', line 18

def cascading_name(language)
  str = name.send language
  if str.to_s.empty? && sequence
    str = sequence.cascading_name language
  end
  str
end

#comparable?(other) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/oddb/drugs/package.rb', line 25

def comparable?(other)
  return false unless(other.is_a?(Package))
  csizes = comparable_size.collect { |psize|
    (psize*0.75)..(psize*1.25)
  }
  osizes = other.comparable_size
  idx = -1
  osizes.length == csizes.length && csizes.all? { |range|
    idx += 1
    range.include?(osizes.at(idx))
  }
end

#comparablesObject



37
38
39
40
41
42
43
# File 'lib/oddb/drugs/package.rb', line 37

def comparables
  @sequence.comparables.inject([]) { |memo, sequence|
    memo.concat sequence.packages.select { |package|
      (package != self) && comparable?(package)
    }
  }
end

#dose_price(dose) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/oddb/drugs/package.rb', line 44

def dose_price(dose)
  if(price = price(:public))
    pdose = doses.first.want(dose.unit)
    Util::Money.new((dose / pdose).to_f * (price.to_f / size))
  end
rescue StandardError
end

#price(type, country = 'DE') ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/oddb/drugs/package.rb', line 51

def price(type, country='DE')
  case type.to_s
  when 'zuzahlung'
    price_zuzahlung(country)
  else
    prices.find { |money| money.is_for?(type, country) }
  end
end

#price_exfactory(country = 'DE') ⇒ Object



59
60
61
# File 'lib/oddb/drugs/package.rb', line 59

def price_exfactory(country='DE')
  price(:exfactory, country)
end

#price_zuzahlung(country = 'DE') ⇒ Object



73
74
75
76
77
# File 'lib/oddb/drugs/package.rb', line 73

def price_zuzahlung(country='DE')
  unless((code = code(:zuzahlungsbefreit)) && code.value)
    _price_zuzahlung country
  end
end

#sequence=(seq) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/oddb/drugs/package.rb', line 92

def sequence=(seq)
  old = @sequence
  __sequence_writer__(seq)
  if(seq)
    comps = seq.compositions
    parts.each_with_index { |part, idx|
      part.composition = comps.at(idx)
      part.save
    }
  else
    parts.each { |part| part.composition = nil }
  end
  seq
end

#sizeObject



106
107
108
# File 'lib/oddb/drugs/package.rb', line 106

def size
  parts.inject(0) { |memo, part| memo + part.comparable_size.qty }
end

#to_yaml_map(map) ⇒ Object



96
97
98
99
100
101
102
# File 'lib/oddb/export/yaml.rb', line 96

def to_yaml_map(map)
  super
  map.add('prices', self.prices.inject({}) { |memo, price|
    memo.store(price.type, price.to_f)
    memo 
  } )
end

#to_yaml_propertiesObject



103
104
105
# File 'lib/oddb/export/yaml.rb', line 103

def to_yaml_properties
  (super - ['@prices']).push('@parts')
end