Class: ODDB::RegistrationCommon

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

Direct Known Subclasses

Registration

Constant Summary

SEQUENCE =
Sequence

Constants included from Persistence

ODBA_PREDEFINE_SERIALIZABLE

Instance Attribute 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

- (RegistrationCommon) initialize(iksnr)

A new instance of RegistrationCommon



24
25
26
27
# File 'src/model/registration.rb', line 24

def initialize(iksnr)
  @iksnr = iksnr
  @sequences = {}
end

Instance Attribute Details

- (Object) activate_fachinfo

Returns the value of attribute activate_fachinfo



15
16
17
# File 'src/model/registration.rb', line 15

def activate_fachinfo
  @activate_fachinfo
end

- (Object) comarketing_with

Returns the value of attribute comarketing_with



15
16
17
# File 'src/model/registration.rb', line 15

def comarketing_with
  @comarketing_with
end

- (Object) company

Returns the value of attribute company



15
16
17
# File 'src/model/registration.rb', line 15

def company
  @company
end

- (Object) complementary_type



73
74
75
76
77
# File 'src/model/registration.rb', line 73

def complementary_type
  @complementary_type || if(@company)
    @company.complementary_type
  end
end

- (Object) deactivate_fachinfo

Returns the value of attribute deactivate_fachinfo



15
16
17
# File 'src/model/registration.rb', line 15

def deactivate_fachinfo
  @deactivate_fachinfo
end

- (Object) expiration_date

Returns the value of attribute expiration_date



15
16
17
# File 'src/model/registration.rb', line 15

def expiration_date
  @expiration_date
end

- (Object) export_flag

Returns the value of attribute export_flag



15
16
17
# File 'src/model/registration.rb', line 15

def export_flag
  @export_flag
end

- (Object) fachinfo

Returns the value of attribute fachinfo



15
16
17
# File 'src/model/registration.rb', line 15

def fachinfo
  @fachinfo
end

- (Object) fachinfo_oid (readonly)

Returns the value of attribute fachinfo_oid



12
13
14
# File 'test/test_model/registration.rb', line 12

def fachinfo_oid
  @fachinfo_oid
end

- (Object) generic_type



122
123
124
125
126
# File 'src/model/registration.rb', line 122

def generic_type
  @generic_type || if(@company)
    @company.generic_type
  end
end

- (Object) ignore_patent

Returns the value of attribute ignore_patent



15
16
17
# File 'src/model/registration.rb', line 15

def ignore_patent
  @ignore_patent
end

- (Object) ikscat

Returns the value of attribute ikscat



15
16
17
# File 'src/model/registration.rb', line 15

def ikscat
  @ikscat
end

- (Object) iksnr (readonly) Also known as: pointer_descr

Returns the value of attribute iksnr



13
14
15
# File 'src/model/registration.rb', line 13

def iksnr
  @iksnr
end

- (Object) inactive_date

Returns the value of attribute inactive_date



15
16
17
# File 'src/model/registration.rb', line 15

def inactive_date
  @inactive_date
end

- (Object) index_therapeuticus

Returns the value of attribute index_therapeuticus



15
16
17
# File 'src/model/registration.rb', line 15

def index_therapeuticus
  @index_therapeuticus
end

- (Object) indication

Returns the value of attribute indication



15
16
17
# File 'src/model/registration.rb', line 15

def indication
  @indication
end

- (Object) ith_swissmedic

Returns the value of attribute ith_swissmedic



15
16
17
# File 'src/model/registration.rb', line 15

def ith_swissmedic
  @ith_swissmedic
end

- (Object) manual_inactive_date

Returns the value of attribute manual_inactive_date



15
16
17
# File 'src/model/registration.rb', line 15

def manual_inactive_date
  @manual_inactive_date
end

- (Object) market_date

Returns the value of attribute market_date



15
16
17
# File 'src/model/registration.rb', line 15

def market_date
  @market_date
end

- (Object) minifi

Returns the value of attribute minifi



15
16
17
# File 'src/model/registration.rb', line 15

def minifi
  @minifi
end

- (Object) parallel_import

Returns the value of attribute parallel_import



15
16
17
# File 'src/model/registration.rb', line 15

def parallel_import
  @parallel_import
end

- (Object) patent (readonly)

Returns the value of attribute patent



13
14
15
# File 'src/model/registration.rb', line 13

def patent
  @patent
end

- (Object) product_group

Returns the value of attribute product_group



15
16
17
# File 'src/model/registration.rb', line 15

def product_group
  @product_group
end

- (Object) production_science

Returns the value of attribute production_science



15
16
17
# File 'src/model/registration.rb', line 15

def production_science
  @production_science
end

- (Object) registration_date

Returns the value of attribute registration_date



15
16
17
# File 'src/model/registration.rb', line 15

def registration_date
  @registration_date
end

- (Object) renewal_flag

Returns the value of attribute renewal_flag



15
16
17
# File 'src/model/registration.rb', line 15

def renewal_flag
  @renewal_flag
end

- (Object) replaced (readonly)

Returns the value of attribute replaced



12
13
14
# File 'test/test_model/registration.rb', line 12

def replaced
  @replaced
end

- (Object) revision_date

Returns the value of attribute revision_date



15
16
17
# File 'src/model/registration.rb', line 15

def revision_date
  @revision_date
end

- (Object) sequences

Returns the value of attribute sequences



13
14
15
# File 'src/model/registration.rb', line 13

def sequences
  @sequences
end

- (Object) source

Returns the value of attribute source



15
16
17
# File 'src/model/registration.rb', line 15

def source
  @source
end

- (Object) vaccine

Returns the value of attribute vaccine



15
16
17
# File 'src/model/registration.rb', line 15

def vaccine
  @vaccine
end

Instance Method Details

- (Boolean) active?(cutoff = @@two_years_ago)

Returns:

  • (Boolean)


28
29
30
31
32
# File 'src/model/registration.rb', line 28

def active?(cutoff=@@two_years_ago)
  !inactive? \
    && (!@expiration_date || @expiration_date > cutoff || @renewal_flag) \
    && (!@market_date || @market_date <= @@today) 
end

- (Object) active_package_count



42
43
44
45
46
47
48
49
50
# File 'src/model/registration.rb', line 42

def active_package_count
  if(active?)
    @sequences.values.inject(0) { |inj, seq|
      inj + seq.active_package_count
    }
  else
    0
  end
end

- (Object) active_packages



33
34
35
36
37
38
39
40
41
# File 'src/model/registration.rb', line 33

def active_packages
  if active?
    @sequences.values.inject([]) do |memo, seq|
      memo.concat seq.active_packages
    end
  else
    []
  end
end

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



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'src/model/registration.rb', line 213

def adjust_types(hash, app=nil)
  hash = hash.dup
  hash.each { |key, value|
    if(value.is_a?(Persistence::Pointer))
      hash[key] = value.resolve(app)
    else
      case(key)
      when :generic_type, :complementary_type
        if(value.is_a? String)
          hash[key] = value.intern
        end
      when :registration_date, :revision_date, 
        :expiration_date, :inactive_date, :market_date
        #key != for elements that can be nil
        if(value.is_a?(String))
          hash.store(key, Date.parse(value.tr('.', '-')))
        end
      when :company
        hash[key] = if(company.is_a? String)
          app.company_by_name(value)
        else
          app.company(value)
        end
      when :index_therapeuticus, :ith_swissmedic
        hash.store key, IndexTherapeuticus.normalize_code(value)
      end
    end
  }
  hash
end

- (Object) atc_classes



51
52
53
54
55
# File 'src/model/registration.rb', line 51

def atc_classes
  @sequences.values.collect { |seq|
    seq.atc_class
  }.compact.uniq
end

- (Object) atcless_sequences



56
57
58
59
60
# File 'src/model/registration.rb', line 56

def atcless_sequences
  @sequences.values.select { |seq|
    seq.atc_class.nil?
  }
end

- (Object) checkout



61
62
63
64
65
66
67
68
69
# File 'src/model/registration.rb', line 61

def checkout
  checkout_helper([@company, @indication, @fachinfo], 
    :remove_registration)
  @sequences.each_value { |seq| 
    seq.checkout 
    seq.odba_delete
  }
  @sequences.odba_delete
end

- (Object) company_name



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

def company_name
  @company.name if @company
end

- (Object) compositions



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

def compositions
  @sequences.sort.inject([]) { |memo, (seqnr, seq)| 
    memo.concat seq.compositions
  }
end

- (Object) create_patent



83
84
85
# File 'src/model/registration.rb', line 83

def create_patent
  @patent = Patent.new
end

- (Object) create_sequence(seqnr)



86
87
88
89
90
91
92
# File 'src/model/registration.rb', line 86

def create_sequence(seqnr)
  seq = self::class::SEQUENCE.new(seqnr)
  unless @sequences.include?(seq.seqnr)
    seq.registration = self
    @sequences.store(seq.seqnr, seq)
  end
end

- (Object) delete_patent



93
94
95
# File 'src/model/registration.rb', line 93

def delete_patent
  @patent = nil
end

- (Object) delete_sequence(seqnr)



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

def delete_sequence(seqnr)
  seqnr = sprintf('%02d', seqnr.to_i)
  if(seq = @sequences.delete(seqnr))
    @sequences.odba_isolated_store
    seq
  end
end

- (Object) each_package(&block)



103
104
105
106
107
# File 'src/model/registration.rb', line 103

def each_package(&block)
  @sequences.each_value { |seq|
    seq.each_package(&block)
  }
end

- (Object) each_sequence(&block)



108
109
110
# File 'src/model/registration.rb', line 108

def each_sequence(&block)
  @sequences.values.each(&block)
end

- (Boolean) expired?

Returns:

  • (Boolean)


111
112
113
114
# File 'src/model/registration.rb', line 111

def expired?
  inactive? \
    || (!@renewal_flag && @expiration_date && @expiration_date <= @@today)
end

- (Boolean) fachinfo_active?

Returns:

  • (Boolean)


115
116
117
118
# File 'src/model/registration.rb', line 115

def fachinfo_active?
  @fachinfo && (@deactivate_fachinfo.nil? || @deactivate_fachinfo > @@today) \
    && (@activate_fachinfo.nil? || @activate_fachinfo <= @@today)
end

- (Boolean) generic?

Returns:

  • (Boolean)


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

def generic?
  self.generic_type == :generic
end

- (Boolean) has_fachinfo?

Returns:

  • (Boolean)


127
128
129
# File 'src/model/registration.rb', line 127

def has_fachinfo?
  !@fachinfo.nil?
end

- (Boolean) ignore_patent?

Returns:

  • (Boolean)


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

def ignore_patent?
  !!@ignore_patent
end

- (Boolean) inactive?

Returns:

  • (Boolean)


133
134
135
# File 'src/model/registration.rb', line 133

def inactive?
  (date = @manual_inactive_date || @inactive_date) && date <= @@today
end

- (Object) limitation_text_count



136
137
138
139
140
# File 'src/model/registration.rb', line 136

def limitation_text_count
  @sequences.values.inject(0) { |inj, seq|     
    inj + seq.limitation_text_count
  }
end

- (Object) localized_name(lang)



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

def localized_name(lang)
  if(seq = @sequences.values.first)
    seq.localized_name(lang)
  end
end

- (Boolean) may_violate_patent?

Returns:

  • (Boolean)


146
147
148
149
150
151
152
153
154
155
156
# File 'src/model/registration.rb', line 146

def may_violate_patent?
  # we are making the assumption that no generic registration will be
  # created more than a year before the original's patent protection 
  # expires. Registrations where the @registration_date is not known can 
  # be considered old enough to fall out of consideration for 
  # patent violation
  !@ignore_patent && @registration_date \
    && !@comarketing_with \
    && (@generic_type != :original) \
    && (@registration_date > @@one_year_ago)
end

- (Object) name_base



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

def name_base
  if(seq = @sequences.values.first)
    seq.name_base
  end
end

- (Boolean) original?

Returns:

  • (Boolean)


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

def original?
  self.generic_type == :original
end

- (Object) out_of_trade



165
166
167
168
169
# File 'src/model/registration.rb', line 165

def out_of_trade
  @sequences.all? { |key, seq|
    seq.out_of_trade
  }
end

- (Object) package(ikscd)



170
171
172
173
174
175
176
177
# File 'src/model/registration.rb', line 170

def package(ikscd)
  @sequences.each_value { |seq|
    if(package = seq.package(ikscd))
      return package 
    end
  }
  nil
end

- (Object) package_count



178
179
180
181
182
# File 'src/model/registration.rb', line 178

def package_count
  @sequences.values.inject(0) { |inj, seq|
    inj + seq.package_count
  }
end

- (Object) packages



183
184
185
186
187
# File 'src/model/registration.rb', line 183

def packages
  @sequences.values.inject([]) { |memo, seq|
    memo.concat(seq.packages.values)
  }
end

- (Boolean) patent_protected?

Returns:

  • (Boolean)


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

def patent_protected?
  @patent && @patent.protected?
  #@patented_until && (@patented_until >= @@today)
end

- (Boolean) public?(cutoff = @@two_years_ago)

Returns:

  • (Boolean)


192
193
194
# File 'src/model/registration.rb', line 192

def public?(cutoff=@@two_years_ago)
  !@export_flag && active?(cutoff)
end

- (Object) public_package_count



195
196
197
198
199
200
201
202
203
# File 'src/model/registration.rb', line 195

def public_package_count
  if(active?)
    @sequences.values.inject(0) { |inj, seq|
      inj + seq.public_package_count
    }
  else
    0
  end
end

- (Object) sequence(seqnr)



204
205
206
# File 'src/model/registration.rb', line 204

def sequence(seqnr)
  @sequences[sprintf('%02d', seqnr.to_i)]
end

- (Object) substance_names



207
208
209
210
211
# File 'src/model/registration.rb', line 207

def substance_names
  @sequences.values.collect { |seq|
    seq.substance_names
  }.flatten.uniq
end