Module: ODDB::Html::State::Drugs::Events

Included in:
Global
Defined in:
lib/oddb/html/state/drugs/global.rb

Instance Method Summary collapse

Instance Method Details

#_compare(code) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/oddb/html/state/drugs/global.rb', line 40

def _compare(code)
  if(package = _package_by_code(code))
    result = ODDB::Util::AnnotatedList.new(package.comparables)
    if(@session.lookandfeel.enabled?(:remote_databases, false))
      result.concat(_remote_comparables(package))
    end
    result.origin = package
    result.query = code
    Compare.new(@session, result)
  end
end

#_complete(result) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/oddb/html/state/drugs/global.rb', line 51

def _complete(result)
  atcs = {}
  result.dup.each { |package|
    if((atc = package.atc) && !atcs[atc])
      atcs.store(atc, true)
      result.concat(atc.packages)
    end
  }
  result.uniq!
end

#_explain_ddd_price(code, idx) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/oddb/html/state/drugs/global.rb', line 67

def _explain_ddd_price(code, idx)
  if((package = _package_by_code(code)) \
     && (ddd = package.ddds.at(idx)))
    Ajax::ExplainDddPrice.new(@session, 
                              :ddd => ddd, :package => package)
  end
end

#_explain_price(code) ⇒ Object



74
75
76
77
78
# File 'lib/oddb/html/state/drugs/global.rb', line 74

def _explain_price(code)
  if(package = _package_by_code(code))
    Ajax::ExplainPrice.new(@session, package.price(:public))
  end
end

#_fachinfo(uid) ⇒ Object



79
80
81
82
83
# File 'lib/oddb/html/state/drugs/global.rb', line 79

def _fachinfo(uid)
  if(sequence = ODDB::Drugs::Sequence.find_by_uid(uid))
    Fachinfo.new(@session, sequence)
  end
end

#_feedback(code) ⇒ Object



84
85
86
87
88
# File 'lib/oddb/html/state/drugs/global.rb', line 84

def (code)
  if(package = _package_by_code(code))
    Feedback.new(@session, package)
  end
end

#_package(code) ⇒ Object



95
96
97
98
99
# File 'lib/oddb/html/state/drugs/global.rb', line 95

def _package(code)
  if(package = _package_by_code(code))
    Package.new(@session, package)
  end
end

#_package_by_code(code) ⇒ Object



100
101
102
103
104
# File 'lib/oddb/html/state/drugs/global.rb', line 100

def _package_by_code(code)
  ODDB::Drugs::Package.find_by_code(:type => 'cid', 
                                    :value   => code, 
                                    :country => ODDB.config.country)
end

#_package_infos(code) ⇒ Object



105
106
107
108
109
# File 'lib/oddb/html/state/drugs/global.rb', line 105

def _package_infos(code)
  if(package = _package_by_code(code))
    Ajax::PackageInfos.new(@session, package)
  end
end

#_patinfo(uid) ⇒ Object



110
111
112
113
114
# File 'lib/oddb/html/state/drugs/global.rb', line 110

def _patinfo(uid)
  if(sequence = ODDB::Drugs::Sequence.find_by_uid(uid))
    Patinfo.new(@session, sequence)
  end
end

#_products(query) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/oddb/html/state/drugs/global.rb', line 115

def _products(query)
  result = ODDB::Util::AnnotatedList.new
  result.query = query
  if(query)
    if(query == '0-9')
      alpha, others = partitioned_keys(ODDB::Drugs::Product.name_keys(1))
      others.each { |key|
        result.concat(ODDB::Drugs::Product.search_by_name(key))
      }
    else
      result.concat(ODDB::Drugs::Product.search_by_name(query.downcase))
    end
  end
  Products.new(@session, result)
end

#_remote(uri, &block) ⇒ Object



130
131
132
133
134
# File 'lib/oddb/html/state/drugs/global.rb', line 130

def _remote(uri, &block)
  block.call DRbObject.new(nil, uri)
rescue StandardError => e
  warn e.message 
end

#_remote_comparables(package) ⇒ Object



135
136
137
138
139
140
141
# File 'lib/oddb/html/state/drugs/global.rb', line 135

def _remote_comparables(package)
  if(atc = package.atc)
    _remote_packages { |remote| 
      remote.remote_comparables(ODBA::DRbWrapper.new(package))
    }
  end
end

#_remote_infos(uid) ⇒ Object



142
143
144
145
146
# File 'lib/oddb/html/state/drugs/global.rb', line 142

def _remote_infos(uid)
  if(pac = _remote_package(uid))
    Ajax::RemoteInfos.new(@session, pac)
  end
end

#_remote_package(id) ⇒ Object



147
148
149
150
151
152
153
154
155
# File 'lib/oddb/html/state/drugs/global.rb', line 147

def _remote_package(id)
  source, ref = id.split('.', 2)
  uri = ODDB.config.remote_databases.at(source.to_i)
  if(pac = DRbObject._load(Marshal.dump([uri, ref])))
    rate = _remote(uri) { |remote| 
      remote.get_currency_rate("EUR") }
    Remote::Drugs::Package.new(source, pac, rate, _tax_factor)
  end
end

#_remote_packages(&block) ⇒ Object



156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/oddb/html/state/drugs/global.rb', line 156

def _remote_packages(&block)
  result = []
  ODDB.config.remote_databases.each_with_index { |uri, source|
    _remote(uri) { |remote|
      rate = remote.get_currency_rate("EUR")
      block.call(remote).each { |pac|
        result.push Remote::Drugs::Package.new(source, pac, rate, 
                                               _tax_factor)
      }
    }
  }
  result
end

#_search(query, dstype) ⇒ Object



176
177
178
179
180
181
182
# File 'lib/oddb/html/state/drugs/global.rb', line 176

def _search(query, dstype)
  result = _search_local(query, dstype)
  if(@session.lookandfeel.enabled?(:remote_databases, false))
    result.concat(_search_remote(query))
  end
  Result.new(@session, result)
end

#_search_append_products(query, result) ⇒ Object



183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/oddb/html/state/drugs/global.rb', line 183

def _search_append_products(query, result)
  table = {}
  result.each do |package|
    table.store package.product.uid, true
  end
  products = ODDB::Drugs::Product.search_by_name(query)
  products.reject! do |prod| table[prod.uid] end
  products.collect! do |prod|
    Util::KnowItAll.new prod, :active_agents => [], :parts => [], :ddds => []
  end
  result.concat products
end

#_search_append_sequences(query, result) ⇒ Object



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/oddb/html/state/drugs/global.rb', line 195

def _search_append_sequences(query, result)
  table = {}
  result.each do |package|
    table.store package.sequence.uid, true
  end
  sequences = ODDB::Drugs::Sequence.search_by_product(query)
  sequences.reject! do |seq| table[seq.uid] end
  sequences.collect! do |seq|
    parts = seq.compositions.collect do |comp|
      Util::KnowItAll.new nil, :unit => comp.galenic_form
    end
    Util::KnowItAll.new seq, :active_agents => [], :parts => parts,
                             :ddds => [], :sequence => seq
  end
  result.concat sequences
end

#_search_by(key, query, result) ⇒ Object



211
212
213
# File 'lib/oddb/html/state/drugs/global.rb', line 211

def _search_by(key, query, result)
  result.concat ODDB::Drugs::Package.send("search_by_#{key}", query)
end

#_search_local(query, dstype) ⇒ Object



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
243
# File 'lib/oddb/html/state/drugs/global.rb', line 214

def _search_local(query, dstype)
  result = ODDB::Util::AnnotatedList.new
  result.query = query
  result.dstype = dstype || ODDB.config.default_dstype
  if(query.length < 3)
    result.error = :e_query_short
  else
    case dstype
    when 'company'
      _search_by(:company, query, result)
    when 'substance'
      _search_by(:substance, query, result)
    when 'compare'
      _search_by(:atc, query, result)
      _search_by(:company, query, result) if result.empty?
      _search_by(:substance, query, result) if result.empty?
      _complete(_search_by(:name, query, result)) if result.empty?
      _complete(_search_by(:product, query, result)) if result.empty?
    when 'indication'
      seqs = ODDB::Drugs::Sequence.search_by_fachinfo_indications_de(query)
      seqs.each { |seq| result.concat seq.packages }
    else
      _search_by(:name, query, result)
      _search_by(:product, query, result) if result.empty?
      _search_append_sequences(query, result)
      _search_append_products(query, result)
    end
  end
  result
end

#_search_remote(query) ⇒ Object



244
245
246
# File 'lib/oddb/html/state/drugs/global.rb', line 244

def _search_remote(query)
  _remote_packages { |remote| remote.remote_packages(query) }
end

#_tax_factorObject



169
170
171
# File 'lib/oddb/html/state/drugs/global.rb', line 169

def _tax_factor
  @session.lookandfeel.tax_factor
end

#compare_remoteObject



31
32
33
34
35
36
37
38
39
# File 'lib/oddb/html/state/drugs/global.rb', line 31

def compare_remote
  if((uid = @session.user_input(:uid)) \
     && (package = _remote_package(uid)))
    result = ODDB::Util::AnnotatedList.new(package.comparables)
    result.origin = package
    result.query = uid
    CompareRemote.new(@session, result)
  end
end

#dddObject



61
62
63
64
65
66
# File 'lib/oddb/html/state/drugs/global.rb', line 61

def ddd
  if((code = @session.user_input(:code)) \
     && (atc = ODDB::Drugs::Atc.find_by_code(code)))
    AtcGuidelines.new(@session, atc)
  end
end

#limited?(*args) ⇒ Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/oddb/html/state/drugs/global.rb', line 89

def limited?(*args)
  super && !@session.allowed?('view', ODDB.config.auth_domain)
end


92
93
94
# File 'lib/oddb/html/state/drugs/global.rb', line 92

def navigation
  [:products, :atc_browser].concat(super)
end

#searchObject



172
173
174
175
# File 'lib/oddb/html/state/drugs/global.rb', line 172

def search
  _search(@session.persistent_user_input(:query),
          @session.persistent_user_input(:dstype) || ODDB.config.default_dstype)
end