view · edit · sidebar · attach · print · history

20110111-debug-bsv_xml-testcase

<< | Index | >>


  1. Make a test-case update_preparation__update_only_sb_flag
  2. Discussion with Davatz-san
  3. Update package updating process
  4. Registration number, Swissmedic Registration, Pharmacode, SwissmedicNo5, SwissmedicNo8, Sequence number, Package number, EAN Code
  5. Resolve Limitation problem

Goal
  • Test-case bsv_xml.rb / 100%
Milestones
  1. Update
Summary
Commits
ToDo Tomorrow
Keep in Mind
  1. Limitation Ticket 248
  2. swissmedic_followers debug
  3. On Ice
  4. emerge --sync

Make a test-case update_preparation__update_only_sb_flag

Confirm the current test passing

test/test_plugin/bsv_xml.rb

    def test_update_preparation__update_only_SB_flag
      # prepare the same entry with load data, @src
      package = setup_package :pharmacode => "987654",
                              :steps => %w{39271 02 028},
                              :price_public => Util::Money.new(2.9),
                              :price_exfactory => Util::Money.new(7.5)
      #                        :generic_type => :original,
      #                        :index_therapeuticus => '07.10.10.' 

      package.should_receive(:deductible).and_return(:deductible_g)
      reg = setup_registration :iksnr => '39271', :package => package
      reg.should_receive(:packages).and_return []
      package.should_receive(:registration).and_return reg
      flexmock(Package).should_receive(:find_by_pharmacode).
                        times(1).and_return nil
      setup_meddata_server :ean13 => '7680392710281'
      @app.should_receive(:registration).and_return reg
      @app.should_receive(:each_package)
      expected_updates = {}
      ptr = Persistence::Pointer.new [:registration, '39271']
      expected_updates.store ptr, { :generic_type => :original,
                              :index_therapeuticus => '07.10.10.'}

#      expected_updates.store ptr, {}
      expected_pointer = ptr
#      ptr += [:sequence, '02']
#      pac_pointer = ptr += [:package, '028']
      @app.should_receive(:update).and_return do |pointer, update_data|
        assert_equal expected_pointer, pointer
        assert_equal expected_updates[pointer], update_data
      end
      @plugin.update_preparations StringIO.new(@sb_flag_src)
end
masa@masa ~/ywesee/oddb.org $ ruby test/test_plugin/bsv_xml.rb 
Loaded suite test/test_plugin/bsv_xml
Started
"getin in tag_end#Pack"
.
Finished in 0.029834 seconds.

1 tests, 3 assertions, 0 failures, 0 errors

Notes

  • It is not finished
  • 'expected_update' should be [:deductible => :deductible_g]

Experiment

test/test_plugin/bsv_xml.rb

    def test_update_preparation__update_only_SB_flag
      # prepare the same entry with load data, @src
      ## set up an package instance in the cache (@app)
      price_exfactory = Util::Money.new(2.9, 'exfactory', 'CH')
      price_exfactory.mutation_code="NORMAL"
      price_exfactory.origin=
          "http://bag.e-mediat.net/SL2007.Web.External/File.axd?file=XMLPublications.zip (11.01.2011)"
      price_exfactory.valid_from = Time.local(2006,8,1)
      price_exfactory.authority = :sl
      price_public = Util::Money.new(7.5, 'public', 'CH')
      price_public.mutation_code="NORMAL"
      price_public.origin=
          "http://bag.e-mediat.net/SL2007.Web.External/File.axd?file=XMLPublications.zip (11.01.2011)"
      price_public.valid_from = Time.local(2006,8,1)
      price_public.authority = :sl

      #package = setup_package :pharmacode => "987654",
      package = setup_package :pharmacode => "703279",
                              :steps => %w{39271 02 028},
                              :price_public => price_public,
                              :price_exfactory => price_exfactory
                              #:sl_generic_type => :original,

      package.should_receive(:deductible).and_return(:deductible_o)

      package.should_receive(:deductible).and_return(:deductible_o)
      ## set up an registration on the cache
      reg = setup_registration :iksnr => '39271', :package => package,
                              :generic_type => :original,
                              :index_therapeuticus => '07.10.10.',

      reg.should_receive(:packages).and_return []
      reg.should_receive(:sequence).and_return do
        flexmock('seq') do |seq|
          seq.should_receive(:package)
        end
      end
      package.should_receive(:registration).and_return reg
      flexmock(Package).should_receive(:find_by_pharmacode).
                        times(1).and_return nil
                        #times(1).and_return package
      setup_meddata_server :ean13 => '7680392710281'
      ## set the registration to the cache
      @app.should_receive(:registration).and_return reg
      @app.should_receive(:each_package)
      ## preparation of expected result
      expected_updates = {}
      ptr = Persistence::Pointer.new [:registration, '39271']
      reg_pointer = ptr
      seq_pointer = ptr += [:sequence, '02']
      pac_pointer = ptr += [:package, '028']

      expected_pointer = pac_pointer
      expected_updates.store ptr, {
            :sl_generic_type => :original,
            :pharmacode => "703279",
            :narcotic => false,
            :deductible => :deductible_g,
            :price_public => price_public,
            :price_exfactory => price_exfactory
      }

counter = 0
      @app.should_receive(:update).and_return do |pointer, update_data|
counter += 1
print "counter=", counter, "\n"
        if counter == 1 # update sequence
          assert_equal seq_pointer, pointer
          assert_equal({:atc_class=>"M01AG01"}, update_data)
        elsif counter == 2 # update package
          assert_equal expected_pointer, pointer
          assert_equal expected_updates[pointer], update_data
        elsif counter == 3 # update registration
          assert_equal reg_pointer, pointer
          assert_equal({:index_therapeuticus=>"07.10.10.", :generic_type=>:original}, update_data)
        end
      end
      @plugin.update_preparations StringIO.new(@sb_flag_src)

Result

masa@masa ~/ywesee/oddb.org $ ruby test/test_plugin/bsv_xml.rb 
Loaded suite test/test_plugin/bsv_xml
Started
counter=1
counter=2
counter=3
.
Finished in 0.032388 seconds.

1 tests, 7 assertions, 0 failures, 0 errors

Note

  • This means '@app.update' method is called 3 times in total
  • I should make it only once for the updating part

Consideration

  • The updating part is called in the following condition
    • @pack != nil && (@conflict==true || @deplicate_iksnr==true)
    • This means that @package instance is already in the cache, and confliction or deplication happens
  • The 'conflication' is
    • if !@pcode.empty? && @pack && @pack.pharmacode && @pack.pharmacode != @pcode
    • This case is that the pharmacode is different between in the cache and in loaded xml file
  • '@duplicate_iksnr' becomes true when 'iksnr' is duplicated in Preparation.xml
    • 'iksnr' is the number of 'SwissmedicNo5' in Preparation.xml
    • 'iksnr' is the 'registration' number
  • Usually if there is no updated information for a package, '@app.update @pack.pointer, @data, :bag' rans
  • then 'SB' flag should be also updated
  • but this time '@app.update @pack.pointer, @data, :bag' dose not run

Next

  • I have to check the @pack and @conflict and @duplicate_iksnr condition

Discussion with Davatz-san

Reference

  • Ticket#250
  • The package data comes from both BAG (xml, update_bsv) and meddata
  • The pharmacodes are (probably) originally from meddata
  • In the current source code (update_bsv), if there is pharmacode 'conflict' the package is not updated
  • The 'conflict' means that the pharmacode in the cache is different from the one in Preparations.xml
  • Actuall, the pharmacode is '0'(nil) in the cache
  • That is why the update does not run

Next

  • If the pharmacode in the cache is '0' or nil, the pharmacode is updated from the Preparations.xml

Update package updating process

src/plugin/bsv_xml.rb#tag_end

            if !@pcode.empty? && @pack && @pack.pharmacode \
              && @pack.pharmacode != @pcode && @pack.pharmacode.to_i != 0
              @report.store :pharmacode_oddb, @pack.pharmacode
              @conflict = true
            end

Note

  • If the pharmacode in the cache is '0', then @conflict flag does not become true
    • This means 'conflict' of pharmacode does not happen
    • We expect the update procedure runs as usual in this case
  • Also I do not have to create a new test-case

Check test-cases

masa@masa ~/ywesee/oddb.org $ ruby test/test_plugin/bsv_xml.rb 
Loaded suite test/test_plugin/bsv_xml
Started
.........
Finished in 0.144679 seconds.

9 tests, 71 assertions, 0 failures, 0 errors

Note

  • Good

Run

  • oddbd
  • currencyd
  • meddatad

Run update_bsv (with the latest XMLPublications.zip)

masa@masa ~/ywesee/oddb.org $ bin/admin
ch.oddb> Updater.new(self).update_bsv

Result

Created SL-Entries                                           92
Updated SL-Entries                                         8364
Deleted SL-Entries                                            6
Created Limitation-Texts                                     16
Updated Limitation-Texts                                   1286
Deleted Limitation-Texts                                      0

Duplicate Registrations in SL 11.01.2011                      0
Package-Data was completed from SL                            0
SMeX/SL-Differences (Registrations) 11.01.2011                0
Critical Pharmacodes BAG-XML 11.01.2011                      26
Missing Swissmedic-Codes in SL 11.01.2011                     0
Missing Pharmacodes in SL 11.01.2011                        268
Missing Swissmedic-Codes in SL (out of trade) 11.01.2011     37
Unknown Packages in SL 11.01.2011                            29
Unknown Registrations in SL 11.01.2011                        1
Unknown Packages in SL (out of trade) 11.01.2011             92
Packungen in der ODDB Total: 23259
Packungen ohne Pharmacode: 8625
- ausser Handel: 7790
- inaktive Registration: 671
- noch nicht auf MedWin: 164

Before

After

Commit

Registration number, Swissmedic Registration, Pharmacode, SwissmedicNo5, SwissmedicNo8, Sequence number, Package number, EAN Code

  • Each drug package is identified by Pharmacode (7 digits) or SwissmedicNo8 (8 digits) or EAN Code (13 digits)
  • It means Pharmacode and SiwssmedicNo8 and EAN Code are unique numbers
  • EAN Code can be calculated from SwissmedicNo8 but Pharmacode is independent from the other numbers
  • EAN Code = 7680 (Swiss code) + SwissmedicNo8 + Checkdigit (1 digit)
  • Refer to
  • 'Registration number' is used as 'Swissmedic Registration' on website of ch.oddb.org and used as 'iksnr' in the source code, and used as 'SwissmedicNo5' in Preparations.xml
  • 'Registration' data is written in 'Preparation' tag in Preparation.xml, but the data 'Preparation' is NOT exactly corresponding to 'Registration' data
    • because there is no 'Sequence' layer in the Preparation.xml
  • The first 5 digits of 'SwissmedicNo8' is the same to 'SwissmedicNo5'
  • The last 3 digits of 'SwissmedicNo8' is used to identify a package, which is also used as 'ikscd' in the source code, which data is written in 'Pack' tag of Preparations.xml
  • 'SwissmedicNo8' is provided by the government but 'Pharmacode' is provided by a private company (meddata)
  • The 2 digit between 'SwissmedicNo5' and package number in 'SwissmedicNo8' is used to identify a sequence (sequence number), which is used as 'seqnr' in the source code
  • The hierarchy is as follows
    • Registration number (5 digits) - Sequence number (2 digits) - Package number (3 digits)

Resolve Limitation problem

Reference

Notes

  • There is a pharmacode in Preparation.xml for the Package data in Ticket#248
  • Usually the limitation flag and SB flag and Kat. information are update in 'swissmedic_folowers' job
  • 'swissmedic_followers' compares the drug data with meddata
  • But if there is no package data in meddata, the flags are not updated

Check the package by the following website (for example, 'Thallous chloride')

Resolve

  • We should run 'update_bsv' with the commit today and correct the Pharmacode
  • This does the comparison the Pharmacodes between the cache and the Preparations.xml, and correct it if the Pharmacode is '0' in the cache
  • Delete XMLPublications-latest.zip online
  • Run update_bsv online

Result

view · edit · sidebar · attach · print · history
Page last modified on January 11, 2011, at 04:52 PM