Class: ODDB::OdbaExporter::GenericXls

Inherits:
Object
  • Object
show all
Defined in:
ext/export/src/generics_xls.rb

Constant Summary collapse

RECIPIENTS =
[ '[email protected]', '[email protected]' ]
FLAGS =
{
	:address					=> 'neue Herstelleradresse',
	:comment					=> 'neue Bemerkung',
	:composition			=> 'veränderte Zusammensetzung',
	:delete						=> 'Registration läuft aus',
	:expirydate				=> 'Registration verlängert',
	:ikscat						=> 'neue Abgabekategorie',
	:indication				=> 'neue Indikation',
	:new							=> 'neue Registration',
	:price_rise				=> 'Preiserhöhung',
	:price_cut				=> 'Preissenkung',
	:productname			=> 'neue Produktbezeichnung',
	:sequence					=> 'veränderte Handelsform',
	:sl_entry_delete	=> 'aus SL gelöscht',
	:sl_entry					=> 'neu in SL',
}

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ GenericXls

Returns a new instance of GenericXls.



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
63
64
65
66
# File 'ext/export/src/generics_xls.rb', line 29

def initialize(path)
	@workbook = Spreadsheet::Excel.new(path)
	@fmt_title = Spreadsheet::Format.new(:bold=>true)
	@fmt_original = Spreadsheet::Format.new(:color => 'red')
	@fmt_original_name = Spreadsheet::Format.new(:bold => true, :color => 'red')
	@fmt_generic = Spreadsheet::Format.new(:color => 'green')
	@fmt_generic_name = Spreadsheet::Format.new(:bold => true, :color => 'green')
	@worksheet = @workbook.add_worksheet("Generikaliste")
	@worksheet.format_column(0, 24.0, @fmt_original_name)
	@worksheet.format_column(1..3, 4.0, @fmt_original)
	@worksheet.format_column(4, 24.0, @fmt_original_name)
	@worksheet.format_column(5..12, 4.0, @fmt_original)
	@worksheet.format_column(13..14, 4.0, @fmt_generic)
	@worksheet.format_column(15, 24.0, @fmt_generic_name)
	@worksheet.format_column(16..23, 4.0, @fmt_generic)
	columns = [
		'Basename Original', 'Basename Original erweitert',
		'EAN-Code Original', 'Pharmacode  Original', 
		'Bezeichnung Original', 'Dosierung Original', 
		'Packungsgrösse Original', 'Fabrikabgabe-preis Original', 
		'Publikums-preis Original (inkl. MwSt)', 
		'Zulassungsinhaberin', 'Kat.', 'SL', 'Reg.Dat.', 
		'EAN-Code Generikum', 'Pharmacode Generikum',
		'Bezeichnung Generikum', 'Dosierung Generikum',
		'Packungsgrösse Generikum', 'Fabrikabgabe-preis Generikum',
		'Publikums-preis Generikum (inkl. MwSt)',
		'Zulassungsinhaberin', 'Kat.', 'SL', 'Reg.Dat.', 'Bemerkung',
	]
	@worksheet.write(0, 0, columns, @fmt_title)
	@app = ODBA.cache.fetch_named('oddbapp', nil)
	smj_grp = @app.log_group(:swissmedic_journal)
	smj_log = smj_grp.latest
	@smj_flags = smj_log.change_flags
	bsv_grp = @app.log_group(:bsv_sl)
	bsv_log = bsv_grp.latest
	@bsv_flags = bsv_log.change_flags
	@rows = 1
end

Instance Method Details

#_remarks(package, title) ⇒ Object



180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'ext/export/src/generics_xls.rb', line 180

def _remarks(package, title)
	flags = []
	if(smj_flags = @smj_flags[package.registration.pointer])
		flags += smj_flags
	end
	if(bsv_flags = @bsv_flags[package.pointer])
		flags += bsv_flags
	end
	unless(flags.empty?)
		'' << title << ': ' << flags.collect { |flag|
			FLAGS[flag]
		}.join(', ')
	end
end

#closeObject



67
68
69
# File 'ext/export/src/generics_xls.rb', line 67

def close
	@workbook.close
end

#export_comparable(package, comp) ⇒ Object



70
71
72
73
74
# File 'ext/export/src/generics_xls.rb', line 70

def export_comparable(package, comp)
	row = format_row(package, comp)
	@worksheet.write(@rows, 0, row)
	@rows += 1
end

#export_comparables(package) ⇒ Object



75
76
77
78
79
80
81
82
# File 'ext/export/src/generics_xls.rb', line 75

def export_comparables(package)
	package.comparables.sort.each { |comp| 
		if(comp.registration.generic?)
			export_comparable(package, comp)
		end
	}
	@rows
end

#export_generic(package) ⇒ Object



83
84
85
86
87
88
# File 'ext/export/src/generics_xls.rb', line 83

def export_generic(package)
	row = Array.new(13, '').concat(format_generic(package))\
		.push(_remarks(package, 'Generikum').to_s)
	@worksheet.write(@rows, 0, row)
	@rows += 1
end

#export_genericsObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'ext/export/src/generics_xls.rb', line 89

def export_generics
	originals = []
	generics = []
	comparables = []
	@app.each_package { |pac|
		if(pac.public? && pac.registration.active?)
			if(pac.registration.original? && (comps = pac.comparables) \
				 && !comps.empty?)
				originals.push(pac)
				comparables.concat(comps)
			elsif(pac.registration.generic?)
				generics.push(pac)
			end
		end
	}
             # Check Packages
             # Some packages cannot be compared if package basename is nil
             nilpackages = originals.select{|pac| pac.basename.nil?} + generics.select{|pac| pac.basename.nil?}
             unless nilpackages.empty? 
               message =  "Package name may have a number in it and therefore basename becomes nil.\n"
               message << "The following packages are skipped during export_generics, since the packages are not comparable.\n\n"
               link = "http://#{SERVER_NAME}/de/gcc/search/zone/drugs/search_query/"
               message << "Package (company, EAN code, link):\n" 
               message << nilpackages.map{|pac| [pac.company_name, pac.barcode, link + pac.barcode].join(", ")}.join("\n")
               message << "\n"
	  log = Log.new(@@today)
	  log.report = [
		"Class: #{self.class}",
                 "Method: export_generics",
		"Message: #{message}",
		"Backtrace:",
		caller(0).join("\n"),
	  ].join("\n")
	  log.recipients = RECIPIENTS.dup
	  log.notify("Warning: Nil basename packages")

               # Remove the packages that basename is nil
               originals -= nilpackages
               generics  -= nilpackages
             end

	originals.sort.each { |pac| export_comparables(pac) }
	@rows += 1 # leave a space in the xls
	(generics - comparables).sort.each { |pac| export_generic(pac) }
	@rows
end

#format_generic(comparable) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
160
# File 'ext/export/src/generics_xls.rb', line 149

def format_generic(comparable)
	preprocess_fields [
		comparable.barcode, comparable.pharmacode,
		comparable.name, comparable.dose, 
		comparable.comparable_size, 
		format_price(comparable.price_exfactory),
		format_price(comparable.price_public), 
		comparable.company_name,
		comparable.ikscat, (comparable.sl_entry ? 'SL' : nil),
		comparable.registration_date,
	]
end

#format_original(package) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'ext/export/src/generics_xls.rb', line 135

def format_original(package)
	preprocess_fields [
		package.basename, 
		sprintf("%s %s/%i", package.basename, 
			package.dose, package.comparable_size),
		package.barcode, package.pharmacode, 
		package.name, package.dose, 
		package.comparable_size, 
		format_price(package.price_exfactory),
		format_price(package.price_public), package.company_name,
		package.ikscat, (package.sl_entry ? 'SL' : nil),
		package.registration_date,
	]
end

#format_price(price) ⇒ Object



161
162
163
164
165
# File 'ext/export/src/generics_xls.rb', line 161

def format_price(price)
	if(price && price > 0.0)
		sprintf("%4.2f", price.to_f)
	end
end

#format_row(package, comparable) ⇒ Object



166
167
168
169
# File 'ext/export/src/generics_xls.rb', line 166

def format_row(package, comparable)
	fields = format_original(package).concat(format_generic(comparable))
	fields.push(remarks(package, comparable))
end

#preprocess_fields(fields) ⇒ Object



170
171
172
173
# File 'ext/export/src/generics_xls.rb', line 170

def preprocess_fields(fields)
	fields.collect { |item| 
		(item.is_a?(Date)) ? item.strftime('%d.%m.%Y') : item.to_s }
end

#remarks(package, comparable) ⇒ Object



174
175
176
177
178
179
# File 'ext/export/src/generics_xls.rb', line 174

def remarks(package, comparable)
	[
		_remarks(package, 'Original'),
		_remarks(comparable, 'Generikum'),
	].compact.join(' ')
end