Class: Oddb2xml::SwissmedicExtractor
- Defined in:
- lib/oddb2xml/extractor.rb
Instance Attribute Summary
Attributes inherited from Extractor
Instance Method Summary collapse
-
#initialize(filename, type) ⇒ SwissmedicExtractor
constructor
A new instance of SwissmedicExtractor.
- #to_arry ⇒ Object
-
#to_hash ⇒ Object
Packungen.xlsx COLUMNS_JULY_2015.
Constructor Details
#initialize(filename, type) ⇒ SwissmedicExtractor
Returns a new instance of SwissmedicExtractor.
206 207 208 209 210 211 212 |
# File 'lib/oddb2xml/extractor.rb', line 206 def initialize(filename, type) @filename = File.join(Downloads, File.basename(filename)) @filename = File.join(SpecData, File.basename(filename)) if defined?(RSpec) and not File.exists?(@filename) @type = type return unless File.exists?(@filename) @sheet = RubyXL::Parser.parse(File.(@filename)).worksheets[0] end |
Instance Method Details
#to_arry ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/oddb2xml/extractor.rb', line 213 def to_arry data = [] return data unless @sheet case @type when :orphan i = 1 @sheet.each do |row| next unless row[1] number = row[1].value.to_i if number != 0 data << sprintf("%05d", number) end end when :fridge i,c = 1,7 @sheet.each do |row| if row[i] and number = row[i].value and row[c] and row[c].value.to_s.downcase == 'x' data << sprintf("%05d", number) end end end cleanup_file data.uniq end |
#to_hash ⇒ Object
Packungen.xlsx COLUMNS_JULY_2015
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
# File 'lib/oddb2xml/extractor.rb', line 238 def to_hash # Packungen.xlsx COLUMNS_JULY_2015 data = {} return data unless @sheet case @type when :package Oddb2xml.check_column_indices(@sheet) ith = COLUMNS_JULY_2015.keys.index(:index_therapeuticus) i_5 = COLUMNS_JULY_2015.keys.index(:iksnr) seq_name = COLUMNS_JULY_2015.keys.index(:name_base) i_3 = COLUMNS_JULY_2015.keys.index(:ikscd) p_1_2 = COLUMNS_JULY_2015.keys.index(:seqnr) cat = COLUMNS_JULY_2015.keys.index(:ikscat) siz = COLUMNS_JULY_2015.keys.index(:size) atc = COLUMNS_JULY_2015.keys.index(:atc_class) list_code = COLUMNS_JULY_2015.keys.index(:production_science) eht = COLUMNS_JULY_2015.keys.index(:unit) sub = COLUMNS_JULY_2015.keys.index(:substances) comp = COLUMNS_JULY_2015.keys.index(:composition) # production_science Heilmittelcode, possible values are # Allergene # Anthroposophika # ayurvedische Arzneimittel # Bakterien- und Hefepräparate # Biotechnologika # Blutprodukte # Generator # Heilmittelcode # Homöopathika # Impfstoffe # Phytotherapeutika # Radiopharmazeutika # Synthetika human # tibetische Arzneimittel # Tierarzneimittel # Transplantat: Gewebeprodukt @sheet.each_with_index do |row, i| next if (i <= 1) next unless row and row[i_5] and row[i_3] no8 = sprintf('%05d',row[i_5].value.to_i) + sprintf('%03d',row[i_3].value.to_i) prodno = sprintf('%05d',row[i_5].value.to_i) + row[p_1_2].value.to_i.to_s unless no8.empty? next if no8.to_i == 0 ean_base12 = "7680#{no8}" data[no8.intern] = { :ean => (ean_base12.ljust(12, '0') + Oddb2xml.calc_checksum(ean_base12)), :prodno => prodno ? prodno : '', :ith_swissmedic => row[ith] ? row[ith].value.to_s : '', :swissmedic_category => row[cat].value.to_s, :atc_code => row[atc] ? Oddb2xml.add_epha_changes_for_ATC(row[i_5].value.to_s, row[atc].value.to_s) : '', :list_code => row[list_code] ? row[list_code].value.to_s : '', :package_size => row[siz] ? row[siz].value.to_s : '', :einheit_swissmedic => row[eht] ? row[eht].value.to_s : '', :substance_swissmedic => row[sub] ? row[sub].value.to_s : '', :composition_swissmedic => row[comp] ? row[comp].value.to_s : '', :sequence_name => row[seq_name] ? row[seq_name].value.to_s : '', :is_tier => (row[list_code] == 'Tierarzneimittel' ? true : false), } end end end cleanup_file data end |