Module: ODDB::OdbaExporter::CsvExporter

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

Constant Summary

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

+ (Object) address_data(item, opts = {})



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

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

+ (Object) analysis_anonymous(item, opts = {})



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

+ (Object) analysis_footnote(item, opts = {})



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

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

+ (Object) analysis_limitation(item, opts = {})



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

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

+ (Object) analysis_list_title(item, opts = {})



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

+ (Object) analysis_permissions(item, opts = {})



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

+ (Object) analysis_taxnote(item, opts = {})



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

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

+ (Object) collect_data(keys, item, opts = {})



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

+ (Object) collect_languages(keys, item, opts = {})



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

+ (Object) defr(item, opts = {})



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

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

+ (Object) defrit(item, opts = {})



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

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

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



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

+ (Object) first_address_data(item, opts = {})



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

+ (Object) format_date(item, opts = {})



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

+ (Object) format_price(item, opts = {})



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

+ (Object) idx_th_comment(item, opts = {})



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

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

+ (Object) idx_th_limitation(item, opts = {})



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

+ (Object) migel_group(item, opts = {})



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

+ (Object) migel_limitation(item, opts = {})



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

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

+ (Object) migel_product_text(item, opts = {})



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

+ (Object) migel_subgroup(item, opts = {})



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

+ (Object) migel_unit(item, opts = {})



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

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

+ (Object) narc_reservation_text(item, opts = {})



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

+ (Object) narc_substance(item, opts = {})



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

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

+ (Object) out_of_trade(item, opts = {})



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

+ (Object) price_history(item, opts = {})



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

+ (Object) price_point(item, date, type)



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