Sha256: 3f7e54c0e5d1498a690251a798b63b9b5b5a3822db2774078d442163e56bfe6c
Contents?: true
Size: 1.8 KB
Versions: 5
Compression:
Stored size: 1.8 KB
Contents
require_dependency "renalware/patients" module Renalware module Patients # Represents a Primary Care Physician (PCP). The PCP could either be: # - a UK-based General Practitioner (GP) # - a foreign PCP or other referring physician # class PrimaryCarePhysician < ApplicationRecord include ActiveModel::Validations include Personable acts_as_paranoid has_one :address, as: :addressable has_many :patients has_many :practice_memberships has_many :practices, through: :practice_memberships accepts_nested_attributes_for :address, reject_if: Address.reject_if_blank validates_with PrimaryCarePhysicians::AddressValidator validates :code, uniqueness: true validates :practitioner_type, presence: true validates :name, presence: true alias_attribute :family_name, :name def full_name :name end def given_name "" end def skip_given_name_validation? true end scope :ordered, -> { order(name: :asc) } def title "Dr" end def salutation [title, name].join(" ") end class PrimaryCarePhysicianAddressAccessError < StandardError; end def current_address raise PrimaryCarePhysicianAddressAccessError, "primary_care_physician#current_address should not be called: "\ "we always use the patient.practice.address when contacting the GP. "\ "In a sense the practice is more important that the GP, as the GP may have "\ "moved on" # address || practice_address end def practice_address address = practices.first.try(:address) address.name = "#{title} #{name}".strip if address.present? address end end end end
Version data entries
5 entries across 5 versions & 1 rubygems