Class: ODDB::SwissregPlugin

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

Constant Summary

SWISSREG_SERVER =
DRb::DRbObject.new(nil, SWISSREG_URI)

Constants inherited from Plugin

ARCHIVE_PATH, RECIPIENTS

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

- (SwissregPlugin) initialize(app)

A new instance of SwissregPlugin



10
11
12
13
14
15
16
17
# File 'src/plugin/swissreg.rb', line 10

def initialize(app)
  super
  @substances = 0
  @patents = 0
  @iksnrs = 0
  @successes = 0
  @failures = []
end

Instance Method Details

- (Object) format_data(data)



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

def format_data(data)
  fmt = "%s -> http://www.swissreg.ch/srclient/faces/jsp/spc/sr300.jsp?language=de&section=spc&id=%s\n"
  iksnrs = data[:iksnrs] || []
  sprintf(fmt, iksnrs.join(','), data[:certificate_number])
end

- (Object) get_detail(url)



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

def get_detail(url)
  uri = URI.parse(url)
  SWISSREG_SERVER.detail(uri.request_uri)
end

- (Object) report



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

def report
  fmt =  "Checked   %4i Substances for connected Patents\n"
  fmt << "Found     %4i Patents\n"
  fmt << "of which  %4i had a Swissmedic-Number.\n"
  fmt << "          %4i Registrations were successfully updated;\n"
  fmt << "for these %4i Swissmedic-Numbers no Registration was found:\n\n"
  str = sprintf(fmt, 
                @substances, @patents, @iksnrs, @successes, @failures.size)
  @failures.each { |data|
    str << format_data(data)
  }
  str
end

- (Object) update



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'src/plugin/swissreg.rb', line 40

def update
  substances = []
  @app.substances.each { |substance|
    if((substance_name = substance.de.split(' ').first) \
       && (substance_name.length > 6) \
       && (substance.is_effective_form? \
       || (!substance.has_effective_form? && !substance.sequences.empty?)) \
       && !substance.sequences.any? { |seq| seq.registration.patent })
       #|| (!substance.has_effective_form? && !substance.sequences.empty?)))#
      substances.push(substance_name)
    end
  }
  update_substances(substances)
end

- (Object) update_news



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'src/plugin/swissreg.rb', line 54

def update_news
  substances = []
  if((group = @app.log_group(:swissmedic)) && (log = group.latest))
    log.change_flags.each_key { |ptr| 
      if(reg = ptr.resolve(@app))
        reg.each_sequence { |seq|
          substances += seq.active_agents.collect { |act| 
            act.substance.to_s.split(' ').first
          }
        }
      end
    }
  end
  update_substances(substances)
end

- (Object) update_registration(iksnr, data)



82
83
84
85
86
87
88
89
90
# File 'src/plugin/swissreg.rb', line 82

def update_registration(iksnr, data)
  if(reg = @app.registration(iksnr))
    @successes += 1
    ptr = reg.pointer + [:patent]
    @app.update(ptr.creator, data, :swissreg)
  else
    @failures.push(data)
  end
end

- (Object) update_registrations(substance_name)



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'src/plugin/swissreg.rb', line 69

def update_registrations(substance_name)
  @substances += 1
  SWISSREG_SERVER.search(substance_name).each { |data|
    @patents += 1
    if(iksnrs = data[:iksnrs])
      @iksnrs += 1
      iksnrs.each { |iksnr|
        update_registration(iksnr, data)
      }
    end
    sleep(2)
  }
end

- (Object) update_substances(substances)



91
92
93
94
95
96
97
# File 'src/plugin/swissreg.rb', line 91

def update_substances(substances)
  substances.collect { |substance|
    substance.to_s.gsub(/(i|e|um)$/u, '')
  }.compact.uniq.each { |substance_name|
    update_registrations(substance_name) 
  }
end