Created
November 3, 2012 06:23
-
-
Save jnwheeler44/4006269 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Chair < ActiveRecord::Base | |
belongs_to :person | |
belongs_to :location | |
has_one :result | |
has_many :reports, :through=>:result | |
def self.get_home_page_data(location, user) | |
sql = 'SELECT DISTINCT c.id, c.received_on, c.info, c.number, c.condition_id, | |
p.first_name, p.last_name, p.middle_initial, ' | |
sql += ' rp.active, rp.viewed, rp.printed, rs.diagnosis_id ' | |
sql += "FROM chairs c, reports rp, results rs, persons p " | |
sql += "WHERE rs.chairs_id = chairs.id AND " | |
search_user = User.find(user) | |
sql += '(' | |
for permission in search_user.chair_permissions | |
sql += "person_id ='#{permission.owner_id}' OR " | |
end | |
sql.chop! | |
sql.chop! | |
sql.chop! | |
sql += ') AND ' | |
sql += "rp.result_id = rs.id AND " | |
sql += "rp.active = 1 AND" | |
sql += "rp.viewed = 0 AND " | |
sql += "c.person_id = p.id AND " | |
sql += "c.location_id = #{location}" | |
Chair.find_by_sql(sql) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment