Sha256: fb79214a9b9714d3a42957b07a4636ea3f8d9a5157bbb68019853009038359d3

Contents?: true

Size: 1006 Bytes

Versions: 121

Compression:

Stored size: 1006 Bytes

Contents

# frozen_string_literal: true

require_dependency "renalware/letters"

module Renalware
  module Letters
    class Patient < ActiveType::Record[Renalware::Patient]
      has_many :letters, dependent: :restrict_with_exception
      has_many :contacts, dependent: :restrict_with_exception
      belongs_to :primary_care_physician, class_name: "Renalware::Letters::PrimaryCarePhysician"

      def cc_on_letter?(letter)
        return false unless letter.subject?(self)
        return false unless cc_on_all_letters?

        !letter.main_recipient.patient?
      end

      def assign_contact(params)
        contacts.build(params)
      end

      def has_available_contact?(person)
        contacts.map(&:person).include?(person)
      end

      def has_default_cc?(person)
        contacts.default_ccs.map(&:person).include?(person)
      end

      def with_contact_for(person, &block)
        contact = contacts.detect { |c| c.person == person }
        block.call(contact)
      end
    end
  end
end

Version data entries

121 entries across 121 versions & 1 rubygems

Version Path
renalware-core-2.0.104 app/models/renalware/letters/patient.rb
renalware-core-2.0.103 app/models/renalware/letters/patient.rb
renalware-core-2.0.102 app/models/renalware/letters/patient.rb
renalware-core-2.0.101 app/models/renalware/letters/patient.rb
renalware-core-2.0.100 app/models/renalware/letters/patient.rb
renalware-core-2.0.99 app/models/renalware/letters/patient.rb
renalware-core-2.0.98 app/models/renalware/letters/patient.rb
renalware-core-2.0.97 app/models/renalware/letters/patient.rb
renalware-core-2.0.96 app/models/renalware/letters/patient.rb
renalware-core-2.0.95 app/models/renalware/letters/patient.rb
renalware-core-2.0.94 app/models/renalware/letters/patient.rb
renalware-core-2.0.93 app/models/renalware/letters/patient.rb
renalware-core-2.0.92 app/models/renalware/letters/patient.rb
renalware-core-2.0.91 app/models/renalware/letters/patient.rb
renalware-core-2.0.90 app/models/renalware/letters/patient.rb
renalware-core-2.0.89 app/models/renalware/letters/patient.rb
renalware-core-2.0.88 app/models/renalware/letters/patient.rb
renalware-core-2.0.87 app/models/renalware/letters/patient.rb
renalware-core-2.0.86 app/models/renalware/letters/patient.rb
renalware-core-2.0.85 app/models/renalware/letters/patient.rb