Class: ODDB::PackageCommon

Inherits:
Object show all
Includes:
Persistence
Defined in:
src/model/package.rb,
test/test_plugin/bsv_xml.rb

Direct Known Subclasses

Package

Constant Summary

@@ddd_galforms =
/tabletten?/iu

Constants included from Persistence

ODBA_PREDEFINE_SERIALIZABLE

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from PersistenceMethods

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

Constructor Details

- (PackageCommon) initialize(ikscd)

A new instance of PackageCommon



57
58
59
60
61
62
# File 'src/model/package.rb', line 57

def initialize(ikscd)
  super()
  @ikscd = sprintf('%03d', ikscd.to_i)
  @narcotics = []
  @parts = []
end

Instance Attribute Details

- (Object) ddd_dose

Returns the value of attribute ddd_dose



41
42
43
# File 'src/model/package.rb', line 41

def ddd_dose
  @ddd_dose
end

- (Object) deductible

Returns the value of attribute deductible



41
42
43
# File 'src/model/package.rb', line 41

def deductible
  @deductible
end

- (Object) deductible_m

Returns the value of attribute deductible_m



41
42
43
# File 'src/model/package.rb', line 41

def deductible_m
  @deductible_m
end

- (Object) descr

Returns the value of attribute descr



41
42
43
# File 'src/model/package.rb', line 41

def descr
  @descr
end

- (Object) disable

Returns the value of attribute disable



41
42
43
# File 'src/model/package.rb', line 41

def disable
  @disable
end

- (Object) disable_ddd_price

Returns the value of attribute disable_ddd_price



41
42
43
# File 'src/model/package.rb', line 41

def disable_ddd_price
  @disable_ddd_price
end

- (Object) generic_group

Returns the value of attribute generic_group



41
42
43
# File 'src/model/package.rb', line 41

def generic_group
  @generic_group
end

- (Object) generic_group_factor

Returns the value of attribute generic_group_factor



41
42
43
# File 'src/model/package.rb', line 41

def generic_group_factor
  @generic_group_factor
end

- (Object) ikscat

Returns the value of attribute ikscat



41
42
43
# File 'src/model/package.rb', line 41

def ikscat
  @ikscat
end

- (Object) ikscd Also known as: pointer_descr

Returns the value of attribute ikscd



40
41
42
# File 'src/model/package.rb', line 40

def ikscd
  @ikscd
end

- (Object) lppv

Returns the value of attribute lppv



41
42
43
# File 'src/model/package.rb', line 41

def lppv
  @lppv
end

- (Object) market_date

Returns the value of attribute market_date



41
42
43
# File 'src/model/package.rb', line 41

def market_date
  @market_date
end

- (Object) medwin_ikscd

Returns the value of attribute medwin_ikscd



41
42
43
# File 'src/model/package.rb', line 41

def medwin_ikscd
  @medwin_ikscd
end

- (Object) narcotics (readonly)

Returns the value of attribute narcotics



40
41
42
# File 'src/model/package.rb', line 40

def narcotics
  @narcotics
end

- (Object) out_of_trade

Returns the value of attribute out_of_trade



41
42
43
# File 'src/model/package.rb', line 41

def out_of_trade
  @out_of_trade
end

- (Object) parts (readonly)

Returns the value of attribute parts



40
41
42
# File 'src/model/package.rb', line 40

def parts
  @parts
end

- (Object) pharmacode

Returns the value of attribute pharmacode



40
41
42
# File 'src/model/package.rb', line 40

def pharmacode
  @pharmacode
end

Returns the value of attribute photo_link



41
42
43
# File 'src/model/package.rb', line 41

def photo_link
  @photo_link
end

- (Object) pretty_dose

Returns the value of attribute pretty_dose



41
42
43
# File 'src/model/package.rb', line 41

def pretty_dose
  @pretty_dose
end

- (Object) preview_with_market_date

Returns the value of attribute preview_with_market_date



41
42
43
# File 'src/model/package.rb', line 41

def preview_with_market_date
  @preview_with_market_date
end

- (Object) price_exfactory

Returns the value of attribute price_exfactory



41
42
43
# File 'src/model/package.rb', line 41

def price_exfactory
  @price_exfactory
end

- (Object) price_public

Returns the value of attribute price_public



41
42
43
# File 'src/model/package.rb', line 41

def price_public
  @price_public
end

- (Object) refdata_override

Returns the value of attribute refdata_override



41
42
43
# File 'src/model/package.rb', line 41

def refdata_override
  @refdata_override
end

- (Object) sequence

Returns the value of attribute sequence



41
42
43
# File 'src/model/package.rb', line 41

def sequence
  @sequence
end

- (Object) sl_entry (readonly)

Returns the value of attribute sl_entry



40
41
42
# File 'src/model/package.rb', line 40

def sl_entry
  @sl_entry
end

- (Object) sl_generic_type

Returns the value of attribute sl_generic_type



41
42
43
# File 'src/model/package.rb', line 41

def sl_generic_type
  @sl_generic_type
end

- (Object) swissmedic_source

Returns the value of attribute swissmedic_source



41
42
43
# File 'src/model/package.rb', line 41

def swissmedic_source
  @swissmedic_source
end

Class Method Details

+ (Object) price_internal(price, type = nil)



17
18
19
20
21
22
# File 'src/model/package.rb', line 17

def price_internal(price, type=nil)
  unless(price.is_a?(Util::Money))
    price = Util::Money.new(price, type, 'CH')
  end
  price
end

+ (Object) registration_data(*names)



23
24
25
26
27
28
29
30
31
# File 'src/model/package.rb', line 23

def registration_data(*names)
  names.each { |name|
    define_method(name) { 
      if(@sequence && (reg = @sequence.registration))
        reg.send(name)
      end
    }
  }
end

+ (Object) sequence_data(*names)



32
33
34
35
36
37
38
# File 'src/model/package.rb', line 32

def sequence_data(*names)
  names.each { |name|
    define_method(name) { 
      @sequence && @sequence.send(name)
    }
  }
end

Instance Method Details

- (Object) <=>(other)



273
274
275
276
# File 'src/model/package.rb', line 273

def <=>(other)
  [self.basename, self.dose.to_f, self.comparable_size.to_f] <=> \
    [other.basename, other.dose.to_f, other.comparable_size.to_f]
end

- (Boolean) active?

Returns:

  • (Boolean)


63
64
65
66
# File 'src/model/package.rb', line 63

def active?
  !@disable && (@preview_with_market_date || @market_date.nil? \
                || @market_date <= @@today)
end

- (Object) active_agents



67
68
69
# File 'src/model/package.rb', line 67

def active_agents
  @parts.inject([]) { |acts, part| acts.concat part.active_agents }
end

- (Object) add_narcotic(narc)



70
71
72
73
74
75
76
77
# File 'src/model/package.rb', line 70

def add_narcotic(narc)
  unless(narc.nil? || @narcotics.include?(narc))
    @narcotics.push(narc)
    @narcotics.odba_isolated_store
    narc.add_package(self)
  end
  narc
end

- (Object) barcode



78
79
80
81
82
# File 'src/model/package.rb', line 78

def barcode
  if(key = ikskey)
    Ean13.new_unchecked('7680'+key).to_s
  end
end

- (Object) checkout



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'src/model/package.rb', line 83

def checkout
  checkout_helper([@generic_group], :remove_package)
  @narcotics.each { |narc| 
    narc.remove_package(self)
  } if @narcotics
  @parts.dup.each { |part|
    part.checkout
    part.odba_delete
  }
  @parts.odba_delete
  if(@sl_entry.respond_to?(:checkout))
    @sl_entry.checkout 
    @sl_entry.odba_delete
  end
end

- (Object) commercial_forms



98
99
100
# File 'src/model/package.rb', line 98

def commercial_forms
  @parts.collect { |part| part.commercial_form }
end

- (Object) company_name



101
102
103
# File 'src/model/package.rb', line 101

def company_name
  (cmp = company) && cmp.name
end

- (Boolean) comparable?(bottom, top, pack)

Returns:

  • (Boolean)


107
108
109
110
111
112
113
114
115
116
117
# File 'src/model/package.rb', line 107

def comparable?(bottom, top, pack)
  begin
    pack != self \
      && (other = pack.comparable_size) \
      && bottom < other \
      && top > other \
      && !pack.basename.nil?
  rescue RuntimeError => e
    false
  end
end

- (Object) comparable_size



133
134
135
136
137
138
139
# File 'src/model/package.rb', line 133

def comparable_size
  @parts.collect { |part| part.comparable_size }.inject{ |a, b| a + b } or raise RuntimeError
rescue RuntimeError
  @parts.inject(Dose.new(0)) { |comp, part|
    ODDB::Dose.new(comp.qty + part.comparable_size.qty)
  } rescue nil
end

- (Object) comparables



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'src/model/package.rb', line 118

def comparables
  cs = comparable_size
  bottom = cs * 0.75
  top = cs * 1.25
  comparables = generic_group_comparables
  @sequence.comparables.each { |seq|
    comparables.concat seq.public_packages.select { |pack|
      comparable?(bottom, top, pack)
    }
  }
  comparables.concat @sequence.public_packages.select { |pack|
    comparable?(bottom, top, pack)
  }
  comparables.uniq
end

- (Object) compositions



104
105
106
# File 'src/model/package.rb', line 104

def compositions
  @parts.inject([]) { |comps, part| comps.push part.composition }.compact
end

- (Object) create_part



140
141
142
143
144
145
# File 'src/model/package.rb', line 140

def create_part
  part = Part.new
  part.package = self
  @parts.push part
  part
end

- (Object) create_sl_entry



146
147
148
# File 'src/model/package.rb', line 146

def create_sl_entry
  @sl_entry = SlEntry.new
end

- (Object) ddd



149
150
151
152
153
# File 'src/model/package.rb', line 149

def ddd
  if (atc = atc_class) && atc.has_ddd?
    atc.ddds['O']
  end
end

- (Object) ddd_price



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'src/model/package.rb', line 154

def ddd_price
  if(!@disable_ddd_price && (ddd = self.ddd) \
    && (grp = galenic_group) && grp.match(@@ddd_galforms) \
    && (price = price_public) && (ddose = ddd.dose) && (mdose = dose) \
    && size = comparable_size)
    factor = (longevity || 1).to_f
    if(mdose > (ddose * factor))
      (price / size.to_f) / factor
    else
      (price / size.to_f) \
        * (ddose.to_f * factor / mdose.want(ddose.unit).to_f) / factor
    end
  end
rescue RuntimeError
end

- (Object) delete_part(oid)



169
170
171
# File 'src/model/package.rb', line 169

def delete_part(oid)
  @parts.delete_if { |comp| comp.oid == oid }
end

- (Object) delete_sl_entry



172
173
174
175
176
177
178
179
180
181
182
183
# File 'src/model/package.rb', line 172

def delete_sl_entry
  @sl_entry = nil
  @deductible = nil
  @sl_generic_type = nil
  reg = @sequence.registration
  unless reg.nil? || reg.packages.any? do |pac| pac.sl_entry end
    reg.generic_type = nil
    reg.odba_isolated_store
  end
  self.odba_isolated_store
  nil
end

- (Object) dose



184
185
186
# File 'src/model/package.rb', line 184

def dose
  @ddd_dose || (@sequence.dose if @sequence)
end

- (Object) fix_pointers



187
188
189
190
191
192
193
194
195
196
197
# File 'src/model/package.rb', line 187

def fix_pointers
  @pointer = @sequence.pointer + [:package, @ikscd]
  if(sl = @sl_entry)
    sl.pointer = @pointer + [:sl_entry]
    sl.odba_store
  end
  @parts.each { |part|
    part.fix_pointers
  }
  odba_store
end

- (Object) generic_group_comparables(filters = [])



198
199
200
201
202
203
204
205
# File 'src/model/package.rb', line 198

def generic_group_comparables(filters=[])
  if @generic_group \
    && !((go = data_origins['generic_group']) && filters.include?(go))
    @generic_group.packages - [self]
  else
    []
  end
end

- (Boolean) good_result?(query)

Returns:

  • (Boolean)


206
207
208
209
# File 'src/model/package.rb', line 206

def good_result?(query)
  query = query.to_s.downcase
  basename.to_s.downcase[0,query.length] == query
end

- (Boolean) has_generic?

Returns:

  • (Boolean)


210
211
212
# File 'src/model/package.rb', line 210

def has_generic?
  @generic_type == :original && !comparables.empty?
end

- (Object) ikskey



227
228
229
230
231
# File 'src/model/package.rb', line 227

def ikskey
  if(nr = iksnr)
    nr + @ikscd
  end
end

- (Object) limitation



232
233
234
# File 'src/model/package.rb', line 232

def limitation
  @sl_entry.limitation unless @sl_entry.nil?
end

- (Object) limitation_text



235
236
237
# File 'src/model/package.rb', line 235

def limitation_text
  @sl_entry.limitation_text unless @sl_entry.nil?
end

- (Object) localized_name(language)



224
225
226
# File 'src/model/package.rb', line 224

def localized_name(language)
  @sequence.localized_name(language)
end

- (Object) most_precise_dose



238
239
240
# File 'src/model/package.rb', line 238

def most_precise_dose
  @pretty_dose || dose
end

- (Object) name_with_size



241
242
243
# File 'src/model/package.rb', line 241

def name_with_size
  [name_base, size].join(', ')
end

- (Boolean) narcotic?

Returns:

  • (Boolean)


244
245
246
# File 'src/model/package.rb', line 244

def narcotic?
  @narcotics.any? { |narc| narc.category == 'a' }
end

- (Object) part(oid)



247
248
249
# File 'src/model/package.rb', line 247

def part(oid)
  @parts.find { |part| part.oid == oid }
end

- (Boolean) preview?

Returns:

  • (Boolean)


253
254
255
# File 'src/model/package.rb', line 253

def preview?
  @preview_with_market_date && @market_date && @market_date > @@today
end

- (Boolean) public?

Returns:

  • (Boolean)


256
257
258
259
# File 'src/model/package.rb', line 256

def public?
  active? && (@refdata_override || !@out_of_trade \
              || registration.active?)
end

- (Object) remove_narcotic(narc)



260
261
262
263
264
265
266
# File 'src/model/package.rb', line 260

def remove_narcotic(narc)
  if(res = @narcotics.delete(narc))
    @narcotics.odba_isolated_store
    narc.remove_package(self)
  end
  res
end

- (Object) size



267
268
269
# File 'src/model/package.rb', line 267

def size
  @parts.collect { |part| part.size }.compact.join(' + ')
end

- (Object) substances



270
271
272
# File 'src/model/package.rb', line 270

def substances
  active_agents.collect { |active| active.substance }.compact
end