Class: Oddb2xml::Calc

Inherits:
Object
  • Object
show all
Defined in:
lib/oddb2xml/calc.rb

Defined Under Namespace

Classes: Composition, Substance

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.expand_path(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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, size = nil, unit = nil, active_substance = nil, composition = nil) ⇒ Calc

Returns a new instance of Calc.



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/oddb2xml/calc.rb', line 225

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 = []
  else
    @compositions = update_compositions(active_substance)
  end
end

Instance Attribute Details

#additionObject (readonly)

s.a. commercial_form in oddb.org/src/model/part.rb



106
107
108
# File 'lib/oddb2xml/calc.rb', line 106

def addition
  @addition
end

#compositionObject (readonly)

Returns the value of attribute composition.



105
106
107
# File 'lib/oddb2xml/calc.rb', line 105

def composition
  @composition
end

#compositionsObject (readonly)

Returns the value of attribute compositions.



105
106
107
# File 'lib/oddb2xml/calc.rb', line 105

def compositions
  @compositions
end

#countObject (readonly)

s.a. commercial_form in oddb.org/src/model/part.rb



106
107
108
# File 'lib/oddb2xml/calc.rb', line 106

def count
  @count
end

#galenic_formObject

Returns the value of attribute galenic_form.



104
105
106
# File 'lib/oddb2xml/calc.rb', line 104

def galenic_form
  @galenic_form
end

#measureObject (readonly)

s.a. commercial_form in oddb.org/src/model/part.rb



106
107
108
# File 'lib/oddb2xml/calc.rb', line 106

def measure
  @measure
end

#multiObject (readonly)

s.a. commercial_form in oddb.org/src/model/part.rb



106
107
108
# File 'lib/oddb2xml/calc.rb', line 106

def multi
  @multi
end

#nameObject (readonly)

Returns the value of attribute name.



105
106
107
# File 'lib/oddb2xml/calc.rb', line 105

def name
  @name
end

#pkg_sizeObject

Returns the value of attribute pkg_size.



104
105
106
# File 'lib/oddb2xml/calc.rb', line 104

def pkg_size
  @pkg_size
end

#scaleObject (readonly)

s.a. commercial_form in oddb.org/src/model/part.rb



106
107
108
# File 'lib/oddb2xml/calc.rb', line 106

def scale
  @scale
end

#selling_unitsObject (readonly)

s.a. commercial_form in oddb.org/src/model/part.rb



106
107
108
# File 'lib/oddb2xml/calc.rb', line 106

def selling_units
  @selling_units
end

#substancesObject (readonly)

Returns the value of attribute substances.



105
106
107
# File 'lib/oddb2xml/calc.rb', line 105

def substances
  @substances
end

#unitObject

Returns the value of attribute unit.



104
105
106
# File 'lib/oddb2xml/calc.rb', line 104

def unit
  @unit
end

Class Method Details

.check_for_value_and_units(what) ⇒ Object

Parse a string for a numerical value and unit, e.g. 1.5 ml



355
356
357
358
359
360
361
362
# File 'lib/oddb2xml/calc.rb', line 355

def self.check_for_value_and_units(what)
  if m = /^([\d.]+)\s*(\D+)/.match(what)
    # return [m[1], m[2] ]
    return m[0].to_s
  else
    nil
  end
end

.dump_names_without_galenic_formsObject



146
147
148
149
150
151
152
# File 'lib/oddb2xml/calc.rb', line 146

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_formsObject



139
140
141
142
143
144
145
# File 'lib/oddb2xml/calc.rb', line 139

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



129
130
131
132
133
134
135
136
137
# File 'lib/oddb2xml/calc.rb', line 129

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



107
108
109
110
111
112
# File 'lib/oddb2xml/calc.rb', line 107

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_conversionObject



114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/oddb2xml/calc.rb', line 114

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__xxxObject



262
263
264
# File 'lib/oddb2xml/calc.rb', line 262

def galenic_form__xxx
  @galenic_form.description
end

#galenic_groupObject



243
244
245
# File 'lib/oddb2xml/calc.rb', line 243

def galenic_group
  @@galenic_groups[@galenic_form.galenic_group]
end

#headersObject

helper for generating csv



248
249
250
251
252
253
254
# File 'lib/oddb2xml/calc.rb', line 248

def headers
  [ "name", "pkg_size", "selling_units", "measure",
    # "count", "multi", "addition", "scale", "unit",
    "galenic_form",
    "galenic_group"
    ]
end

#to_arrayObject



255
256
257
258
259
260
261
# File 'lib/oddb2xml/calc.rb', line 255

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

#update_compositions(active_substance) ⇒ Object



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
# File 'lib/oddb2xml/calc.rb', line 163

def update_compositions(active_substance)
  rep_1 = '----';   to_1 = '('
  rep_2 = '-----';  to_2 = ')'
  rep_3 = '------'; to_3 = ','

  comps = []
  label_pattern = /^(?<label>A|I|B|II|C|III|D|IV|E|V|F|VI)[)]\s*(?<designation>[^)]+):/
  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]
    else
      label = nil
    end
    idx += 1
    next if idx > 1 and not label # avoid lines like 'I) et II)'
    substances = []
    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 = Substance.new(m2[2], '', '')
        substances << to_add
      elsif m
        ptrn = /(\s*(?:ut|corresp\.?)\s+(?<chemical>[^\d,]+)\s*(?<cdose>[\d\-.]+(\s*(?:(Mio\.?\s*)?(U\.\s*Ph\.\s*Eur\.|[^\s,]+))(\s*[mv]\/[mv])?))?)/
        m3 = ptrn.match(component.strip)
        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
        next if /\s+pro($|\s+)|emulsion|solution/i.match(name)
        chemical = m3 ? capitalize(m3[:chemical]) : nil
        cdose    = m3 ? m3[:cdose] : nil
        substances << Substance.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,
                                    chemical, cdose)
      end
    }
    comps << Composition.new(line, label, substances) if substances.size > 0
  end
  comps
end