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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Accountable

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

Instance Attribute Details

#skip_death_validationsObject

Returns the value of attribute skip_death_validations.



111
112
113
# File 'app/models/renalware/patient.rb', line 111

def skip_death_validations
  @skip_death_validations
end

Class Method Details

.policy_classObject



123
124
125
# File 'app/models/renalware/patient.rb', line 123

def self.policy_class
  BasePolicy
end

Instance Method Details

#ageObject



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

def age
  Patients::CalculateAge.for(self)
end

#assigned_to_primary_care_physician?(primary_care_physician) ⇒ Boolean

Returns:

  • (Boolean)


153
154
155
# File 'app/models/renalware/patient.rb', line 153

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

#current_modality_death?Boolean

Returns:

  • (Boolean)


161
162
163
164
165
# File 'app/models/renalware/patient.rb', line 161

def current_modality_death?
  return false if current_modality.blank?

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

#diabetic?Boolean

Returns:

  • (Boolean)


127
128
129
# File 'app/models/renalware/patient.rb', line 127

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

#hospital_identifierObject



167
168
169
# File 'app/models/renalware/patient.rb', line 167

def hospital_identifier
  hospital_identifiers.first
end

#hospital_identifiersObject



171
172
173
# File 'app/models/renalware/patient.rb', line 171

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

#nhs_number_formattedObject

Add spacing to an NHS number e.g. “7465613493” => “746 561 3493” Although this is arguably a view concern, formati



133
134
135
# File 'app/models/renalware/patient.rb', line 133

def nhs_number_formatted
  nhs_number&.gsub(/(\d{3})(\d{3})(\d{4})/, '\1 \2 \3')
end

#secure_idObject

For compactness in urls, remove the dashes, so that

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

becomes

a12d9a8e9cc94fbe88dd2d1c983ea04f


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

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

#secure_id_dashedObject



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

def secure_id_dashed
  self[:secure_id]
end

#to_s(format = :default) ⇒ Object

Overrides Personable mixin



138
139
140
141
142
143
144
145
146
147
# File 'app/models/renalware/patient.rb', line 138

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

#validate_death_attributes?Boolean

Returns:

  • (Boolean)


157
158
159
# File 'app/models/renalware/patient.rb', line 157

def validate_death_attributes?
  current_modality_death? && !skip_death_validations
end