signature_tracking.rb
def track_signatures(scope = nil)
        self.class_eval do
          scope ||= -> { order 'signatures.created_at DESC' }
          has_many :signatures, scope, :as => :owner, :dependent => :destroy
        end
        
        self.class_eval <<-RUBY
          def self.has_signature_tracking?
            true
          end
          
          def self.unsigned_items
            self.all :joins => "LEFT JOIN signatures ON signatures.owner_id = #{self.table_name}.id AND signatures.owner_type = '#{self.name}' AND signatures.physician_id IS NOT NULL", :conditions => 'signatures.physician_id IS NULL'
          end
          
          def track_signature!(user, physician = nil, effective_date = nil, recorded_by = nil)
            effective_date ||= Time.zone.try(:today)
            effective_date ||= Date.today
            physician ||= user.physician if user.physician
            recorded_by ||= user
            self.signatures.create(
              :user => user,
              :physician => physician,
              :effective_date => (physician.nil? ? nil : effective_date),
              :recorded_by => recorded_by
            )
          end
          
          def is_signed_by_user?(user)
            self.signatures.detect do |signature|
              signature.user_id == user.id and user.physician.try(:id) == signature.physician_id
            end
          end
          
          def is_signed_by_physician?(physician)
            self.signatures.detect do |signature|
              physician and physician == signature.physician
            end
          end
          
          def is_signed_by_discipline?(discipline)
            role_name = Role.extended_base_roles[discipline]
            physician_match = discipline == :physician
            self.signatures.detect do |signature|
              signature.user.roles.detect do |role|
                role.name == role_name and (physician_match or signature.physician_id.nil?)
              end
            end
          end
        RUBY
        
        Signature.track_type(self.name)
        
        include Consolo::SignatureTracking::InstanceMethods
      end
##
# Tracks signatures for a model. Adds a nice untracked_items method to
# the class for easy tracking later.
#
# @param scope [Proc] optional scope to pass to the association. Defaults to
# ordering signatures by created_at DESC.
#
Tracks signatures for a model. Adds a nice untracked_items method to
the class for easy tracking later.
Tracks signatures for a model . Adds a nice untracked_items method to the class for easy tracking later .
def track_signatures(scope = nil)
        self.class_eval do
          scope ||= -> { order 'signatures.created_at DESC' }
          has_many :signatures, scope, :as => :owner, :dependent => :destroy
        end
        self.class_eval <<-RUBY
          def self.has_signature_tracking?
            true
          end
          def self.unsigned_items
            self.all :joins => "LEFT JOIN signatures ON signatures.owner_id = #{self.table_name}.id AND signatures.owner_type = '#{self.name}' AND signatures.physician_id IS NOT NULL", :conditions => 'signatures.physician_id IS NULL'
          end
          def track_signature!(user, physician = nil, effective_date = nil, recorded_by = nil)
            effective_date ||= Time.zone.try(:today)
            effective_date ||= Date.today
            physician ||= user.physician if user.physician
            recorded_by ||= user
            self.signatures.create(
              :user => user,
              :physician => physician,
              :effective_date => (physician.nil? ? nil : effective_date),
              :recorded_by => recorded_by
            )
          end
          def is_signed_by_user?(user)
            self.signatures.detect do |signature|
              signature.user_id == user.id and user.physician.try(:id) == signature.physician_id
            end
          end
          def is_signed_by_physician?(physician)
            self.signatures.detect do |signature|
              physician and physician == signature.physician
            end
          end
          def is_signed_by_discipline?(discipline)
            role_name = Role.extended_base_roles[discipline]
            physician_match = discipline == :physician
            self.signatures.detect do |signature|
              signature.user.roles.detect do |role|
                role.name == role_name and (physician_match or signature.physician_id.nil?)
              end
            end
          end
        RUBY
        Signature.track_type(self.name)
        include Consolo::SignatureTracking::InstanceMethods
      end
def track_signatures ( scope = nil ) self . class_eval do scope ||= -> { order 'signatures.created_at DESC' } has_many :signatures , scope , :as => :owner , :dependent => :destroy end self . class_eval <<-RUBY 
          def self.has_signature_tracking?
            true
          end
          
          def self.unsigned_items
            self.all :joins => "LEFT JOIN signatures ON signatures.owner_id =  #{ self . table_name } .id AND signatures.owner_type = ' #{ self . name } ' AND signatures.physician_id IS NOT NULL", :conditions => 'signatures.physician_id IS NULL'
          end
          
          def track_signature!(user, physician = nil, effective_date = nil, recorded_by = nil)
            effective_date ||= Time.zone.try(:today)
            effective_date ||= Date.today
            physician ||= user.physician if user.physician
            recorded_by ||= user
            self.signatures.create(
              :user => user,
              :physician => physician,
              :effective_date => (physician.nil? ? nil : effective_date),
              :recorded_by => recorded_by
            )
          end
          
          def is_signed_by_user?(user)
            self.signatures.detect do |signature|
              signature.user_id == user.id and user.physician.try(:id) == signature.physician_id
            end
          end
          
          def is_signed_by_physician?(physician)
            self.signatures.detect do |signature|
              physician and physician == signature.physician
            end
          end
          
          def is_signed_by_discipline?(discipline)
            role_name = Role.extended_base_roles[discipline]
            physician_match = discipline == :physician
            self.signatures.detect do |signature|
              signature.user.roles.detect do |role|
                role.name == role_name and (physician_match or signature.physician_id.nil?)
              end
            end
          end
         RUBY Signature . track_type ( self . name ) include Consolo :: SignatureTracking :: InstanceMethods end
Tracks signatures for a model.
Tracks signatures for a model .
scope
optional scope to pass to the association. Defaults to ordering signatures by created_at DESC.
optional scope to pass to the association . Defaults to ordering signatures by created_at DESC .