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



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

alias :__sequence_writer__ :sequence=

#_price_exfactory(country = ODDB.config.country) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/oddb/drugs/package.rb', line 54

def _price_exfactory(country=ODDB.config.country)
  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

#comparable?(other) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/oddb/drugs/package.rb', line 21

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? { |lower, upper|
    idx += 1
    size = osizes.at(idx)
    lower <= size && size <= upper
  }
end

#comparablesObject



34
35
36
37
38
39
40
# File 'lib/oddb/drugs/package.rb', line 34

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

#dose_price(dose) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/oddb/drugs/package.rb', line 41

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 = ODDB.config.country) ⇒ Object



48
49
50
# File 'lib/oddb/drugs/package.rb', line 48

def price(type, country=ODDB.config.country)
  prices.find { |money| money.is_for?(type, country) }
end

#price_exfactory(country = ODDB.config.country) ⇒ Object



51
52
53
# File 'lib/oddb/drugs/package.rb', line 51

def price_exfactory(country=ODDB.config.country)
  price(:exfactory, country)
end

#sequence=(seq) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/oddb/drugs/package.rb', line 68

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



82
83
84
# File 'lib/oddb/drugs/package.rb', line 82

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

#to_yaml_map(map) ⇒ Object



93
94
95
96
97
98
99
# File 'lib/oddb/export/yaml.rb', line 93

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



100
101
102
# File 'lib/oddb/export/yaml.rb', line 100

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