Module: ODDB::State::Admin::SequenceMethods

Includes:
PatinfoPdfMethods
Included in:
Sequence
Defined in:
src/state/admin/sequence.rb

Constant Summary

Constants included from PatinfoPdfMethods

HTML_PARSER, PDF_DIR

Instance Method Summary (collapse)

Methods included from PatinfoPdfMethods

#assign_patinfo, #get_patinfo_input, #parse_patinfo, #store_slate, #store_slate_item

Instance Method Details

- (Object) ajax_create_active_agent



211
212
213
214
215
216
217
218
219
220
221
# File 'src/state/admin/sequence.rb', line 211

def ajax_create_active_agent
  check_model
  keys = [:pointer, :composition]
  input = user_input(keys, keys)
  agents = []
  if(!error? \
     && (composition = @model.compositions.at(input[:composition].to_i)))
    agents = composition.active_agents
  end
  AjaxActiveAgents.new(@session, agents.dup.push(nil))
end

- (Object) ajax_create_composition



222
223
224
225
226
227
228
229
230
231
# File 'src/state/admin/sequence.rb', line 222

def ajax_create_composition
  check_model
  comps = @model.compositions.dup
  if(!error?)
    comp = ODDB::Composition.new
    comp.active_agents.push nil
    comps.push comp
  end
  AjaxCompositions.new @session, comps
end

- (Object) ajax_delete_active_agent



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'src/state/admin/sequence.rb', line 232

def ajax_delete_active_agent
  check_model
  keys = [:pointer, :active_agent, :composition]
  input = user_input(keys, keys)
  agents = []
  if(!error? \
     && (composition = @model.compositions.at(input[:composition].to_i)))
    if(agent = composition.active_agents.at(input[:active_agent].to_i))
      @session.app.delete agent.pointer
      #composition.remove_active_agent(agent)
      #composition.save
    end
    agents = composition.active_agents
  end
  AjaxActiveAgents.new(@session, agents)
end

- (Object) ajax_delete_composition



248
249
250
251
252
253
254
255
256
257
258
# File 'src/state/admin/sequence.rb', line 248

def ajax_delete_composition
  check_model
  keys = [:pointer, :composition]
  input = user_input(keys, keys)
  agents = []
  if(!error? \
     && (composition = @model.compositions.at(input[:composition].to_i)))
    @session.app.delete composition.pointer
  end
  AjaxCompositions.new(@session, @model.compositions)
end

- (Object) check_model



259
260
261
262
263
264
265
# File 'src/state/admin/sequence.rb', line 259

def check_model
  if(@model.pointer != @session.user_input(:pointer))
    @errors.store :pointer, create_error(:e_state_expired, :pointer, nil)
  elsif !allowed?
    @errors.store :pointer, create_error(:e_not_allowed, :pointer, nil)
  end
end

- (Object) delete



108
109
110
111
112
113
114
# File 'src/state/admin/sequence.rb', line 108

def delete
  registration = @model.parent(@session.app) 
  if(klass = resolve_state(registration.pointer))
    @session.app.delete(@model.pointer)
    klass.new(@session, registration)
  end
end

- (Object) new_active_agent



115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'src/state/admin/sequence.rb', line 115

def new_active_agent
  pointer = @session.user_input(:pointer)
  model = pointer.resolve(@session.app)
  aa_pointer = pointer + [:active_agent]
  item = Persistence::CreateItem.new(aa_pointer)
  item.carry(:iksnr, model.iksnr)
  item.carry(:name_base, model.name_base)
  item.carry(:sequence, model)
  if (klass=resolve_state(aa_pointer))
    klass.new(@session, item)
  else
    self
  end
end

- (Object) new_package



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'src/state/admin/sequence.rb', line 129

def new_package
  pointer = @session.user_input(:pointer)
  model = pointer.resolve(@session.app)
  p_pointer = pointer + [:package]
  item = Persistence::CreateItem.new(p_pointer)
  item.carry(:iksnr, model.iksnr)
  item.carry(:name_base, model.name_base)
  item.carry(:sequence, model)
  item.carry(:parts, [])
  if (klass=resolve_state(p_pointer))
    klass.new(@session, item)
  else
    self
  end
end

- (Object) update



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'src/state/admin/sequence.rb', line 144

def update
  newstate = self
  if(@model.is_a? Persistence::CreateItem)
    seqnr = @session.user_input(:seqnr)
    error =  if(seqnr.is_a? RuntimeError)
      seqnr
    elsif(seqnr.empty?)
      create_error(:e_missing_seqnr, :seqnr, seqnr)
    elsif(@model.parent(@session.app).sequence(seqnr))
      create_error(:e_duplicate_seqnr, :seqnr, seqnr)
    end
    if error
      @errors.store(:seqnr, error)
      return newstate
    end
    @model.append(seqnr)
  end
  keys = [
    :composition_text,
    :dose,
    :export_flag,
    :name_base,
    :name_descr,
    :longevity,
    :substance,
    :galenic_form,
    :activate_patinfo,
    :deactivate_patinfo,
    :sequence_date,
  ]
  input = user_input(keys)
=begin
  galform = @session.user_input(:galenic_form)
  if(@session.app.galenic_form(galform))
    input.store(:galenic_form, galform)
  else
    err = create_error(:e_unknown_galenic_form, 
      :galenic_form, galform)
    @errors.store(:galenic_form, err)
  end
=end


  atc_input = self.user_input(:code, :code)
  atc_code = atc_input[:code]
  if(atc_code.nil?)
    # error already stored by user_input(:code, :code)
  elsif((descr = @session.user_input(:atc_descr)) \
    && !descr.empty?)
    pointer = Persistence::Pointer.new([:atc_class, atc_code])
    values = {
      @session.language => descr, 
    }
    @session.app.update(pointer.creator, values, unique_email)
    input.store(:atc_class, atc_code)
  elsif(@session.app.atc_class(atc_code))
    input.store(:atc_class, atc_code)
  else
    @errors.store(:atc_class, create_error(:e_unknown_atc_class, :code, atc_code))
  end
  newstate = get_patinfo_input(input)
  if((company = @model.company) \
    && (mail = user_input(:regulatory_email)) && !mail.empty?)
    @session.app.update(company.pointer, mail, unique_email)
  end
  @model = @session.app.update(@model.pointer, input, unique_email)
  update_compositions input
  newstate
end

- (Object) update_compositions(input)



266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# File 'src/state/admin/sequence.rb', line 266

def update_compositions(input)
  saved = nil
  if(substances = input[:substance])
    substances.each { |cmp_idx, substances|
      doses = input[:dose][cmp_idx]
      galform = input[:galenic_form][cmp_idx]
      cmp_idx = cmp_idx.to_i
      comp = @model.compositions.at(cmp_idx)
      ptr = comp ? comp.pointer : (@model.pointer + :composition).creator
      comp = @session.app.update ptr, { :galenic_form => galform },
                                 unique_email
      substances.each { |sub_idx, sub|
        ## create missing substance on the fly
        unless @session.app.substance(sub)
          sptr = Persistence::Pointer.new(:substance)
          @session.app.update(sptr.creator, 'lt' => sub)
        end
        parts = doses[sub_idx]
        sub_idx = sub_idx.to_i
        agent = comp.active_agents.at(sub_idx)
        ptr = agent ? agent.pointer \
                    : (comp.pointer + [:active_agent, sub]).creator
        agent = @session.app.update ptr, { :dose => parts, :substance => sub },
                                    unique_email
        unless agent.substance
          key = :"substance[#{cmp_idx}][#{sub_idx}]"
          @errors.store key, create_error(:e_unknown_substance, key, sub)
        end
      }
    }
  end
  saved
end