Class: ODDB::Html::State::Drugs::Admin::Sequence

Inherits:
Global
  • Object
show all
Defined in:
lib/oddb/html/state/drugs/admin/sequence.rb

Direct Known Subclasses

NewSequence

Constant Summary collapse

VIEW =
View::Drugs::Admin::Sequence

Constants inherited from Global

Global::GLOBAL_MAP, Global::LIMIT

Instance Attribute Summary

Attributes inherited from Global

#passed_turing_test

Attributes included from LoginMethods

#desired_input

Instance Method Summary collapse

Methods inherited from Global

transparent_login

Methods included from Events

#_compare, #_complete, #_explain_ddd_price, #_explain_price, #_fachinfo, #_feedback, #_package, #_package_by_code, #_package_infos, #_patinfo, #_products, #_remote, #_remote_comparables, #_remote_infos, #_remote_package, #_remote_packages, #_search, #_search_append_products, #_search_append_sequences, #_search_by, #_search_local, #_search_remote, #_tax_factor, #compare_remote, #ddd, #limited?, #navigation, #search

Methods inherited from Global

#_download, #compare, #explain_ddd_price, #explain_price, #fachinfo, #feedback, #home, #limit_state, #limited?, #logout, #method_missing, #navigation, #package, #package_infos, #partitioned_keys, #patinfo, #proceed_export, #proceed_poweruser, #product, #products, #remote_infos

Methods included from PayPal::Checkout

#ajax_autofill, #checkout, #checkout_keys, #checkout_mandatory, #collect, #create_user

Methods included from LoginMethods

#login_

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ODDB::Html::State::Global

Instance Method Details

#_update(input) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
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
# File 'lib/oddb/html/state/drugs/admin/sequence.rb', line 129

def _update input
  email = @session.user.email
  if((prod = @model.product) && prod.is_a?(Util::UnsavedHelper))
    @model.product = prod.delegate
  end
  input.each { |key, value|
    unless(@errors[key])
      set = case key
            when :atc
              if(value.empty?)
                warn "empty atc"
              elsif(atc = ODDB::Drugs::Atc.find_by_code(value))
                @model.atc = atc
              elsif((name = input[:atc_name]) && !name.empty?)
                atc = ODDB::Drugs::Atc.new value
                atc.name.de = name
                atc.save
                @model.atc = atc
              else
                @errors.store :atc, create_error(:e_unknown_atc, :atc, value)
                nil
              end
=begin ## temporarily disabled: this should be recoded to work with swiss infos
     #  in 2.0
            when :fachinfo_url
              unless value == @model.fachinfo_url
                _import_rtf(:fachinfo, @model, value)
              end
            when :patinfo_url
              unless value == @model.patinfo_url
                _import_rtf(:patinfo, @model, value)
              end
=end
            when :registration
              if(value.empty?)
                @model.remove_code(@model.registration)
              elsif(code = @model.registration)
                code.value = value unless code == value
              else
                @model.add_code ODDB::Util::Code.new(:registration, value, 'EU')
              end
            when :substance
              update_compositions(input)
            end
      unless(set.nil?)
        @model.data_origins.store key, email
      end
    end
  }
  @model.save
  self
end

#ajax_create_active_agentObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/oddb/html/state/drugs/admin/sequence.rb', line 22

def ajax_create_active_agent
  check_model
  keys = [:uid, :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

#ajax_create_compositionObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/oddb/html/state/drugs/admin/sequence.rb', line 33

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

#ajax_delete_active_agentObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/oddb/html/state/drugs/admin/sequence.rb', line 43

def ajax_delete_active_agent
  check_model
  keys = [:uid, :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))
      agent.delete
      composition.remove_active_agent(agent)
      composition.save
    end
    agents = composition.active_agents
  end
  AjaxActiveAgents.new(@session, agents)
end

#ajax_delete_compositionObject



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/oddb/html/state/drugs/admin/sequence.rb', line 59

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

#check_modelObject



70
71
72
73
74
# File 'lib/oddb/html/state/drugs/admin/sequence.rb', line 70

def check_model
  if(@model.uid.to_s != @session.user_input(:uid))
    @errors.store :uid, create_error(:e_state_expired, :uid, nil)
  end
end

#deleteObject



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/oddb/html/state/drugs/admin/sequence.rb', line 75

def delete
  check_model
  unless error?
    prod = @model.product
    if(prod.is_a? Util::UnsavedHelper)
      prod = prod.delegate
    end
    @model.delete
    Product.new(@session, prod)
  end
end

#direct_eventObject



86
87
88
89
90
91
92
# File 'lib/oddb/html/state/drugs/admin/sequence.rb', line 86

def direct_event
  direct_event = [:sequence]
  if(uid = @model.uid)
    direct_event.push([:uid, uid])
  end
  direct_event
end

#sequenceObject



181
182
183
184
185
186
187
# File 'lib/oddb/html/state/drugs/admin/sequence.rb', line 181

def sequence
  if((uid = @session.user_input(:uid)) && @model.uid.to_s == uid)
    self
  else
    super
  end
end

#updateObject

# in 2.0

def _import_rtf(key, seq, url)
  if(url && !url.empty?)
    seq.send "#{key}_url=", url
    imp = Import::PharmNet::Import.new
    document = imp.import_rtf(key, WWW::Mechanize.new, url, seq.product.name.de,
                              :reparse => true, :reload => true)
    parent = seq.send(key)
    parent.de = document
    parent.save
  end
rescue StandardError
end


108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/oddb/html/state/drugs/admin/sequence.rb', line 108

def update
  check_model
  mandatory = [ :atc ]
  keys = [ :atc_name, :registration, :fachinfo_url, :patinfo_url,
    :galenic_form, :substance, :dose ]
  input = user_input(mandatory + keys, mandatory)
  unless /^EU/.match input[:registration].to_s
    others = ODDB::Drugs::Sequence.search_by_code(:type => 'registration',
                                                  :value => input[:registration],
                                                  :country => 'EU')
    others.delete(@model)
    unless others.empty?
      value = sprintf "'%s' (%s)", input[:registration],
                      others.collect { |seq|
                        seq.name.de || seq.product.name.de }.join(', ')
      @errors.store(:registration,
                    create_error(:e_duplicate_registration, :registration, value))
    end
  end
  _update input
end