<< Masa.20100909-job-import_gkv | 2010 | Masa.20100907-install-ruby >>
masa@masa /etc/portage $ sudo eselect ruby set ruby19 Passwort: !!! Error: Can't use that profile. No suitable Ruby interpreter found. exiting
I did it but got some warning about gem.
masa@masa ~/work/de.oddb.org $ sudo eselect ruby set ruby1.9 Passwort: !!! Warning: Could not set gem symlink It appears you do not have RubyGems installed for this profile. If you need RubyGems, emerge dev-ruby/rubygems with the appropriate RUBY_TARGETS setting. Successfully switched to profile: ruby1.9 masa@masa ~/work/de.oddb.org $ sudo eselect ruby set ruby18 Successfully switched to profile: ruby18
def save(obj) obj.save @system.invalidate obj.uid p @system.invalidate.size end
Confirm failure
masa@masa ~/work/de.oddb.org $ ruby test/import/test_gkv.rb Loaded suite test/import/test_gkv Started F Finished in 0.019584 seconds. 1) Failure: test_import(ODDB::Import::TestGkv) [test/import/test_gkv.rb:115]: <1> expected but was <3>. 1 tests, 3 assertions, 1 failures, 0 errors
def simulate_import handler = GkvHandler.new @import.method(:process_page) File.read(@path).each do |line| handler.send_flowing_data line handler.send_line_break end handler.send_page @import.postprocess @import.report end
Comment
/home/masa/work/de.oddb.org/test/import/data/txt/gkv/gkv_p1.txt
Zuzahlungsbefreite Arzneimittel nach § 31 Abs. 3 Satz 4 SGB V sortiert nach Arzneimittelname Produktstand 01.09.2009 gröĂ<9f>e inkl.MwSt Wirkstoff(e) Wirkstärke Packungs-)n( Arzneimittelname PZN Hersteller Darreichungsform Apothekenverkaufspreis ABSEAMED 10000I.E./1ML 4000741 MEDICE ARZN.GMBH&CO.KG Epoetin alfa 10000 I.E. 6X1 ml Fertigspritzen 611,53 ABSEAMED 1000I.E./0.5ML 4000646 MEDICE ARZN.GMBH&CO.KG Epoetin alfa 1000 I.E. 6X0.5 ml Fertigspritzen 64,20 ABSEAMED 2000I.E./1ML 4000652 MEDICE ARZN.GMBH&CO.KG Epoetin alfa 2000 I.E. 6X1 ml Fertigspritzen 119,04 ABSEAMED 3000I.E./0.3ML 4000669 MEDICE ARZN.GMBH&CO.KG Epoetin alfa 3000 I.E. 6X0.3 ml Fertigspritzen 173,94 ABSEAMED 4000I.E./0.4ML 4000681 MEDICE ARZN.GMBH&CO.KG Epoetin alfa 4000 I.E. 6X0.4 ml Fertigspritzen 228,83 ABSEAMED 5000I.E./0.5ML 4000698 MEDICE ARZN.GMBH&CO.KG Epoetin alfa 5000 I.E. 6X0.5 ml Fertigspritzen 283,70 ABSEAMED 6000I.E./0.6ML 4000729 MEDICE ARZN.GMBH&CO.KG Epoetin alfa 6000 I.E. 6X0.6 ml Fertigspritzen 338,57 ABSEAMED 8000I.E./0.8ML 4000735 MEDICE ARZN.GMBH&CO.KG Epoetin alfa 8000 I.E. 6X0.8 ml Fertigspritzen 448,34 ACC 200 3867219 HEXAL AG Acetylcystein 200 mg 50 St Brausetabletten 12,74 ACC 200 3867225 HEXAL AG Acetylcystein 200 mg 100 St Brausetabletten 15,42 ACC 200 4789763 HEXAL AG Acetylcystein 200 mg 20 St Brausetabletten 11,01 Seite 1 von 1095
Check Drugs::Product.instances.size test/import/test_gkv.rb
def simulate_import p Drugs::Product.instances.size handler = GkvHandler.new @import.method(:process_page) File.read(@path).each do |line| handler.send_flowing_data line handler.send_line_break end p Drugs::Product.instances.size handler.send_page p Drugs::Product.instances.size @import.postprocess @import.report end def test_import existing = Drugs::Package.new existing.add_code(Util::Code.new(:cid, '4000741', 'DE')) existing.add_part(Drugs::Part.new) existing.save sequence = Drugs::Sequence.new product = Drugs::Product.new product.name.de = 'A product' existing.sequence = sequence p Drugs::Product.instances.size sequence.product = product p Drugs::Product.instances.size assert_nil(existing.code(:zuzahlungsbefreit)) puts ## simulate a call to @import.import report = simulate_import
Result
masa@masa ~/work/de.oddb.org $ ruby test/import/test_gkv.rb Loaded suite test/import/test_gkv Started 0 1 1 1 3 F Finished in 0.01983 seconds. 1) Failure: test_import(ODDB::Import::TestGkv) [test/import/test_gkv.rb:120]: <1> expected but was <3>. 1 tests, 3 assertions, 1 failures, 0 errors
This means
Hypothesis
Check commit that counts up Drugs::Product.instances in simulate_import method
From this commit 4adb046616d3cf37ac9644ad2cb26d6c29801a63 2009-09-07 Hannes Wyss Import unknown packages, even if data quality cannot.. simulate_import method counts up Drugs::Product.instances.size
Look at diff and added (+ green) lines carefully http://scm.ywesee.com/?p=de.oddb.org/.git;a=blobdiff;f=lib/oddb/import/gkv.rb;h=d14707b3f0f17937c3ee440a3d2e95eca3f994be;hp=9404dfec1eac950c7a03c0a5af7eef205e663937;hb=4adb046616d3cf37ac9644ad2cb26d6c29801a63;hpb=fc894bb1f561ffe9807cc5ad45bc39cef4f024e4
Check report
First commit 8da2441beead2c66bf2d8f887ce0100a00494c18 2009-09-04 Hannes Wyss Import Zuzahlungs-Befreiung from the GKV-PDF
"Imported 11 FB-Entries on 08.09.2010:", "Visited 0 existing FB-Entries", "Visited 0 existing Companies", "Visited 0 existing Substances", "Created 1 new FB-Entries", "Assigned 0 Companies", "Ignored 10 Unknown Packages"
Fail commit 4adb046616d3cf37ac9644ad2cb26d6c29801a63 2009-09-07 Hannes Wyss Import unknown packages, even if data quality cannot...
"Imported 11 Zubef-Entries on 08.09.2010:", "Visited 0 existing Zubef-Entries", "Visited 9 existing Companies", "Visited 9 existing Substances", "Created 11 new Zubef-Entries", "Created 2 new Products", "Created 10 new Sequences", "Created 2 new Companies", "Created 2 new Substances", "Assigned 0 Chemical Equivalences", "Assigned 0 Companies", "Created 1 Incomplete Packages:", "http://de.oddb.org/de/drugs/package/pzn/4789763"
Comment
Tag set
Check simulate_method carefully
first: lib/oddb/import/gkv.rb
def send_page p Drugs::Product.instances.size @callback.call @rows p Drugs::Product.instances.size
Result
masa@masa ~/work/de.oddb.org $ ruby test/import/test_gkv.rb Loaded suite test/import/test_gkv Started 1 1 . Finished in 0.002832 seconds. 1 tests, 1 assertions, 0 failures, 0 errors
fail: lib/oddb/import/gkv.rb
def send_page p Drugs::Product.instances.size @callback.call @rows p Drugs::Product.instances.size
Result
masa@masa ~/work/de.oddb.org $ ruby test/import/test_gkv.rb Loaded suite test/import/test_gkv Started 1 3 . Finished in 0.026326 seconds. 1 tests, 1 assertions, 0 failures, 0 errors
Consideration
def test p "w" end a = method(:test) a.call #=> "w"
Gkv#process_page
def process_page rows rows.each do |row| import_row row end end
Consideration
Gkv#send_line_break
def send_flowing_data(data) @current_line << data end def send_line_break data = @current_line.strip.split /\s{3,}/ if /^\d{6,}$/.match(data[1].to_s) ## ensure consistent row-length, so we can append additional substances # to the tail data[9] ||= nil @rows.push data else @rows.push :doubtful end reset end
def simulate_import
def simulate_import handler = GkvHandler.new @import.method(:process_page) File.read(@path).each do |line| handler.send_flowing_data line handler.send_line_break end handler.send_page
@rows (after send_flowing_data and send_line_break methods)
@rows.size=17 [:doubtful, :doubtful, :doubtful, :doubtful, :doubtful, ["ABSEAMED 10000I.E./1ML", "4000741", "MEDICE ARZN.GMBH&CO.KG", "Epoetin alfa", "10000", "I.E.", "6X1", "ml", "Fertigspritzen", "611,53"], ["ABSEAMED 1000I.E./0.5ML", "4000646", "MEDICE ARZN.GMBH&CO.KG", "Epoetin alfa", "1000", "I.E.", "6X0.5", "ml", "Fertigspritzen", "64,20"], ["ABSEAMED 2000I.E./1ML", "4000652", "MEDICE ARZN.GMBH&CO.KG", "Epoetin alfa", "2000", "I.E.", "6X1", "ml", "Fertigspritzen", "119,04"], ["ABSEAMED 3000I.E./0.3ML", "4000669", "MEDICE ARZN.GMBH&CO.KG", "Epoetin alfa", "3000", "I.E.", "6X0.3", "ml", "Fertigspritzen", "173,94"], ["ABSEAMED 4000I.E./0.4ML", "4000681", "MEDICE ARZN.GMBH&CO.KG", "Epoetin alfa", "4000", "I.E.", "6X0.4", "ml", "Fertigspritzen", "228,83"], ["ABSEAMED 5000I.E./0.5ML", "4000698", "MEDICE ARZN.GMBH&CO.KG", "Epoetin alfa", "5000", "I.E.", "6X0.5", "ml", "Fertigspritzen", "283,70"], ["ABSEAMED 6000I.E./0.6ML", "4000729", "MEDICE ARZN.GMBH&CO.KG", "Epoetin alfa", "6000", "I.E.", "6X0.6", "ml", "Fertigspritzen", "338,57"], ["ABSEAMED 8000I.E./0.8ML", "4000735", "MEDICE ARZN.GMBH&CO.KG", "Epoetin alfa", "8000", "I.E.", "6X0.8", "ml", "Fertigspritzen", "448,34"], ["ACC 200", "3867219", "HEXAL AG", "Acetylcystein", "200", "mg", "50", "St", "Brausetabletten", "12,74"], ["ACC 200", "3867225", "HEXAL AG", "Acetylcystein", "200", "mg", "100", "St", "Brausetabletten", "15,42"], ["ACC 200", "4789763", "HEXAL AG", "Acetylcystein", "200", "mg", "20", "St", "Brausetabletten", "11,01"], :doubtful]
import_row method extract specific data from this @rows in process_page method
lib/oddb/gkv.rb
process_page
def process_page rows rows.each do |row| import_row row end end
import_row (too long!! need refactoring!
)
xxx
Experiment
def process_page rows p "get-in process_page" previous = Drugs::Product.instances.size current = previous rows.each_with_index do |row,i| import_row row print i, " Drug::Product.instance.size=",Drugs::Product.instances.size,"\n" current = Drugs::Product.instances.size if previous < current pp row end previous = current end end
Result
"get-in process_page" 0 Drug::Product.instance.size=1 1 Drug::Product.instance.size=1 2 Drug::Product.instance.size=1 3 Drug::Product.instance.size=1 4 Drug::Product.instance.size=1 5 Drug::Product.instance.size=1 6 Drug::Product.instance.size=2 ["ABSEAMED 1000I.E./0.5ML", "4000646", "MEDICE ARZN.GMBH&CO.KG", "Epoetin alfa", "1000", "I.E.", "6X0.5", "ml", "Fertigspritzen", "64,20"] 7 Drug::Product.instance.size=2 8 Drug::Product.instance.size=2 9 Drug::Product.instance.size=2 10 Drug::Product.instance.size=2 11 Drug::Product.instance.size=2 12 Drug::Product.instance.size=2 13 Drug::Product.instance.size=3 ["ACC 200", "3867219", "HEXAL AG", "Acetylcystein", "200", "mg", "50", "St", "Brausetabletten", "12,74"] 14 Drug::Product.instance.size=3 15 Drug::Product.instance.size=3 16 Drug::Product.instance.size=3
Point
Hypothesis: 4adb046616d3cf37ac9644ad2cb26d6c29801a63 2009-09-07 Hannes Wyss Import unknown packages, even if data quality cannot...
- if((company = import_company(row)) && product && product.company != company) + if(product && (company = import_company(row)) && product.company != company)
Answer
def import_row(row) package = import_package(row)
import_package method looks counting up Drugs::Product.instances.size
import_package
def import_package(row) pzn = row.at(1).to_i return if(pzn == 0) pzn = u(pzn.to_s) package = Drugs::Package.find_by_code(:type => 'cid', :value => pzn, :country => 'DE') @created_pzn = nil if(package.nil?) @created_pzn = pzn package = Drugs::Package.new package.add_code(Util::Code.new(:cid, pzn, 'DE')) part = Drugs::Part.new part.package = package save part product = import_product(package, row)
import_product method looks counting up Drugs::Product.instances.size
def import_product(package, row) name = product_name(row) search = name.dup product = nil candidates = [] until(product || search.empty? || candidates.size > 1) candidates = Drugs::Product.search_by_name(search) if(candidates.size == 1) product = candidates.first product.name.add_synonym(name) && save(product) end search.sub!(/(\s|^)\S*$/, '') end if(product.nil?) @created_products += 1 product = Drugs::Product.new product.name.de = name save product end product end
'save product' looks counting up Drugs::Product.instances.size
test/import/test_gkv.rb
test_import
fail
Confirm failure
masa@masa ~/ywesee/de.oddb.org $ ruby test/import/test_gkv.rb Loaded suite test/import/test_gkv Started .FF..... Finished in 0.047509 seconds. 1) Failure: test_import(ODDB::Import::TestGkv) [test/import/test_gkv.rb:130]: <1> expected but was <11>. 2) Failure: test_import__ml(ODDB::Import::TestGkv) [test/import/test_gkv.rb:181]: <1> expected but was <3>. 8 tests, 20 assertions, 2 failures, 0 errors
I have to understand @confirmed_pzns
Backtrace @confirmed_pzns
test/import/test_gkv.rb
test_import
confirmed = @import.instance_variable_get('@confirmed_pzns') assert_equal(1, confirmed.size)
Check lib/oddb/import/gkv.rb
def import_row(row) if row == :doubtful @doubtful_pzns.push @created_pzn if @created_pzn @created_pzn = nil return end @count += 1 package = import_package(row) return if package.nil? @confirmed_pzns.store(package.code(:cid).value, true)
Consideration
good
Correct
Confirm all the test
masa@masa ~/ywesee/de.oddb.org $ ruby test/import/test_gkv.rb Loaded suite test/import/test_gkv Started ........ Finished in 0.089895 seconds. 8 tests, 43 assertions, 0 failures, 0 errors
Refer