Module: ODDB::ResultSort

Included in:
AtcFacade, State::Drugs::RecentRegs::PackageMonth
Defined in:
src/util/resultsort.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) dose_value(dose)



35
36
37
# File 'src/util/resultsort.rb', line 35

def dose_value(dose)
  dose || Dose.new(0)
end

- (Object) galform_str(galform, session)



41
42
43
44
45
46
47
# File 'src/util/resultsort.rb', line 41

def galform_str(galform, session)
  if(galform.odba_instance.nil?)
    ''
  else
    galform.send(session.language)
  end
end

- (Object) generic_type_weight(package)



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

def generic_type_weight(package)
  case package.generic_type
  when :original
    0
  when :generic
    5
  when :comarketing
    10
  when :complementary
    15
  else
    20
  end
  # the following was madly inefficient!
=begin
  types = session.valid_values(:generic_type)
  index = types.index(package.generic_type.to_s).to_i
  10 - (index*2)
=end


end

- (Object) package_count



38
39
40
# File 'src/util/resultsort.rb', line 38

def package_count
  @packages.size
end

- (Object) sort_result(packages, session)



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'src/util/resultsort.rb', line 16

def sort_result(packages, session)
  begin
    packages.sort_by { |package|
      [
        package.expired? ? 1 : -1,
        generic_type_weight(package),
        package.name_base.to_s,
        package.galenic_forms.collect { |gf| galform_str(gf, session) },
        dose_value(package.dose),
        package.comparable_size,
      ]
    }
  rescue StandardError => e
    puts e.class
    puts e.message
    puts e.backtrace
    packages
  end
end