Permalink
Browse files

Add sorting and 18 and under to post clinic report

  • Loading branch information...
1 parent d75ff44 commit c31a201ab79851b19bec51882618839433a6d441 @jordanbyron committed Apr 22, 2011
Showing with 15 additions and 6 deletions.
  1. +10 −3 app/models/reports/post_clinic.rb
  2. +5 −3 app/views/admin/reports/post_clinic.html.haml
@@ -27,7 +27,8 @@ def load_treatment_areas
GROUP BY patient_flows.patient_id, patient_flows.treatment_area_id
) AS pf LEFT JOIN treatment_areas
ON treatment_areas.id = pf.treatment_area_id
- GROUP BY treatment_areas.name}
+ GROUP BY treatment_areas.name
+ ORDER BY treatment_areas.name}
@areas = Patient.connection.select_all(sql)
@@ -40,9 +41,10 @@ def load_treatment_areas
end
def load_towns
- sql = %{SELECT patients.city, count(*) as patient_count
+ sql = %{SELECT patients.city, patients.state, count(*) as patient_count
FROM patients
- GROUP BY patients.city}
+ GROUP BY patients.city, patients.state
+ ORDER BY patients.state, patients.city}
@towns = Patient.connection.select_all(sql)
@@ -88,6 +90,11 @@ def load_ages
@ages << {"age" => "ages 65 and over",
"patient_count" => count}
+ count = patients.reject {|p| !(p.age <= 18) }.length
+
+ @ages << {"age" => "18 and under",
+ "patient_count" => count}
+
calculate_percentage @ages
end
@@ -30,18 +30,20 @@
%table
%thead
%tr
- %th Town Name
+ %th City
+ %th State
%th Total Patients
%th Percent
%tbody
- @report.towns.each do |town|
%tr
- %td{:id => "town_#{town['city']}"}= town["city"]
+ %td= town["city"]
+ %td= town["state"]
%td= town["patient_count"]
%td= town["percent"]
%tfoot
%tr
- %td{:colspan => 3}= "Total towns represented: #{@report.town_count}"
+ %td{:colspan => 4}= "Total towns represented: #{@report.town_count}"
%h2
%u Ethnicities

0 comments on commit c31a201

Please sign in to comment.