From 43ec5fb7fb3eefc8bd6b6912ea63a486d6c2e889 Mon Sep 17 00:00:00 2001 From: Niklaus Giger Date: Wed, 21 Feb 2024 16:28:51 +0100 Subject: [PATCH 1/3] (#250) Remove obsolete update_btm --- jobs/update_narcotics | 16 --------- src/plugin/narcotic.rb | 65 ------------------------------------ src/util/updater.rb | 4 --- test/test_plugin/narcotic.rb | 32 ------------------ 4 files changed, 117 deletions(-) delete mode 100755 jobs/update_narcotics delete mode 100644 src/plugin/narcotic.rb delete mode 100755 test/test_plugin/narcotic.rb diff --git a/jobs/update_narcotics b/jobs/update_narcotics deleted file mode 100755 index 0f1104696..000000000 --- a/jobs/update_narcotics +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/local/bin/ruby-271 -# must be scheduled in crontab to run as the same user as oddb - -$: << File.expand_path('../src', File.dirname(__FILE__)) -$: << File.expand_path('..', File.dirname(__FILE__)) - -require 'util/job' -require 'util/updater' - -module ODDB - module Util - Job.run do |system| - Updater.new(system).update_btm ARGV.first - end - end -end diff --git a/src/plugin/narcotic.rb b/src/plugin/narcotic.rb deleted file mode 100644 index f3417463f..000000000 --- a/src/plugin/narcotic.rb +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/env ruby -# encoding: utf-8 -# ODDB::NarcoticPlugin -- oddb.org -- 19.01.2012 -- mhatakeyama@ywesee.com -# ODDB::NarcoticPlugin -- oddb.org -- 03.11.2005 -- ffricker@ywesee.com - -$: << File.expand_path('../../src', File.dirname(__FILE__)) - -require 'plugin/plugin' -require 'model/package' -require 'spreadsheet' - -module ODDB - class NarcoticPlugin < Plugin - MEDDATA_SERVER = DRbObject.new(nil, MEDDATA_URI) - def initialize(app) - super(app) - end - def report - [ - "Updated packages Narcotic flag(true): #{@update_bm_flag}", - "Updated packages Category(A+): #{@update_ikscat}", - ].join("\n") - end - def update_from_xls(path, lang='de') - if File.exist?(path) - @update_bm_flag = 0 - @update_ikscat = 0 - workbook = Spreadsheet.open(path) - workbook.worksheet(0).each do |row| - iksnr = ikscd = ikscat = nil - if row[5] and items = row[5].split(/\s/) - iksnr = items[2] - ikscd = items[3] - end - if reg = @app.registration(iksnr) and pac = reg.package(ikscd) - # update package - values = {} - unless pac.bm_flag - values.store(:bm_flag, true) - @update_bm_flag += 1 - end - if row[8] == 'A+' and ikscat = row[8] and pac.ikscat != ikscat - values.store(:ikscat, ikscat) - @update_ikscat += 1 - end - @app.update(pac.pointer, values, :narcotic) - - # update narcotics - values = { - :ikskey => iksnr + ikscd, - :package => pac - } - values.store(lang.to_sym, pac.name_base) - pointer = if narc = @app.narcotic_by_ikskey(pac.ikskey) - narc.pointer - else - Persistence::Pointer.new(:narcotic).creator - end - @app.update(pointer, values, :swissmedic) - end - end - end - end - end -end diff --git a/src/util/updater.rb b/src/util/updater.rb index fa9800208..641a12fe5 100644 --- a/src/util/updater.rb +++ b/src/util/updater.rb @@ -18,7 +18,6 @@ require 'plugin/epha_interactions' require 'plugin/lppv' require 'plugin/medical_products' -require 'plugin/narcotic' require 'plugin/ouwerkerk' require 'plugin/rss' require 'plugin/swissmedic' @@ -367,9 +366,6 @@ def update_recall_feed(month = @@today) def update_hpc_feed(month = @@today) update_immediate_with_error_report(RssPlugin, 'hpc.rss', :update_hpc_feed) end - def update_btm(path) - update_notify_simple(NarcoticPlugin, 'Narcotics (XLS)', :update_from_xls, [path]) - end def update_swissmedic(*args) logs_pointer = Persistence::Pointer.new([:log_group, :swissmedic]) logs = @app.create(logs_pointer) diff --git a/test/test_plugin/narcotic.rb b/test/test_plugin/narcotic.rb deleted file mode 100755 index ac75c7ca6..000000000 --- a/test/test_plugin/narcotic.rb +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env ruby -# encoding: utf-8 -# ODDB::TestNarcoticPlugin -- oddb.org -- 19.01.2012 -- mhatakeyama@ywesee.com -# ODDB::TestNarcoticPlugin -- oddb.org -- 03.11.2005 -- ffricker@ywesee.com - -$: << File.expand_path('../../src', File.dirname(__FILE__)) -$: << File.expand_path('..', File.dirname(__FILE__)) - - - -require 'minitest/autorun' -require 'plugin/narcotic' -require 'flexmock/minitest' - - -module ODDB - class TestNarcoticPlugin Date: Wed, 21 Feb 2024 16:51:05 +0100 Subject: [PATCH 2/3] (#250) BSV: Fix updating iksnr smaller 6 digits --- src/plugin/bsv_xml.rb | 19 ++++-- test/data/xml/hepatec.xml | 131 ++++++++++++++++++++++++++++++++++++ test/test_plugin/bsv_xml.rb | 71 ++++++++----------- 3 files changed, 172 insertions(+), 49 deletions(-) create mode 100644 test/data/xml/hepatec.xml diff --git a/src/plugin/bsv_xml.rb b/src/plugin/bsv_xml.rb index cc404379e..87c94e675 100644 --- a/src/plugin/bsv_xml.rb +++ b/src/plugin/bsv_xml.rb @@ -353,13 +353,17 @@ def tag_end name }) elsif @pack && !@duplicate_iksnr ## don't take the Swissmedic-Category unless it's missing in the DB + ## IKS Cat kommt von der Swissmedic Packungen Datei @data.delete :ikscat if @pack.ikscat + @data.delete :narcotic # Der Narcotics Flag kommt von der Swissmedic Packungen Datei, Spalte X. if !@price_exfactory.to_s.eql?(@pack.price_exfactory.to_s) || !@pexf_change_code.eql?(@pack.price_exfactory.mutation_code) LogFile.debug "#{@iksnr} #{@pack.seqnr} #{@ikscd}: #{@price_exfactory.valid_from.to_date} set price_exfactory #{@pack.price_exfactory} now #{@price_exfactory}. #{@pack.price_exfactory&.mutation_code} now #{@pexf_change_code}" @pack.price_exfactory = @price_exfactory @pack.price_exfactory.mutation_code = @pexf_change_code @pack.price_exfactory.valid_from = @price_exfactory.valid_from @data.store :price_exfactory, @price_exfactory + else + @data.delete :price_exfactory end if @price_exfactory if !@price_public.to_s.eql?(@pack.price_public.to_s) || !@ppub_change_code.eql?(@pack.price_public.mutation_code) LogFile.debug "#{@iksnr} #{@pack.seqnr} #{@ikscd}: #{@price_public.valid_from.to_date} set price_public #{@pack.price_public} now #{@price_public}. #{@pack.price_public&.mutation_code} now #{@ppub_change_code}" @@ -367,11 +371,11 @@ def tag_end name @pack.price_public.valid_from = @price_public.valid_from @pack.price_public.mutation_code = @ppub_change_code @data.store :price_public, @price_public + else + @data.delete :price_public end if @price_public - @data.delete(:sl_generic_type) if @pack.generic_type.eql?(@data[:sl_generic_type]) - @data.delete(:deductible) if @pack.deductible.eql?(@data[:deductible]) - @data.delete(:ikscat) if @pack.registration.ikscat.eql?(@data[:ikscat]) - @data.delete(:narcotic) if @pack.narcotic?.eql?(@data[:narcotic]) + @pack.deductible.eql?(@data[:deductible]) ? @data.delete(:deductible) : @pack.deductible = @data[:deductible] + @pack.sl_generic_type.eql?(@data[:sl_generic_type]) ? @data.delete(:sl_generic_type) : @pack.sl_generic_type = @data[:sl_generic_type] if @data.keys.size > 0 @app.update @pack.pointer, @data, :bag end @@ -528,7 +532,7 @@ def tag_end name end if @registration @ikscd = '%03i' % @text[-3,3].to_i - @pack ||= @app.package_by_ikskey(@text) + @pack ||= @app.package_by_ikskey(sprintf('%08i', @text.to_i)) @out_of_trade = @pack.out_of_trade if @pack if !@pack.nil? && @pack.pointer.nil? @pack.fix_pointers @@ -721,16 +725,19 @@ def fix_flags_with_rss_logic first = Time.local(cutoff.year, cutoff.month, cutoff.day) last = Time.local(today.year, today.month, today.day) range = first..last - if (current = @price) && range.cover?(current.valid_from) && !@pack.nil? + if (current = @price_public) && range.cover?(current.valid_from) && !@pack.nil? previous = @pack.price_public if previous.nil? if current.authority == :sl + LogFile.debug("fix_flags_with_rss_logic #{@iksnr} sl_entry") flag_change @pack.pointer, :sl_entry end elsif [:sl, :lppv, :bag].include?(@pack.data_origin(:price_public)) if previous > current + LogFile.debug("fix_flags_with_rss_logic #{@iksnr} price_cut") flag_change @pack.pointer, :price_cut elsif current > previous + LogFile.debug("fix_flags_with_rss_logic #{@iksnr} price_rise") flag_change @pack.pointer, :price_rise end end diff --git a/test/data/xml/hepatec.xml b/test/data/xml/hepatec.xml new file mode 100644 index 000000000..e3348b497 --- /dev/null +++ b/test/data/xml/hepatec.xml @@ -0,0 +1,131 @@ + + + + Hepatect CP + Hepatect CP + Hepatect CP + Inj Lös 500 E/10ml + sol inj 500 U/10ml + Inj Lös 500 E/10ml + J06BB04 + Y + + N + N + + + + N + 1165 + Hepatect Parenteral + + + + Amp 10 ml + amp 10 ml + Amp 10 ml + B + 488001 + + N + Y + N + 16710 + 7680004880018 + + + + + + + 415.25 + 01.01.2024 + + PPUB + Publikumspreis + Prix public + Prix public + MWSTAENDERUNG + MwSt-Änderung + MwSt-Änderung + MwSt-Änderung + + + 347.09 + 01.12.2022 + + PEXF + Ex-Factory Preis + Prix ex-factory + Prix ex-factory + 3JUEBERPRUEF + Preisänderung nach 3-jährlicher Überprüfung der Aufnahmebedingungen + Réduction de prix à cause du réexamen des conditions d’admission tous les trois ans + Preisänderung nach 3-jährlicher Überprüfung der Aufnahmebedingungen + 01.12.2022 + + + + + V + Biotest (Schweiz) AG + Schützenstrasse 17 + 5102 + Rupperswil + +41628890000 + + + + 15.03.1997 + 15.03.1997 + 31.12.9999 + 0 + Initialzustand + N + + + + + + Immunoglobulinum humanum hepatitidis B + 500 + UI + + + + + EXPO TRANSPL + DIA + P + + Bei Exposition und bei Transplantationen. + En cas d'exposition et de transplantations. + In caso di esposizione e di trapianti. + 01.01.2007 + 31.12.9999 + + + + + INFEKTIONSKRANKHEITEN + MALADIES INFECTIEUSES + MALATTIE INFETTIVE  + + + + Immuno-Globuline ex Plasma humano + Immuno-Globuline ex Plasma humano + Immunoglobuline umane  + + + + + 15.03.1997 + 15.03.1997 + 31.12.9999 + 0 + Initialzustand + N + + + diff --git a/test/test_plugin/bsv_xml.rb b/test/test_plugin/bsv_xml.rb index 930ef2368..3c067a079 100755 --- a/test/test_plugin/bsv_xml.rb +++ b/test/test_plugin/bsv_xml.rb @@ -21,7 +21,6 @@ require 'ext/refdata/src/refdata' require 'test_helpers' -RUN_ALL = true module ODDB class PackageCommon end @@ -83,7 +82,7 @@ def test_update_chapter expected = ["hello", "\n", "<", "h>hello", "<", "/h>"] assert_equal(expected, paragraph) end - end if RUN_ALL + end class TestGenericsListener nil, :price_exfactory => 2} @listener.instance_eval('@pack = package') @@ -671,7 +672,7 @@ def test_tag_end__error @listener.tag_end('Preparations') end end - end if RUN_ALL + end class TestBsvXmlPlugin2 'Ponstan'}).and_return seq pack_ptr = (reg.pointer + [:package, '028']).creator @app.should_receive(:update).once.with(reg.pointer, {}).and_return reg -# @app.should_receive(:update).once.with(pack_ptr, {:sl_generic_type=>:original, :deductible=>:deductible_g, :ikscat=>"B", :narcotic=>false, :price_exfactory=>2.90, :price_public=>7.50}).and_return true @app.should_receive(:update).once @app.should_receive(:update) do | arg1 | assert(false) end composition = flexmock 'composition' @@ -1384,7 +1383,6 @@ def test_update_preparation__unknown_package # assert_equal({}, expected_updates) assert_equal expected[0], listener.unknown_packages[2] end - end def test_update_preparation__conflicted_package package = setup_package :pharmacode => "987654", :steps => %w{39271 02 028}, @@ -1443,7 +1441,6 @@ def test_update_preparation__conflicted_package assert_equal [], listener.unknown_registrations assert_equal [], listener.conflicted_registrations end - if RUN_ALL def test_update_preparation reg = setup_registration :iksnr => '39271' reg.should_receive(:packages).and_return [] @@ -1510,7 +1507,6 @@ def test_update_preparation puts "Line #{__LINE__}: Don't know why we should have a price_cut here and were it should come from" skip { assert_equal({pac_pointer => [:price_cut]}, @plugin.change_flags) } end - end def setup_package opts={} pack = flexmock('package_1', opts) atc_class = flexmock('atc_class_1') do |atc_class| @@ -1642,6 +1638,8 @@ def test_nasonex_exfactory_price @myPackage.price_exfactory.valid_from = Time.new(2024,1,1) @myPackage.price_exfactory.origin = "Dummy-01-01-2024.xls" @myPackage.price_exfactory.type = "exfactory" + @myPackage.deductible = :deductible_o; + @myPackage.ikscat = 'MustNotBeOverwritten'; # See https://github.com/zdavatz/oddb.org/issues/240#issuecomment-1932371433 # we must correct this false price @@ -1661,6 +1659,10 @@ def test_nasonex_exfactory_price @plugin.update_preparations File.open(@test_file) seqs = @plugin.preparations_listener.test_sequences nasonex = seqs.first.packages.values.first + assert_equal(:original, nasonex.sl_generic_type) + assert_equal(nil, nasonex.bm_flag) + assert_equal('MustNotBeOverwritten', nasonex.ikscat) + assert_equal(:deductible_g, nasonex.deductible) assert_equal('18.0', nasonex.price_public.amount.to_s) assert_equal('8.5', nasonex.price_exfactory.amount.to_s) assert_equal(true, nasonex.has_price_history?, 'nasonex must have a price_history') @@ -1671,55 +1673,39 @@ def test_nasonex_exfactory_price assert_equal(1, nasonex.oid) end - # This is test where the old prices and field like deductible are already correct - def test_nasonex_no_price_changes - setup_read_from_file('nasonex_2024', '54189', '02', '036') + # This is test where we have a swissmedicn08 shorter than 8 digits + def test_hepatec + setup_read_from_file('hepatec', '00488', '01', '001') originUrl22 = "Dummy-31-01-2022.xls" @myReg.generic_type = :original @myReg.index_therapeuticus = "12.02.30." @myReg.ikscat = 'B' @myPackage.bm_flag = false # narcotic @myPackage.deductible = :deductible_g - @myPackage.price_public = Util::Money.new(18.0033, @price_type, 'CH') - assert_equal('18.00', @myPackage.price_public.to_s) - assert_equal('18.0033', @myPackage.price_public.amount.to_s) - @myPackage.price_public.valid_from = Time.new(2024,1,1) - @myPackage.price_public.origin = originUrl22 - @myPackage.price_public.mutation_code = 'FREIWILLIGEPS' - @myPackage.price_public.type = "public" + @myPackage.prices[:public] = [] + @myPackage.prices[:exfactory ] = [] - @myPackage.price_exfactory = Util::Money.new(8.5, @price_type, 'CH') - @myPackage.price_exfactory.valid_from = Time.new(2024,1,1) - @myPackage.price_exfactory.origin = originUrl22 - @myPackage.price_exfactory.mutation_code = 'FREIWILLIGEPS' - @myPackage.price_exfactory.type = "exfactory" - - @myPackage.price_public @app.should_receive(:each_package).and_return([@myPackage]) - @app.should_receive(:package_by_ikskey).and_return @myPackage + @app.should_receive(:package_by_ikskey).with('00488001').and_return @myPackage @myPackage.pointer= 'pointer' @app.should_receive(:registration).and_return @myReg @app.should_receive(:update).at_least.once @app.should_receive(:create).with(nil).and_return(@composition) - assert_equal('2024-01-01 00:00:00 +0000', @myPackage.price_exfactory.valid_from.to_s) - assert_equal('2024-01-01 00:00:00 +0000', @myPackage.price_public.valid_from.to_s) @plugin.update_preparations File.open(@test_file) seqs = @plugin.preparations_listener.test_sequences - nasonex = seqs.first.packages.values.first - assert_equal('18.0033', nasonex.price_public.amount.to_s) - assert_equal('18.00', nasonex.price_public.to_s) - assert_equal('8.50', nasonex.price_exfactory.to_s) - assert_equal(false, nasonex.has_price_history?, 'nasonex may not have a price_history, as price already correct') - assert_equal('2024-01-01 00:00:00 +0000', nasonex.price_exfactory.valid_from.to_s) - assert_equal('2024-01-01 00:00:00 +0000', nasonex.price_public.valid_from.to_s) - assert_equal('FREIWILLIGEPS', nasonex.price_public.mutation_code, 'mutation_code for public price') - assert_equal('FREIWILLIGEPS', nasonex.price_exfactory.mutation_code, 'mutation_code for exfactory price') - assert_equal(1, nasonex.oid) + hepatec = seqs.first.packages.values.first + assert_equal('415.25', hepatec.price_public.amount.to_s) + assert_equal('347.09', hepatec.price_exfactory.to_s) + assert_equal(false, hepatec.has_price_history?, 'hepatec may not have a price_history, as price already correct') + assert_equal('2022-12-01 00:00:00 +0000', hepatec.price_exfactory.valid_from.to_s) + assert_equal('2024-01-01 00:00:00 +0000', hepatec.price_public.valid_from.to_s) + assert_equal('MWSTAENDERUNG', hepatec.price_public.mutation_code, 'mutation_code for public price') + assert_equal('3JUEBERPRUEF', hepatec.price_exfactory.mutation_code, 'mutation_code for exfactory price') end # This is test where we have an old price and a new one with a different VAT def test_amlodipin_with_new_vat - setup_read_from_file('Amlodipin_MwSt', '54189', '02', '036') + setup_read_from_file('Amlodipin_MwSt', '66015', '01', '011') @myPackage.price_exfactory = Util::Money.new(36.71, @price_type, 'CH') @myPackage.price_exfactory.valid_from = Time.new(2020,12,1) @myPackage.price_exfactory.origin = "Dummy-01-12-2020.xls" @@ -1751,7 +1737,6 @@ def test_amlodipin_with_new_vat seqs = @plugin.preparations_listener.test_sequences amlodipin = seqs.first.packages.values.first assert_equal(true, amlodipin.has_price_history?, 'amlodipin must have a price_history') - assert_equal(true, amlodipin.has_price_history?) assert_equal('58.6', amlodipin.price_public.amount.to_s) assert_equal('36.71', amlodipin.price_exfactory.amount.to_s) assert_equal('MWSTAENDERUNG', amlodipin.price_public.mutation_code, 'mutation_code for public price') From a2c3e4f8beb9133e0aa5d977871939f666b9660f Mon Sep 17 00:00:00 2001 From: Niklaus Giger Date: Thu, 22 Feb 2024 09:50:11 +0100 Subject: [PATCH 3/3] (#250) Cleanup price compare --- src/plugin/bsv_xml.rb | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/plugin/bsv_xml.rb b/src/plugin/bsv_xml.rb index 87c94e675..31c9ce26e 100644 --- a/src/plugin/bsv_xml.rb +++ b/src/plugin/bsv_xml.rb @@ -316,10 +316,10 @@ def tag_start name, attrs @valid_from = nil @ppub_change_code = nil @price = nil - @price_type = :public @price_public = Util::Money.new(0, :public, 'CH') @price_public.origin = @origin @price_public.authority = :sl + @price_type = :public when 'Limitation' @in_limitation = true when 'ItCode' @@ -361,18 +361,12 @@ def tag_end name @pack.price_exfactory = @price_exfactory @pack.price_exfactory.mutation_code = @pexf_change_code @pack.price_exfactory.valid_from = @price_exfactory.valid_from - @data.store :price_exfactory, @price_exfactory - else - @data.delete :price_exfactory end if @price_exfactory if !@price_public.to_s.eql?(@pack.price_public.to_s) || !@ppub_change_code.eql?(@pack.price_public.mutation_code) LogFile.debug "#{@iksnr} #{@pack.seqnr} #{@ikscd}: #{@price_public.valid_from.to_date} set price_public #{@pack.price_public} now #{@price_public}. #{@pack.price_public&.mutation_code} now #{@ppub_change_code}" @pack.price_public = @price_public @pack.price_public.valid_from = @price_public.valid_from @pack.price_public.mutation_code = @ppub_change_code - @data.store :price_public, @price_public - else - @data.delete :price_public end if @price_public @pack.deductible.eql?(@data[:deductible]) ? @data.delete(:deductible) : @pack.deductible = @data[:deductible] @pack.sl_generic_type.eql?(@data[:sl_generic_type]) ? @data.delete(:sl_generic_type) : @pack.sl_generic_type = @data[:sl_generic_type] @@ -562,19 +556,17 @@ def tag_end name @sl_data.store :bsv_dossier, @text if @sl_data when 'LastPriceChange' # just ignore when 'ExFactoryPrice' - @price_exfactory = Util::Money.new(@price_amount, @price_type, 'CH') + @price_exfactory = Util::Money.new(@price_amount, :exfactory, 'CH') @price_exfactory.origin = @origin @price_exfactory.authority = :sl @price_exfactory.mutation_code = @pexf_change_code @price_exfactory.valid_from = @valid_from - @data.store :"price_#{@price_type}", @price_exfactory when 'PublicPrice' - @price_public = Util::Money.new(@price_amount, @price_type, 'CH') + @price_public = Util::Money.new(@price_amount, :public, 'CH') @price_public.origin = @origin @price_public.authority = :sl @price_public.mutation_code = @ppub_change_code @price_public.valid_from = @valid_from - @data.store :"price_#{@price_type}", @price_public when 'Price' @price_amount = @text when 'ValidFromDate'