Class: Renalware::Patients::PatientHospitalIdentifiers
- Inherits:
-
Object
- Object
- Renalware::Patients::PatientHospitalIdentifiers
- Defined in:
- app/models/renalware/patients/patient_hospital_identifiers.rb
Defined Under Namespace
Classes: Identifier
Instance Attribute Summary collapse
-
#first ⇒ Object
readonly
Returns the value of attribute first.
-
#name ⇒ Object
(also: #to_sym)
readonly
Returns the value of attribute name.
-
#patient ⇒ Object
readonly
Returns the value of attribute patient.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #all ⇒ Object
-
#initialize(patient) ⇒ PatientHospitalIdentifiers
constructor
A new instance of PatientHospitalIdentifiers.
-
#patient_at?(hospital_code) ⇒ Boolean
Returns true if the patient has a hospital number at the requested hospital.
-
#to_s ⇒ Object
Renders all patients hospital numbers in the format e.g.
- #to_s_multiline ⇒ Object
Constructor Details
#initialize(patient) ⇒ PatientHospitalIdentifiers
Returns a new instance of PatientHospitalIdentifiers.
32 33 34 |
# File 'app/models/renalware/patients/patient_hospital_identifiers.rb', line 32 def initialize(patient) @patient = patient end |
Instance Attribute Details
#first ⇒ Object (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 |
#name ⇒ Object (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 |
#patient ⇒ Object (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 |
#value ⇒ Object (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
#all ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'app/models/renalware/patients/patient_hospital_identifiers.rb', line 40 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
63 64 65 66 67 |
# File 'app/models/renalware/patients/patient_hospital_identifiers.rb', line 63 def patient_at?(hospital_code) return false if hospital_code.blank? all.key?(hospital_code.to_sym.upcase) end |
#to_s ⇒ Object
Renders all patients hospital numbers in the format e.g. “KCH: X12344 QEH: 12123123 XXX: Xxxxx …”
52 53 54 |
# File 'app/models/renalware/patients/patient_hospital_identifiers.rb', line 52 def to_s all.map { |name, hosp_no| "#{name}: #{hosp_no}" }.join(" ") end |
#to_s_multiline ⇒ Object
56 57 58 |
# File 'app/models/renalware/patients/patient_hospital_identifiers.rb', line 56 def to_s_multiline all.map { |name, hosp_no| "#{name}: #{hosp_no}" }.join("<br>").html_safe end |