Class: Renalware::Letters::Recipient

Inherits:
ApplicationRecord show all
Extended by:
Enumerize
Defined in:
app/models/renalware/letters/recipient.rb

Instance Method Summary collapse

Instance Method Details

#archive!Object



29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/renalware/letters/recipient.rb', line 29

def archive!
  build_address if address.blank?

  address.copy_from(current_address)
  # Its possible a migrated address might not have a postcode. Don't let archiving fail
  # at this stage because of that as the user cannot be informed at this stage
  # so skip address validation.
  address.skip_validation = true

  address.save!
end

#current_addressObject



41
42
43
44
45
# File 'app/models/renalware/letters/recipient.rb', line 41

def current_address
  return address_for_patient if patient?
  return practice_address_for_patient if primary_care_physician?
  address_for_addressee_eg_contact
end

#for_contact?(contact) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
50
# File 'app/models/renalware/letters/recipient.rb', line 47

def for_contact?(contact)
  return false unless person_role.contact?
  addressee_id == contact.id
end

#statment_to_indicate_letter_will_be_emailedObject



52
53
54
55
56
# File 'app/models/renalware/letters/recipient.rb', line 52

def statment_to_indicate_letter_will_be_emailed
  if primary_care_physician? && practice_email_address.present?
    "VIA EMAIL to #{practice_email_address}"
  end
end

#to_sObject



25
26
27
# File 'app/models/renalware/letters/recipient.rb', line 25

def to_s
  (address || current_address).to_s
end