Skip to content

Instantly share code, notes, and snippets.

@chrislerum
Forked from esparkman/claim_builder.rb
Created January 13, 2011 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrislerum/778122 to your computer and use it in GitHub Desktop.
Save chrislerum/778122 to your computer and use it in GitHub Desktop.
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} }
ruby lib/claim_builder.rb
lib/claim_builder.rb:57: can't find string "SQL" anywhere before EOF
lib/claim_builder.rb:30: syntax error, unexpected $end, expecting tSTRING_CONTENT or tSTRING_DBEG or tSTRING_DVAR or tSTRING_END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment