Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
---|---|---|---|---|
/home/masa/ywesee/oddb.org/src/util/exporter.rb | 320 | 306 | 57.19%
|
57.84%
|
Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.
1 #!/usr/bin/env ruby |
2 # Exporter -- oddb -- 30.07.2003 -- hwyss@ywesee.com |
3 |
4 require 'plugin/oddbdat_export' |
5 require 'plugin/fipdf' |
6 require 'plugin/yaml' |
7 require 'plugin/csv_export' |
8 require 'plugin/patinfo_invoicer' |
9 require 'plugin/fachinfo_invoicer' |
10 require 'plugin/download_invoicer' |
11 require 'plugin/ouwerkerk' |
12 require 'plugin/xls_export' |
13 require 'util/log' |
14 require 'util/logfile' |
15 require 'util/schedule' |
16 |
17 module ODDB |
18 class Exporter |
19 include Util::Schedule |
20 EXPORT_SERVER = DRbObject.new(nil, EXPORT_URI) |
21 EXPORT_DIR = File.expand_path('../../data/downloads', |
22 File.dirname(__FILE__)) |
23 FileUtils.mkdir_p(EXPORT_DIR) |
24 class SessionStub |
25 attr_accessor :language, :flavor, :lookandfeel |
26 alias :default_language :language |
27 end |
28 def initialize(app) |
29 @app = app |
30 end |
31 def run |
32 ## restart the export server |
33 EXPORT_SERVER.clear |
34 sleep(30) |
35 # |
36 mail_patinfo_invoices |
37 mail_fachinfo_log |
38 run_on_monthday(1) { |
39 mail_download_invoices |
40 } |
41 run_on_monthday(15) { |
42 mail_download_invoices |
43 } |
44 run_on_weekday(0) { |
45 mail_download_stats |
46 mail_feedback_stats |
47 #mail_notification_stats |
48 } |
49 export_sl_pcodes |
50 export_yaml |
51 export_oddbdat |
52 export_csv |
53 export_doc_csv |
54 export_index_therapeuticus_csv |
55 export_price_history_csv |
56 =begin # inoperable atm. |
57 run_on_monthday(1) { |
58 export_fachinfo_pdf |
59 } |
60 =end |
61 nil |
62 end |
63 def export_helper(name) |
64 EXPORT_SERVER.remote_safe_export(EXPORT_DIR, name) { |path| |
65 yield path |
66 } |
67 end |
68 def export_all_csv |
69 export_csv |
70 export_doc_csv |
71 export_index_therapeuticus_csv |
72 export_price_history_csv |
73 end |
74 def export_competition_xls(company, db_path=nil) |
75 plug = XlsExportPlugin.new(@app) |
76 plug.export_competition(company, db_path) |
77 plug |
78 end |
79 def export_csv |
80 plug = CsvExportPlugin.new(@app) |
81 safe_export 'oddb.csv' do |
82 plug.export_drugs |
83 end |
84 safe_export 'oddb.csv' do |
85 plug.export_drugs_extended |
86 end |
87 EXPORT_SERVER.clear |
88 sleep(30) |
89 end |
90 def export_analysis_csv |
91 plug = CsvExportPlugin.new(@app) |
92 plug.export_analysis |
93 EXPORT_SERVER.clear |
94 sleep(30) |
95 end |
96 def export_doc_csv |
97 safe_export 'doctors.csv' do |
98 plug = CsvExportPlugin.new(@app) |
99 plug.export_doctors |
100 end |
101 EXPORT_SERVER.clear |
102 sleep(30) |
103 end |
104 def export_fachinfo_pdf(langs = [:de, :fr]) |
105 plug = FiPDFExporter.new(@app) |
106 langs.each { |lang| |
107 name = "fachinfos_#{lang}.pdf" |
108 safe_export name do |
109 path = File.join(EXPORT_DIR, name) |
110 plug.write_pdf(lang, path) |
111 EXPORT_SERVER.compress(EXPORT_DIR, name) |
112 end |
113 } |
114 end |
115 def export_generics_xls |
116 plug = XlsExportPlugin.new(@app) |
117 plug.export_generics |
118 plug |
119 end |
120 def export_swissdrug_xls(date = @@today, opts={}) |
121 plug = OuwerkerkPlugin.new(@app, "swissdrug update") |
122 plug.export_xls opts |
123 name = 'swissdrug-update.xls' |
124 path = File.join(EXPORT_DIR, name) |
125 FileUtils.cp(plug.file_path, path) |
126 EXPORT_SERVER.compress(EXPORT_DIR, name) |
127 plug |
128 end |
129 def export_index_therapeuticus_csv |
130 safe_export 'index_therapeuticus' do |
131 plug = CsvExportPlugin.new(@app) |
132 plug.export_index_therapeuticus |
133 end |
134 EXPORT_SERVER.clear |
135 sleep(30) |
136 end |
137 def export_migel_csv |
138 plug = CsvExportPlugin.new(@app) |
139 plug.export_migel |
140 EXPORT_SERVER.clear |
141 sleep(30) |
142 end |
143 def export_narcotics_csv |
144 plug = CsvExportPlugin.new(@app) |
145 plug.export_narcotics |
146 EXPORT_SERVER.clear |
147 sleep(30) |
148 end |
149 def export_oddbdat |
150 dose_missing_list = [] |
151 safe_export 'oddbdat' do |
152 exporter = OdbaExporter::OddbDatExport.new(@app) |
153 dose_missing_list = exporter.export |
154 EXPORT_SERVER.clear |
155 sleep(30) |
156 run_on_weekday(1) { |
157 exporter.export_fachinfos |
158 EXPORT_SERVER.clear |
159 sleep(30) |
160 } |
161 |
162 # here to raise warning if package.parts is empty |
163 if !dose_missing_list.empty? |
164 log = Log.new(@@today) |
165 log.report = [ |
166 "Warning: Dose data (ODDB::Package.parts, Array of ODDB::Dose instances) is empty.", |
167 "Message: export_oddbdat succeeded but the following package(s) do not have Dose data.", |
168 "Package(s):", |
169 dose_missing_list.collect do |list| |
170 list[0].to_s + ", " + \ |
171 "http://#{SERVER_NAME}/de/gcc/resolve/pointer/%3A!registration%2C" + list[1].to_s + \ |
172 "!sequence%2C" + list[2].to_s + "!package%2C" + list[3].to_s + ".\n" |
173 end |
174 ].join("\n") |
175 log.notify("Warning Export: oddbdat") |
176 end |
177 end |
178 end |
179 def export_pdf |
180 FiPDFExporter.new(@app).run |
181 end |
182 def export_sl_pcodes |
183 safe_export 'sl_pcodes.txt' do |
184 path = File.expand_path('../../data/txt/sl_pcodes.txt', |
185 File.dirname(__FILE__)) |
186 File.open(path, 'w') { |fh| |
187 @app.each_package { |pac| |
188 if(pac.sl_entry && pac.pharmacode) |
189 fh.puts(pac.pharmacode) |
190 end |
191 } |
192 } |
193 end |
194 end |
195 def export_patents_xls |
196 plug = XlsExportPlugin.new(@app) |
197 plug.export_patents |
198 plug |
199 end |
200 def export_yaml |
201 exporter = YamlExporter.new(@app) |
202 safe_export 'oddb.yaml' do |
203 exporter.export |
204 end |
205 safe_export 'atc.yaml' do |
206 exporter.export_atc_classes |
207 end |
208 safe_export 'interactions.yaml' do |
209 exporter.export_interactions |
210 end |
211 safe_export 'narcotics.yaml' do |
212 exporter.export_narcotics |
213 end |
214 safe_export 'price_history.yaml' do |
215 exporter.export_prices |
216 end |
217 run_on_weekday(2) { |
218 safe_export 'fachinfo.yaml' do |
219 exporter.export_fachinfos |
220 end |
221 } |
222 run_on_weekday(3) { |
223 safe_export 'patinfo.yaml' do |
224 exporter.export_patinfos |
225 end |
226 } |
227 run_on_weekday(4) { |
228 safe_export 'doctors.yaml' do |
229 exporter.export_doctors |
230 end |
231 } |
232 EXPORT_SERVER.clear |
233 sleep(30) |
234 end |
235 def mail_download_stats |
236 safe_export 'Mail Download-Statistics' do |
237 mail_stats('download') |
238 end |
239 end |
240 def mail_download_invoices |
241 safe_export 'Mail Download-Invoices' do |
242 DownloadInvoicer.new(@app).run |
243 end |
244 end |
245 def mail_fachinfo_log(day = @@today) |
246 safe_export 'Mail Fachinfo-Invoices' do |
247 plug = FachinfoInvoicer.new(@app) |
248 plug.run(day) |
249 if report = plug.report |
250 log = Log.new(day) |
251 log.date_str = day.strftime("%d.%m.%Y") |
252 log.report = report |
253 log.notify("Fachinfo-Uploads") |
254 end |
255 end |
256 end |
257 def mail_feedback_stats |
258 safe_export 'Mail Feedback-Statistics' do |
259 mail_stats('feedback') |
260 end |
261 end |
262 def mail_notification_stats |
263 file = @app.notification_logger.create_csv(@app) |
264 headers = { |
265 :filename => 'notifications.csv', |
266 :mime_type => 'text/csv', |
267 :subject => 'Täglicher CSV-Export der Notifications', |
268 } |
269 Log.new(@@today).notify_attachment(file, headers) |
270 end |
271 def mail_patinfo_invoices |
272 safe_export 'Mail Patinfo-Invoices' do |
273 PatinfoInvoicer.new(@app).run |
274 end |
275 end |
276 def export_price_history_csv |
277 safe_export 'price_history.csv' do |
278 plug = CsvExportPlugin.new(@app) |
279 plug.export_price_history |
280 end |
281 EXPORT_SERVER.clear |
282 sleep(30) |
283 end |
284 def mail_stats(key) |
285 date = @@today |
286 if(date.mday < 8) |
287 date = date << 1 |
288 end |
289 log = Log.new(date) |
290 begin |
291 log.report = File.read(LogFile.filename(key, date)) |
292 rescue StandardError => e |
293 log.report = ([ |
294 "Nothing to Report.", |
295 nil, |
296 e.class, |
297 e.message |
298 ] + e.backtrace).join("\n") |
299 end |
300 log.notify("#{key.capitalize}-Statistics") |
301 end |
302 def mail_swissmedic_notifications |
303 SwissmedicPlugin.new(@app).mail_notifications |
304 end |
305 def safe_export subject, &block |
306 block.call |
307 rescue StandardError => e |
308 EXPORT_SERVER.clear rescue nil |
309 log = Log.new(@@today) |
310 log.report = [ |
311 "Error: #{e.class}", |
312 "Message: #{e.message}", |
313 "Backtrace:", |
314 e.backtrace.join("\n"), |
315 ].join("\n") |
316 log.notify("Error Export: #{subject}") |
317 sleep(30) |
318 end |
319 end |
320 end |
Generated on Mon Feb 07 10:36:39 +0100 2011 with rcov 0.9.8