Class: Oddb2xml::Calc

Inherits:
Object
  • Object
show all
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)',
]
Mesurements =
[ '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.



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

def initialize(name = nil, size = nil, unit = nil, active_substance = nil, composition= nil)
  @name = name
  @pkg_size = 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")
    compositions = composition_text.split(/\n/u).select do |line|
      if match = /^(#{current})\)/.match(line)
        labels.push match[1]
        current = numbers.shift
      end
    end
    if compositions.empty?
      compositions.push composition_text.gsub(/\n/u, ' ')
    end
    agents = []
    comps = []
    compositions.each_with_index do |composition, idx|
      composition.gsub!(/'/, '')
      @active_substances.each { |name|
        name, qty, unit = Calc.update_active_agent(name, composition)
        res << Composition.new(name, qty.to_f, unit) if name
      }
    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

#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

.update_active_agent(name, part) ⇒ Object



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/oddb2xml/calc.rb', line 156

def self.update_active_agent(name, part)
  units = 'U\.\s*Ph\.\s*Eur\.'
  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
  if(match = ptrn.match(part.sub(/\.$/, '')))
    dose = match[:dose].split(/\b\s*(?![.,\d\-]|Mio\.?)/u, 2) if match[:dose]
    cdose = match[:cdose].split(/\b\s*(?![.,\d\-]|Mio\.?)/u, 2) if match[:cdose]
    if dose && (scale = SCALE_P.match(part)) && !dose[1].include?('/')
      unit = dose[1] << '/'
      num = scale[:qty].to_f
      if num <= 1
        unit << scale[:unit]
      else
        unit << scale[:scale]
      end
    end
    if(chemical = match[:chemical])
      chemical = capitalize(chemical)
      chemical = nil if chemical.empty?
    end if false # TODO:
    [name, dose ? [dose[0], dose[1]] : [nil, nil] ].flatten
  end
end

Instance Method Details

#galenic_form__xxx ⇒ Object



250
251
252
# File 'lib/oddb2xml/calc.rb', line 250

def galenic_form__xxx
  @galenic_form.description
end

#galenic_group ⇒ Object



231
232
233
# File 'lib/oddb2xml/calc.rb', line 231

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

#headers ⇒ Object

helper for generating csv



236
237
238
239
240
241
242
# File 'lib/oddb2xml/calc.rb', line 236

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

#to_array ⇒ Object



243
244
245
246
247
248
249
# File 'lib/oddb2xml/calc.rb', line 243

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