Class: ODDB::Remote::Drugs::Package
- Defined in:
- lib/oddb/remote/drugs/package.rb
Instance Attribute Summary
Attributes inherited from Object
Instance Method Summary collapse
- #active_agents ⇒ Object
- #atc ⇒ Object
- #code(type, country = 'CH') ⇒ Object
- #company ⇒ Object
- #comparable_size ⇒ Object
- #comparables ⇒ Object
- #ddds ⇒ Object
- #dose_price(dose) ⇒ Object
- #galenic_forms ⇒ Object
-
#initialize(source, remote, currency_rate = 1.0, tax_factor = 1.0) ⇒ Package
constructor
A new instance of Package.
- #local_comparables ⇒ Object
- #name ⇒ Object
- #parts ⇒ Object
- #price(type) ⇒ Object
- #remote_price(key) ⇒ Object
- #size ⇒ Object
Methods inherited from Object
Constructor Details
#initialize(source, remote, currency_rate = 1.0, tax_factor = 1.0) ⇒ Package
Returns a new instance of Package.
20 21 22 23 24 25 |
# File 'lib/oddb/remote/drugs/package.rb', line 20 def initialize(source, remote, currency_rate=1.0, tax_factor=1.0) @tax_factor = tax_factor.to_f @currency_rate = currency_rate.to_f @cache = {} super(source, remote) end |
Instance Method Details
#active_agents ⇒ Object
26 27 28 29 30 |
# File 'lib/oddb/remote/drugs/package.rb', line 26 def active_agents @active_agents ||= @remote.active_agents.collect { |act| Remote::Drugs::ActiveAgent.new(@source, act) } end |
#atc ⇒ Object
31 32 33 |
# File 'lib/oddb/remote/drugs/package.rb', line 31 def atc @atc ||= Remote::Drugs::Atc.new(@source, @remote.atc_class) end |
#code(type, country = 'CH') ⇒ Object
34 35 36 37 38 39 |
# File 'lib/oddb/remote/drugs/package.rb', line 34 def code(type, country='CH') case type when :ean @ean ||= ODDB::Util::Code.new(:ean, @remote., 'CH') end end |
#company ⇒ Object
40 41 42 |
# File 'lib/oddb/remote/drugs/package.rb', line 40 def company @company ||= Remote::Business::Company.new(@source, @remote.company) end |
#comparable_size ⇒ Object
48 49 50 |
# File 'lib/oddb/remote/drugs/package.rb', line 48 def comparable_size @comparable_size ||= @remote.comparable_size end |
#comparables ⇒ Object
43 44 45 46 47 |
# File 'lib/oddb/remote/drugs/package.rb', line 43 def comparables local_comparables.concat @remote.comparables.collect { |pac| Package.new(@source, pac, @currency_rate, @tax_factor) } end |
#ddds ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/oddb/remote/drugs/package.rb', line 51 def ddds @ddds ||= galenic_forms.inject([]) { |memo, form| if(group = form.group) memo.concat atc.ddds(group.administration) end memo } end |
#dose_price(dose) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/oddb/remote/drugs/package.rb', line 59 def dose_price(dose) if(price = price(:public)) pdose = doses.first.want(dose.unit) ODDB::Util::Money.new((dose / pdose).to_f * (price.to_f / size)) end rescue StandardError end |
#galenic_forms ⇒ Object
66 67 68 69 70 |
# File 'lib/oddb/remote/drugs/package.rb', line 66 def galenic_forms @galenic_forms ||= @remote.galenic_forms.collect { |form| Remote::Drugs::GalenicForm.new(@source, form) } end |
#local_comparables ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/oddb/remote/drugs/package.rb', line 71 def local_comparables comparables = [] doses = active_agents.collect { |act| act.dose } if(doses.size == 1 \ && (atc = ODDB::Drugs::Atc.find_by_code(self.atc.code))) descriptions = galenic_forms.collect { |form| form.description.de } groupnames = galenic_forms.collect { |form| form.groupname } range = (size*0.75)..(size*1.25) atc.products.each { |prod| prod.sequences.each { |seq| if(seq.doses == doses) descs = [] names = [] seq.galenic_forms.each { |form| descs.push form.description if grp = form.group names.push grp.name end } if(descs == descriptions || groupnames.all? { |name| names.any? { |other| other == name } }) comparables.concat seq.packages.select { |pac| range.include?(pac.size) } end end } } end comparables end |
#name ⇒ Object
102 103 104 |
# File 'lib/oddb/remote/drugs/package.rb', line 102 def name @name ||= ODDB::Util::Multilingual.new(:de => @remote.name_base) end |
#parts ⇒ Object
105 106 107 108 109 |
# File 'lib/oddb/remote/drugs/package.rb', line 105 def parts @parts ||= @remote.parts.collect { |part| Remote::Drugs::Part.new(@source, part) } end |
#price(type) ⇒ Object
110 111 112 113 114 115 |
# File 'lib/oddb/remote/drugs/package.rb', line 110 def price(type) case type when :public, :exfactory @cache.fetch(type) { @cache.store(type, remote_price(type)) } end end |
#remote_price(key) ⇒ Object
116 117 118 119 |
# File 'lib/oddb/remote/drugs/package.rb', line 116 def remote_price(key) pr = @remote.send("price_#{key}").to_f * @currency_rate / @tax_factor ODDB::Util::Money.new(pr.to_f) if(pr > 0) end |
#size ⇒ Object
120 121 122 |
# File 'lib/oddb/remote/drugs/package.rb', line 120 def size @size ||= comparable_size.qty end |