Class: ODDB::State::Substances::Substance

Inherits:
Global show all
Defined in:
src/state/admin/root.rb,
src/state/substances/substance.rb

Constant Summary

VIEW =
View::Substances::Substance

Constants inherited from Global

HOME_STATE, ZONE, ZONE_NAVIGATION

Constants inherited from Global

DIRECT_EVENT, GLOBAL_MAP, HOME_STATE, LIMITED, PRINT_STATES, READONLY_STATES, RESOLVE_STATES, REVERSE_MAP, VIEW, ZONE_NAVIGATION

Constants included from UmlautSort

FILTER_PAIRS

Instance Method Summary (collapse)

Methods inherited from Global

#_search_drugs, #_search_drugs_state, #_trigger, #add_to_interaction_basket, #allowed?, #atc_chooser, #checkout, #clear_interaction_basket, #creditable?, #direct_request_path, #doctorlist, #download, #export_csv, #extend, #fachinfo, #feedbacks, #help_navigation, #home_navigation, #home_state, #hospitallist, #interaction_basket, #limit_state, #limited?, #logout, #navigation, #notify, #password_reset, #paypal_return, #powerlink, #print, #proceed_download, #proceed_poweruser, #resolve, #resolve_state, #rss, #search, #show, #snapback_event, #sort, #sponsorlink, #suggest_address, #switch, #unique_email, #user_input, #user_navigation, #ywesee_contact, #zone_navigation, #zones

Methods included from Admin::LoginMethods

#autologin, #login

Methods included from UmlautSort

#sort_model, #umlaut_filter

Instance Method Details

- (Object) assign



13
14
15
16
17
18
19
20
21
22
# File 'src/state/substances/substance.rb', line 13

def assign
  substance_name = @session.user_input(:effective_form)
  if(substance = @session.substance(substance_name))
    args = {
      :effective_form =>  substance.pointer,
    }
    @session.app.update(@model.pointer, args, unique_email)
  end
  self
end

- (Object) delete



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'src/state/substances/substance.rb', line 23

def delete
  if(@model.empty?)
    @session.app.delete(@model.pointer)
    #substances() # from RootState
    new_state = result()
    mdl = new_state.model
    mdl.delete(@model) if(mdl.is_a?(Array))
    new_state
  else
    @errors.store(:substance, create_error('e_substance_not_empty', :substance, @model))
    self
  end
end

- (Object) delete_connection_key



36
37
38
39
40
41
42
43
# File 'src/state/substances/substance.rb', line 36

def delete_connection_key
  if(key = @session.user_input(:connection_key))
    keys = @model.connection_keys
    keys.delete(key)
    @session.app.update(@model.pointer, keys, unique_email)
  end
  self
end

- (Boolean) duplicate?(string)

Returns:

  • (Boolean)


44
45
46
47
# File 'src/state/substances/substance.rb', line 44

def duplicate?(string)
  !(string.to_s.empty? \
    || [nil, @model].include?(@session.app.substance(string)))
end

- (Object) merge



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'src/state/substances/substance.rb', line 48

def merge
  substance = @session.user_input(:substance_form)
  new_state = self
  if(substance.size < 3)
    @errors.store(:substance_form, create_error('e_search_query_short',
      :substance_form, substance))
  else
    substances = @session.app.search_substances(substance)
    substances.delete(@model)
    if(substances.empty?)
      @errors.store(:substance, create_error('e_unknown_substance', 
        :substance, substance))
    else
      new_model = SelectSubstance::SubstanceSelection.new(@model, 
        substances)
      new_state = SelectSubstance.new(@session, new_model)
    end
  end
  new_state
end

- (Object) update



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'src/state/substances/substance.rb', line 68

def update
  languages = @session.lookandfeel.languages + ['lt']
  input = languages.inject({}) { |inj, key|
    sym = key.intern
    value = @session.user_input(sym)
    if(duplicate?(value))
      @errors.store(sym, 
        create_error('e_duplicate_substance_description', key, value))
    end
    inj.store(key, value)
    inj
  }
  if(syn_list = @session.user_input(:synonym_list))
    syns = syn_list.split(/\s*,\s*/u)
    syns.each { |syn| 
      if(duplicate?(syn))
        @errors.store(:synonym_list, 
          create_error('e_duplicate_substance_description', 
            :synonym_list, syn))
      end
    }
    input.store(:synonyms, syns)
  end
  unless error?
    @model = @session.app.update(@model.pointer, input, unique_email)
  end
  self
end