Test C0 Coverage Information - RCov

/home/masa/ywesee/oddb.org/ext/export/src/oddbdat.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
/home/masa/ywesee/oddb.org/ext/export/src/oddbdat.rb 674 658
98.07%
98.02%

Key

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.

Coverage Details

1 #!/usr/bin/env ruby
2 # OddbDat -- oddb -- 09.12.2004 -- hwyss@ywesee.com
3 
4 require 'encoding/character/utf-8'
5 
6 module ODDB
7 	module OdbaExporter
8 		class Table
9 			CRLF = "\r\n"
10 			def filename
11 				self::class::FILENAME
12 			end
13 		end
14 		class AcTable <	Table
15 			FILENAME = 's01x'
16 			def lines(package)
17 				[AcLine.new(package)]
18 			end
19 		end
20 		class AccompTable < Table
21 			FILENAME = 's19x'
22 			def lines(package)
23 				[AccompLine.new(package)]
24 			end
25 		end
26 		class AcLimTable < Table
27 			FILENAME = 's09x'
28 			def lines(package)
29 				lines = []
30 				unless((sl = package.sl_entry).nil?)
31 					if(lim = sl.limitation_text)
32 						chap = lim.descriptions.values.first
33 						chap.paragraphs.each_with_index { |par, idx|
34 							pack = package.oid
35 							line = idx 
36 							lim = (pack.to_s + sprintf('%03i', line).to_s).to_i
37 							lines << AcLimLine.new(pack, line, lim)
38 						}
39 					end
40 				end
41 				lines
42 			end
43 		end
44 		class AcmedTable < Table
45 			FILENAME = 's02x'
46 			def lines(package)
47 				[AcmedLine.new(package)]
48 			end
49 		end
50 		class AcnamTable < Table
51 			FILENAME = 's03x'
52 			def lines(package)
53 				[AcnamLine.new(package)]
54 			end
55 		end
56 		class AcOddbTable < Table
57 			FILENAME = 's99x'
58 			def lines(package)
59 				lines = []
60 				if(package.pharmacode)
61 					lines << AcOddbLine.new(package)
62 				end
63 				lines
64 			end
65 		end
66 		class AcpricealgTable < Table
67 			FILENAME = 's07x'
68 			def lines(package)
69 				lines = [
70 					AcpricealgPublicLine.new(package),
71 					AcpricealgExfactoryLine.new(package),
72 				]
73 				lines.delete_if { |line| line.empty? }
74 				lines
75 			end
76 		end
77 		class AcscTable < Table
78 			FILENAME = 's41x'
79 			def lines(package)
80 				lines = []
81 				package.active_agents.each_with_index { |act, idx|
82 					lines.push(AcscLine.new(package, act, idx))
83 				}
84 				lines
85 			end
86 		end
87 		class LimitationTable < Table
88 			FILENAME = 's16x'
89 			def lines(package)
90 				lines = []
91 				unless((sl = package.sl_entry).nil?)
92 					if(lim = sl.limitation_text)
93 						chap = lim.descriptions.values.first
94 						chap.paragraphs.each_with_index { |par, idx|
95 							pack = package.oid
96 							line = idx 
97 							lim = (pack.to_s + sprintf('%03i', line).to_s).to_i
98 							lines << LimitationLine.new(lim)
99 						}
100 					end
101 				end
102 				lines
103 			end
104 		end
105 		class LimTxtTable < Table
106 			FILENAME = 's10x'
107 			def lines(package)
108 				lines = []
109 				unless((sl = package.sl_entry).nil?)
110 					if(lim = sl.limitation_text)
111 						lim.descriptions.each { |lang, value|
112 							value.paragraphs.each_with_index { |par, idx|
113 								language = lang[0,1].upcase
114 								lim = (package.oid.to_s + sprintf('%03i', idx).to_s).to_i
115 								txt = par.text
116 								lines << LimTxtLine.new(lim, language, txt)
117 							}
118 						}
119 					end
120 				end
121 				lines
122 			end
123 		end
124 		class EanTable < Table
125 			FILENAME = 's06x'
126 			def lines(package)
127 				[EanLine.new(package)]
128 			end
129 		end
130 		class MCMTable < Table
131 			FILENAME = 's31x'
132 			def lines(fi)
133 				lines = []
134 				fi.descriptions.each { |lang, doc|
135 					line = 1
136 					doc.each_chapter { |chap|
137 						text = format_line(chap)
138 						while(text.size > 220)
139 							pos = text.rindex(' ', 220)
140 							if(pos.nil?)
141 								pos = text.rindex('<P>', 220)-1
142 							end
143 							txt = text.slice!(0..pos)
144 							lines << MCMLine.new(fi.oid, line, lang, txt)
145 							line = line.next
146 						end
147 						lines << MCMLine.new(fi.oid, line, lang, text)
148 						line = line.next
149 					}	
150 				}
151 				lines
152 			end
153 			def format_line(chapter)
154 				string = String.new
155 				unless((head = chapter.heading).empty?)
156 					string << '<BI>' << head.to_s << '<E><P>'
157 				end
158 				chapter.sections.each { |sec|
159 					unless((subhead = sec.subheading).empty?)
160 						subhead = subhead.gsub(/\n/u, "<P>")
161 						string << '<I>' << subhead.to_s << '<E>'
162 					end
163 					sec.paragraphs.each { |par|
164             case par
165             when ODDB::Text::ImageLink
166               string << "<IMG src='http://#{SERVER_NAME}#{par.src}'/>"
167             when ODDB::Text::Table
168               string << '<N>' << par.to_s << '<E>'
169             else
170               text = u par.text
171 							par.formats.each { |format|
172 								start_tag = ""
173 								end_tag = ""
174 								if(format.italic?)
175 									start_tag = "<I>"
176 									end_tag = "<E>"
177 								elsif(format.bold?)
178 									start_tag = "<B>"
179 									end_tag = "<E>"
180 								end
181                 if formatted = text[format.range]
182                   string << start_tag << formatted << end_tag
183                 end
184 							}
185               string << "<P>"
186 							if(par.preformatted?)
187 								string.gsub!(/ /, '_')
188 								string.gsub!(/\n/, "<P>")
189 							end
190             end
191 					}
192 				}
193 				string.gsub(/\n/u, ' ')
194 			end
195 		end
196 		class CodesTable < Table
197 			FILENAME = 's11x'
198 			def lines(item)
199 				case item
200 				when AtcClass
201 					atclines(item)
202 				when GalenicForm
203 					gallines(item)
204 				end
205 			end
206 			def atclines(atcclass)
207 				[AtcLine.new(atcclass)]
208 			end
209 			def gallines(galform)
210 				[GalenicFormLine.new(galform)]
211 			end
212 		end
213 		class ScTable < Table
214 			FILENAME = 's40x'
215 			def lines(substance)
216 				[ScLine.new(nil, substance)]
217 			end
218 		end
219 		class CompTable < Table
220 			FILENAME = 's12x'
221 			def lines(company)
222 				[CompLine.new(company)]
223 			end
224 		end
225 		class Readme < Table
226 			FILENAME = 'README'
227 			def lines
228 				<<-EOS
229 	oddbdat.tar.gz und oddbdat.zip enthalten die täglich aktualisierten Artikelstammdaten der ODDB. Die Daten werden von ywesee in das OddbDat-Format umgewandelt und allen gewünschten Systemlieferanten von Schweizer Spitälern zur Verfügung gestellt.
230 
231 	Feedback bitte an zdavatz@ywesee.com
232 
233 	-AC (Tabelle 1) - ODDB-Code
234 	-ACMED (Tabelle 2) - Weitere Produktinformationen
235 	-ACNAM (Tabelle 3) - Sprachen
236 	-ACBARCODE (Tabelle 6) - EAN-Artikelcode
237 	-ACPRICEALG (Tabelle 7) - Preise
238 	-ACLIM (Tabelle 9) - Limitationen
239 	-LIMTXT (Tabelle 10) - Limitationstexte
240 	-CODES (Tabelle 11) - Codebeschreibungen (ATC-Beschreibung, Galenische Form)
241 	-COMP (Tabelle 12) - Hersteller
242 	-LIMITATION (Tabelle 16) - Limitationen der SL
243 	-ACCOMP (Tabelle 19) - Verbindungstabelle zwischen AC und COMP
244 	-SC (Tabelle 40) - Substanzen
245 	-ACSC (Tabelle 41) - Verbindungstabelle zwischen AC und SC
246 	-ACODDB (Tabelle 99) - Verbindungstabelle zwischen ODDB-ID und Pharmacode
247 
248 	Folgende Tabelle mit den Fachinformationen steht wegen ihrer Grösse separat als tar.gz- oder zip-Download zur Verfügung.
249 
250 	-MCM (Tabelle 31)	- Fachinformationen
251 
252 	Die Daten werden als oddbdat.tar.gz und oddbdat.zip auf unserem Server bereitgestellt - Vorzugsweise benutzen Sie einen der folgenden direkten Links.
253 
254 	Ganze Packages (ohne Fachinformationen):
255 	http://www.oddb.org/resources/downloads/oddbdat.tar.gz
256 	http://www.oddb.org/resources/downloads/oddbdat.zip
257 
258 	Nur Fachinformationen (sehr grosse Dateien):
259 	http://www.oddb.org/resources/downloads/s31x.tar.gz
260 	http://www.oddb.org/resources/downloads/s31x.zip
261 
262 
263 				EOS
264 			end
265 		end
266 		class Line
267 			def initialize(*args)
268 				@date = Date.today.strftime("%Y%m%d%H%M%S")
269 				@structure = structure
270 			end
271 			def content(structure)
272 				return [] if structure.nil?
273 				fields = Array.new(self::class::LENGTH)
274 				structure.each_pair { |place, field|
275 					# schlüssel in structure entsprechen der OddbDat-Doku
276 					fields[place-1] = field 
277 				}
278 				fields
279 			end
280 			def empty?
281 				@structure.nil?
282 			end
283 			def structure
284 			end
285 			def to_s
286 				content(@structure).join('|').gsub("\000", "")
287 			end	
288 		end
289 		class PackageLine < Line
290 			def initialize(package, *args)
291 				@package = package
292 				super
293 			end
294 		end
295 		class SubstanceLine < PackageLine
296 			def initialize(package, substance, *args)
297 				@substance = substance
298 				super
299 			end
300 		end
301 		class AcLine < PackageLine
302 			LENGTH = 55
303 			def structure
304 				{
305 					1		=>	'01',
306 					2		=>	@date,
307 					3		=>	'1',
308 					4		=>	@package.oid,
309 					5		=>	'4',
310 					7		=>	ikskey,
311 					14	=>	@package.ikscat,
312 					# @package hat immer eine registration, da
313 					# Registration::create_package die Verknüpfung erstellt
314 					20	=>	generic_code(@package.registration),
315 					22	=>	iks_date(@package.registration),
316 					29	=>	(@package.sl_entry) ? '3' : nil,
317 					32	=>	(@package.public?) ? nil : 'H',
318 					39	=>	inscode,
319 					40	=>	limitation,
320 					41	=>	limitation_points,
321 					47	=>	(@package.narcotics.empty?) ? nil : 'y',
322 				}
323 			end
324 			def generic_code(registration)
325 				if registration.generic_type == :generic
326 					'Y'
327 				end
328 			end	
329 			def iks_date(registration)
330 				if(date = registration.registration_date)
331 					date.strftime("%Y%m%d")
332 				end
333 			end
334 			def ikskey
335 				ikskey = @package.iksnr.dup
336 				ikskey << @package.ikscd
337 				ikskey
338 			end
339 			def inscode
340 				if @package.sl_entry
341 					'1'
342 				end
343 			end
344 			def limitation
345 				if((sl = @package.sl_entry) && (sl.limitation))
346 					'Y'
347 				end
348 			end
349 			def limitation_points
350 				if(sl = @package.sl_entry)
351 					sl.limitation_points
352 				end
353 			end
354 		end
355 		class AccompLine < PackageLine
356 			LENGTH = 8
357 			def structure
358 				if(comp = @package.registration.company)
359 					{
360 						1		=>	'19',
361 						2		=>	@date,
362 						3		=>	@package.oid,
363 						4		=>	comp.oid,
364 						5		=>	'H',
365 						6		=>	'4',
366 					}
367 				end
368 			end
369 		end
370 		class AcLimLine < PackageLine
371 			LENGTH = 8
372 			def initialize(package_oid, line_oid, lim_oid)
373 				@package_oid = package_oid
374 				@line_oid = line_oid
375 				@lim_oid = lim_oid
376 				super
377 			end
378 			def structure
379 				{
380 					1		=>	'09',
381 					2		=>	@date,
382 					3		=>	@package_oid,
383 					4		=>	@lim_oid,
384 					5		=>	@line_oid,
385 					6		=>	'4',
386 				}
387 			end
388 		end
389 		class AcnamLine < PackageLine
390 			LENGTH = 26
391 			def structure
392 				seq = @package.sequence
393 				galform = if(gf = seq.galenic_forms.first)
394 					gf.to_s
395 				end
396 				conc, unit = if((dose = seq.dose) && dose.is_a?(Quanty))
397 					[dose.qty, dose.unit]
398 				end
399         measures = @package.parts.collect { |part| part.measure }.compact
400 				measure, munit = unless(measures.empty?)
401                            ms = measures.inject { |a, b| a + b }
402                            [ms.qty, ms.unit] if ms.is_a?(Quanty)
403                          end
404         comform = @package.commercial_forms.first
405 				qty, qty_unit = if(munit && !munit.empty?)
406 					[measure, munit]
407 				else
408 					[@package.comparable_size.qty, comform]
409 				end	
410 				{
411 					1		=>	'03',
412 					2		=>	@date,
413 					3		=>	'1',
414 					4		=>	@package.oid,
415 					5		=>	'D',
416 					6		=>	'4',
417 					7		=>	seq.name,
418 					8		=>	seq.name_base,
419 					9		=>	seq.name_descr,
420 					11	=>	galform,
421 					12	=>	conc,
422 					13	=>	unit,
423 					16	=>	@package.parts.first ? @package.parts.first.multi : '',
424 					17	=>	comform,
425 					18	=>	qty,
426 					19	=>	qty_unit,
427 				}
428 			end
429 		end
430 		class AcmedLine	< PackageLine
431 			LENGTH = 27
432 			def structure
433 				atccd = if(atc = @package.sequence.atc_class)
434 					atc.code
435 				end
436 				gfid = if(galform = @package.galenic_forms.first)
437 					galform.oid
438 				end
439 				fioid = if(fachinfo = @package.fachinfo)
440 					fachinfo.oid
441 				end	
442 				atc = @package.sequence.atc_class
443 				{
444 					1		=>	'02',
445 					2		=>	@date,
446 					3		=>	'1',
447 					4		=>	@package.oid,
448 					5		=>	'4',
449 					7		=>	fioid,
450 					10	=>	atccd,
451 					12	=>	gfid,
452 				}
453 			end
454 		end
455 		class AcOddbLine < PackageLine
456 			LENGTH = 2 
457 			def structure
458 				{
459 					1		=>	@package.oid,
460 					2		=>	@package.pharmacode,
461 				}
462 			end
463 		end
464 		class AcpricealgPublicLine	< PackageLine
465 			LENGTH = 9
466 			def structure
467 				if(ppub = @package.price_public)
468 					{
469 						1		=>	'07',
470 						2		=>	@date,
471 						3		=>	@package.oid,
472 						4		=>	price_public_type,
473 						5		=>	'4',
474 						6		=>	sprintf('%2.2f', ppub.to_f),
475 					}
476 				end
477 			end
478 			def price_public_type
479 				if @package.sl_entry
480 					'PSL2'
481 				else
482 					'PPUB'
483 				end
484 			end
485 		end
486 		class AcpricealgExfactoryLine	< PackageLine
487 			LENGTH = 9
488 			def structure
489 				if(pexf = @package.price_exfactory)
490 					{
491 						1		=>	'07',
492 						2		=>	@date,
493 						3		=>	@package.oid,
494 						4		=>	'PSL1',
495 						5		=>	'4',
496 						6		=>	sprintf('%2.2f', pexf.to_f),
497 					}
498 				end
499 			end
500 		end
501 		class AcscLine < SubstanceLine
502 			LENGTH = 10
503 			def initialize(package, active_agent, count)
504 				@count = count
505 				super
506 			end	
507 			def structure
508 				return if @substance.nil?
509 				qty, unit = if((dose = @substance.dose) && dose.is_a?(Quanty))
510 					[dose.qty, dose.unit]
511 				end
512 				{
513 					1		=>	'41',
514 					2		=>	@date,
515 					3		=>	@package.oid,
516 					4		=>	@count,
517 					5		=>	'4',
518 					6		=>	@substance.substance.oid,
519 					7		=>	qty,
520 					8		=>	unit,
521 					9		=>	'W',
522 				}
523 			end
524 		end
525 		class AtcLine	< Line
526 			LENGTH = 9
527 			def initialize(atcclass)
528 				@atcclass = atcclass
529 				super
530 			end
531 			def structure
532 				return if @atcclass.nil?
533 				{
534 					1		=>	'11',
535 					2		=>	@date,
536 					3		=>	'8',
537 					4		=>	@atcclass.code,
538 					5		=>	'D',
539 					6		=>	'4',
540 					7		=>	@atcclass.description,
541 				}
542 			end
543 		end
544 		class CompLine < Line
545 			LENGTH = 19
546 			def initialize(company)
547 				@company = company
548 				super
549 			end
550 			def structure
551 				addr = @company.address(0)
552 				{
553 					1		=>	'12',
554 					2		=>	@date,
555 					3		=>	@company.oid,
556 					4		=>	'4',
557 					5		=>	@company.ean13,
558 					7		=>	@company.name,
559 					8		=>	addr.address,
560 					9		=>	'CH',
561 					10	=>	addr.plz,
562 					11	=>	addr.city,
563 					13	=>	addr.fon.first,
564 					15	=>	addr.fax.first,
565 					16	=>	@company.address_email,
566 					17	=>	@company.url,
567 				}
568 			end
569 		end
570 		class EanLine < PackageLine
571 			LENGTH = 8
572 			def structure
573 				{
574 					1		=>	'06',
575 					2		=>	@date,
576 					3		=>	@package.oid,
577 					4		=>	'E13',
578 					5		=>	barcode,
579 					6		=>	'4',
580 				}
581 			end
582 			def barcode
583 				@package.barcode
584 			end
585 		end
586 		class GalenicFormLine	< Line
587 			LENGTH = 9
588 			def initialize(galenic_form)
589 				@galenic_form = galenic_form
590 				super
591 			end
592 			def structure
593 				{
594 					1		=>	'11',
595 					2		=>	@date,
596 					3		=>	'5',
597 					4		=>	@galenic_form.oid,
598 					5		=>	'D',
599 					6		=>	'4',
600 					7		=>	@galenic_form.to_s,
601 				}
602 			end
603 		end
604 		class ScLine < SubstanceLine
605 			LENGTH = 8
606 			def structure
607 				{
608 					1		=>	'40',
609 					2		=>	@date,
610 					3		=>	@substance.oid,
611 					4		=>	'L',
612 					5		=>	'4',
613 					6		=>	@substance,
614 				}
615 			end
616 		end
617 		class LimitationLine < PackageLine
618 			LENGTH = 10
619 			def initialize(lim_oid)
620 				@lim_oid = lim_oid
621 				super
622 			end
623 			def structure
624 				{
625 					1		=>	'16',
626 					2		=>	@date,
627 					3		=>	@lim_oid,
628 					5		=>	'4',
629 					6		=>	'COM',
630 				}
631 			end
632 		end
633 		class LimTxtLine < Line
634 			LENGTH = 8
635 			def initialize(lim_oid, language, txt)
636 				@lim_oid = lim_oid
637 				@language = language
638 				@txt = txt
639 				super
640 			end
641 			def structure
642 				{	
643 					1	=>	'10',
644 					2	=>	@date,
645 					3	=>	@lim_oid,
646 					4	=>	@language,
647 					5	=>	'4',
648 					6	=>	@txt,
649 				}
650 			end
651 		end
652 		class MCMLine < Line
653 			LENGTH = 7
654 			def initialize(fi_oid, line_nr, language, text)
655 				@fi_oid = fi_oid
656 				@line_nr = line_nr
657 				@language = language
658 				@text = text
659 				super
660 			end
661 			def structure
662 				{
663 					1	=>	'31',
664 					2	=>	@date,
665 					3	=>	@fi_oid,
666 					4	=>	@language.to_s[0,1].upcase,
667 					5	=>	@line_nr,
668 					6	=>	'4',
669 					7	=>	@text,
670 				}
671 			end
672 		end
673 	end
674 end

Generated on Fri Feb 04 16:13:38 +0100 2011 with rcov 0.9.8