Skip to content

Commit

Permalink
After add a registration, it can be found by name
Browse files Browse the repository at this point in the history
  • Loading branch information
ngiger committed Sep 30, 2013
1 parent cba7b8c commit 9627ffe
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 45 deletions.
36 changes: 12 additions & 24 deletions src/plugin/text_info.rb
Expand Up @@ -87,7 +87,7 @@ def save_info type, name, lang, page, flags={}
def puts_sync(msg)
puts Time.now.to_s + ': ' + msg; $stdout.flush
end
Package = Struct.new("Package", :iksnr, :seqnr, :name_base)
IKS_Package = Struct.new("IKS_Package", :iksnr, :seqnr, :name_base)
def read_packages # adapted from swissmedic.rb
latest_name = File.join ARCHIVE_PATH, 'xls', 'Packungen-latest.xls'
@packages = {}
Expand All @@ -98,7 +98,7 @@ def read_packages # adapted from swissmedic.rb
iksnr = row[0].to_s
seqnr = row[1].to_i.to_s
name_base = row[2]
@packages[iksnr] = Package.new(iksnr, seqnr, name_base)
@packages[iksnr] = IKS_Package.new(iksnr, seqnr, name_base)
end
end
end
Expand Down Expand Up @@ -554,8 +554,10 @@ def TextInfoPlugin::get_iksnrs_meta_info
end

def create_registration(info)
puts_sync "create_registration info #{info.inspect}"
# should probably be similar to method update_registration in src/plugin/swissmedic.rb
iksnr = info.iksnr
puts_sync "create_registration info #{info.inspect} include? #{@app.registrations.include?(iksnr)}"
# return if not @options[:iksnrs].nil? and not @options[:iksnrs].empty? and not @options[:iksnrs].index(info.iksnr)
# similar to method update_registration in src/plugin/swissmedic.rb
reg_ptr = Persistence::Pointer.new([:registration, info.iksnr]).creator
args = {
:ith_swissmedic => nil,
Expand All @@ -572,19 +574,16 @@ def create_registration(info)
company_args = { :name => info.authHolder, :business_area => 'ba_pharma' }
company = nil
if(company = @app.company_by_name(info.authHolder, 0.8))
puts_sync "create_registration set company '#{info.authHolder}'"
@app.update company.pointer, args
else
puts_sync "create_registration created company #{info.authHolder}"
company_ptr = Persistence::Pointer.new(:company).creator
company = @app.update company_ptr, company_args
end
args.store :company, company.pointer

registration = @app.update reg_ptr, args, :swissmedic_text_info

# create dummy sequence 00 TODO: remove this sequence when Packungen.xls contains this iksnr
# seq_ptr = Persistence::Pointer.new([:sequence, 0]).creator
res = @app.registrations.store(iksnr, registration)

seq_ptr = (registration.pointer + [:sequence, 0]).creator
unless seq_ptr
puts_sync "Failed to create"
Expand All @@ -599,26 +598,15 @@ def create_registration(info)
:export_flag => nil,
}
if info.atcCode and atc = @app.unique_atc_class(info.atcCode)
puts_sync "create_registration found atc #{info.atcCode}"
seq_args.store :atc_class, atc.code
else
puts_sync "create_registration created atc #{info.atcCode}"
seq_args.store :atc_class, info.atcCode
end
res = @app.update seq_ptr, seq_args, :swissmedic_text_info

puts_sync "create_registration #{info.iksnr} #{reg_ptr.inspect}"
if @app.atc_classes and info.atcCode and @app.atc_classes[info.atcCode]
puts_sync "Check 1 atcCode #{@app.atc_classes[info.atcCode].id}"
else
puts_sync "Check 1 atcCode not found"
end
# puts_sync "Check 2 registration substance_names #{@app.registration(info.iksnr).substance_names}"
if reg = @app.registration(info.iksnr) and not defined?(MiniTest)
puts_sync "Check 3 registration company #{reg.company}"
puts_sync "Check 4 registration iksnr #{reg.iksnr}"
puts_sync "Check 5 registration name_base #{reg.name_base}"
end
sequence = registration.sequence('00')
package = sequence.create_package('000')
res = @app.update(sequence.pointer, {:packages => sequence.packages}, :swissmedic_text_info)
@new_iksnrs[info.iksnr] = info.title
end

Expand All @@ -636,7 +624,7 @@ def add_all_iksnr(info, typ, all_numbers)
elsif typ.eql?('pi')
@pis_to_iksnrs[id] ? @pis_to_iksnrs[id] += ids : @pis_to_iksnrs[id] = ids
else
puts_sync "anhandled type #{x.text} at #{x.text}"
puts_sync "unhandled type #{x.text} at #{x.text}"
end
} if ids
end
Expand Down
15 changes: 8 additions & 7 deletions src/view/additional_information.rb
Expand Up @@ -112,14 +112,15 @@ def complementary_type(model, session=@session)
end
def compositions(model, session=@session)
link = HtmlGrid::Link.new(:show, model, session, self)
smart_link_format = model.pointer.to_csv.gsub(/registration/, 'reg').gsub(/sequence/, 'seq').gsub(/package/, 'pack').split(/,/)
if smart_link_format.include?('reg')
link.href = @lookandfeel._event_url(:show, smart_link_format)
else
old_link_format = {:pointer => model.pointer}
link.href = @lookandfeel._event_url(:show, old_link_format)
if model.pointer
smart_link_format = model.pointer.to_csv.gsub(/registration/, 'reg').gsub(/sequence/, 'seq').gsub(/package/, 'pack').split(/,/)
if smart_link_format.include?('reg')
link.href = @lookandfeel._event_url(:show, smart_link_format)
else
old_link_format = {:pointer => model.pointer}
link.href = @lookandfeel._event_url(:show, old_link_format)
end
end

lang = @session.language
comps = []
if !model.compositions.empty?
Expand Down
34 changes: 20 additions & 14 deletions test/test_plugin/text_info_swissmedicinfo.rb
Expand Up @@ -70,18 +70,27 @@ def setup
@dest = File.join(@@vardir, 'xml', 'AipsDownload_latest.xml')
FileUtils.makedirs(File.dirname(@dest))
FileUtils.cp(File.join(@@datadir, 'AipsDownload_xeljanz.xml'), @dest)
@sequence = flexmock('sequence', :creator => 'creator')
@sequence = flexmock('sequence',
:packages => ['packages'],
:pointer => 'pointer',
:creator => 'creator')
@sequence.should_receive(:create_package)
@pointer = flexmock('pointer', :+ => @sequence)
@company = flexmock('company',
:pointer => @pointer)
@registration = flexmock('registration',
:pointer => @pointer)
@registration2 = flexmock('registration2')
@registrations = []
@registration = flexmock('registration1',
:pointer => @pointer,
:store => 'store')
@registration.should_receive(:sequence).and_return(@sequence)
@registrations = flexmock('registrations')
@registrations.should_receive(:include?).and_return(true)
@registrations.should_receive(:store).and_return(true)
@registrations.should_receive(:sequence).and_return(@sequence)
@registrations.should_receive(:size).once.and_return(2)
@app = flexmock('application',
:update => @registration,
:delete => 'delete',
:registrations => [@registration, @registration2])
:registrations => @registrations,)
@app.should_receive(:textinfo_swissmedicinfo_index)
@parser = flexmock 'parser (simulates ext/fiparse for swissmedicinfo_xml)'
@fi_path_de = File.join(@@vardir, "html/fachinfo/de/#{Test_Name}_swissmedicinfo.html")
Expand All @@ -98,7 +107,10 @@ def teardown
end

def test_import_new_registration_from_swissmedicinfo_xml
reg = flexmock('registration', :new => 'new')
reg = flexmock('registration',
:new => 'new',
:store => 'store',
)
reg.should_receive(:fachinfo)
ptr = Persistence::Pointer.new([:registration, Test_Iksnr])
fi = flexmock 'fachinfo'
Expand All @@ -107,16 +119,10 @@ def test_import_new_registration_from_swissmedicinfo_xml

newReg = ODDB::Registration.new(Test_Iksnr)
atc = ODDB::AtcClass.new(Test_Atc)
@app.should_receive(:registration).with(Test_Iksnr).once.and_return(nil)
@app.should_receive(:registration).with(Test_Iksnr).times(1).and_return(newReg)
@app.should_receive(:registration).once.with("32917").and_return("32917")
# @app.should_receive(:create_registration).once.with(Test_Iksnr).and_return(newReg)
@app.should_receive(:company_by_name).and_return(@company)
@company.should_receive(:pointer).and_return('pointerx')
# @app.should_receive(:atc_class).with(Test_Atc).once.and_return(nil)
@app.should_receive(:unique_atc_class).with(Test_Atc).once.and_return(nil)
# @app.should_receive(:create_atc_class).with(Test_Atc).once.and_return(atc)
@app.should_receive(:atc_classes).times(3).and_return({Test_Atc => atc})
@company.should_receive(:pointer).and_return('pointer')
assert(@plugin.import_swissmedicinfo(@opts), 'must be able to run import_swissmedicinfo and add a new registration')
meta = TextInfoPlugin::get_iksnrs_meta_info
refute_nil(meta)
Expand Down

0 comments on commit 9627ffe

Please sign in to comment.