Skip to content

Commit

Permalink
Extract Weight as a value object
Browse files Browse the repository at this point in the history
  • Loading branch information
nilbus committed Jul 10, 2015
1 parent 18b143e commit 67b31e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
9 changes: 2 additions & 7 deletions app/models/patient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions app/models/weight.rb
Original file line number Diff line number Diff line change
@@ -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.