Skip to content

Commit

Permalink
Merge pull request #255 from ngiger/master
Browse files Browse the repository at this point in the history
  • Loading branch information
zdavatz authored Feb 23, 2024
2 parents ac5443d + 3a8d9f7 commit a8f6e9b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 26 deletions.
11 changes: 5 additions & 6 deletions src/plugin/text_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def initialize app, opts={:newest => true}
@wrong_meta_tags = []
@news_log = File.join ODDB.config.log_dir, 'textinfos.txt'
@problematic_fi_pi = File.join ODDB.config.log_dir, 'problematic_fi_pi.lst'
@missing_override_file = File.join ODDB.config.log_dir, 'missing_override.lst'
@title = '' # target fi/pi name
@format = :swissmedicinfo
@target = :both
Expand All @@ -73,8 +72,9 @@ def initialize app, opts={:newest => true}
@fi_atc_code_missmatch = []
@target_keys = Util::COLUMNS_FEBRUARY_2019
@iksnrs_meta_info = {}
@specify_barcode_to_text_info ||= {}
@skipped_override ||= []
@missing_override ||= []
@missing_override ||= {}
end
def save_info type, name, lang, page, flags={}
dir = File.join @dirs[type], lang.to_s
Expand Down Expand Up @@ -405,7 +405,7 @@ def update_patinfo_lang(meta_info, pis)
@skipped_override << barcode_override
else
LogFile.debug "missing_override: not found via #{barcode_override}: '#{name}' != '#{meta_info.title}'"
@missing_override << "#{barcode_override}: #{meta_info.title} # != override #{name}"
@missing_override["#{barcode_override}"] = "#{meta_info.title} # != override #{name}"
end
puts "package.patinfo updated sequence #{package.iksnr}/#{package.seqnr}/#{package.ikscd} #{package.pointer}"
end
Expand Down Expand Up @@ -603,6 +603,7 @@ def report
res << "\n#{Override_file}: The #{@missing_override.size} missing overrides are\n"
res << @missing_override.join("\n")
end
File.open(Override_file, 'w+' ) { |out| YAML.dump(@specify_barcode_to_text_info.merge(@missing_override), out, line_width: -1 )}
res
end
def init_agent
Expand Down Expand Up @@ -647,7 +648,7 @@ def TextInfoPlugin::create_sequence(app, registration, title, seqNr ='00', packN
# are found after an import_daily
registration.sequences.values.first.name_base = title;
registration.sequences.values.first.odba_store;
LogFile.debug "create_sequence #{registration.iksnr} seqNr #{seqNr} #{sequence.pointer} seq_args #{seq_args} app.name #{title} should match #{app.registration(registration.iksnr).name_base} registration.sequences #{registration.sequences}"
LogFile.debug "create_sequence #{registration.iksnr} seqNr #{seqNr} #{sequence.pointer} seq_args #{seq_args.keys} app.name #{title} should match #{app.registration(registration.iksnr).name_base} registration.sequences #{registration.sequences}"
end

def TextInfoPlugin::create_registration(app, info, seqNr ='00', packNr = '000')
Expand Down Expand Up @@ -1367,7 +1368,6 @@ def handle_chunk(chunk)
def report_problematic_names
LogFile.debug "Creating #{@problematic_fi_pi} with #{@duplicate_entries.size} @duplicate_entries"
File.open(@problematic_fi_pi, 'w+') do |file|
file.write("# resolve these problems and add them to #{@missing_override_file}")
@iksnrs_from_aips.sort.uniq.each do|iksnr|
file.puts "# known packages. There are #{@duplicate_entries.size} @duplicate_entries"
@app.registration(iksnr).packages.each do |pack|
Expand Down Expand Up @@ -1509,7 +1509,6 @@ def import_swissmedicinfo(options=nil)
@iksnrs_meta_info.values.flatten.sort{|x,y| x.iksnr.to_i <=> y.iksnr.to_i}.each do |meta_info|
parse_textinfo(meta_info)
end
File.open(@missing_override_file, 'w+') {|f| f.puts @missing_override.join("\n")}
if @options[:download] != false
puts_sync "job is done. now postprocess works ..."
postprocess
Expand Down
8 changes: 4 additions & 4 deletions test/test_plugin/swissmedic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ def setup
prep_from = File.expand_path('../data/xlsx/Erweiterte_Arzneimittelliste_HAM_31012019.xlsx', File.dirname(__FILE__))
@plugin.should_receive(:fetch_with_http).with( ODDB::SwissmedicPlugin.get_packages_url).and_return(File.open(@state_2015_07_02).read).by_default
@plugin.should_receive(:fetch_with_http).with( ODDB::SwissmedicPlugin.get_preparations_url).and_return(File.open(prep_from).read).by_default
@target = File.join @archive, 'xls', @@today.strftime('Packungen-%Y.%m.%d.xlsx')
@latest = File.join @archive, 'xls', 'Packungen-latest.xlsx'
@target = File.join @archive, 'xls', @@today.strftime('Packungen-%Y.%m.%d.xlsx')
@latest = File.join @archive, 'xls', 'Packungen-latest.xlsx'
FileUtils.makedirs(File.dirname(@latest)) unless File.exist?(File.dirname(@latest))
FileUtils.rm(@latest) if File.exist?(@latest)

@test_packages = File.expand_path '../data/xlsx/Packungen-2019.01.31.xlsx', File.dirname(__FILE__)
latest_to = File.expand_path('../../data/xls/Packungen-latest.xlsx', File.dirname(__FILE__))
@test_packages = File.expand_path('../data/xlsx/Packungen-2019.01.31.xlsx', File.dirname(__FILE__))
latest_to = File.expand_path('../data/xls/Packungen-latest.xlsx', File.dirname(__FILE__))
FileUtils.makedirs(File.dirname(latest_to))
FileUtils.cp(@test_packages, latest_to, :verbose => true, :preserve => true)
FileUtils.cp(prep_from, File.join(@archive, 'xls', @@today.strftime('Präparateliste-%Y.%m.%d.xlsx')),
Expand Down
45 changes: 33 additions & 12 deletions test/test_plugin/text_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
require 'plugin/text_info'
require 'model/text'
module ODDB
RUN_ALL = false
class FachinfoDocument
def odba_id
1
Expand Down Expand Up @@ -160,7 +159,7 @@ def test_true_news
old_news = ["Amiodarone Winthrop\302\256/- Mite"]
assert_equal news, @plugin.true_news(news, old_news)
end
end if RUN_ALL
end

class TestExtractMatchedName <MiniTest::Test
Nr_FI_in_AIPS_test = 4
Expand All @@ -171,15 +170,19 @@ def teardown
end

def setup
path_check = File.expand_path(File.join(File.dirname(__FILE__), '../../etc', 'barcode_minitest.yml'))
assert_equal(ODDB::TextInfoPlugin::Override_file, path_check)
FileUtils.rm_f(path_check, :verbose => true)
pointer = flexmock 'pointer'
@aips_download = File.expand_path('../data/xml/Aips_test.xml', File.dirname(__FILE__))
latest_from = File.expand_path('../data/xlsx/Packungen-latest.xlsx', File.dirname(__FILE__))
latest_to = File.expand_path('../../data/xls/Packungen-latest.xlsx', File.dirname(__FILE__))
FileUtils.cp(latest_from, latest_to, :verbose => true, :preserve => true)
@app = flexmock 'application'
@reg = flexmock 'registration'
@reg = flexmock "registration_#{__LINE__}"
@reg.should_receive(:pointer).and_return(pointer).by_default
@reg.should_receive(:odba_store).and_return(nil).by_default
@reg.should_receive(:odba_isolated_store).and_return(nil).by_default
@reg.should_receive(:company).and_return('company')
@reg.should_receive(:inactive?).and_return(false)
lang_de = flexmock 'lang_de'
Expand All @@ -204,21 +207,27 @@ def setup

@app.should_receive(:create_patinfo).and_return(Patinfo.new)

atc_class = flexmock('atc_class')
atc_class = flexmock("atc_class_#{__LINE__}")
atc_class.should_receive(:oid).and_return('oid')
atc_class.should_receive(:code).and_return('code')
@sequence = flexmock 'sequence'
@sequence = flexmock "sequence_#{__LINE__}"
@sequence.should_receive(:seqnr).and_return('01')
@sequence.should_receive(:pointer).and_return(pointer)
@sequence.should_receive(:odb_store)
@sequence.should_receive(:odba_isolated_store)
@sequence.should_receive(:atc_class=).and_return(atc_class)
@sequence.should_receive(:atc_class).and_return(atc_class)
@sequence.should_receive(:patinfo).and_return(nil).by_default
@sequence.should_receive(:patinfo=).and_return(nil).by_default
@sequence.should_receive(:odba_store)
@package = flexmock('package')
@sequence.should_receive(:package).and_return(@package)

atc_class = flexmock 'atc_class'
atc_class = flexmock("atc_class_#{__LINE__}")
atc_class.should_receive(:oid).and_return('oid')
atc_class.should_receive(:code).and_return('code')
atc_class.should_receive(:pointer).and_return(pointer)
atc_class.should_receive(:odba_store).and_return(true)
@app.should_receive(:atc_class).and_return(atc_class)
@app.should_receive(:update).and_return(@fachinfo)
@reg.should_receive(:fachinfo).and_return(@fachinfo)
Expand All @@ -245,7 +254,7 @@ def setup
:xml_file => @aips_download,
}
end
if RUN_ALL

def test_53662_pi_de
@options[:iksnrs] = ['53662']
@plugin.import_swissmedicinfo(@options)
Expand Down Expand Up @@ -281,15 +290,15 @@ def test_import_daily_fi

assert_equal(Nr_PI_in_AIPS_test, @plugin.iksnrs_meta_info.keys.find_all{|key| key[1] == 'pi'}.size, 'must find patinfo')

assert_equal(Nr_PI_in_AIPS_test, @plugin.updated_fis.size, 'nr updated fis must match')
assert_equal(Nr_FI_in_AIPS_test, @plugin.updated_fis.size, 'nr updated fis must match')
assert_equal(0, @plugin.updated_pis.size, 'nr updated pis must match')

assert_equal(0, @plugin.corrected_fis.size, 'corrected_fis must match')
assert_equal(0, @plugin.corrected_pis.size, 'corrected_pis must match')

assert_equal(0, @plugin.up_to_date_pis, 'up_to_date_pis must match')
# nr_fis = 6 # we add all missing
assert_equal(3, @plugin.up_to_date_fis, 'up_to_date_fis must match')
assert_equal(0, @plugin.up_to_date_fis, 'up_to_date_fis must match')

@plugin = TextInfoPlugin.new @app
@plugin.parser = @parser
Expand Down Expand Up @@ -319,20 +328,32 @@ def test_import_daily_pi
assert_equal(0, @plugin.updated_fis.size, 'nr updated fis must match')
assert_equal(0, @plugin.up_to_date_fis, 'up_to_date_fis must match')
end
end
def test_import_daily_packungen
@options[:target] = :pi
@options[:newest] = true
old_missing = {'680109990223_pi_de' => 'Osanit® Kügelchen',
'7680109990223_pi_fr' => 'Osanit® globules',
'7680109990224_pi_fr' => 'Test mit langem Namen der nicht umgebrochen sein sollte mehr als 80 Zeichen lang'}
real_override_file = File.join(File.dirname(__FILE__), '../../etc', 'barcode_to_text_info.yml')
assert_equal(false, File.exist?(ODDB::TextInfoPlugin::Override_file), "File #{ODDB::TextInfoPlugin::Override_file} must not exist")
assert_equal(true, File.exist?(real_override_file), "File #{real_override_file} must exist")
real_overrides = YAML.load(File.read(real_override_file))
File.open(ODDB::TextInfoPlugin::Override_file, 'w+' ) do |out|
YAML.dump(old_missing, out)
end
assert_equal(5, File.readlines(ODDB::TextInfoPlugin::Override_file).size, 'File must be now 5 lines long, as one is too long')
old_time = File.ctime(ODDB::TextInfoPlugin::Override_file)
# Add tests that patinfo gets updated
@plugin.import_swissmedicinfo(@options)

puts @plugin.report
assert(@plugin.iksnrs_meta_info.keys.find_all{|key| key[1] == 'pi'}.size > 0, 'must find at least one find patinfo')
assert_equal(Nr_FI_in_AIPS_test, @plugin.iksnrs_meta_info.keys.find_all{|key| key[1] == 'fi'}.size, 'must find fachinfo')
assert_equal(Nr_PI_in_AIPS_test, @plugin.iksnrs_meta_info.keys.find_all{|key| key[1] == 'pi'}.size, 'may not find patinfo')
assert_equal(Nr_PI_in_AIPS_test , @plugin.updated_pis.size, 'nr updated pis must match')
assert_equal(Nr_PI_in_AIPS_test, @plugin.corrected_pis.size, "nr corrected_pis must match")

new_time = File.ctime(ODDB::TextInfoPlugin::Override_file)
assert(new_time > old_time, "ctime of #{ODDB::TextInfoPlugin::Override_file} should have changed")
assert_equal(4, File.readlines(ODDB::TextInfoPlugin::Override_file).size, 'File must be now 4 lines long')
assert_equal(0, @plugin.corrected_fis.size, 'nr corrected_fis must match')
assert_equal(0, @plugin.updated_fis.size, 'nr updated fis must match')
assert_equal(0, @plugin.up_to_date_fis, 'up_to_date_fis must match')
Expand Down
7 changes: 3 additions & 4 deletions test/test_plugin/text_info_swissmedicinfo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -488,10 +488,9 @@ def test_import_patinfo_tramal_43788
replace_constant('ODDB::RefdataPlugin::REFDATA_SERVER', @server) do
assert(@plugin.import_swissmedicinfo(@opts), 'must be able to run import_swissmedicinfo')
end
[ @plugin.problematic_fi_pi, @plugin.missing_override_file].each do |filename|
assert(File.exist?(filename))
# assert(File.size(filename) > 100, "#{filename} must be longer than 100 chars, but is only #{File.size(filename)}")
end
assert(File.exist?(@plugin.problematic_fi_pi), "Datei #{ @plugin.problematic_fi_pi} must exist")
path = File.join(File.dirname(__FILE__), '../../doc/resources/images/pi/de/43788Tramal_Tropfen__L_sung_zum_Einnehmen_files/1.png')
assert(File.exist?(path), "Created image file #{path} must exist")
@app.registration('15219').packages.size
@app.registration('15219').packages.values.find_all { |x| x.patinfo}
@app.registration('15219').sequences.values.find_all { |x| x.patinfo}
Expand Down

0 comments on commit a8f6e9b

Please sign in to comment.