Sha256: 4bc64841928e80aa33c3de5309a2ad21af52094667f3b0b6cf21c3c275f76f55

Contents?: true

Size: 1.29 KB

Versions: 8

Compression:

Stored size: 1.29 KB

Contents

require_dependency "renalware/letters"

module Renalware
  module Letters
    class Contact < ApplicationRecord

      belongs_to :patient
      belongs_to :person, class_name: "Directory::Person"
      belongs_to :description, class_name: "ContactDescription"

      validates :person, presence: true, uniqueness: { scope: :patient }
      validates :description, presence: true
      validates :other_description, presence: true, if: -> { unspecified_description? }

      delegate :salutation, to: :person
      delegate :address, :to_s, :family_name, to: :person
      delegate :name, to: :address, prefix: true

      accepts_nested_attributes_for :person

      scope :with_person, -> { includes(person: :address) }
      scope :with_description, -> { includes(:description) }
      scope :ordered, lambda {
        with_person.order("directory_people.family_name, directory_people.given_name")
      }

      scope :default_ccs, -> { where(default_cc: true) }

      def self.locate_by_given_name(name)
        with_person.find_by(directory_people: { given_name: name })
      end

      def described_as?(description)
        (self.description == description) || (other_description == description)
      end

      def unspecified_description?
        description.try(:unspecified?)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
renalware-core-2.0.0.pre.beta11 app/models/renalware/letters/contact.rb
renalware-core-2.0.0.pre.beta10 app/models/renalware/letters/contact.rb
renalware-core-2.0.0.pre.beta9 app/models/renalware/letters/contact.rb
renalware-core-2.0.0.pre.beta8 app/models/renalware/letters/contact.rb
renalware-core-2.0.0.pre.beta7 app/models/renalware/letters/contact.rb
renalware-core-2.0.0.pre.beta6 app/models/renalware/letters/contact.rb
renalware-core-2.0.0.pre.beta5 app/models/renalware/letters/contact.rb
renalware-core-2.0.0.pre.beta4 app/models/renalware/letters/contact.rb