Class: ODDB::View::Drugs::CsvResult

Inherits:
HtmlGrid::Component show all
Defined in:
src/view/drugs/csv_result.rb

Constant Summary

CSV_KEYS =
[
  :rectype,
  :barcode,
  :name_base,
  :galenic_form,
  :most_precise_dose,
  :size,
  :numerical_size,
  :price_exfactory,
  :price_public,
  :company_name,
  :ikscat,
  :sl_entry,
  :registration_date,
  :casrn,
  :ddd_dose,
  :ddd_price,
]

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from HtmlGrid::Component

#additional_javascripts, #dynamic_html

Instance Attribute Details

- (Object) counts (readonly)

Returns the value of attribute counts



12
13
14
# File 'src/view/drugs/csv_result.rb', line 12

def counts
  @counts
end

- (Object) duplicates (readonly)

Returns the value of attribute duplicates



12
13
14
# File 'src/view/drugs/csv_result.rb', line 12

def duplicates
  @duplicates
end

Instance Method Details

- (Object) boolean(bool)



66
67
68
69
# File 'src/view/drugs/csv_result.rb', line 66

def boolean(bool)
  key = bool ? :true : :false
  @lookandfeel.lookup(key)
end

- (Object) bsv_dossier(pack)



70
71
72
73
74
75
76
77
78
79
# File 'src/view/drugs/csv_result.rb', line 70

def bsv_dossier(pack)
  if(sl = pack.sl_entry)
    dossier = sl.bsv_dossier
    if dossier
      @bsv_dossiers.store dossier, true
      @counts['bsv_dossiers'] = @bsv_dossiers.size
    end
    dossier
  end
end

- (Object) c_type(pack)



86
87
88
89
90
91
# File 'src/view/drugs/csv_result.rb', line 86

def c_type(pack)
  if ctype = pack.complementary_type
    @counts[ctype.to_s] += 1
    @lookandfeel.lookup("square_#{ctype}")
  end
end

- (Object) casrn(pack)



80
81
82
83
84
85
# File 'src/view/drugs/csv_result.rb', line 80

def casrn(pack)
  str = pack.narcotics.collect { |narc|
    narc.casrn
  }.compact.join(',')
  str unless str.empty?
end

- (Object) ddd_dose(model, session = @session)



92
93
94
95
96
# File 'src/view/drugs/csv_result.rb', line 92

def ddd_dose(model, session=@session)
  if(ddd = model.ddd)
    ddd.dose
  end
end

- (Object) deductible(pack)



97
98
99
100
101
102
103
# File 'src/view/drugs/csv_result.rb', line 97

def deductible(pack)
  if(pack.sl_entry)
    deductible = pack.deductible || :deductible_g
    @counts[deductible.to_s] += 1
    @lookandfeel.lookup(deductible)
  end
end

- (Object) expiration_date(pack)



104
105
106
# File 'src/view/drugs/csv_result.rb', line 104

def expiration_date(pack)
  formatted_date(pack, :expiration_date)
end

- (Object) export_flag(pack)



107
108
109
110
111
112
# File 'src/view/drugs/csv_result.rb', line 107

def export_flag(pack)
  if flag = pack.export_flag
    @counts['export_registrations'] += 1
    flag
  end
end

- (Object) formatted_date(pack, key)



113
114
115
116
117
118
# File 'src/view/drugs/csv_result.rb', line 113

def formatted_date(pack, key)
  if(date = pack.send(key))
    @counts[key.to_s] += 1
    @lookandfeel.format_date(date)
  end
end

- (Object) galenic_form(pack, lang = @lookandfeel.language)



119
120
121
122
123
124
125
# File 'src/view/drugs/csv_result.rb', line 119

def galenic_form(pack, lang = @lookandfeel.language)
  if(galform = pack.galenic_forms.first)
    @galforms.store galform, true
    @counts['galenic_forms'] = @galforms.size
    galform.description(lang)
  end
end

- (Object) galenic_form_de(pack)



126
127
128
# File 'src/view/drugs/csv_result.rb', line 126

def galenic_form_de(pack)
  galenic_form(pack, :de)
end

- (Object) galenic_form_fr(pack)



129
130
131
# File 'src/view/drugs/csv_result.rb', line 129

def galenic_form_fr(pack)
  galenic_form(pack, :fr)
end

- (Object) galenic_group(pack, lang = @lookandfeel.language)



132
133
134
135
136
137
138
# File 'src/view/drugs/csv_result.rb', line 132

def galenic_group(pack, lang = @lookandfeel.language)
  if(galgroup = pack.galenic_group)
    @galgroups.store galgroup, true
    @counts['galenic_groups'] = @galgroups.size
    galgroup.description(lang)
  end
end

- (Object) galenic_group_de(pack)



139
140
141
# File 'src/view/drugs/csv_result.rb', line 139

def galenic_group_de(pack)
  galenic_group(pack, :de)
end

- (Object) galenic_group_fr(pack)



142
143
144
# File 'src/view/drugs/csv_result.rb', line 142

def galenic_group_fr(pack)
  galenic_group(pack, :fr)
end

- (Object) generic_type(pack)



288
289
290
291
292
293
294
295
296
297
# File 'src/view/drugs/csv_result.rb', line 288

def generic_type(pack)
  case pack.sl_generic_type || pack.generic_type
  when :original
    @counts['originals'] += 1
    'O'
  when :generic
    @counts['generics'] += 1
    'G'
  end
end

- (Object) has_generic(pack)



145
146
147
148
149
150
151
# File 'src/view/drugs/csv_result.rb', line 145

def has_generic(pack)
  flag = pack.has_generic?
  if flag
    @counts['has_generic'] += 1
  end
  boolean(flag)
end

- (Object) http_headers



152
153
154
155
156
157
158
159
160
161
162
# File 'src/view/drugs/csv_result.rb', line 152

def http_headers
  file = @session.user_input(:filename)
  if file.nil?
    file = "#{@model.search_query}.#{@session.lookandfeel.lookup(@model.search_type)}.csv"
  end
  url = @lookandfeel._event_url(:home)
  {
    'Content-Type'       => 'text/csv',
    'Content-Disposition'  => "attachment;filename=#{file}",
  }
end

- (Object) inactive_date(pack)



163
164
165
# File 'src/view/drugs/csv_result.rb', line 163

def inactive_date(pack)
  formatted_date(pack, :inactive_date)
end

- (Object) init



31
32
33
34
35
36
37
38
39
40
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
# File 'src/view/drugs/csv_result.rb', line 31

def init
  @counts = {
    'anthroposophy'            => 0,
    'bsv_dossiers'             => 0,
    'complementary'            => 0,
    'deductible_g'             => 0,
    'deductible_o'             => 0,
    'expiration_date'          => 0,
    'export_registrations'     => 0,
    'galenic_forms'            => 0,
    'generics'                 => 0,
    'has_generic'              => 0,
    'homeopathy'               => 0,
    'inactive_date'            => 0,
    'limitations'              => 0,
    'limitation_both'          => 0,
    'limitation_points'        => 0,
    'limitation_texts'         => 0,
    'lppv'                     => 0,
    'missing_size'             => 0,
    'originals'                => 0,
    'out_of_trade'             => 0,
    'phytotherapy'             => 0,
    'price_exfactory'          => 0,
    'price_public'             => 0,
    'registration_date'        => 0,
    'routes_of_administration' => 0,
    'sl_entries'               => 0,
  }
  @bsv_dossiers = {}
  @roas = {}
  @galforms = {}
  @galgroups = {}
  super
end

- (Object) introduction_date(pack)



166
167
168
169
170
# File 'src/view/drugs/csv_result.rb', line 166

def introduction_date(pack)
  if((sl = pack.sl_entry) && (date = sl.introduction_date))
    @lookandfeel.format_date(date)
  end
end

- (Object) limitation(pack)



171
172
173
174
175
176
177
178
179
# File 'src/view/drugs/csv_result.rb', line 171

def limitation(pack)
  if(sl = pack.sl_entry)
    lim = sl.limitation
    if lim
      @counts['limitations'] += 1
      boolean(lim)
    end
  end
end

- (Object) limitation_points(pack)



180
181
182
183
184
185
186
187
188
189
190
191
# File 'src/view/drugs/csv_result.rb', line 180

def limitation_points(pack)
  if(sl = pack.sl_entry)
    points = sl.limitation_points.to_i
    if points > 0
      if sl.limitation_text
        @counts['limitation_both'] += 1
      end
      @counts['limitation_points'] += 1
      points
    end
  end
end

- (Object) limitation_text(pack)



192
193
194
195
196
197
# File 'src/view/drugs/csv_result.rb', line 192

def limitation_text(pack)
  if((sl = pack.sl_entry) && (txt = sl.limitation_text))
    @counts['limitation_texts'] += 1
    txt.send(@lookandfeel.language).to_s.gsub(/\n/u, '|')
  end
end

- (Object) lppv(pack)



198
199
200
201
202
203
204
# File 'src/view/drugs/csv_result.rb', line 198

def lppv(pack)
  lppv = pack.lppv
  if lppv
    @counts['lppv'] += 1
  end
  boolean(lppv)
end

- (Object) narcotic(pack)



205
206
207
# File 'src/view/drugs/csv_result.rb', line 205

def narcotic(pack)
  boolean(pack.narcotic?)
end

- (Object) numerical_size(pack)



208
209
210
211
212
213
214
# File 'src/view/drugs/csv_result.rb', line 208

def numerical_size(pack)
  qty = pack.comparable_size.qty
  if qty == 0
    @counts['missing_size'] += 1
  end
  qty
end

- (Object) numerical_size_extended(pack)



215
216
217
218
219
220
221
222
223
224
225
# File 'src/view/drugs/csv_result.rb', line 215

def numerical_size_extended(pack)
  case ((group = pack.galenic_group) && group.de)
  when 'Brausetabletten', 'Gastrointenstinales Therapiesystem',
    'Kaugummi', 'Lutschtabletten', 'Pflaster/Transdermale Systeme',
    'Retard-Tabletten', 'Subkutane Implantate', 'Suppositorien',
    'Tabletten', 'Tests', 'Vaginal-Produkte'
    numerical_size(pack)
  else
    0
  end
end

- (Object) out_of_trade(pack)



226
227
228
229
230
231
232
# File 'src/view/drugs/csv_result.rb', line 226

def out_of_trade(pack)
  oot = !pack.public?
  if oot
    @counts['out_of_trade'] += 1
  end
  boolean(oot)
end

- (Object) price_exfactory(pack)



233
234
235
236
237
238
# File 'src/view/drugs/csv_result.rb', line 233

def price_exfactory(pack)
  if price = @lookandfeel.format_price(pack.price_exfactory.to_i)
    @counts['price_exfactory'] += 1
    price
  end
end

- (Object) price_public(pack)



239
240
241
242
243
244
# File 'src/view/drugs/csv_result.rb', line 239

def price_public(pack)
  if price = @lookandfeel.format_price(pack.price_public.to_i)
    @counts['price_public'] += 1
    price
  end
end

- (Object) rectype(pack)



245
246
247
# File 'src/view/drugs/csv_result.rb', line 245

def rectype(pack)
  '#Medi'
end

- (Object) registration_date(pack)



248
249
250
# File 'src/view/drugs/csv_result.rb', line 248

def registration_date(pack)
  formatted_date(pack, :registration_date)
end

- (Object) route_of_administration(pack)



251
252
253
254
255
256
257
# File 'src/view/drugs/csv_result.rb', line 251

def route_of_administration(pack)
  if(roa = pack.route_of_administration)
    @roas[roa.to_s] = true
    @counts['routes_of_administration'] = @roas.size
    roa.gsub('roa_', '')
  end
end

- (Object) size(model, session = @session)



265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'src/view/drugs/csv_result.rb', line 265

def size(model, session=@session)
  model.parts.collect { |part|
    parts = []
    multi = part.multi.to_i
    count = part.count.to_i
    if(multi > 1) 
      parts.push(multi)
    end
    if(multi > 1 && count > 1)
      parts.push('x')
    end
    if(count > 1 || multi <= 1)
      parts.push(part.count)
    end
    if(comform = part.commercial_form)
      parts.push(comform.send(@session.language))
    end
    if((measure = part.measure) && measure != 1)
      parts.push("à", measure)
    end
    parts.join(' ')
  }.join(' + ')
end

- (Object) sl_entry(pack)



258
259
260
261
262
263
264
# File 'src/view/drugs/csv_result.rb', line 258

def sl_entry(pack)
  sl_entry = pack.sl_entry
  if sl_entry
    @counts['sl_entries'] += 1
  end
  boolean(sl_entry)
end

- (Object) to_csv(keys, symbol = :active_packages)



301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'src/view/drugs/csv_result.rb', line 301

def to_csv(keys, symbol=:active_packages)
  eans = {}
  result = []
  lang = @lookandfeel.language
  header = keys.collect { |key|
    @lookandfeel.lookup("th_#{key}") || key.to_s
  }
  result.push(header)
  @model.each { |atc|
    result.push(['#MGrp', atc.code.to_s, atc.description(lang).to_s])
    atc.send(symbol).each { |pack|
      eans[pack.ikskey] = eans[pack.ikskey].to_i + 1
      line = keys.collect { |key|
        if(self.respond_to?(key))
          self.send(key, pack)
        else
          pack.send(key)
        end
      }
      result.push(line)
    }
  }
  @duplicates = eans.collect { |ikskey, count| 
    ikskey if count > 1 }.compact.sort
  result.collect { |line|
    CSV.generate_line(line, ';')
  }.join("\n")
end

- (Object) to_csv_file(keys, path, symbol = :active_packages)



329
330
331
# File 'src/view/drugs/csv_result.rb', line 329

def to_csv_file(keys, path, symbol=:active_packages)
  File.open(path, 'w') { |fh| fh.puts to_csv(keys, symbol) }
end

- (Object) to_html(context)



298
299
300
# File 'src/view/drugs/csv_result.rb', line 298

def to_html(context)
  to_csv(CSV_KEYS)
end

- (Object) vaccine(pack)



332
333
334
# File 'src/view/drugs/csv_result.rb', line 332

def vaccine(pack)
  boolean(pack.vaccine)
end