Class: ODDB::Import::Whocc::Ddd

Inherits:
Xml show all
Defined in:
lib/oddb/import/whocc.rb

Constant Summary collapse

UNIT_REPLACEMENTS =
{
  'TSD E' => 'TsdI.E.',
  'MIO E' => 'MioI.E.',
}

Instance Method Summary collapse

Methods inherited from Xml

#import

Instance Method Details

#import_document(doc) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/oddb/import/whocc.rb', line 29

def import_document(doc)
  REXML::XPath.each(doc, '//rs:data/rw:row', 
    "rs" => 'urn:schemas-microsoft-com:rowset',
    "rw" => '#RowsetSchema') { |row|
    attrs = row.attributes
    code = attrs['ATCCode']
    atc = Drugs::Atc.find_by_code(code) || Drugs::Atc.new(code)
    adm = attrs['AdmCode']
    comment = attrs['DDDComment']
    ddd = atc.ddds.find { |candidate|
      adm == candidate.administration \
        && comment == candidate.comment
    } || Drugs::Ddd.new(adm)
    ddd.comment = comment
    unit = attrs['UnitType']
    unit = UNIT_REPLACEMENTS.fetch(unit, unit)
    ddd.dose = Drugs::Dose.new(attrs['DDD'], unit)
    ddd.atc = atc
    ddd.save
    atc.save
  }
end