<< | Index | >>
Goal
Check src/plugin/swissmedic.rb#update_sequence
def update_sequence(registration, row, opts={:create_only => false}) seqnr = "%02i" % cell(row, column(:seqnr)).to_i ptr = if(sequence = registration.sequence(seqnr)) return sequence if opts[:create_only] sequence.pointer else (registration.pointer + [:sequence, seqnr]).creator end ## some names use commas for dosageparts = cell(row, column(:name_base)).split(/\s*,(?!\d|[^(]+\))\s*/u)
descr = parts.pop
## some names have dosage data after the galenic formif /[\d\s][m]?[glL]\b/.match(descr) && parts.size > 1
descr = parts.pop << ', ' << descr
end
base = parts.join(', ')
base, descr = descr, nil if base.empty?
... args = { :composition_text => ctext,:name_base => base,
:name_descr => descr, :dose => nil, :sequence_date => date_cell(row, column(:sequence_date)), :export_flag => nil, }
Test
namestr = "Iscador M 0,0001 mg, Injektionslösung, anthroposophisches Arzneimittel" parts = namestr.split(/\s*,(?!\d|[^(]+\))\s*/u) descr = parts.pop print "parts = " p parts print "descr = " p descr if /[\d\s][m]?[glL]\b/.match(descr) && parts.size > 1 descr = parts.pop << ', ' << descr end base = parts.join(', ') puts print "parts = " p parts print "base = " p base print "descr = " p descr
Result
parts = ["Iscador M 0,0001 mg", "Injektionsl\303\266sung"] descr = "anthroposophisches Arzneimittel" parts = ["Iscador M 0,0001 mg", "Injektionsl\303\266sung"] base = "Iscador M 0,0001 mg, Injektionsl\303\266sung" descr = "anthroposophisches Arzneimittel"
Note
Consideration
Re-design the algorithm
Experiment (src/plugin/swissmedic.rb#update_sequence)
def update_sequence(registration, row, opts={:create_only => false}) seqnr = "%02i" % cell(row, column(:seqnr)).to_i ptr = if(sequence = registration.sequence(seqnr)) return sequence if opts[:create_only] sequence.pointer else (registration.pointer + [:sequence, seqnr]).creator end ## some names use commas for dosage parts = cell(row, column(:name_base)).split(/\s*,(?!\d|[^(]+\))\s*/u) base = parts.shift # descr = parts.pop ## some names have dosage data after the galenic form # if /[\d\s][m]?[glL]\b/.match(descr) && parts.size > 1 # descr = parts.pop << ', ' << descr # end # base = parts.join(', ') # base, descr = descr, nil if base.empty? descr = unless parts.empty? parts.join(', ') else nil end
Run
masa@masa ~/ywesee/oddb.org $ bin/admin ch.oddb> ODDB::SwissmedicPlugin.new(self).fix_compositions
Result
Problem
Solution
Check
def update_compositions(seq, row, opts={:create_only => false}) if opts[:create_only] && !seq.active_agents.empty? seq.compositions elsif(namestr = cell(row, column(:substances))) res = [] names = namestr.split(/\s*,\s*/u).collect { |name| capitalize(name) }.uniq substances = names.collect { |name| update_substance(name) } ...
Test
namestr = 'globulina equina (Immunisation mit Schweine-Knochen, -Knorpel, -Bindegewebe, -Serosa, -Lymphknoten)' parts = namestr.split(/\s*,(?!\d|[^(]+\))\s*/u) p parts namestr = 'viscum album (mali) recens, argenti carbonas (0,01 ug pro 100 mg herba recente)' parts = namestr.split(/\s*,(?!\d|[^(]+\))\s*/u) p parts
Result
["globulina equina (Immunisation mit Schweine-Knochen, -Knorpel, -Bindegewebe, -Serosa, -Lymphknoten)"] ["viscum album (mali) recens", "argenti carbonas (0,01 ug pro 100 mg herba recente)"]
Experiment (src/plugin/swissmedic.rb#update_compositions)
def update_compositions(seq, row, opts={:create_only => false})
if opts[:create_only] && !seq.active_agents.empty?
seq.compositions
elsif(namestr = cell(row, column(:substances)))
res = []
#names = namestr.split(/\s*,\s*/u).collect { |name|
names = namestr.split(/\s*,(?!\d|[^(]+\))\s*/u).collect { |name|
capitalize(name) }.uniq
Run
masa@masa ~/ywesee/oddb.org $ bin/admin ch.oddb> ODDB::SwissmedicPlugin.new(self).fix_compositions
Result
Commit
Commit