view · edit · sidebar · attach · print · history

20110512-debug-update-function-de_oddb

<< Masa.20110513-debug-import-process-de_oddb-debug-rpdf2txt | 2011 | Masa.20110511-swissindex_plugin-ch_oddb-debug-atc-zuweisen-de_oddb >>


  1. Bug: Strange company name
  2. Confirm the bug in local
  3. Look for the method to update the company information
  4. Update the updating process of company
  5. Check import process

Goal/Estimate/Evaluation
  • Debug update-function de.oddb / 70% / 90%
Milestones
  1. Confirm the bug
  2. Look for the source code part for the updating
  3. Fix the update function
Summary

:Commits


Bug: Strange company name

Problem

  • Some company names are strange
  • Even if it is corrected on browser, the change is not reflected immediately to the cache data
  • After rebooting de.oddb, the result changes

Example

Confirm the bug in local

To find the bug company name

  1. Take an atcless sequence name (from the result of atcless bin/admin command)
  2. Search the name on de.oddb (ex. Ticlopidin)
  3. Take a look at the company name, sometimes it has too many 'Wirkstoff' (Active agents) and the names are strange

To correct the company name

  1. Click 'Wirkstoff'
  2. Click 'Product'
  3. Click 'Sequenzen' number
  4. Take a 'Packungen' number (Pharmazentralnummer)
  5. Search the number in the PDF file
  6. Copy the company name
  7. Click 'Product' again
  8. Correct the company name (Zulassungsinhaber)
  9. Click 'Speichern' (Save)

Check the result

  1. Click 'Suchresultat' (Search Result)
  2. Look at the 'Hersteller' (Company)
  3. Confirm that the change is not updated
  4. Reboot de.oddb
  5. Reload
  6. Then the change is updated

Look for the method to update the company information

Hint

Note

  • After the clicking of 'Speichern' on the screen of Product, the company name is updated actually
  • But the change is not update in the search result.
    • This means
    • the company data that belongs to the Product instance is updated in the cache
    • but the company data that belongs to the search result (maybe, Package instance) is not updated in the case

Experiment (lib/oddb/html/state/drugs/admin/product.rb#update)

  def update
p "getin ODDB::Html::State::Drugs::Admin::Product#update"
    value = user_input :company
print "value = "
p value
    error_check_and_store(:company, value, [:company])
    unless error?
      set = if(company = ODDB::Business::Company.find_by_name(value))
              @model.company = company
            else
              @errors.store :company, create_error(:e_unknown_company,
                                                   :company, value)
              nil
            end
      unless(set.nil?)
        @model.data_origins.store :company, @session.user.email
        @model.save
print "@model.class = "
p @model.class
      end
    end
    self
  end

Restart

  • de.oddb/bin/oddbd
  • Update company name in the product screen

Result (the console of bin/oddbd)

"getin ODDB::Html::State::Drugs::Admin::Product#update"
value = "Actavis Dtl. GmbH & Co KG"
ODBA::Stub was unable to replace Hash#4267068 from ODDB::Drugs::Product:#53926
@model.class = ODDB::Drugs::Product
D, [2011-05-12T09:52:53.369549 #6713] DEBUG -- User: mhatakeyama@ywesee.com: allowed?(login, org.oddb.de.Admin) -> true
D, [2011-05-12T09:52:59.114444 #6713] DEBUG -- User: mhatakeyama@ywesee.com: allowed?(login, org.oddb.de.Admin) -> true
D, [2011-05-12T09:53:01.003531 #6713] DEBUG -- User: mhatakeyama@ywesee.com: allowed?(login, org.oddb.de.Admin) -> true

Note

  • The wrong company name that is not saved in the database is not available
 if company = ODDB::Business::Company.find_by_name(value)
  • The code above searches the company name
  • @model.save method is the method that save the company data in the database
  • @model is an instance of ODDB::Drugs::Product class

Question

  • Are the company of Product and the one of Package different on the cache?

Experiment (lib/oddb/html/state/drugs/admin/package.rb#update)

  def update
p "getin ODDB::Html::State::Drugs::Admin::Package#update"
print "@model.class = "
p @model.class
print "@model.company.odba_id = "
p @model.company.odba_id
print "@model.company.name = "
p @model.company.name
...
  end
  def _update input
...
p "after update"
print "@model.class = "
p @model.class
print "@model.company.odba_id = "
p @model.company.odba_id
print "@model.company.name = "
p @model.company.name
    self
  end

Restart

  • de.oddb/bin/oddbd

Register a different company name

  1. Update a company name in the Product screen, and click 'Speichern'
  2. Click 'Speichern' in the Package screen
  3. Check the search result

Result

0. Search result

1. Update a company name in the Product screen, and click 'Speichern'

"getin ODDB::Html::State::Drugs::Admin::Product#update"
value = "Sandz O"
ODBA::Stub was unable to replace Hash#4267103 from ODDB::Drugs::Product:#58154
@model.class = ODDB::Drugs::Product
@model.company.odba_id = 3851493
@model.company.name = #<ODDB::Util::Multilingual:0x7f0e8ca65dc8 @synonyms=[], @canonical={:de=>u"Sandz O"}>

2. Click 'Speichern' in the Package screen

"getin ODDB::Html::State::Drugs::Admin::Package#update"
@model.class = ODDB::Drugs::Package
@model.company.odba_id = 3523958
@model.company.name = #<ODDB::Util::Multilingual:0x7f0e8ca6a0a8 @synonyms=[], @canonical={:de=>u"Heumann Pharma"}>
ODBA::Stub was unable to replace Hash#4267171 from ODDB::Drugs::Package:#58167
ODBA::Stub was unable to replace Array#4267172 from ODDB::Drugs::Package:#58167
ODBA::Stub was unable to replace Array#4267170 from ODDB::Drugs::Package:#58167
ODBA::Stub was unable to replace Hash#4267174 from ODDB::Drugs::Package:#58170
ODBA::Stub was unable to replace Array#4267175 from ODDB::Drugs::Package:#58170
ODBA::Stub was unable to replace Array#4267173 from ODDB::Drugs::Package:#58170
ODBA::Stub was unable to replace Hash#4267179 from ODDB::Util::M10lDocument:#4267177
ODBA::Stub was unable to replace Hash#4267181 from ODDB::Util::M10lDocument:#4267176
ODBA::Stub was unable to replace Hash#4267171 from ODDB::Drugs::Package:#58167
ODBA::Stub was unable to replace Hash#4267174 from ODDB::Drugs::Package:#58170
ODBA::Stub was unable to replace Hash#4267184 from ODDB::Drugs::Package:#58164
ODBA::Stub was unable to replace Array#4267185 from ODDB::Drugs::Package:#58164
ODBA::Stub was unable to replace Array#4267183 from ODDB::Drugs::Package:#58164
ODBA::Stub was unable to replace Hash#4267188 from ODDB::Util::M10lDocument:#4267187
ODBA::Stub was unable to replace Hash#4267184 from ODDB::Drugs::Package:#58164
"after update"
@model.class = ODDB::Drugs::Package
@model.company.odba_id = 3851493
@model.company.name = #<ODDB::Util::Multilingual:0x7f0e8ca65dc8 @synonyms=[], @canonical={:de=>u"Sandz O"}>

3. Check the search result

Summary

  • The company data of Package instance is not updated immediately after the updating of company of Product instance.
  • The company data of Package instance is updated after the 'Speichern' in the Package screen

Update the updating process of company

Plan

  • Call the update method of Packge in the update method of Product

Experiment (lib/oddb/html/state/drugs/admin/package.rb#_update)

  def _update input
    email = @session.user.email
    input.each { |key, value|
      unless(@errors[key])
        set = case key
              when :name
                @model.name.de = value unless(@model.name.de == value)
              when :price_public, :price_festbetrag, :price_exfactory
                update_price(/price_(.*)/.match(key.to_s)[1].to_sym, value.to_f)
              when :code_cid, :code_festbetragsgruppe, :code_festbetragsstufe
                update_code(/code_(.*)/.match(key.to_s)[1].to_sym, value)
              when :code_zuzahlungsbefreit, :code_prescription
                update_code(/code_(.*)/.match(key.to_s)[1].to_sym, !!value)
              when :size
                update_parts(input)
              end
        unless(set.nil?)
          @model.data_origins.store key, email
        end
      end
    }
    if((uid = input[:sequence]) \
       && (seq = ODDB::Drugs::Sequence.find_by_uid(uid)) \
       && @model.sequence != seq)
p "A"
print "@model.company.odba_id = "
p @model.company.odba_id
print "@model.company.name = "
p @model.company.name
p "B"
      @model.sequence = seq
print "@model.company.odba_id = "
p @model.company.odba_id
print "@model.company.name = "
p @model.company.name
      @model.parts.each_with_index { |part, idx|
        part.composition = seq.compositions[idx]
        part.save
      }
p "C"
print "@model.company.odba_id = "
p @model.company.odba_id
print "@model.company.name = "
p @model.company.name
    elsif((seq = @model.sequence) && seq.is_a?(Util::UnsavedHelper))
      @model.sequence = seq.delegate
    end
    @model.save

p "After update"
print "@model.class = "
p @model.class
print "@model.company.odba_id = "
p @model.company.odba_id
print "@model.company.name = "
p @model.company.name
    self
  end

Result

"getin ODDB::Html::State::Drugs::Admin::Package#update"
@model.class = ODDB::Drugs::Package
@model.company.odba_id = 3851493
@model.company.name = #<ODDB::Util::Multilingual:0x7f46ae7f2c58 @synonyms=[], @canonical={:de=>u"Sandz O"}>
"A"
@model.company.odba_id = 3851493
@model.company.name = #<ODDB::Util::Multilingual:0x7f46ae7f2c58 @synonyms=[], @canonical={:de=>u"Sandz O"}>
"B"
ODBA::Stub was unable to replace Hash#4267260 from ODDB::Drugs::Package:#58170
ODBA::Stub was unable to replace Array#4267263 from ODDB::Drugs::Sequence:#58160
ODBA::Stub was unable to replace Hash#4267265 from ODDB::Util::M10lDocument:#4267262
ODBA::Stub was unable to replace Hash#4267267 from ODDB::Util::M10lDocument:#4267264
ODBA::Stub was unable to replace Hash#4267260 from ODDB::Drugs::Package:#58170
ODBA::Stub was unable to replace Hash#4267269 from ODDB::Drugs::Package:#58164
ODBA::Stub was unable to replace Hash#4267272 from ODDB::Util::M10lDocument:#4267271
@model.company.odba_id = 213712
@model.company.name = #<ODDB::Util::Multilingual:0x7f46aed71e68 @synonyms=[], @canonical={:de=>u"Actavis Dtl. GmbH & Co KG"}>
"C"
@model.company.odba_id = 213712
@model.company.name = #<ODDB::Util::Multilingual:0x7f46aed71e68 @synonyms=[], @canonical={:de=>u"Actavis Dtl. GmbH & Co KG"}>
ODBA::Stub was unable to replace Hash#4267269 from ODDB::Drugs::Package:#58164
"After update"
@model.class = ODDB::Drugs::Package
@model.company.odba_id = 213712
@model.company.name = #<ODDB::Util::Multilingual:0x7f46aed71e68 @synonyms=[], @canonical={:de=>u"Actavis Dtl. GmbH & Co KG"}>

Note

  • When the 'Speichern' in the Package screen, the Package.company instance changes
 @model.sequence = ODDB::Drugs::Sequence.find_by_uid(@model.sequence.uid)
  • The code above updates the company information

Experiment (lib/oddb/html/state/drugs/admin/product.rb#update)

  def update
p "getin ODDB::Html::State::Drugs::Admin::Product#update"
    value = user_input :company
    error_check_and_store(:company, value, [:company])
    unless error?
      set = if(company = ODDB::Business::Company.find_by_name(value))
              @model.company = company
            else
              @errors.store :company, create_error(:e_unknown_company,
                                                   :company, value)
              nil
            end
      unless(set.nil?)
        @model.data_origins.store :company, @session.user.email
        @model.save
print "@model.company.odba_id = "
p @model.company.odba_id
print "@model.company.name = "
p @model.company.name

new_seq = ODDB::Drugs::Sequence.find_by_uid(@model.sequences[0].uid)

p (new_seq == @model.sequences[0])
@model.packages.each do |pac|
  print "package name: "
  p pac.cascading_name('de')
  print "company odba_id: "
  p pac.company.odba_id
  print "company name: "
  p pac.company.name
end
      end
    end
    self
  end

Result

"getin ODDB::Html::State::Drugs::Admin::Product#update"
ODBA::Stub was unable to replace Hash#4267318 from ODDB::Drugs::Product:#58154
@model.company.odba_id = 3851493
@model.company.name = #<ODDB::Util::Multilingual:0x7fb9d0ab2db8 @synonyms=[], @canonical={:de=>u"Sandz O"}>
true
package name: "Ticlopidin 250 Heumann Filmtabletten"
company odba_id: 213712
company name: #<ODDB::Util::Multilingual:0x7fb9d09f4908 @synonyms=[], @canonical={:de=>u"Actavis Dtl. GmbH & Co KG"}>
package name: "Ticlopidin 250 Heumann Filmtabletten"
company odba_id: 213712
company name: #<ODDB::Util::Multilingual:0x7fb9d09f4908 @synonyms=[], @canonical={:de=>u"Actavis Dtl. GmbH & Co KG"}>
package name: "Ticlopidin 250 Heumann Filmtabletten"
company odba_id: 213712
company name: #<ODDB::Util::Multilingual:0x7fb9d09f4908 @synonyms=[], @canonical={:de=>u"Actavis Dtl. GmbH & Co KG"}>

Note

  • failed

Note (new hint)

  • The 'Speichern' of 'Sequence' also update the company data of 'Package' (also search result)

Consideration

  • Sequence and Packages data is not updated after the Product#save method

Experiment (lib/oddb/html/state/drugs/admin/product.rb#update)

  def update
p "getin ODDB::Html::State::Drugs::Admin::Product#update"
    value = user_input :company
    error_check_and_store(:company, value, [:company])
    unless error?
      set = if(company = ODDB::Business::Company.find_by_name(value))
              @model.company = company
            else
              @errors.store :company, create_error(:e_unknown_company,
                                                   :company, value)
              nil
            end
      unless(set.nil?)
        @model.data_origins.store :company, @session.user.email
        @model.save

print "@model.company.odba_id = "
p @model.company.odba_id
print "@model.company.name = "
p @model.company.name

@model.sequences[0].product = @model

@model.packages.each do |pac|
  print "package name: "
  p pac.cascading_name('de')
  print "company odba_id: "
  p pac.company.odba_id
  print "company name: "
  p pac.company.name
end
      end
    end
    self
  end

Result

"getin ODDB::Html::State::Drugs::Admin::Product#update"
ODBA::Stub was unable to replace Hash#4267344 from ODDB::Drugs::Product:#58154
@model.company.odba_id = 3851493
@model.company.name = #<ODDB::Util::Multilingual:0x7f0bcbe217c8 @synonyms=[], @canonical={:de=>u"Sandz O"}>
ODBA::Stub was unable to replace Hash#4267345 from ODDB::Drugs::Product:#58154
ODBA::Stub was unable to replace Hash#4267344 from ODDB::Drugs::Product:#58154
package name: "Ticlopidin 250 Heumann Filmtabletten"
company odba_id: 3851493
company name: #<ODDB::Util::Multilingual:0x7f0bcbe217c8 @synonyms=[], @canonical={:de=>u"Sandz O"}>
package name: "Ticlopidin 250 Heumann Filmtabletten"
company odba_id: 3851493
company name: #<ODDB::Util::Multilingual:0x7f0bcbe217c8 @synonyms=[], @canonical={:de=>u"Sandz O"}>
package name: "Ticlopidin 250 Heumann Filmtabletten"
company odba_id: 3851493
company name: #<ODDB::Util::Multilingual:0x7f0bcbe217c8 @synonyms=[], @canonical={:de=>u"Sandz O"}>

Note

  • Success
  • The point is
 @model.sequences[0].product = @model

Example

1. search result

2. Click 'Wirkstoffe'

3. Click 'Produkt' and update the company name (Zulassungsinhaber) and click 'Speichern'

4. Click 'Suchresultat' (Search result)

Summary

  • The hierarchical structure is
 Product *--1 Sequence *--1 Package
  • but each child node has its parent's link property, for example
 Sequence#product, Pakcage#sequence
  • These link properties are not automatically updated when the parent instance is updated
  • I do not know why they are not updated but the link should also be updated
  • But anyhow the link is automatically updated when the de.oddb restarts
  • I guess the link data is re-constructed when the cache data is loaded

lib/oddb/html/state/drugs/admin/product.rb#update

  def update
    value = user_input :company
    error_check_and_store(:company, value, [:company])
    unless error?
      set = if(company = ODDB::Business::Company.find_by_name(value))
              @model.company = company
            else
              @errors.store :company, create_error(:e_unknown_company,
                                                   :company, value)
              nil
            end
      unless(set.nil?)
        @model.data_origins.store :company, @session.user.email
        @model.save
        @model.sequences.each do |seq|
          seq.product = @model
        end
      end
    end
    self
  end

Commit

Check import process

Look for the import part (focus only on 'company' first. 'Wirkstoff' looks also strange, though)

  • lib/oddb/import/gkv.rb

Test run

  • jobs/import_gkv

Error

Thu May 12 16:32:16 2011: de.oddb.org ODDB::Import::Gkv#import
NoMethodError
undefined method `type=' for #<ODDB::Util::Money:0x7f39ed49deb8>
./lib/oddb/drugs/package.rb:68:in `_price_exfactory'
./lib/oddb/import/gkv.rb:266:in `import_package'
./lib/oddb/import/gkv.rb:111:in `import_row'
./lib/oddb/import/gkv.rb:459:in `process_page'
./lib/oddb/import/gkv.rb:458:in `each'
./lib/oddb/import/gkv.rb:458:in `process_page'
./lib/oddb/import/gkv.rb:40:in `call'
./lib/oddb/import/gkv.rb:40:in `send_page'
/usr/lib64/ruby/site_ruby/1.8/rpdf2txt/parser.rb:43:in `extract_text'
/usr/lib64/ruby/site_ruby/1.8/rpdf2txt/object.rb:493:in `each'
/usr/lib64/ruby/site_ruby/1.8/rpdf2txt/object.rb:452:in `each'
/usr/lib64/ruby/site_ruby/1.8/rpdf2txt/object.rb:493:in `each'
/usr/lib64/ruby/site_ruby/1.8/rpdf2txt/object.rb:492:in `each'
/usr/lib64/ruby/site_ruby/1.8/rpdf2txt/object.rb:477:in `each'
/usr/lib64/ruby/site_ruby/1.8/rpdf2txt/parser.rb:41:in `extract_text'
./lib/oddb/import/gkv.rb:100:in `import'
/usr/lib64/ruby/site_ruby/1.8/oddb/util/updater.rb:96:in `reported_import'
/usr/lib64/ruby/site_ruby/1.8/oddb/util/updater.rb:103:in `call'
/usr/lib64/ruby/site_ruby/1.8/oddb/util/updater.rb:103:in `_reported_import'
/usr/lib64/ruby/site_ruby/1.8/oddb/util/updater.rb:96:in `reported_import'
/usr/lib64/ruby/site_ruby/1.8/oddb/util/updater.rb:58:in `import_gkv'
/usr/lib64/ruby/1.8/open-uri.rb:32:in `open_uri_original_open'
/usr/lib64/ruby/1.8/open-uri.rb:32:in `open'
./lib/oddb/import/gkv.rb:77:in `download_latest'
/usr/lib64/ruby/site_ruby/1.8/oddb/util/updater.rb:57:in `import_gkv'
jobs/import_gkv:16
./lib/oddb/util/job.rb:16:in `call'
./lib/oddb/util/job.rb:16:in `run'
jobs/import_gkv:15
Imported     1 Zubef-Entries on 12.05.2011:
Visited      0 existing Zubef-Entries
Visited      0 existing Companies
Visited      0 existing Substances
Created      0 new Zubef-Entries
Created      0 new Products
Created      0 new Sequences
Created      0 new Companies
Created      0 new Substances
Assigned     0 Chemical Equivalences
Assigned     0 Companies
Created      0 Incomplete Packages:
Created      0 Product(s) without a name (missing product name):

Note

  • But actually the 'type' method is defined in Money class
  • lib/oddb/util/money.rb
  def type=(type)
    @type = type.to_s.downcase
  end
view · edit · sidebar · attach · print · history
Page last modified on April 25, 2012, at 02:12 PM