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
46
# 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)


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

def for_contact?(contact)
  return false unless person_role.contact?

  addressee_id == contact.id
end

#statment_to_indicate_letter_will_be_emailedObject



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

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