Class: ODDB::MedwinCompanyPlugin

Inherits:
MedwinPlugin show all
Defined in:
src/plugin/medwin.rb,
test/test_plugin/medwin.rb

Constant Summary

MEDDATA_SERVER =
DRbObject.new(nil, MEDDATA_URI)

Constants inherited from MedwinPlugin

HTTP_SERVER

Constants inherited from Plugin

ARCHIVE_PATH, RECIPIENTS

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Plugin

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

Methods included from HttpFile

#http_body, #http_file

Constructor Details

- (MedwinCompanyPlugin) initialize(app)

A new instance of MedwinCompanyPlugin



27
28
29
30
31
32
33
34
35
36
37
# File 'src/plugin/medwin.rb', line 27

def initialize(app)
  super
  @medwin_template = {
    :ean13    =>  [1,0],
    :address  =>  [1,5],
    :plz      =>  [1,6],
    :location =>  [2,6],
    :phone    =>  [1,7],
    :fax      =>  [2,7],
  }
end

Instance Attribute Details

- (Object) update_company_called

Returns the value of attribute update_company_called



18
19
20
# File 'test/test_plugin/medwin.rb', line 18

def update_company_called
  @update_company_called
end

Instance Method Details

- (Object) report



38
39
40
41
42
43
44
45
46
47
48
49
# File 'src/plugin/medwin.rb', line 38

def report
  lines = [
    "Checked #{@checked} Companies",
    "Compared #{@found} Medwin Entries",
    "Updated  #{@updated.size} Companies:",
  ] + @updated.sort
  lines.push("Errors:")
  @errors.each { |key, value|
    lines.push(key + " => " + value)
  }
  lines.join("\n")
end

- (Object) update



50
51
52
53
54
55
# File 'src/plugin/medwin.rb', line 50

def update
  @checked = @app.companies.size
  @app.companies.each_value { |comp| 
    update_company(comp)
  }
end

- (Object) update_company(comp)



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

def update_company(comp)
  ean = comp.ean13.to_s
  eanc = { :ean =>  ean }
  namec = { :name =>  comp.name.to_s }
  criteria = ean.empty? ? namec : eanc
  MEDDATA_SERVER.session(:partner) { |meddata|
    results = meddata.search(criteria)
    if(results.empty? && criteria.include?(:ean))
      results = meddata.search(namec)
    end
    if(results.size == 1)
      result = results.first
      details = meddata.detail(result, @medwin_template)
      update_company_data(comp, details)
    end
    nil # return nil across DRb
  }
rescue MedData::OverflowError
end

- (Object) update_company_data(comp, data)



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'src/plugin/medwin.rb', line 75

def update_company_data(comp, data)
  addr = Address2.new
  addr.address = data[:address]
  addr.location = [data[:plz], data[:location]].compact.join(' ')
  if(fon = data[:phone])
    addr.fon = [fon]
  end
  if(fax = data[:fax])
    addr.fax = [fax]
  end
  update = {
    :ean13  => data[:ean13],
    :addresses => [addr],
  }
  update.delete_if { |key, val| 
    (orig = comp.data_origin(key)) && orig != :refdata 
  }
  @updated.push(comp.name)
  @app.update(comp.pointer, update, :refdata)
end