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_FEBRUARY_2019.
Constructor Details
#initialize(filename, type) ⇒ SwissmedicExtractor
Returns a new instance of SwissmedicExtractor.
244 245 246 247 248 249 250 251 |
# File 'lib/oddb2xml/extractor.rb', line 244 def initialize(filename, type) @filename = File.join(DOWNLOADS, File.basename(filename)) @filename = File.join(SpecData, File.basename(filename)) if defined?(RSpec) && !File.exist?(@filename) @type = type Oddb2xml.log("SwissmedicExtractor #{@filename} #{File.size(@filename)} bytes") return unless File.exist?(@filename) @sheet = RubyXL::Parser.parse(File.(@filename)).worksheets[0] end |
Instance Method Details
#to_arry ⇒ Object
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/oddb2xml/extractor.rb', line 253 def to_arry data = [] return data unless @sheet case @type when :orphan col_zulassung = 6 raise "Could not find Zulassungsnummer in column #{col_zulassung} of #{@filename}" unless /Zulassungs.*nummer/.match?(@sheet[3][col_zulassung].value) @sheet.each do |row| next unless row[col_zulassung] number = row[col_zulassung].value.to_i if number != 0 data << sprintf("%05d", number) end end end # puts "found #{data.uniq.size} entities for type #{@type}" data.uniq end |
#to_hash ⇒ Object
Packungen.xlsx COLUMNS_FEBRUARY_2019
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 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
# File 'lib/oddb2xml/extractor.rb', line 273 def to_hash data = {} return data unless @sheet case @type when :package Oddb2xml.check_column_indices(@sheet) ith = COLUMNS_FEBRUARY_2019.keys.index(:index_therapeuticus) iksnr = COLUMNS_FEBRUARY_2019.keys.index(:iksnr) seq_name = COLUMNS_FEBRUARY_2019.keys.index(:name_base) i_3 = COLUMNS_FEBRUARY_2019.keys.index(:ikscd) seqnr = COLUMNS_FEBRUARY_2019.keys.index(:seqnr) cat = COLUMNS_FEBRUARY_2019.keys.index(:ikscat) siz = COLUMNS_FEBRUARY_2019.keys.index(:size) atc = COLUMNS_FEBRUARY_2019.keys.index(:atc_class) list_code = COLUMNS_FEBRUARY_2019.keys.index(:production_science) eht = COLUMNS_FEBRUARY_2019.keys.index(:unit) sub = COLUMNS_FEBRUARY_2019.keys.index(:substances) comp = COLUMNS_FEBRUARY_2019.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 && row[iksnr] && row[i_3] next unless (row[iksnr].value.to_i > 0) && (row[i_3].value.to_i > 0) no8 = sprintf("%05d", row[iksnr].value.to_i) + sprintf("%03d", row[i_3].value.to_i) unless no8.empty? next if no8.to_i == 0 ean_base12 = "7680#{no8}" prodno = Oddb2xml.gen_prodno(row[iksnr].value.to_i, row[seqnr].value.to_i) ean13 = (ean_base12.ljust(12, "0") + Oddb2xml.calc_checksum(ean_base12)) Oddb2xml.setEan13forProdno(prodno, ean13) Oddb2xml.setEan13forNo8(no8, ean13) data[no8] = { iksnr: row[iksnr].value.to_i, no8: no8, ean13: ean13, prodno: prodno, seqnr: row[seqnr].value, 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[iksnr].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"), gen_production: row[COLUMNS_FEBRUARY_2019.keys.index(:gen_production)].value.to_s, insulin_category: row[COLUMNS_FEBRUARY_2019.keys.index(:insulin_category)].value.to_s, drug_index: row[COLUMNS_FEBRUARY_2019.keys.index(:drug_index)].value.to_s, data_origin: "swissmedic_package", expiry_date: row[COLUMNS_FEBRUARY_2019.keys.index(:expiry_date)].value.to_s, company_name: row[COLUMNS_FEBRUARY_2019.keys.index(:company)].value.to_s, size: row[COLUMNS_FEBRUARY_2019.keys.index(:size)].value.to_s, unit: row[COLUMNS_FEBRUARY_2019.keys.index(:unit)].value.to_s } end end end data end |