Class: Renalware::Clinics::CurrentObservations

Inherits:
Object
  • Object
show all
Defined in:
app/models/renalware/clinics/current_observations.rb

Overview

TODO: Move this to a view?

Defined Under Namespace

Classes: Observation

Constant Summary collapse

NULL_DATE =
nil

Instance Method Summary collapse

Instance Method Details

#blood_pressureObject

Returns [date, [systolic_bp, diastolic_bp]]



40
41
42
43
44
45
46
47
48
49
# File 'app/models/renalware/clinics/current_observations.rb', line 40

def blood_pressure
  @blood_pressure ||= begin
    result = ClinicVisit
              .most_recent_for_patient(patient)
              .where("systolic_bp is not null and diastolic_bp is not null")
              .pluck(:date, :systolic_bp, :diastolic_bp).first || [nil, nil, nil]

    Observation.new(result[0], [result[1], result[2]])
  end
end

#bmiObject



51
52
53
54
55
56
57
# File 'app/models/renalware/clinics/current_observations.rb', line 51

def bmi
  bmi = BMI.new(
    height: height.measurement,
    weight: weight.measurement
  )
  Observation.new(NULL_DATE, bmi.to_f)
end

#heightObject

Returns [date, height]



28
29
30
31
32
33
34
35
36
37
# File 'app/models/renalware/clinics/current_observations.rb', line 28

def height
  @height ||= begin
    result = ClinicVisit
              .most_recent_for_patient(patient)
              .where("height is not null")
              .pluck(:date, :height).first || []

    Observation.new(result.first, result.last)
  end
end

#weightObject

Returns [date, weight]



16
17
18
19
20
21
22
23
24
25
# File 'app/models/renalware/clinics/current_observations.rb', line 16

def weight
  @weight ||= begin
    result = ClinicVisit
              .most_recent_for_patient(patient)
              .where("weight is not null")
              .pluck(:date, :weight).first || []

    Observation.new(result.first, result.last)
  end
end