Created
January 13, 2011 16:07
-
-
Save chrislerum/778100 to your computer and use it in GitHub Desktop.
thing.rb
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
require 'rubygems' | |
require 'active_record' | |
require 'active_support' | |
#require_relative '/data/database.rb' | |
ActiveRecord::Base.establish_connection( | |
:adapter => "mysql", | |
:user => "root", | |
:password => "", | |
:database => "arvest" | |
) | |
class Employee < ActiveRecord::Base | |
end | |
class Dependents < ActiveRecord::Base | |
end | |
class WellnessPolicies < ActiveRecord::Base | |
end | |
class WellnessScreening < ActiveRecord::Base | |
end | |
class NewBillingRecord < ActiveRecord::Base | |
end | |
person = WellnessScreening.find_by_sql(<<-SQL | |
SELECT br.account_name, br.account_id, | |
if((participant_first_name = "Spouse"), if((d.dependent_first_name != ""),d.dependent_first_name,participant_first_name), participant_first_name) as participant_first_name, | |
participant_last_name, | |
if((participant_first_name = "Spouse"), d.dependent_dob, e.dob) AS dob, | |
ws.insured_first, ws.insured_last, ws.insured_id AS "", | |
e.address, e.city, e.state, e.zip, e.home_phone, | |
p.policy_number, p.policy_type | |
FROM wellness_screenings as ws | |
LEFT JOIN employees as e ON e.`employee_id` = ws.employee_id | |
LEFT JOIN dependents as d ON d.employee_ident = ws.employee_id and d.dependent_relationship = "S" and ws.participant_first_name = "Spouse" | |
LEFT JOIN wellness_policies as p ON ws.employee_id = p.payor_number | |
JOIN newBillingRecord as br | |
SQL) | |
puts "Employee Record" | |
person.each do |p| | |
puts %{#{p.payor_number} - #{p.employee_id} - #{p.policy}} | |
end | |
policy = WellnessPolicies.find(:first) | |
puts "Wellness Record" | |
puts %{ #{policy.payor_number} #{policy.payor_name} #{policy.policy_number} #{policy.policy_type} } | |
screening = WellnessScreening.find(:first) | |
puts "Screening Record" | |
puts %{ #{screening.account_name} #{screening.account_id} #{screening.employee_id} } | |
SELECT br.account_name, br.account_id, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment