Class: ParseComposition
- Inherits:
-
Object
- Object
- ParseComposition
- Defined in:
- lib/oddb2xml/parslet_compositions.rb
Constant Summary collapse
- ERRORS_TO_FIX =
{ /(\d+)\s+-\s*(\d+)/ => '\1-\2', "o.1" => "0.1", /\s+(mg|g) DER:/ => ' \1, DER:', " mind. " => " min. ", " streptococci pyogen. " => " streptococci pyogen ", " ut excipiens" => ", excipiens", " Corresp. " => " corresp. ", ",," => ",", "avena elatior,dactylis glomerata" => "avena elatior, dactylis glomerata", " color.: corresp. " => " corresp.", / U\.: (excipiens) / => ' U. \1 ', / U\.: (alnus|betula|betula|betulae) / => ' U., \1 ', /^(acari allergeni extractum (\(acarus siro\)|).+\s+U\.:)/ => 'A): \1', "Solvens: alprostadilum" => "alprostadilum" }
- @@error_handler =
ParseUtil::HandleSwissmedicErrors.new(ERRORS_TO_FIX)
Instance Attribute Summary collapse
-
#corresp ⇒ Object
Returns the value of attribute corresp.
-
#excipiens ⇒ Object
Returns the value of attribute excipiens.
-
#galenic_form ⇒ Object
Returns the value of attribute galenic_form.
-
#label ⇒ Object
Returns the value of attribute label.
-
#label_description ⇒ Object
Returns the value of attribute label_description.
-
#route_of_administration ⇒ Object
Returns the value of attribute route_of_administration.
-
#source ⇒ Object
Returns the value of attribute source.
-
#substances ⇒ Object
Returns the value of attribute substances.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(source) ⇒ ParseComposition
constructor
A new instance of ParseComposition.
Constructor Details
#initialize(source) ⇒ ParseComposition
Returns a new instance of ParseComposition.
391 392 393 394 395 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 391 def initialize(source) @substances ||= [] puts "ParseComposition.new from #{source.inspect} @substances #{@substances.inspect}" if VERBOSE_MESSAGES @source = source.to_s end |
Instance Attribute Details
#corresp ⇒ Object
Returns the value of attribute corresp.
370 371 372 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 370 def corresp @corresp end |
#excipiens ⇒ Object
Returns the value of attribute excipiens.
370 371 372 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 370 def excipiens @excipiens end |
#galenic_form ⇒ Object
Returns the value of attribute galenic_form.
370 371 372 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 370 def galenic_form @galenic_form end |
#label ⇒ Object
Returns the value of attribute label.
370 371 372 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 370 def label @label end |
#label_description ⇒ Object
Returns the value of attribute label_description.
370 371 372 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 370 def label_description @label_description end |
#route_of_administration ⇒ Object
Returns the value of attribute route_of_administration.
370 371 372 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 370 def route_of_administration @route_of_administration end |
#source ⇒ Object
Returns the value of attribute source.
370 371 372 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 370 def source @source end |
#substances ⇒ Object
Returns the value of attribute substances.
370 371 372 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 370 def substances @substances end |
Class Method Details
.from_string(string) ⇒ Object
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 405 def self.from_string(string) return nil if string.nil? || string.eql?(".") || string.eql?("") stripped = string.gsub(/^"|["\n]+$/, "") return nil unless stripped cleaned = if /(U\.I\.|U\.)$/.match?(stripped) stripped else stripped.sub(/\.+$/, "") end puts "ParseComposition.from_string #{string}" if VERBOSE_MESSAGES # /ng-tr/.match(Socket.gethostbyname(Socket.gethostname).first) cleaned = @@error_handler.apply_fixes(cleaned) puts "ParseComposition.new cleaned #{cleaned}" if VERBOSE_MESSAGES && !cleaned.eql?(stripped) CompositionTransformer.clear_substances result = ParseComposition.new(cleaned) parser = CompositionParser.new transf = CompositionTransformer.new begin if defined?(RSpec) ast = transf.apply(parser.parse_with_debug(cleaned)) puts "#{File.basename(__FILE__)}:#{__LINE__}: ==> " if VERBOSE_MESSAGES pp ast if VERBOSE_MESSAGES else ast = transf.apply(parser.parse(cleaned)) end rescue Parslet::ParseFailed => error @@error_handler.nrParsingErrors += 1 puts "#{File.basename(__FILE__)}:#{__LINE__}: failed parsing ==> #{cleaned} #{error}" return nil end result.source = string return result unless ast return result if ast.is_a?(Parslet::Slice) result.substances = CompositionTransformer.substances result.excipiens = CompositionTransformer.excipiens result.corresp = CompositionTransformer.corresp if CompositionTransformer.corresp if result&.excipiens&.unit pro_qty = "/#{result.excipiens.qty} #{result.excipiens.unit}".sub(/\/1\s+/, "/") result.substances.each { |substance| next unless substance.is_a?(ParseSubstance) substance.chemical_substance.unit = "#{substance.chemical_substance.unit}#{pro_qty}" if substance.chemical_substance substance.dose.unit = "#{substance.dose.unit}#{pro_qty}" if substance.unit && !substance.unit.eql?(result.excipiens.unit) } end if ast.is_a?(Array) && ast.first.is_a?(Hash) label = ast.first[:label].to_s if ast.first[:label] label_description = ast.first[:label_description].to_s if ast.first[:label_description] elsif ast&.is_a?(Hash) label = ast[:label].to_s if ast[:label] label_description = ast[:label_description].to_s if ast[:label_description] end if label if label && !/((A|B|C|D|E|I|II|III|IV|\)+)\s+et\s+(A|B|C|D|E|I|II|III|IV|\))+)/.match(label) result.label = label end result.label_description = label_description.gsub(/:+$/, "").strip if label_description end result.corresp = ast[:corresp].to_s.sub(/:\s+/, "") if !result.corresp && ast.is_a?(Hash) && ast[:corresp] result end |
.report ⇒ Object
401 402 403 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 401 def self.report @@error_handler.report end |
.reset ⇒ Object
397 398 399 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 397 def self.reset @@error_handler = ParseUtil::HandleSwissmedicErrors.new(ERRORS_TO_FIX) end |