Skip to content

Commit

Permalink
Readded description for label
Browse files Browse the repository at this point in the history
  • Loading branch information
ngiger committed Mar 17, 2015
1 parent 4ee15a6 commit 7c82f1f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/oddb2xml/builder.rb
Expand Up @@ -681,6 +681,7 @@ def build_calc
xml.COMPOSITION {
# xml.SOURCE composition.source # emit this if you want to debug the results
xml.LABEL composition.label if composition.label
xml.LABEL_DESCRIPTION composition.label_description if composition.label_description
xml.SUBSTANCES {
composition.substances.each { |substance|
xml.SUBSTANCE {
Expand Down
8 changes: 5 additions & 3 deletions lib/oddb2xml/parse_compositions.rb
Expand Up @@ -8,7 +8,7 @@

module ParseUtil
SCALE_P = %r{pro\s+(?<scale>(?<qty>[\d.,]+)\s*(?<unit>[kcmuµn]?[glh]))}u
ParseComposition = Struct.new("ParseComposition", :source, :label, :substances, :galenic_form, :route_of_administration)
ParseComposition = Struct.new("ParseComposition", :source, :label, :label_description, :substances, :galenic_form, :route_of_administration)
ParseSubstance = Struct.new("ParseSubstance", :name, :qty, :unit, :chemical_substance, :chemical_dose)
def ParseUtil.capitalize(string)
string.split(/\s+/u).collect { |word| word.capitalize }.join(' ')
Expand All @@ -20,16 +20,18 @@ def ParseUtil.parse_compositions(composition)
rep_3 = '------'; to_3 = ','

comps = []
label_pattern = /^(?<label>A|I|B|II|C|III|D|IV|E|V|F|VI)[)]\s*(?<designation>[^)]+):/
label_pattern = /^(?<label>A|I|B|II|C|III|D|IV|E|V|F|VI)[)]\s*(?<description>[^)]+):/
composition_text = composition.gsub(/\r\n?/u, "\n")
puts "composition_text for #{name}: #{composition_text}" if composition_text.split(/\n/u).size > 1 and $VERBOSE
lines = composition_text.split(/\n/u)
idx = 0
compositions = lines.select do |line|
if match = label_pattern.match(line)
label = match[:label]
label_description = match[:description]
else
label = nil
label_description = nil
end
idx += 1
next if idx > 1 and not label # avoid lines like 'I) et II)'
Expand Down Expand Up @@ -71,7 +73,7 @@ def ParseUtil.parse_compositions(composition)
chemical, cdose)
end
}
comps << ParseComposition.new(line, label, substances) if substances.size > 0
comps << ParseComposition.new(line, label, label_description, substances) if substances.size > 0
end
comps
end
Expand Down
2 changes: 2 additions & 0 deletions spec/calc_spec.rb
Expand Up @@ -314,6 +314,7 @@ def url
XPath.match( doc, "//ARTICLE[GTIN='7680545250363']/COMPOSITIONS/COMPOSITION/SUBSTANCES/SUBSTANCE/SUBSTANCE_NAME").last.text.should eq 'Alprostadilum'
XPath.match( doc, "//ARTICLE[GTIN='7680458820202']/NAME").last.text.should eq 'Magnesiumchlorid 0,5 molar B. Braun, Zusatzampulle für Infusionslösungen'
XPath.match( doc, "//ARTICLE[GTIN='7680555940018']/COMPOSITIONS/COMPOSITION/LABEL").first.text.should eq 'I'
XPath.match( doc, "//ARTICLE[GTIN='7680555940018']/COMPOSITIONS/COMPOSITION/LABEL_DESCRIPTION").first.text.should eq 'Glucoselösung'
XPath.match( doc, "//ARTICLE[GTIN='7680555940018']/COMPOSITIONS/COMPOSITION/LABEL").last.text.should eq 'III'
end
end
Expand Down Expand Up @@ -423,6 +424,7 @@ def url

specify { expect(result.compositions[0].source).to eq Line_1}
specify { expect(result.compositions[0].label).to eq 'I'}
specify { expect(result.compositions[0].label_description).to eq 'Glucoselösung'}
specify { expect(result.compositions[1].label).to eq 'II' }
specify { expect(result.compositions[2].label).to eq 'III' }
glucosum = result.compositions.first.substances.first
Expand Down

0 comments on commit 7c82f1f

Please sign in to comment.