Sha256: c56a0b19464df2c1c3539f4e65640cba33c931c919fc13a54c0099ea4348d757

Contents?: true

Size: 1.97 KB

Versions: 28

Compression:

Stored size: 1.97 KB

Contents

# frozen_string_literal: true

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 to_s
        [title, name].compact.join(" ")
      end

      def skip_given_name_validation?
        true
      end

      scope :ordered, -> { order(name: :asc) }

      def title
        "Dr"
      end

      def salutation
        [
          Renalware.config.salutation_prefix,
          title,
          name
        ].compact.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

28 entries across 28 versions & 1 rubygems

Version Path
renalware-core-2.0.39 app/models/renalware/patients/primary_care_physician.rb
renalware-core-2.0.38 app/models/renalware/patients/primary_care_physician.rb
renalware-core-2.0.37 app/models/renalware/patients/primary_care_physician.rb
renalware-core-2.0.36 app/models/renalware/patients/primary_care_physician.rb
renalware-core-2.0.35 app/models/renalware/patients/primary_care_physician.rb
renalware-core-2.0.34 app/models/renalware/patients/primary_care_physician.rb
renalware-core-2.0.33 app/models/renalware/patients/primary_care_physician.rb
renalware-core-2.0.32 app/models/renalware/patients/primary_care_physician.rb
renalware-core-2.0.31 app/models/renalware/patients/primary_care_physician.rb
renalware-core-2.0.30 app/models/renalware/patients/primary_care_physician.rb
renalware-core-2.0.28 app/models/renalware/patients/primary_care_physician.rb
renalware-core-2.0.27 app/models/renalware/patients/primary_care_physician.rb
renalware-core-2.0.26 app/models/renalware/patients/primary_care_physician.rb
renalware-core-2.0.25 app/models/renalware/patients/primary_care_physician.rb
renalware-core-2.0.24 app/models/renalware/patients/primary_care_physician.rb
renalware-core-2.0.23 app/models/renalware/patients/primary_care_physician.rb
renalware-core-2.0.22 app/models/renalware/patients/primary_care_physician.rb
renalware-core-2.0.21 app/models/renalware/patients/primary_care_physician.rb
renalware-core-2.0.20 app/models/renalware/patients/primary_care_physician.rb
renalware-core-2.0.18 app/models/renalware/patients/primary_care_physician.rb