Module: ODDB::State::Admin::ActiveAgentMethods

Included in:
ActiveAgent
Defined in:
src/state/admin/activeagent.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) delete



14
15
16
17
18
19
20
# File 'src/state/admin/activeagent.rb', line 14

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

- (Object) new_active_agent



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'src/state/admin/activeagent.rb', line 21

def new_active_agent
  if(sequence = @model.sequence)
    aa_pointer = sequence.pointer + [:active_agent]
    item = Persistence::CreateItem.new(aa_pointer)
    item.carry(:iksnr, sequence.iksnr)
    item.carry(:name_base, sequence.name_base)
    item.carry(:sequence, sequence)
    #item.carry(:dose, " ")
    #item.carry(:substance, " ")
    if (klass=resolve_state(aa_pointer))
      klass.new(@session, item)
    else
      self
    end
  else
    error = create_error(:e_no_seq_to_activeagent, :substance, @model.substance)
    @errors.store(:substance, error)
    self
  end
end

- (Object) substance_selection



80
81
82
83
84
85
# File 'src/state/admin/activeagent.rb', line 80

def substance_selection 
  sub = @session.user_input(:substance)
  sequence = @model.parent(@session.app)
  comparable = @session.app.soundex_substances(sub)
  comparable - sequence.substances
end

- (Object) update



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'src/state/admin/activeagent.rb', line 41

def update
  keys = [:substance, :dose, :chemical_substance, :chemical_dose,
    :spagyric_dose, :equivalent_substance, :equivalent_dose]
  input = user_input(keys, [:substance])
  newstate = self
  unless (error?)
    substance = @session.substance(input[:substance]) 
    if(substance.nil?)
      selection = self.substance_selection
      model = ODDB::SelectSubstance.new(input, selection, @model)
      newstate = self.class::SELECT_STATE.new(@session, model)
    elsif(@model.substance != substance && \
      @model.sequence.active_agent(substance))
      error = create_error(:e_seq_dup_substance, :substance, input[:substance])
      @errors.store(:substance, error)
    else
      if(@model.is_a?(Persistence::CreateItem))
        @model.append(input[:substance])
      end
      chem = input[:chemical_substance]
      if(chemical = @session.substance(chem))
        input[:chemical_substance] = chemical.pointer
      elsif(chem.empty?)
        input[:chemical_substance] = nil
        input[:chemical_dose] = nil
      else
        error = create_error(:e_unknown_substance, 
          :chemical_substance, chem)
        @errors.store(:chemical_substance, error)
        input.delete(:chemical_substance)
        input.delete(:chemical_dose)
      end
      input[:substance] = substance.pointer
      @model = @session.app.update(@model.pointer, input,
                                   unique_email)
    end
  end
  newstate
end