Class: Renalware::Patients::PatientHospitalIdentifiers

Inherits:
Object
  • Object
show all
Defined in:
app/models/renalware/patients/patient_hospital_identifiers.rb

Defined Under Namespace

Classes: Identifier

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(patient) ⇒ PatientHospitalIdentifiers

Returns a new instance of PatientHospitalIdentifiers.



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

def initialize(patient)
  @patient = patient
end

Instance Attribute Details

#firstObject (readonly)

Returns the value of attribute first.



17
18
19
# File 'app/models/renalware/patients/patient_hospital_identifiers.rb', line 17

def first
  @first
end

#nameObject (readonly) Also known as: to_sym

Returns the value of attribute name.



17
18
19
# File 'app/models/renalware/patients/patient_hospital_identifiers.rb', line 17

def name
  @name
end

#patientObject (readonly)

Returns the value of attribute patient.



17
18
19
# File 'app/models/renalware/patients/patient_hospital_identifiers.rb', line 17

def patient
  @patient
end

#valueObject (readonly)

Returns the value of attribute value.



17
18
19
# File 'app/models/renalware/patients/patient_hospital_identifiers.rb', line 17

def value
  @value
end

Instance Method Details

#allObject



39
40
41
42
43
44
45
46
47
# File 'app/models/renalware/patients/patient_hospital_identifiers.rb', line 39

def all
  @all ||= begin
    identifier_map.each_with_object({}) do |name_and_column, hash|
      name, column = name_and_column
      patient_id = patient.public_send(column)
      hash[name] = patient_id if patient_id.present?
    end
  end
end

#patient_at?(hospital_code) ⇒ Boolean

Returns true if the patient has a hospital number at the requested hospital. Example usage

PatientHospitalIdentifiers.new(patient).patient_at?(:KCH) # => true

Returns:

  • (Boolean)


62
63
64
65
66
# File 'app/models/renalware/patients/patient_hospital_identifiers.rb', line 62

def patient_at?(hospital_code)
  return false if hospital_code.blank?

  all.key?(hospital_code.to_sym.upcase)
end

#to_sObject

Renders all patients hospital numbers in the format e.g. “KCH: X12344 QEH: 12123123 XXX: Xxxxx …”



51
52
53
# File 'app/models/renalware/patients/patient_hospital_identifiers.rb', line 51

def to_s
  all.map { |name, hosp_no| "#{name}: #{hosp_no}" }.join(" ")
end

#to_s_multilineObject



55
56
57
# File 'app/models/renalware/patients/patient_hospital_identifiers.rb', line 55

def to_s_multiline
  all.map { |name, hosp_no| "#{name}: #{hosp_no}" }.join("<br>").html_safe
end