Skip to content

Commit

Permalink
Adding default ATC-code to pseudo-fachinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
ngiger committed Mar 5, 2014
1 parent 04d3894 commit a7f0dd3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
3 changes: 3 additions & 0 deletions ext/fiparse/test/test_pseudo_fachinfo.rb
Expand Up @@ -73,6 +73,9 @@ def test_fachinfo_sinovial_DE
}
assert_equal(["7612291078458", "7612291078472"], @@fachinfo.iksnrs)
assert_equal( 2, @@fachinfo.composition.paragraphs.size)
owner = 'IBSA Institut Biochimique SA, 6903 Lugano.'
assert_equal( owner, @@fachinfo.distributor.paragraphs.first.text)
assert_equal( owner, @@fachinfo.registration_owner)
end
end
end
Expand Down
31 changes: 26 additions & 5 deletions src/plugin/medical_products.rb
Expand Up @@ -14,10 +14,13 @@
require 'ydocx/templates/fachinfo'
require 'textinfo_pseudo_fachinfo'

module ODDB
module ODDB
class MedicalProductPlugin < Plugin
@@errors = []
@@products = []
ATC_CLASS_CODE = 'medical product'
ATC_CLASS_NAME_DE = 'Medizinprodukte ohne ATC-Klassierung'
SEQ_ZERO = '00'
def initialize(app, opts = {:files => ['*.docx']})
super(app)
@options = opts
Expand All @@ -32,9 +35,21 @@ def report
msg
end

def add_dummy_medical_product(atc_code = ATC_CLASS_CODE, lang = :de, name = ATC_CLASS_NAME_DE)
pointer = if atc = @app.atc_class(atc_code)
atc.pointer
else
Persistence::Pointer.new([:atc_class, atc_code]).creator
end
LogFile.debug ("Adding #{atc_code} #{lang} #{name}")
@app.update(pointer.creator, lang => name)
end

def update
data_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', defined?(Minitest) ? 'test' : '.', 'data', 'docx'))
LogFile.debug "file #{@options[:files]} YDocx #{YDocx::VERSION} data_dir #{data_dir}"
atc_code = @app.atc_class(atc_code)
atc_code = add_dummy_medical_product unless atc_code
@options[:files].each{
|param|
files = (Dir.glob(param) + Dir.glob(File.join(data_dir, param))).collect{ |file| File.expand_path(file) }.uniq
Expand Down Expand Up @@ -63,19 +78,24 @@ def update
parts[ean] = [m2[3].strip, m2[4].strip, m2[5].strip ] if m2
authHolder = pseudo_fi_text.distributor.paragraphs.first.strip.match(/^[^,\n]+/)[0]
info = SwissmedicMetaInfo.new(number, nil, pseudo_fi_text.name, authHolder, nil)
reg = TextInfoPlugin::create_registration(@app, info, '00', packNr)
reg = TextInfoPlugin::create_registration(@app, info, SEQ_ZERO, packNr)
@@products << "#{pseudo_fi_text.lang} #{number} #{packNr}: #{pseudo_fi_text.name}"
registration = @app.registration(number)
unless registration
@app.registrations.store(number, reg)
@app.registrations.odba_store
registration = @app.registration(number)
end
sequence = registration.sequence(SEQ_ZERO)
unless unless sequence.atc_class
LogFile.debug "Adding atc #{atc_code.code} to #{registration.iksnr}"
res = @app.update(sequence.pointer, {:atc_class => atc_code.code }, :medical_product)
end
fachinfo = nil
fachinfo ||= TextInfoPlugin::store_fachinfo(@app, registration, {pseudo_fi_text.lang => pseudo_fi_text})
TextInfoPlugin::replace_textinfo(@app, fachinfo, registration, :fachinfo)
if parts[ean]
package = registration.sequence('00').package(packNr)
package = registration.sequence(SEQ_ZERO).package(packNr)
oldParts = package.parts
pInfo = parts[ean]
pSize = "#{pInfo[0]} #{pInfo[1]} #{pInfo[2]}"
Expand Down Expand Up @@ -103,10 +123,11 @@ def update
package.fix_pointers unless defined?(MiniTest)
@app.odba_isolated_store # Why doesn't @app.updated consider the Part class?
end
end
}
end
}
}
end
end
end # update
end # MedicalProductPlugin
end
8 changes: 8 additions & 0 deletions test/test_plugin/medical_products.rb
Expand Up @@ -75,6 +75,14 @@ def initialize
@pointer_mock.should_receive(:notify).and_return([])
@pointer_mock.should_receive(:+).and_return(@pointer_mock)
end
def atc_class(name)
@atc_name = name
@atc_class_mock = FlexMock.new(ODDB::AtcClass)
@atc_class_mock.should_receive(:pointer).and_return(@pointer_mock)
@atc_class_mock.should_receive(:pointer_descr).and_return(@atc_name)
@atc_class_mock.should_receive(:code).and_return(@atc_name)
return @atc_class_mock
end
def commercial_form_by_name(name)
if name.match(/Fertigspritze/i)
@commercial_mock = FlexMock.new(ODDB::CommercialForm)
Expand Down

0 comments on commit a7f0dd3

Please sign in to comment.