Skip to content

Commit

Permalink
counting only checked in patients
Browse files Browse the repository at this point in the history
  • Loading branch information
kbl committed Jan 13, 2012
1 parent 885b5dd commit bab2fc7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
12 changes: 7 additions & 5 deletions app/models/treatment_area.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
class TreatmentArea < ActiveRecord::Base
has_many :procedure_treatment_area_mappings
has_many :procedures, :through => :procedure_treatment_area_mappings,
:order => "code"
has_many :procedures, through: :procedure_treatment_area_mappings,
order: 'code'
# TODO kbl
has_many :patient_assignments
has_many :patients, :through => :patient_assignments
has_many :patients, through: :patient_assignments,
conditions: 'checked_out_at IS NULL'

accepts_nested_attributes_for :procedure_treatment_area_mappings, :allow_destroy => true,
:reject_if => proc { |attributes| attributes['assigned'] == "0" }
accepts_nested_attributes_for :procedure_treatment_area_mappings,
allow_destroy: true,
reject_if: proc { |attributes| attributes['assigned'] == "0" }

def self.radiology
TreatmentArea.find(:first, :conditions => {:name => "Radiology"})
Expand Down
19 changes: 19 additions & 0 deletions test/unit/treatment_area_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'test_helper'

class TreatmentAreaTest < ActiveSupport::TestCase

def test_should_count_only_checked_in_patients
area = Factory(:treatment_area)
p1 = Factory(:patient)
p2 = Factory(:patient)
p3 = Factory(:patient)

[p1, p2, p3].each { |p| p.check_in(area) }

assert_equal 3, area.patients.count

p3.check_out(area)
assert_equal 2, area.patients.count
end

end

0 comments on commit bab2fc7

Please sign in to comment.