Permalink
Browse files

Extract Weight as a value object

  • Loading branch information...
1 parent 18b143e commit 67b31e9a37074a51fccf51495a333c207ec7d097 @nilbus committed Jul 10, 2015
Showing with 14 additions and 7 deletions.
  1. +2 −7 app/models/patient.rb
  2. +12 −0 app/models/weight.rb
@@ -24,13 +24,8 @@ def full_name
end
def weight
- if observations.map(&:code_display).include?("Body Weight")
- body_weight_observation = [observations.select{|observation| observation.code_display == "Body Weight"}].flatten.sort_by(&:date).last
- weight = "#{body_weight_observation.value} #{body_weight_observation.units}"
- else
- weight = "N/A"
- end
- weight
+ body_weight_observation = observations.select { |observation| observation.code_display == "Body Weight"}
+ Weight.new(body_weight_observation).to_s
end
def birthday
View
@@ -0,0 +1,12 @@
+class Weight
+ def initialize(observation)
+ return unless observation.present?
+ @weight = observation.value
+ @unit = observation.units
+ end
+
+ def to_s
+ return 'N/A' unless @weight.present?
+ "#{@weight} #{@unit}"
+ end
+end

0 comments on commit 67b31e9

Please sign in to comment.