Class: ODDB::Import::Dimdi::GalenicForm

Inherits:
ODDB::Import::DatedExcel show all
Defined in:
lib/oddb/import/dimdi.rb

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) ⇒ GalenicForm

Returns a new instance of GalenicForm.



76
77
78
79
80
81
# File 'lib/oddb/import/dimdi.rb', line 76

def initialize(date = Date.today)
  super
  @count = 0
  @created = 0
  @existing = 0
end

Instance Method Details

#import_row(row) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/oddb/import/dimdi.rb', line 82

def import_row(row)
  abbr = cell(row, 0)
  value = cell(row, 1)
  if(abbr != nil && value != nil)
    @count += 1
    description = capitalize_all(value)
    galenic_form = Drugs::GalenicForm.find_by_code(:value => abbr, 
                                                 :type => "galenic_form",
                                                 :country => 'DE')
    galenic_form ||= Drugs::GalenicForm.find_by_description(description)
    if(galenic_form)
      @existing += 1
    else
      @created += 1
      galenic_form = Drugs::GalenicForm.new
      galenic_form.description.de = description
    end
    galenic_form.add_code(Util::Code.new("galenic_form", 
                                       abbr, 'DE', @date))
    galenic_form.save
    galenic_form
  end
end

#postprocessObject



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/oddb/import/dimdi.rb', line 105

def postprocess
  {
    'Injektion/Infusion' \
                      => [ 'P', 'Fertigspritzen' ],
    'Tabletten'       => [ 'O', 'Tabletten', 'Filmtabletten', 
                           'Kapseln', 'Dragees', 'Lacktabletten' ],
    'Transdermale Systeme' \
                      => [ 'TD', 'Pflaster, transdermal' ],
    'Tropfen'         => [ 'P', 'Tropfen' ],
    'Retard-Tabletten'=> [ 'O', 'Retardtabletten', 
                           'Retardfilmtabletten', 'Retardkapseln',
                           'Retarddragees' ],
    'Salben'          => [ 'T', 'Creme', 'Gel', 'Lotion', 'Salbe' ],
    'Suppositorien'   => [ 'R', 'Suppositorien' ], 
    'Vaginal-Produkte'=> [ 'V', 'Vaginalcreme', 'Vaginalovula', 
                           'Vaginaltabletten', 
                           'Vaginalsuppositorien']
  }.each { |groupname, formnames|
    group = Drugs::GalenicGroup.find_by_name(groupname) \
      || Drugs::GalenicGroup.new(groupname)
    group.administration = formnames.shift
    group.save
    formnames.each { |name|
      if((form = Drugs::GalenicForm.find_by_description(name)) \
         && !form.group)
        form.group = group
        form.save
      end
    }
  }
end

#reportObject



136
137
138
139
140
141
142
143
# File 'lib/oddb/import/dimdi.rb', line 136

def report
  [
    sprintf("Imported %3i Galenic Forms per %s:", 
            @count, @date.strftime("%d.%m.%Y")),
    sprintf("Visited  %3i existing", @existing),
    sprintf("Created  %3i new", @created),
  ]
end