Class: ODDB::Import::Dimdi::Substance
Instance Method Summary
collapse
Methods inherited from Excel
#cell, #import, #import_worksheet, #parse
Methods inherited from Importer
#capitalize_all, #company_name, #utf8
Constructor Details
#initialize(date = Date.today) ⇒ Substance
Returns a new instance of Substance.
504
505
506
507
508
509
510
511
|
# File 'lib/oddb/import/dimdi.rb', line 504
def initialize(date = Date.today)
super
@combi_created = 0
@combi_existing = 0
@count = 0
@created = 0
@existing = 0
end
|
Instance Method Details
#import_row(row) ⇒ Object
512
513
514
515
516
517
518
519
520
521
|
# File 'lib/oddb/import/dimdi.rb', line 512
def import_row(row)
@count += 1
abbr = cell(row, 0)
names = capitalize_all(cell(row, 1)).split('+')
if(names.size == 1)
import_substance(abbr, names.pop)
else
import_substances(abbr, names)
end
end
|
#import_substance(abbr, name) ⇒ Object
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
|
# File 'lib/oddb/import/dimdi.rb', line 522
def import_substance(abbr, name)
substance = Drugs::Substance.find_by_code(:value => abbr,
:type => "substance", :country => "DE")
substance ||= Drugs::Substance.find_by_name(name)
unsaved = false
if(substance)
@existing += 1
else
@created += 1
substance = Drugs::Substance.new
substance.name.de = name
unsaved = true
end
unless(substance.code('substance', 'DE'))
substance.add_code(Util::Code.new("substance", abbr,
'DE', @date))
unsaved = true
end
substance.save if(unsaved)
substance
end
|
#import_substances(abbr, names) ⇒ Object
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
|
# File 'lib/oddb/import/dimdi.rb', line 543
def import_substances(abbr, names)
code = Util::Code.new('substance-combination', abbr,
'DE', @date)
names.collect { |name|
substance = Drugs::Substance.find_by_name(name)
if(substance)
@combi_existing += 1
else
@combi_created += 1
substance = Drugs::Substance.new
substance.name.de = name
end
substance.add_code(code)
substance.save
substance
}
end
|
#postprocess ⇒ Object
560
561
562
563
564
565
566
567
568
|
# File 'lib/oddb/import/dimdi.rb', line 560
def postprocess
if((ass = Drugs::Substance.find_by_name('ASS')) \
&& ass.name.de == 'ASS')
ass.name.add_synonym('ASS')
ass.name.de = 'Acetylsalicylsäure'
ass.save
end
end
|
#report ⇒ Object
569
570
571
572
573
574
575
576
577
578
579
|
# File 'lib/oddb/import/dimdi.rb', line 569
def report
[
sprintf("Imported %3i Substances per %s:",
@count, @date.strftime("%d.%m.%Y")),
sprintf("Visited %3i existing", @existing),
sprintf("Visited %3i existing in Combinations",
@combi_existing),
sprintf("Created %3i new", @created),
sprintf("Created %3i new from Combinations", @combi_created),
]
end
|