Class: ODDB::Import::PharmNet::PiParser

Inherits:
TermedRtf show all
Defined in:
lib/oddb/import/pharmnet.rb

Constant Summary

Constants inherited from Rtf

Rtf::SYMBOLS

Instance Method Summary collapse

Methods inherited from TermedRtf

#initialize

Methods inherited from Rtf

#_import_text, #_next_paragraph, #align, #current_chapter, #current_group, #current_table, #ignore?, #import, #import_control, #import_group, #import_text, #import_token, #init, #next_paragraph, #parent_group, #set_font_size

Constructor Details

This class inherits a constructor from ODDB::Import::PharmNet::TermedRtf

Instance Method Details

#_sanitize_text(value) ⇒ Object



228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/oddb/import/pharmnet.rb', line 228

def _sanitize_text(value)
  ## some rtfs have unusable information prior to the actual PI
  case value
  when /^PCX\b/
    init
  when /Gebrauchsinformation/
    init if /Recyclinglogo/.match(current_chapter.to_s)
  end
  if @buffer.empty? && @buffer.is_a?(Text::Paragraph)
    value.gsub! /^([P][A-Z0-9]{1,2})?\b/, ''
    value.lstrip!
  end
end

#identify_chapter(buffer) ⇒ Object



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/oddb/import/pharmnet.rb', line 155

def identify_chapter buffer
  name = nil
  if(/\b#@term\b/i.match buffer)
    name = case buffer 
           when /wof(ü|Ü|ue)r\s+(wird|werden)\s+(es|sie)\s+(angewendet|eingenommen)/i,
                /wird\s+angewendet$/i
             'indications'
           when /^(3\.?\s*)?Wie\s+(ist|sind).+?(anzuwenden|einzunehmen)\?/i
             'application'
           when /vor\s+der\s+(Anwendung|Einnahme)\s+von/i 
             'precautions'
           when /^([56]\.?\s*)?Wie\s+(ist|sind).+?aufzubewahren/i
             'storage'
           when /^Bitte\s.+für\s+Kinder\s+nicht\s+erreichbar/i
             'personal'
           when /^([45]\.?\s*)?Welche\s+Nebenwirkungen/i, /^Nebenwirkungen:?$/i
             'unwanted_effects'
           when /Behandlungserfolg/i
             nil ## prevent composition if this is a dodgy match
           else
             'composition'
           end
  else
    name = case buffer
           when /^([45]\.?\s*)?Welche\s+Nebenwirkungen/i, /^Nebenwirkungen:?$/i
             'unwanted_effects'
           when /^(4\.?\s*)?Verhalten\s+im\s+Notfall/i
             'emergency'
           when /^(6\.?\s*)?(Weitere\s+)?(Informationen|Angaben)/i,
                /^(6\.?\s*)?Gebrauchsanleitung/i,
                /^Zusätzliche\s+Informationen/i
             'additional_information'
           when /^Anwendungsgebiete/i
             'indications'
           when /^Vorsichtsma(ss|ß)nahmen/i 
             'precautions'
           when /^Dosierung\s*($|und)/i, /^Dosierungsanleitung/
             'application'
           when /Angaben\s+zur\s+Haltbarkeit/i 
             'storage'
           when /^Gegenanzeigen/i
             'counterindications'
           when /^Darreichungsform/i
             'packaging'
           when /^(Hersteller.+)?Pharmazeutischer\s+Unternehmer/i,
                /^Pharmazeutischer\s+Hersteller/i
             'company'
           when /^\s*Stand\b/, /wurde\s+zuletzt\s+überarbeitet/i
             'date'
           when /^(Sehr\s+geehrte|Liebe)r?\s+Patient/i, 
                /^Bitte\s.+für\s+Kinder\s+nicht\s+erreichbar/i
             'personal'
           end
  end
  composition = @document.chapter('composition')
  if(name && (name == 'composition' || composition))
    chapter = @document.chapter(name)
    if(chapter.nil?)
      @document.add_chapter Text::Chapter.new(name)
    else
      pars = chapter.paragraphs.select do |par| !par.to_s.strip.empty? end
      if(pars.size == 1 && /^\d+/.match(pars.first))
        ## some PI insert a document-overview after the composition, in which
        #  case we have an erroneous chapter, identified by only consisting of
        #  a heading. In that case:
        composition.append chapter
        @document.remove_chapter chapter
        @document.add_chapter Text::Chapter.new(name)
      end
    end
  end
  super
end