Class: Oddb2xml::Calc
- Inherits:
-
Object
- Object
- Oddb2xml::Calc
- Defined in:
- lib/oddb2xml/calc.rb
Constant Summary collapse
- FluidForms =
[ 'Ampulle(n)', 'Beutel', 'Bolus/Boli', 'Bq', 'Dose(n)', 'Durchstechflasche(n)', 'Einmaldosenbehälter', 'Einzeldose(n)', 'Fertigspritze', 'Fertigspritze(n)', 'Flasche(n)', 'I.E.', 'Infusionskonzentrat', 'Infusionslösung', 'Infusionsemulsion', 'Inhalationen', 'Inhalator', 'Injektions-Set', 'Injektions-Sets', 'Injektor(en), vorgefüllt/Pen', 'Klistier(e)', 'MBq', 'Pipetten', 'Sachet(s)', 'Spritze(n)', 'Sprühstösse', 'Stechampulle (Lyophilisat) und Ampulle (Solvens)', 'Stechampulle', 'Suspension', 'Zylinderampulle(n)', 'cartouches', 'dose(s)', 'flacon perforable', 'sacchetto', 'vorgefüllter Injektor', ]
- FesteFormen =
[ 'Depotabs', 'Dragée(s)', 'Generator mit folgenden Aktivitäten:', 'Filmtabletten', 'Gerät', 'Kapsel(n)', 'Kautabletten', 'Lutschtabletten', 'Kugeln', 'Ovulum', 'Packung(en)', 'Pflaster', 'Schmelzfilme', 'Set', 'Strips', 'Stück', 'Suppositorien', 'Tablette(n)', 'Tüchlein', 'Urethrastab', 'Vaginalzäpfchen', 'comprimé', 'comprimé pelliculé', 'comprimés', 'comprimés à libération modifiée', 'comprimés à croquer sécables', 'imprägnierter Verband', 'magensaftresistente Filmtabletten', 'ovale Körper', 'tube(s)', ]
- Measurements =
[ 'g', 'kg', 'l', 'mg', 'ml', 'cm', 'GBq']
- Others =
['Kombipackung', 'emballage combiné' ]
- UnknownGalenicForm =
140- UnknownGalenicGroup =
1- Data_dir =
File.(File.join(File.dirname(__FILE__),'..','..', 'data'))
- SCALE_P =
%r{pro\s+(?<scale>(?<qty>[\d.,]+)\s*(?<unit>[kcmuµn]?[glh]))}u
- @@galenic_groups =
YAML.load_file(File.join(Data_dir, 'gal_groups.yaml'))
- @@galenic_forms =
YAML.load_file(File.join(Data_dir, 'gal_forms.yaml'))
- @@new_galenic_forms =
[]
- @@names_without_galenic_forms =
[]
- @@rules_counter =
{}
Instance Attribute Summary collapse
-
#addition ⇒ Object
readonly
s.a.
-
#composition ⇒ Object
readonly
Returns the value of attribute composition.
-
#composition_comment ⇒ Object
readonly
Returns the value of attribute composition_comment.
-
#compositions ⇒ Object
readonly
Returns the value of attribute compositions.
-
#count ⇒ Object
readonly
s.a.
-
#galenic_form ⇒ Object
Returns the value of attribute galenic_form.
-
#measure ⇒ Object
readonly
s.a.
-
#multi ⇒ Object
readonly
s.a.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#pkg_size ⇒ Object
Returns the value of attribute pkg_size.
-
#scale ⇒ Object
readonly
s.a.
-
#selling_units ⇒ Object
readonly
s.a.
-
#substances ⇒ Object
readonly
Returns the value of attribute substances.
-
#unit ⇒ Object
Returns the value of attribute unit.
Class Method Summary collapse
- .dump_names_without_galenic_forms ⇒ Object
- .dump_new_galenic_forms ⇒ Object
- .get_galenic_form(name, lang = 'de') ⇒ Object
- .get_galenic_group(name, lang = 'de') ⇒ Object
- .report_conversion ⇒ Object
Instance Method Summary collapse
- #galenic_form__xxx ⇒ Object
- #galenic_group ⇒ Object
-
#headers ⇒ Object
helper for generating csv.
-
#initialize(name = nil, size = nil, unit = nil, active_substance = nil, composition = nil) ⇒ Calc
constructor
A new instance of Calc.
- #to_array ⇒ Object
Constructor Details
#initialize(name = nil, size = nil, unit = nil, active_substance = nil, composition = nil) ⇒ Calc
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 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
# File 'lib/oddb2xml/calc.rb', line 161 def initialize(name = nil, size = nil, unit = nil, active_substance = nil, composition= nil) @name = remove_duplicated_spaces(name) @pkg_size = remove_duplicated_spaces(size) @unit = unit # @pkg_size, @galenic_group, @galenic_form = search_galenic_info @composition = composition @measure = unit if unit and not @measure @measure = @galenic_form.description if @galenic_form and not @measure @galenic_form ||= @@galenic_forms[UnknownGalenicForm] unless active_substance @compositions = [] @active_substances = [] else # Update of active substances, etc picked up from oddb.org/src/plugin/swissmedic.rb update_compositions @active_substances = active_substance.split(/\s*,(?!\d|[^(]+\))\s*/u).collect { |name| capitalize(name) }.uniq res = [] numbers = [ "A|I", "B|II", "C|III", "D|IV", "E|V", "F|VI" ] current = numbers.shift labels = [] 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 compositions = composition_text.split(/\n/u).select do |line| if match = /^(#{current})\)([^:]+)/.match(line) labels.push [match[1], match[2]] current = numbers.shift end end puts "labels for #{name}: #{labels}" if labels.size > 0 and $VERBOSE if composition_text.split(/\n/u).size > 1 last_line = composition_text.split(/\n/u)[-1] @composition_comment = last_line else @composition_comment = nil end if compositions.empty? compositions.push composition_text.gsub(/\n/u, ' ') end agents = [] comps = [] units = 'U\.\s*Ph\.\s*Eur\.' name = 'dummy' ptrn = %r{(?ix) (^|[[:punct:]]|\bet|\bex)\s*#{Regexp.escape name}(?![:\-]) (\s*(?<dose>[\d\-.]+(\s*(?:(Mio\.?\s*)?(#{units}|[^\s,]+)) (\s*[mv]/[mv])?)))? (\s*(?:ut|corresp\.?)\s+(?<chemical>[^\d,]+) \s*(?<cdose>[\d\-.]+(\s*(?:(Mio\.?\s*)?(#{units}|[^\s,]+)) (\s*[mv]/[mv])?))?)? }u rep_1 = '----'; to_1 = '(' rep_2 = '-----'; to_2 = ')' rep_3 = '------'; to_3 = ',' compositions.each_with_index do |composition, idx| composition.gsub!(/'/, '') label = nil composition_text.split(/\n/u).each { |line| if m = /^(?<part_id>A|I|B|II|C|III|D|IV|E|V|F|VI)\)\s+(?<part_name>[^\s:, ]+):/.match(line) label = "#{m[:part_id]} #{m[:part_name]}" end filler = line.split(',')[-1].sub(/\.$/, '') filler_match = /^(?<name>[^,\d]+)\s*(?<dose>[\d\-.]+(\s*(?:(Mio\.?\s*)?(U\.\s*Ph\.\s*Eur\.|[^\s,]+))))/.match(filler) components = line.split(/([^\(]+\([^)]+\)[^,]+|),/).each { |component| next unless component.size > 0 to_consider = component.strip.split(':')[-1] # remove label # very ugly hack to ignore ,() m = /^(?<name>[^,\d()]+)\s*(?<dose>[\d\-.]+(\s*(?:(Mio\.?\s*)?(U\.\s*Ph\.\s*Eur\.|[^\s,]+))))/.match(to_consider .gsub(to_1, rep_1).gsub(to_2, rep_2).gsub(to_3, rep_3)) if m2 = /^(|[^:]+:\s)(E\s+\d+)$/.match(component.strip) to_add = Composition.new(m2[2], '', '', nil) res << to_add elsif m dose = nil unit = nil name = m[:name].split(/\s/).collect{ |x| x.capitalize }.join(' ').strip.gsub(rep_3, to_3).gsub(rep_2, to_2).gsub(rep_1, to_1) dose = m[:dose].split(/\b\s*(?![.,\d\-]|Mio\.?)/u, 2) if m[:dose] if dose && (scale = SCALE_P.match(filler)) && dose[1] && !dose[1].include?('/') unit = dose[1] << '/' num = scale[:qty].to_f if num <= 1 unit << scale[:unit] else unit << scale[:scale] end elsif dose.size == 2 unit = dose[1] end to_add = Composition.new(name, dose ? dose[0].to_f : nil, unit ? unit.gsub(rep_3, to_3).gsub(rep_2, to_2).gsub(rep_1, to_1) : nil, label) res << to_add end } } end @compositions = res end end |
Instance Attribute Details
#addition ⇒ Object (readonly)
s.a. commercial_form in oddb.org/src/model/part.rb
107 108 109 |
# File 'lib/oddb2xml/calc.rb', line 107 def addition @addition end |
#composition ⇒ Object (readonly)
Returns the value of attribute composition.
106 107 108 |
# File 'lib/oddb2xml/calc.rb', line 106 def composition @composition end |
#composition_comment ⇒ Object (readonly)
Returns the value of attribute composition_comment.
106 107 108 |
# File 'lib/oddb2xml/calc.rb', line 106 def composition_comment @composition_comment end |
#compositions ⇒ Object (readonly)
Returns the value of attribute compositions.
106 107 108 |
# File 'lib/oddb2xml/calc.rb', line 106 def compositions @compositions end |
#count ⇒ Object (readonly)
s.a. commercial_form in oddb.org/src/model/part.rb
107 108 109 |
# File 'lib/oddb2xml/calc.rb', line 107 def count @count end |
#galenic_form ⇒ Object
Returns the value of attribute galenic_form.
105 106 107 |
# File 'lib/oddb2xml/calc.rb', line 105 def galenic_form @galenic_form end |
#measure ⇒ Object (readonly)
s.a. commercial_form in oddb.org/src/model/part.rb
107 108 109 |
# File 'lib/oddb2xml/calc.rb', line 107 def measure @measure end |
#multi ⇒ Object (readonly)
s.a. commercial_form in oddb.org/src/model/part.rb
107 108 109 |
# File 'lib/oddb2xml/calc.rb', line 107 def multi @multi end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
106 107 108 |
# File 'lib/oddb2xml/calc.rb', line 106 def name @name end |
#pkg_size ⇒ Object
Returns the value of attribute pkg_size.
105 106 107 |
# File 'lib/oddb2xml/calc.rb', line 105 def pkg_size @pkg_size end |
#scale ⇒ Object (readonly)
s.a. commercial_form in oddb.org/src/model/part.rb
107 108 109 |
# File 'lib/oddb2xml/calc.rb', line 107 def scale @scale end |
#selling_units ⇒ Object (readonly)
s.a. commercial_form in oddb.org/src/model/part.rb
107 108 109 |
# File 'lib/oddb2xml/calc.rb', line 107 def selling_units @selling_units end |
#substances ⇒ Object (readonly)
Returns the value of attribute substances.
106 107 108 |
# File 'lib/oddb2xml/calc.rb', line 106 def substances @substances end |
#unit ⇒ Object
Returns the value of attribute unit.
105 106 107 |
# File 'lib/oddb2xml/calc.rb', line 105 def unit @unit end |
Class Method Details
.dump_names_without_galenic_forms ⇒ Object
147 148 149 150 151 152 153 |
# File 'lib/oddb2xml/calc.rb', line 147 def self.dump_names_without_galenic_forms if @@names_without_galenic_forms.size > 0 "\n\n\nThe following products did not have a galenic form in column Präparateliste\n"+ @@names_without_galenic_forms.sort.uniq.join("\n") else "\n\n\nColumn Präparateliste has everywhere a name\n" end end |
.dump_new_galenic_forms ⇒ Object
140 141 142 143 144 145 146 |
# File 'lib/oddb2xml/calc.rb', line 140 def self.dump_new_galenic_forms if @@new_galenic_forms.size > 0 "\n\n\nAdded the following galenic_forms\n"+ @@new_galenic_forms.uniq.join("\n") else "\n\n\nNo new galenic forms added" end end |
.get_galenic_form(name, lang = 'de') ⇒ Object
130 131 132 133 134 135 136 137 138 |
# File 'lib/oddb2xml/calc.rb', line 130 def self.get_galenic_form(name, lang = 'de') @@galenic_forms.values.collect { |galenic_form| return galenic_form if galenic_form.descriptions[lang].eql?(name) if name and galenic_form.descriptions[lang].eql?(name.sub(' / ', '/')) return galenic_form end } @@galenic_forms[UnknownGalenicForm] end |
.get_galenic_group(name, lang = 'de') ⇒ Object
108 109 110 111 112 113 |
# File 'lib/oddb2xml/calc.rb', line 108 def self.get_galenic_group(name, lang = 'de') @@galenic_groups.values.collect { |galenic_group| return galenic_group if galenic_group.descriptions[lang].eql?(name) } @@galenic_groups[1] end |
.report_conversion ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/oddb2xml/calc.rb', line 115 def self.report_conversion lines = [ '', '', 'Report of used conversion rules', '-------------------------------', '' ] @@rules_counter.each{ | key, value| lines << "#{key}: #{value} occurrences" } lines << '' lines << '' lines end |
Instance Method Details
#galenic_form__xxx ⇒ Object
281 282 283 |
# File 'lib/oddb2xml/calc.rb', line 281 def galenic_form__xxx @galenic_form.description end |
#galenic_group ⇒ Object
262 263 264 |
# File 'lib/oddb2xml/calc.rb', line 262 def galenic_group @@galenic_groups[@galenic_form.galenic_group] end |
#headers ⇒ Object
helper for generating csv
267 268 269 270 271 272 273 |
# File 'lib/oddb2xml/calc.rb', line 267 def headers [ "name", "pkg_size", "selling_units", "measure", # "count", "multi", "addition", "scale", "unit", "galenic_form", "galenic_group" ] end |
#to_array ⇒ Object
274 275 276 277 278 279 280 |
# File 'lib/oddb2xml/calc.rb', line 274 def to_array [ @name, @pkg_size, @selling_units, @measure, # @count, @multi, @addition, @scale, @unit, galenic_form ? galenic_form.description : '' , galenic_group ? galenic_group.description : '' ] end |