Class: ODDB::SequenceCommon

Inherits:
Object show all
Includes:
Persistence
Defined in:
src/model/sequence.rb,
test/test_model/sequence.rb

Direct Known Subclasses

Sequence

Constant Summary

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

- (SequenceCommon) initialize(seqnr)

A new instance of SequenceCommon



31
32
33
34
35
# File 'src/model/sequence.rb', line 31

def initialize(seqnr)
  @seqnr = sprintf('%02d', seqnr.to_i)
  @packages = {}
  @compositions = []
end

Instance Attribute Details

- (Object) activate_patinfo

Returns the value of attribute activate_patinfo



23
24
25
# File 'src/model/sequence.rb', line 23

def activate_patinfo
  @activate_patinfo
end

- (Object) atc_class

Returns the value of attribute atc_class



23
24
25
# File 'src/model/sequence.rb', line 23

def atc_class
  @atc_class
end

- (Object) atc_request_time

Returns the value of attribute atc_request_time



23
24
25
# File 'src/model/sequence.rb', line 23

def atc_request_time
  @atc_request_time
end

- (Object) composition_text=(value) (writeonly)

Sets the attribute composition_text

Parameters:

  • value

    the value to set the attribute composition_text to.



26
27
28
# File 'src/model/sequence.rb', line 26

def composition_text=(value)
  @composition_text = value
end

- (Object) compositions (readonly)

Returns the value of attribute compositions



21
22
23
# File 'src/model/sequence.rb', line 21

def compositions
  @compositions
end

- (Object) deactivate_patinfo

Returns the value of attribute deactivate_patinfo



23
24
25
# File 'src/model/sequence.rb', line 23

def deactivate_patinfo
  @deactivate_patinfo
end

- (Object) dose

simulate the legacy attribute_reader for dose



129
130
131
132
# File 'src/model/sequence.rb', line 129

def dose 
  doses.inject { |a,b| a + b }
rescue
end

- (Object) export_flag

Returns the value of attribute export_flag



23
24
25
# File 'src/model/sequence.rb', line 23

def export_flag
  @export_flag
end

- (Object) inactive_date=(value) (writeonly)

Sets the attribute inactive_date

Parameters:

  • value

    the value to set the attribute inactive_date to.



26
27
28
# File 'src/model/sequence.rb', line 26

def inactive_date=(value)
  @inactive_date = value
end

- (Object) longevity

Returns the value of attribute longevity



21
22
23
# File 'src/model/sequence.rb', line 21

def longevity
  @longevity
end

- (Object) name_base

Returns the value of attribute name_base



21
22
23
# File 'src/model/sequence.rb', line 21

def name_base
  @name_base
end

- (Object) name_descr

Returns the value of attribute name_descr



21
22
23
# File 'src/model/sequence.rb', line 21

def name_descr
  @name_descr
end

- (Object) packages

Returns the value of attribute packages



21
22
23
# File 'src/model/sequence.rb', line 21

def packages
  @packages
end

- (Object) patinfo

Returns the value of attribute patinfo



23
24
25
# File 'src/model/sequence.rb', line 23

def patinfo
  @patinfo
end

- (Object) patinfo_oid (readonly)

Returns the value of attribute patinfo_oid



19
20
21
# File 'test/test_model/sequence.rb', line 19

def patinfo_oid
  @patinfo_oid
end

- (Object) pdf_patinfo

Returns the value of attribute pdf_patinfo



23
24
25
# File 'src/model/sequence.rb', line 23

def pdf_patinfo
  @pdf_patinfo
end

- (Object) registration

Returns the value of attribute registration



23
24
25
# File 'src/model/sequence.rb', line 23

def registration
  @registration
end

- (Object) seqnr Also known as: pointer_descr

Returns the value of attribute seqnr



21
22
23
# File 'src/model/sequence.rb', line 21

def seqnr
  @seqnr
end

- (Object) sequence_date

Returns the value of attribute sequence_date



23
24
25
# File 'src/model/sequence.rb', line 23

def sequence_date
  @sequence_date
end

Class Method Details

+ (Object) registration_data(*names)



13
14
15
16
17
18
19
# File 'src/model/sequence.rb', line 13

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

Instance Method Details

- (Boolean) _violates_patent?(seq)

Returns:

  • (Boolean)


295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'src/model/sequence.rb', line 295

def _violates_patent?(seq)
  other = seq.active_agents
  agents = active_agents
  other.size == agents.size or return false
  other = other.sort 
  agents = agents.sort
  other.each_with_index { |oth, idx|
    agt = agents.at(idx)
    oth.substance == agt.substance or return false
    oth.chemical_substance == agt.chemical_substance or return false
  }
  true
end

- (Boolean) active?

Returns:

  • (Boolean)


61
62
63
64
# File 'src/model/sequence.rb', line 61

def active?
  (!@inactive_date || (@inactive_date > @@two_years_ago)) \
    && @registration && @registration.active? && !violates_patent?
end

- (Object) active_agents



65
66
67
68
69
# File 'src/model/sequence.rb', line 65

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

- (Object) active_package_count(generic_type = nil)



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'src/model/sequence.rb', line 43

def active_package_count(generic_type=nil)
  if(active? && (generic_type.nil? \
    || @registration.generic_type == generic_type))
    @packages.values.inject(0) { |count, pack|
      if(pack.active?)
        count += 1
      end
      count
    }
  else
    0
  end
end

- (Object) active_packages



36
37
38
39
40
41
42
# File 'src/model/sequence.rb', line 36

def active_packages
  if(active?) 
    @packages.values.select { |pac| pac.active? }
  else
    []
  end
end

- (Object) active_patinfo

active_patinfo is used for invoicing. Returns path to a pdf file, iff it

 is displayed online.


58
59
60
# File 'src/model/sequence.rb', line 58

def active_patinfo
  active? && patinfo_active? && @pdf_patinfo
end

- (Object) adjust_types(values, app = nil)



309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
# File 'src/model/sequence.rb', line 309

def adjust_types(values, app=nil)
  values = values.dup
  values.each { |key, value|
    if(value.is_a?(Persistence::Pointer))
      values[key] = value.resolve(app)
    else
      case(key)
      when :atc_class
        values[key] = if(atc = app.atc_class(value))
          atc
        else
          @atc_class
        end
      when :dose
        values[key] = if(value.is_a? Dose)
          value
        elsif(value.is_a?(Array))
          Dose.new(*value)
        end
      when :inactive_date, :sequence_date
        if(value.is_a?(String))
          values.store(key, Date.parse(value.tr('.', '-')))
        end
      end 
    end
  }
  values
end

- (Object) basename



70
71
72
# File 'src/model/sequence.rb', line 70

def basename
  @name_base.to_s[/^.[^0-9]+/u]
end

- (Object) checkout



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'src/model/sequence.rb', line 73

def checkout
  checkout_helper([@atc_class, @patinfo], :remove_sequence)
  @packages.each_value { |pac| 
    pac.checkout 
    pac.odba_delete
  }
  @packages.odba_delete
  @compositions.dup.each { |comp| 
    comp.checkout 
    comp.odba_delete
  }
  @compositions.odba_delete
end

- (Boolean) comparable?(seq, factor = 1.0, comps = nil)

Returns:

  • (Boolean)


96
97
98
99
100
101
# File 'src/model/sequence.rb', line 96

def comparable?(seq, factor = 1.0, comps = nil)
  comps ||= factored_compositions(factor)
  seq != self \
    && seq.active? \
    && seq.compositions.sort == comps
end

- (Object) comparables(factor = 1.0)



86
87
88
89
90
91
92
93
94
95
# File 'src/model/sequence.rb', line 86

def comparables(factor = 1.0)
  if(@atc_class)
    comps = factored_compositions(factor)
    @atc_class.sequences.select { |seq|
      comparable?(seq, factor, comps)
    }
  else
    []
  end
end

- (Object) composition(oid)



102
103
104
# File 'src/model/sequence.rb', line 102

def composition(oid)
  @compositions.find { |comp| comp.oid == oid }
end

- (Object) create_composition



105
106
107
108
109
110
# File 'src/model/sequence.rb', line 105

def create_composition
  comp = Composition.new
  comp.sequence = self
  @compositions.push comp
  comp
end

- (Object) create_package(ikscd)



111
112
113
114
115
116
117
118
# File 'src/model/sequence.rb', line 111

def create_package(ikscd)
  ikscd = sprintf('%03d', ikscd.to_i)
  unless @packages.include?(ikscd)
    pkg = self::class::PACKAGE.new(ikscd)
    pkg.sequence = self
    @packages.store(ikscd, pkg) 
  end
end

- (Object) delete_composition(oid)



119
120
121
# File 'src/model/sequence.rb', line 119

def delete_composition(oid)
  @compositions.delete_if { |comp| comp.oid == oid }
end

- (Object) delete_package(ikscd)



122
123
124
125
126
127
128
# File 'src/model/sequence.rb', line 122

def delete_package(ikscd)
  ikscd = sprintf('%03d', ikscd.to_i)
  if(pac = @packages.delete(ikscd))
    @packages.odba_isolated_store
    pac
  end
end

- (Object) doses



133
134
135
136
137
# File 'src/model/sequence.rb', line 133

def doses
  @compositions.inject([]) { |doses, comp|
    doses.concat comp.doses
  }
end

- (Object) each_package(&block)



138
139
140
# File 'src/model/sequence.rb', line 138

def each_package(&block)
  @packages.values.each(&block)
end

- (Object) factored_compositions(factor = 1.0)



141
142
143
144
145
146
147
# File 'src/model/sequence.rb', line 141

def factored_compositions(factor=1.0)
  comps = @compositions.sort
  if factor != 1.0
    comps = comps.collect do |comp| comp * factor end
  end
  comps
end

- (Object) fix_pointers



148
149
150
151
152
153
154
155
156
157
# File 'src/model/sequence.rb', line 148

def fix_pointers
  @pointer = @registration.pointer + [:sequence, @seqnr]
  @packages.each_value { |package|
    package.fix_pointers
  }
  @compositions.each { |comp|
    comp.fix_pointers
  }
  odba_store
end

- (Object) galenic_forms



165
166
167
# File 'src/model/sequence.rb', line 165

def galenic_forms
  @compositions.collect { |comp| comp.galenic_form }.compact.uniq
end

- (Object) galenic_group



158
159
160
161
# File 'src/model/sequence.rb', line 158

def galenic_group
  groups = galenic_groups
  groups.first if groups.size == 1
end

- (Object) galenic_groups



162
163
164
# File 'src/model/sequence.rb', line 162

def galenic_groups
  @compositions.collect { |comp| comp.galenic_group }.compact.uniq
end

- (Boolean) has_patinfo?

Returns:

  • (Boolean)


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

def has_patinfo?
  (!@patinfo.nil? || !@pdf_patinfo.nil?) && patinfo_active? \
    && !company.disable_patinfo
end

- (Boolean) has_public_packages?

Returns:

  • (Boolean)


172
173
174
175
176
# File 'src/model/sequence.rb', line 172

def has_public_packages?
  @packages.any? { |key, pac|
    pac.public?
  }
end

- (Object) indication



177
178
179
# File 'src/model/sequence.rb', line 177

def indication
  @indication || @registration.indication if @registration
end

- (Object) indication=(indication)



180
181
182
# File 'src/model/sequence.rb', line 180

def indication=(indication)
  @indication = replace_observer(@indication,indication)
end

- (Object) limitation_text



241
242
243
244
245
246
247
248
# File 'src/model/sequence.rb', line 241

def limitation_text
  @packages.each_value { |package|
    if(txt = package.limitation_text)
      return txt
    end
  }
  nil
end

- (Object) limitation_text_count



249
250
251
252
253
# File 'src/model/sequence.rb', line 249

def limitation_text_count
  @packages.values.select { |package|
    package.limitation_text
  }.size
end

- (Object) localized_name(language)



183
184
185
# File 'src/model/sequence.rb', line 183

def localized_name(language)
  self.name
end

- (Object) match(query)



186
187
188
# File 'src/model/sequence.rb', line 186

def match(query)
  /#{query}/iu.match(@name_base)
end

- (Object) name Also known as: to_s



189
190
191
# File 'src/model/sequence.rb', line 189

def name
  [@name_base, @name_descr].compact.join(', ')
end

- (Object) name=(name)



193
194
195
# File 'src/model/sequence.rb', line 193

def name=(name)
  self.name_base, self.name_descr = name.split(',', 2)
end

- (Object) out_of_trade



202
203
204
205
206
# File 'src/model/sequence.rb', line 202

def out_of_trade
  @packages.all? { |key, pac|
    pac.out_of_trade
  }
end

- (Object) package(ikscd)



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

def package(ikscd)
  @packages[sprintf('%03d', ikscd.to_i)]
end

- (Object) package_count



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

def package_count
  @packages.length
end

- (Boolean) patinfo_active?

Returns:

  • (Boolean)


213
214
215
216
# File 'src/model/sequence.rb', line 213

def patinfo_active?
  (@deactivate_patinfo.nil? || @deactivate_patinfo > @@today) \
    && (@activate_patinfo.nil? || @activate_patinfo <= @@today)
end

- (Boolean) public?

Returns:

  • (Boolean)


217
218
219
# File 'src/model/sequence.rb', line 217

def public?
  !@export_flag && @registration.public? && active?
end

- (Object) public_package_count(generic_type = nil)



227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'src/model/sequence.rb', line 227

def public_package_count(generic_type=nil)
  if(public? && (generic_type.nil? \
    || @registration.generic_type == generic_type))
    count = 0
    @packages.values.each { |pack|
      if(pack.public?)
        count += 1
      end
    }
    count
  else
    0
  end
end

- (Object) public_packages



220
221
222
223
224
225
226
# File 'src/model/sequence.rb', line 220

def public_packages
  if(public?) 
    @packages.values.select { |pac| pac.public? }
  else
    []
  end
end

- (Object) route_of_administration



258
259
260
261
262
263
# File 'src/model/sequence.rb', line 258

def route_of_administration
  roas = @compositions.collect { |comp| 
    comp.route_of_administration 
  }.compact.uniq
  roas.first if(roas.size == 1)
end

- (Object) search_terms



264
265
266
267
# File 'src/model/sequence.rb', line 264

def search_terms
  str = self.name
  ODDB.search_terms(str.split(/\s+/u).push(str))
end

- (Object) substance_names



285
286
287
# File 'src/model/sequence.rb', line 285

def substance_names
  substances.collect { |subst| subst.to_s }
end

- (Object) substances



280
281
282
283
284
# File 'src/model/sequence.rb', line 280

def substances
  @compositions.inject([]) { |subs, comp| 
    subs.concat comp.substances
  }.uniq
end

- (Boolean) violates_patent?

Returns:

  • (Boolean)


288
289
290
291
292
293
294
# File 'src/model/sequence.rb', line 288

def violates_patent?
  @atc_class && @registration.may_violate_patent?  \
    && @atc_class.sequences.any? { |seq| 
    seq.patent_protected? && seq.company != @registration.company \
      && _violates_patent?(seq)
  }
end