Module: ODDB::OdbaExporter::CsvExporter

Defined in:
ext/export/src/csv_exporter.rb

Constant Summary collapse

ANALYSIS =
[ :groupcd, :poscd, :analysis_anonymous, :defr,
:analysis_footnote, :analysis_taxnote, 
:analysis_limitation, :analysis_list_title, 
:lab_areas, :taxpoints, :finding,
:analysis_permissions ]
DOCTOR =
[ :ean13, :exam, :salutation, :title, :firstname,
:name, :praxis, :first_address_data, :email, :language, 
:specialities]
ADDRESS =
[:type, :name, :additional_lines, :address,
:plz, :city, :canton, :fon, :fax]
DEFR =
[:de, :fr]
DEFRIT =
[:de, :fr, :it]
INDEX_THERAPEUTICUS =
[ :code, :defr, :idx_th_comment, :idx_th_limitation ]
MIGEL =
[:migel_code, :migel_subgroup, :product_code,
				:migel_product_text, :accessory_code, :defrit,
:migel_limitation, :format_price, :qty, :migel_unit,
:limitation, :format_date]
MIGEL_SUBGROUP =
[:migel_group, :code, :defrit,
:migel_limitation]
MIGEL_GROUP =
[:code, :defrit, :migel_limitation]
NARCOTIC =
[:casrn, :swissmedic_code, :narc_substance, 
:category, :narc_reservation_text]
PRICE_HISTORY =
[:iksnr, :ikscd, :name, :size, :barcode, :pharmacode,
:out_of_trade, :price_history]
PRICE_POINT =
[:amount, :authority, :origin]

Class Method Summary collapse

Class Method Details

.address_data(item, opts = {}) ⇒ Object



34
35
36
# File 'ext/export/src/csv_exporter.rb', line 34

def CsvExporter.address_data(item, opts={})
	collect_data(ADDRESS, item)
end

.analysis_anonymous(item, opts = {}) ⇒ Object



37
38
39
40
41
42
43
# File 'ext/export/src/csv_exporter.rb', line 37

def CsvExporter.analysis_anonymous(item, opts={})
	if(item.anonymousgroup)
	[item.anonymousgroup, item.anonymouspos].join('.')
	else
		''
	end
end

.analysis_footnote(item, opts = {}) ⇒ Object



58
59
60
# File 'ext/export/src/csv_exporter.rb', line 58

def CsvExporter.analysis_footnote(item, opts={})
	self.defr(item.footnote)
end

.analysis_limitation(item, opts = {}) ⇒ Object



44
45
46
# File 'ext/export/src/csv_exporter.rb', line 44

def CsvExporter.analysis_limitation(item, opts={})
	self.defr(item.limitation_text)
end

.analysis_list_title(item, opts = {}) ⇒ Object



47
48
49
# File 'ext/export/src/csv_exporter.rb', line 47

def CsvExporter.analysis_list_title(item, opts={})
	self.defr(item.list_title)
end

.analysis_permissions(item, opts = {}) ⇒ Object



50
51
52
53
54
55
56
57
# File 'ext/export/src/csv_exporter.rb', line 50

def CsvExporter.analysis_permissions(item, opts={})
	[:de, :fr].collect { |lang|
		item.permissions.send(lang).collect { |perm|
			'{' << perm.specialization.to_s << '}:{' \
				<< perm.restriction.to_s << '}'
		}.join(',')
	}
end

.analysis_taxnote(item, opts = {}) ⇒ Object



61
62
63
# File 'ext/export/src/csv_exporter.rb', line 61

def CsvExporter.analysis_taxnote(item, opts={})
	self.defr(item.taxnote)
end

.collect_data(keys, item, opts = {}) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'ext/export/src/csv_exporter.rb', line 64

def CsvExporter.collect_data(keys, item, opts={})
	keys.collect { |key|
		if(item.nil?)
			''
		elsif(item.respond_to?(key))
			val = item.send(key)
			if(val.is_a?(Array))
				val = val.join(',')
			end
			val.to_s.gsub("\n", "\v")
		else
			self.send(key, item, opts)
		end
	}
end

.collect_languages(keys, item, opts = {}) ⇒ Object



79
80
81
82
83
84
85
86
87
88
# File 'ext/export/src/csv_exporter.rb', line 79

def CsvExporter.collect_languages(keys, item, opts={})
  descr = if(item.respond_to?(:descriptions))
            item.descriptions
          else
            {}
          end
  keys.collect { |key|
    descr.fetch(key.to_s, '').to_s.gsub(/\r?\n/u, ' / ')
  }
end

.defr(item, opts = {}) ⇒ Object



89
90
91
# File 'ext/export/src/csv_exporter.rb', line 89

def CsvExporter.defr(item, opts={})
	self.collect_languages(DEFR, item)
end

.defrit(item, opts = {}) ⇒ Object



92
93
94
# File 'ext/export/src/csv_exporter.rb', line 92

def CsvExporter.defrit(item, opts={})
	self.collect_languages(DEFRIT, item)
end

.dump(keys, item, fh, opts = {}) ⇒ Object



95
96
97
98
99
# File 'ext/export/src/csv_exporter.rb', line 95

def CsvExporter.dump(keys, item, fh, opts={})
     CSV::Writer.generate(fh, ';') { |csv|
       csv << collect_data(keys, item, opts).flatten
     }
end

.first_address_data(item, opts = {}) ⇒ Object



100
101
102
103
# File 'ext/export/src/csv_exporter.rb', line 100

def CsvExporter.first_address_data(item, opts={})
	addr = item.praxis_address || item.address(0)
	address_data(addr)
end

.format_date(item, opts = {}) ⇒ Object



104
105
106
107
108
109
110
# File 'ext/export/src/csv_exporter.rb', line 104

def CsvExporter.format_date(item, opts={})
	if(date = item.date)
		date.strftime('%d.%m.%Y')
	else
		""
	end
end

.format_price(item, opts = {}) ⇒ Object



111
112
113
114
# File 'ext/export/src/csv_exporter.rb', line 111

def CsvExporter.format_price(item, opts={})
	item.price = item.price / 100.0
	item.price = sprintf("%.2f", item.price)
end

.idx_th_comment(item, opts = {}) ⇒ Object



118
119
120
# File 'ext/export/src/csv_exporter.rb', line 118

def CsvExporter.idx_th_comment(item, opts={})
				self.defr(item.comment)
end

.idx_th_limitation(item, opts = {}) ⇒ Object



115
116
117
# File 'ext/export/src/csv_exporter.rb', line 115

def CsvExporter.idx_th_limitation(item, opts={})
				self.defr(item.limitation_text)
end

.migel_group(item, opts = {}) ⇒ Object



124
125
126
# File 'ext/export/src/csv_exporter.rb', line 124

def CsvExporter.migel_group(item, opts={})
	self.collect_data(MIGEL_GROUP, item.group)
end

.migel_limitation(item, opts = {}) ⇒ Object



121
122
123
# File 'ext/export/src/csv_exporter.rb', line 121

def CsvExporter.migel_limitation(item, opts={})
	self.defrit(item.limitation_text)
end

.migel_product_text(item, opts = {}) ⇒ Object



127
128
129
# File 'ext/export/src/csv_exporter.rb', line 127

def CsvExporter.migel_product_text(item, opts={})
	self.defrit(item.product_text)
end

.migel_subgroup(item, opts = {}) ⇒ Object



130
131
132
# File 'ext/export/src/csv_exporter.rb', line 130

def CsvExporter.migel_subgroup(item, opts={})
	self.collect_data(MIGEL_SUBGROUP, item.subgroup)
end

.migel_unit(item, opts = {}) ⇒ Object



133
134
135
# File 'ext/export/src/csv_exporter.rb', line 133

def CsvExporter.migel_unit(item, opts={})
	self.defrit(item.unit)
end

.narc_reservation_text(item, opts = {}) ⇒ Object



136
137
138
# File 'ext/export/src/csv_exporter.rb', line 136

def CsvExporter.narc_reservation_text(item, opts={})
	self.defr(item.reservation_text)
end

.narc_substance(item, opts = {}) ⇒ Object



139
140
141
# File 'ext/export/src/csv_exporter.rb', line 139

def CsvExporter.narc_substance(item, opts={})
	self.defr(item.substance)
end

.out_of_trade(item, opts = {}) ⇒ Object



142
143
144
# File 'ext/export/src/csv_exporter.rb', line 142

def CsvExporter.out_of_trade(item, opts={})
  !!(item.out_of_trade if item.respond_to?(:out_of_trade))
end

.price_history(item, opts = {}) ⇒ Object



145
146
147
148
149
150
151
152
# File 'ext/export/src/csv_exporter.rb', line 145

def CsvExporter.price_history(item, opts={})
  if dates = opts[:dates]
    dates.inject([]) do |memo, date|
      memo.concat self.price_point(item, date, :exfactory)
      memo.concat self.price_point(item, date, :public)
    end
  end
end

.price_point(item, date, type) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
# File 'ext/export/src/csv_exporter.rb', line 153

def CsvExporter.price_point(item, date, type)
  price = (prices = item.prices[type])\
    && prices.find do |price|
    if valid_from = price.valid_from
      valid_from.to_date == date
    else
      date.nil?
    end
  end
  self.collect_data(PRICE_POINT, price)
end