view · edit · sidebar · attach · print · history

20111102-replace-company-link-format-remove-pointer-oddb_org

<< | Index | >>


  1. Replace Company link with ean-code
  2. Replace Admin Company Link
  3. Understand App#update mechanism
  4. Replace ODDB::Part#parse_size without rockit

Goal/Estimate/Evaluation
  • Replace Admin Company link without pointer / 100% / 90%
  • Replace App#update method to the other method / 30% / 100%
  • Replace rockit function in ODDB::Part / 50% / 30%
Commit

Replace Company link with ean-code

Link

Note

  • @companies (Hash) is saved in App instance with key = oid, not ean-code
  • App#search_companies is used to search a company with ean-code, which is a search using 'company_index' index table
  • Some companies do not have an ean-code

Design

  • If some companies are found with an ean-code, the higher (older) oid company will be taken
  • If a company do not have an ean-code, use oid link

Update

  • src/state/global.rb
      def company
        if (oid = @session.user_input(:oid) and model = @session.app.company(oid)) \
          or (ean = @session.user_input(:ean) and model = @session.search_companies(ean).sort_by{|c| c.oid.to_i}.last)
            State::Companies::Company.new(@session, model)
        end
      end
  • src/state/admin/root.rb
  def company
    if (oid = @session.user_input(:oid) and model = @session.app.company(oid)) \
      or (ean = @session.user_input(:ean) and model = @session.search_companies(ean).sort_by{|c| c.oid.to_i}.last)
      State::Companies::RootCompany.new(@session, model)
    end
  end
  • src/state/companies/company.rb
  def init
    if((pointer = @session.user_input(:pointer)))
      @model = pointer.resolve(@session.app)
#    elsif oid = @session.user_input(:oid) and company = @session.app.company(oid)
#      @model = company
#    else
#      @model = nil
    end
  end
  • src/view/companies/company.rb
 def name(model, session=@session)
    link = View::PointerLink.new(:name, model, @session, self)
    if(model.ean13 and !model.ean13.strip.empty?)
      link.set_attribute('title', @lookandfeel.lookup(:ean_code,
                                                      model.ean13))
      link.href = @lookandfeel._event_url(:company, {:ean => model.ean13})
    end
    link
 end

Commit

Replace Admin Company Link

fipi_overview

Link

Design

  • First, search with oid then second search with ean by using company_index table

Commit

patinfo_stats

Update

  • src/state/admin/patinfo_stats.rb
 class PatinfoStatsCommon < State::Admin::Global
   def init
    model = {}
    patinfo_slate = @session.slate(:patinfo)
    patinfo_slate.items.each_value { |item|
      if(item.type == :annual_fee         && (sequence = item.sequence || @session.app.resolve(item.item_pointer)))

 class PatinfoStats < State::Admin::PatinfoStatsCommon
   def init
    super
    company = if oid_or_ean = @session.user_input(:company)
                @session.app.company(oid_or_ean) || @session.search_companies(oid_or_ean).sort_by{|c| c.oid.to_i}.last
              elsif pointer = @session.user_input(:pointer)
                pointer.resolve(@session.app)
              end
  • src/model/invoice.rb
 class InvoiceItem < AbstractInvoiceItem
    attr_accessor :sequence

Note

  • The following method sets the current InvoiceItem#sequence variables but the new InvoiceItem will not be set
ch.oddb> slates[:patinfo].items.values.each{|i| seq = i.item_pointer.resolve(self); update(i.pointer, {:sequence, seq})}

Commit

Understand App#update mechanism

Note

  • Role of Pointer class
    1. Keep object hierarchal structure indepndent from an actual object
    2. it is used to create, update, delete an object with ODDB::App class methods
    3. fetch an object with resolve method
    4. (create an link with @lookandfeel, but this function is mostly replaced)

Main functions

  1. update (issue_update)
  2. create
  3. delete
  4. parent
  5. resolve

Note

  • Persistence::Pointer.parse is only used in src/util/validator.rb
  • Basically, @directions has the object hierarchal structure data as an Array
  • rockit is used in the following files
src/model/part.rb:require 'rockit/rockit'
src/plugin/vaccines.rb:require 'rockit/rockit'
src/util/persistence.rb:require 'rockit/rockit'

App#update

Update

  • src/util/persistent.rb
module ODDB
  module PersistenceMethods
    def issue_update(hook, values, origin = nil)
        diffs = diff(values, hook)
        unless diffs.empty?
          update_values(diffs, origin)
          odba_store
        end
      self
    end
    def update(app, values={}, origin=nil)
      app.update(self, values, origin)
    end

Experiment

ch.oddb> registration('31706').sequence('01').name_base
-> Inderal 10 mg
ch.oddb> registration('31706').sequence('01').update(self, {:name_base, 'hogehoge'})
-> hogehoge, Tabletten
ch.oddb> registration('31706').sequence('01').name_base
-> hogehoge

(reboot)

ch.oddb> registration('31706').sequence('01').name_base
-> hogehoge

Result

  • The data is updated without using pointer

Summary

  • Once we replace all the url link without pointer, rockit library (Pointer.parse method) is no more needed in Pointer class
  • We can remove @parser and parser method from src/util/persistence.rb and src/util/validator.rb
  • issue_update, create, delete, resolve, parent method will work also on Ruby 1.9.3 without rockit library

Replace ODDB::Part#parse_size without rockit

Note

  • Rockit library is used in ODDB::Part#parse_size
  • The part_size method is called only from "size=" method
  • ODDB::Part instance belongs to ODDB::Package#@parts (Array)
  • ODDB::Part#size= method is called only from the following part
  • src/plugin/bsv_xml.rb
        when 'Preparation'
          if !@deferred_packages.empty?             && seq = identify_sequence(@registration, @name, @substances)
            @deferred_packages.each do |info|
              ptr = seq.pointer + [:package, info[:ikscd]]
              @app.update seq.pointer, info[:sequence]
              @app.update ptr.creator, info[:package]
              pptr = ptr + [:part]
              size = info[:size].sub(/(^| )[^\d.,]+(?= )/, '')
              @app.update pptr.creator, :size => size, :composition => seq.compositions.first

Experiment

  • src/model/part.rb
    def size=(size)
p "getin ODDB::Part#size="
p size
    def parse_size(size)
      multi, addition, count, measure, scale, dose, comform = nil
      begin
        ast = @@parser.parse(size)
        multi, addition, count, measure, scale, dose, comform = ast.flatten
p multi + " " + addition + " " + count + " " + measure + " " + scale + " " + dose + " " + comform

  • src/plugin/bsv_xml.rb
      def tag_end name
...
        when 'Preparation'
...
              size = info[:size].sub(/(^| )[^\d.,]+(?= )/, '')
p "size = "
p size
              @app.update pptr.creator, :size => size,
                                        :composition => seq.compositions.first

bin/admin

ch.oddb> ODDB::Package.find_by_pharmacode('223332').parts.first.size = '50 Tablette(n)'

Result

"getin ODDB::Part#size="
"50 Tablette(n)"
0
Quanty(1,'')
50
Quanty(1,'')
Quanty(1,'')
"Tablette(n)"

bin/admin

ch.oddb> Updater.new(self).update_bsv

Result

  • nothing is printed

Note

  • update_bsv may not use ODDB::Part#size= method

Summary

  • Let's see Ruby 1.9.3 running
  • SBSM also use rockit
masa@masa ~/ywesee/oddb.org $ grep -r rockit ../sbsm
../sbsm/lib/sbsm/flavored_uri_parser.rb:require 'rockit/rockit'
../sbsm/lib/sbsm/trans_handler.rb:require 'rockit/rockit'
../sbsm/lib/sbsm/uri_parser.rb:require 'rockit/rockit'
../sbsm/lib/sbsm/zone_uri_parser.rb:require 'rockit/rockit'

Reference

view · edit · sidebar · attach · print · history
Page last modified on November 02, 2011, at 04:50 PM