Class: ODDB::YamlExporter

Inherits:
Plugin show all
Defined in:
src/plugin/yaml.rb,
test/test_plugin/yaml.rb

Constant Summary

EXPORT_SERVER =
DRbObject.new(nil, EXPORT_URI)
EXPORT_DIR =
File.expand_path('../data/export', File.dirname(__FILE__))
@@today =
Time.now

Constants inherited from Plugin

ARCHIVE_PATH, RECIPIENTS

Instance Method Summary (collapse)

Methods inherited from Plugin

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

Methods included from HttpFile

#http_body, #http_file

Constructor Details

This class inherits a constructor from ODDB::Plugin

Instance Method Details

- (Object) check_fachinfos(name = 'fachinfo.yaml')



25
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
56
57
58
59
60
61
62
# File 'src/plugin/yaml.rb', line 25

def check_fachinfos(name='fachinfo.yaml')
  # Check missing data of fachinfo data
  no_descr = {'de' => [], 'fr' => []}
  @app.fachinfos.values.each do |fachinfo|
    no_descr.keys.each do |language|
      unless fachinfo.descriptions[language]
        swissmedic_registration_numbers = ODBA.cache.fetch(fachinfo.odba_id, nil).iksnrs
        no_descr[language].push(
          [fachinfo.company_name, fachinfo.name_base].concat(swissmedic_registration_numbers)
        )
      end
    end
  end
  # Send a warning report of fachinfo description
  if no_descr.values.flatten.length > 0
    log = Log.new(@@today)
    message = []
    no_descr.keys.each do |language|
      unless no_descr[language].empty?
        i = 0
        message.concat([
          "There is no '#{language}' description of Fachinformation of the following",
          "Swissmedic Registration (Company, Product, Numbers):",
          no_descr[language].map{|fachlist| " " + (i+=1).to_s + ". " + fachlist.join(", ") + "\n"}.to_s
        ])
      end
    end
    log.report = [
      "Message: ",
      "YamlExporter#export_fachinfs method is still running,",
      "but I found some missing Fachinfo document data.",
      "This may cause an error in export ebooks process of ebps.",
      "",
    ].concat(message).join("\n")
    log.notify(" Warning Export: #{name}")
  end
  return no_descr
end

- (Object) export(name = 'oddb.yaml')



12
13
14
# File 'src/plugin/yaml.rb', line 12

def export(name='oddb.yaml')
  export_obj(name, @app.companies)
end

- (Object) export_array(name, array, opts = {})



15
16
17
18
# File 'src/plugin/yaml.rb', line 15

def export_array(name, array, opts={})
  ids = array.collect { |item| item.odba_id }
  EXPORT_SERVER.export_yaml(ids, EXPORT_DIR, name, opts)
end

- (Object) export_atc_classes(name = 'atc.yaml')



19
20
21
# File 'src/plugin/yaml.rb', line 19

def export_atc_classes(name='atc.yaml')
  export_array(name, @app.atc_classes.values.sort_by { |atc| atc.code.to_s })
end

- (Object) export_doctors(name = 'doctors.yaml')



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

def export_doctors(name='doctors.yaml')
  export_array(name, @app.doctors.values)
end

- (Object) export_fachinfos(name = 'fachinfo.yaml')



63
64
65
66
# File 'src/plugin/yaml.rb', line 63

def export_fachinfos(name='fachinfo.yaml')
      check_fachinfos(name)
      export_array(name, @app.fachinfos.values)
end

- (Object) export_interactions(name = 'interactions.yaml')



67
68
69
# File 'src/plugin/yaml.rb', line 67

def export_interactions(name='interactions.yaml')
  export_array(name, @app.substances.inject([]) { |memo, sub| memo.concat sub.substrate_connections.values })
end

- (Object) export_narcotics(name = 'narcotics.yaml')



70
71
72
# File 'src/plugin/yaml.rb', line 70

def export_narcotics(name='narcotics.yaml')
  export_array(name, @app.narcotics.values)
end

- (Object) export_obj(name, obj)



73
74
75
# File 'src/plugin/yaml.rb', line 73

def export_obj(name, obj)
  EXPORT_SERVER.export_yaml([obj.odba_id], EXPORT_DIR, name)
end

- (Object) export_patinfos(name = 'patinfo.yaml')



76
77
78
# File 'src/plugin/yaml.rb', line 76

def export_patinfos(name='patinfo.yaml')
  export_array(name, @app.patinfos.values)
end

- (Object) export_prices(name = 'price_history.yaml')



79
80
81
82
83
84
# File 'src/plugin/yaml.rb', line 79

def export_prices(name='price_history.yaml')
  packages = @app.packages.reject do |pac|
    pac.prices.all? do |key, prices| prices.empty? end
  end
  export_array(name, packages, :export_prices => true)
end