Skip to content

Commit

Permalink
Fix handling several substances
Browse files Browse the repository at this point in the history
  • Loading branch information
ngiger committed Apr 15, 2015
1 parent 48fe298 commit 3c9a05e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
13 changes: 6 additions & 7 deletions lib/oddb2xml/parslet_compositions.rb
Expand Up @@ -162,21 +162,20 @@ class SubstanceParser < DoseParser
rule(:substance_residui) { str('residui:') >> space >> substance }
rule(:substance_conserv) { str('conserv.:') >> space >> substance }
rule(:substance_corresp) { substance.as(:substance) >>str('corresp.') >> space >> (str('suspensio reconstituta') >> space).maybe >>
(substance_et | substance).as(:substance_corresp) }
(substance).as(:substance_corresp) }
rule(:substance_ut) { substance.as(:substance_ut) >> space >> str('ut') >> space >> substance }
rule(:substance_et) { (substance.as(:substance) >> str('et') >> space).repeat(1) >> (substance_corresp | substance).as(:substance) }
rule(:praeparatio) { ((identifier >> space?).repeat(1).as(:description) >> str(':') >> space).maybe>>
(identifier >> space?).repeat(1).as(:substance_name) >>
number.as(:qty) >> space >> str('U.:') >> space >>
(identifier >> space?).repeat(1).as(:more_info) >>
space?
}

#rule(:one_substance) { (str(',') >> space).maybe >> (excipiens) } # Sometimes it is handy for debugging to be able to debug just one the different variants
rule(:one_substance) { (str(',') >> space).maybe >> (der | excipiens | praeparatio | histamin | named_substance | substance_residui | substance_conserv | substance_et | substance_ut | substance_corresp | substance ) }
# rule(:one_substance) { (str(',') >> space).maybe >> ( substance | excipiens) }
rule(:one_substance) { ( substance_et | praeparatio | substance | excipiens) >> (str(',') >> space).maybe }
rule(:all_substances) { one_substance.repeat(1) }
rule(:substance_separator) { (comma | str('et')) >> space? }
# rule(:one_substance) { (der | excipiens | praeparatio | histamin | named_substance | substance_residui | substance_conserv | substance_ut | substance_corresp | substance ) >> substance_separator }
# rule(:one_substance) { excipiens >> substance_separator.maybe} # Sometimes it is handy for debugging to be able to debug just one the different variants
rule(:one_substance) { praeparatio | substance_corresp | substance }
rule(:all_substances) { (one_substance >> substance_separator.maybe).repeat(1) }
root :all_substances
end

Expand Down
9 changes: 4 additions & 5 deletions spec/parslet_spec.rb
Expand Up @@ -9,7 +9,7 @@
require "#{Dir.pwd}/lib/oddb2xml/parslet_compositions"
require 'parslet/rig/rspec'

RunAllCompositionsTests = false # takes over a minute!
RunAllCompositionsTests = false # takes over two minutes!
RunFailingSpec = false
RunExcipiensTest = true
RunDoseTests = true
Expand Down Expand Up @@ -307,9 +307,9 @@ def run_substance_tests(hash_string_to_name)
}
run_substance_tests(failing_tests) if RunFailingSpec
run_substance_tests(excipiens_tests) if RunExcipiensTest
# run_substance_tests(tests) if RunAllTests
run_substance_tests(tests) if RunFailingSpec
run_composition_tests( ["acari allergeni extractum 50'000 U.",
"pollinis allergeni extractum 50'000 U.: fraxinus excelsior, conserv.: phenolum, excipiens ad solutionem pro 1 ml."]) if false
"pollinis allergeni extractum 50'000 U.: fraxinus excelsior, conserv.: phenolum, excipiens ad solutionem pro 1 ml."])
if RunMostImportantParserTests
context "should return correct substance for given with et (IKSNR 11879)" do
string = "calcii lactas pentahydricus 25 mg et calcii hydrogenophosphas anhydricus 300 mg"
Expand All @@ -329,6 +329,7 @@ def run_substance_tests(hash_string_to_name)
string = "calcii lactas pentahydricus 25 mg et calcii hydrogenophosphas anhydricus 300 mg corresp. calcium 100 mg"

composition = ParseComposition.from_string(string)
# pp composition.substances; binding.pry
specify { expect(composition.substances.size).to eq 3 }
calcium = composition.substances.find{ |x| /calcium/i.match(x.name) }
pentahydricus = composition.substances.find{ |x| /pentahydricus/i.match(x.name) }
Expand Down Expand Up @@ -499,8 +500,6 @@ def run_substance_tests(hash_string_to_name)
source =
"I) DTPa-IPV-Komponente (Suspension): toxoidum diphtheriae 30 U.I., toxoidum pertussis 25 µg et haemagglutininum filamentosum 25 µg"
composition = ParseComposition.from_string(source)
pp composition
# binding.pry
specify { expect(composition.source).to eq source }

specify { expect(composition.label).to eq 'I' }
Expand Down

0 comments on commit 3c9a05e

Please sign in to comment.