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.1.1 app/models/renalware/letters/patient.rb
renalware-core-2.1.0 app/models/renalware/letters/patient.rb
renalware-core-2.0.167 app/models/renalware/letters/patient.rb
renalware-core-2.0.166 app/models/renalware/letters/patient.rb
renalware-core-2.0.165 app/models/renalware/letters/patient.rb
renalware-core-2.0.164 app/models/renalware/letters/patient.rb
renalware-core-2.0.163 app/models/renalware/letters/patient.rb
renalware-core-2.0.162 app/models/renalware/letters/patient.rb
renalware-core-2.0.161 app/models/renalware/letters/patient.rb
renalware-core-2.0.160 app/models/renalware/letters/patient.rb
renalware-core-2.0.159 app/models/renalware/letters/patient.rb
renalware-core-2.0.158 app/models/renalware/letters/patient.rb
renalware-core-2.0.157 app/models/renalware/letters/patient.rb
renalware-core-2.0.156 app/models/renalware/letters/patient.rb
renalware-core-2.0.155 app/models/renalware/letters/patient.rb
renalware-core-2.0.153 app/models/renalware/letters/patient.rb
renalware-core-2.0.152 app/models/renalware/letters/patient.rb
renalware-core-2.0.151 app/models/renalware/letters/patient.rb
renalware-core-2.0.149 app/models/renalware/letters/patient.rb
renalware-core-2.0.148 app/models/renalware/letters/patient.rb