Class: ODDB::HospitalPlugin

Inherits:
Plugin show all
Defined in:
src/plugin/hospitals.rb

Constant Summary

Constants inherited from Plugin

ARCHIVE_PATH, RECIPIENTS

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Plugin

#l10n_sessions, #log_info, #recipients, #report, #resolve_link, #update_rss_feeds

Methods included from HttpFile

#http_body, #http_file

Constructor Details

- (HospitalPlugin) initialize(app)

A new instance of HospitalPlugin



22
23
24
25
# File 'src/plugin/hospitals.rb', line 22

def initialize(app)
  super
  @meddata_server = DRbObject.new(nil, MEDDATA_URI)
end

Instance Attribute Details

- (Object) meddata_server=(value) (writeonly)

Sets the attribute meddata_server

Parameters:

  • value

    the value to set the attribute meddata_server to.



21
22
23
# File 'src/plugin/hospitals.rb', line 21

def meddata_server=(value)
  @meddata_server = value
end

Instance Method Details

- (Object) hospital_details(meddata, result)



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'src/plugin/hospitals.rb', line 56

def hospital_details(meddata, result)
  template = {
    :ean13          => [1,0],
    :name           => [1,2],
    :business_unit  => [1,3],
    :address        =>  [1,4],
    :plz            =>  [1,5],
    :location       => [2,5],
    :phone          => [1,6],
    :fax            =>  [2,6],
    :canton         =>  [3,5],
    :narcotics      => [1,10],
  }
  meddata.detail(result, template)
end

- (Object) update(current = '7601001', last = '7601004')



26
27
28
29
30
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
# File 'src/plugin/hospitals.rb', line 26

def update(current='7601001', last = '7601004')
  factory =  MedData::EanFactory.new(current)
  while(current < last)
    current = factory.next
    puts current
    criteria = { 
      :name        => '',
      :country   => 'CH',
      :plz       => '',
      :city        => '',
      :state     => '',
      :functions => '10',
      :ean       => current,
    }
    begin
      @meddata_server.session { |meddata|
        meddata.search(criteria) { |result|
          values = hospital_details(meddata, result)
          update_hospital(values)
        }
      }
    rescue MedData::OverflowError
      current = factory.clarify
      retry
    rescue
      puts $!.backtrace
      raise
    end
  end
end

- (Object) update_hospital(values)



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'src/plugin/hospitals.rb', line 71

def update_hospital(values)
  ean13 = values.delete(:ean13)
  if(hospital = @app.hospital(ean13))
    pointer = hospital.pointer
  else
    ptr = Persistence::Pointer.new([:hospital, ean13])
    pointer = ptr.creator
  end
  addr = Address2.new
  addr.address = values.delete(:address)
  addr.location = [values.delete(:plz), 
    values.delete(:location)].compact.join(' ')
  addr.canton   = values.delete(:canton)
  addr.fon = [values.delete(:phone)]
  addr.fax = [values.delete(:fax)]
  addr.additional_lines = [values[:business_unit]]
  values.store(:addresses, [addr])
  @app.update(pointer, values, :refdata)
end