Class: Renalware::Patient

Inherits:
ApplicationRecord show all
Extended by:
Enumerize, FriendlyId
Includes:
Document::Base, Accountable, PatientsRansackHelper, Personable
Defined in:
app/models/renalware/patient.rb

Constant Summary

Constants included from PatientsRansackHelper

Renalware::PatientsRansackHelper::UUID_REGEXP

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Accountable

#first_or_create_by!, #save_by, #save_by!, #update_by

Class Method Details

.policy_classObject



105
106
107
# File 'app/models/renalware/patient.rb', line 105

def self.policy_class
  BasePolicy
end

Instance Method Details

#ageObject

rubocop:disable Style/MultilineTernaryOperator



125
126
127
128
129
130
131
132
133
# File 'app/models/renalware/patient.rb', line 125

def age
  return unless born_on
  now = Time.now.utc.to_date
  now.year - born_on.year - (
    (now.month > born_on.month ||
      (now.month == born_on.month && now.day >= born_on.day)
    ) ? 0 : 1
  )
end

#assigned_to_primary_care_physician?(primary_care_physician) ⇒ Boolean

Returns:

  • (Boolean)


135
136
137
# File 'app/models/renalware/patient.rb', line 135

def assigned_to_primary_care_physician?(primary_care_physician)
  self.primary_care_physician == primary_care_physician
end

#current_modality_death?Boolean

Returns:

  • (Boolean)


139
140
141
142
143
# File 'app/models/renalware/patient.rb', line 139

def current_modality_death?
  return false if current_modality.blank?

  current_modality.description.is_a?(Deaths::ModalityDescription)
end

#diabetic?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'app/models/renalware/patient.rb', line 109

def diabetic?
  document&.diabetes&.diagnosis == true
end

#hospital_identifierObject



145
146
147
# File 'app/models/renalware/patient.rb', line 145

def hospital_identifier
  hospital_identifiers.first
end

#hospital_identifiersObject



149
150
151
# File 'app/models/renalware/patient.rb', line 149

def hospital_identifiers
  @patient_hospital_identifiers ||= Patients::PatientHospitalIdentifiers.new(self)
end

#secure_idObject

For compactness in urls, remove the dashes, so that

a12d9a8e-9cc9-4fbe-88dd-2d1c983ea04f

becomes

a12d9a8e9cc94fbe88dd2d1c983ea04f


27
28
29
# File 'app/models/renalware/patient.rb', line 27

def secure_id
  @secure_id_without_dashes ||= super&.gsub("-", "")
end

#secure_id_dashedObject



31
32
33
# File 'app/models/renalware/patient.rb', line 31

def secure_id_dashed
  self[:secure_id]
end

#to_s(format = :default) ⇒ Object

Overrides Personable mixin



114
115
116
117
118
119
120
121
122
# File 'app/models/renalware/patient.rb', line 114

def to_s(format = :default)
  title_suffix = " (#{title})" if has_title?
  formatted_name = "#{family_name.upcase}, #{given_name}#{title_suffix}"
  case format
  when :default then formatted_name
  when :long then "#{formatted_name} (#{nhs_number})"
  else full_name
  end
end