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 def current_address 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