Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. declare @FacID varchar(max) = 'HW', @Start datetime = '10/1/2014', @End datetime = '10/31/2014',
  2. @UsePPSPayer bit = 0, @UseBPSPayer bit = 1;
  3.  
  4. select left(r.RUG,2) as LetterRUG, COUNT(*) as RUGCount
  5. from DARPatient p
  6. inner join DARPPSCase pc on pc.DarPtID = p.DARPtID
  7. inner join DARRug r on r.DARPPSID = pc.DARPPSCaseID
  8. and r.RUGDate between @Start and @End
  9.  
  10. cross apply (
  11. select top 1 bps.Method
  12. from Facility f
  13. inner join BillingContract bc on bc.Name = f.CurrentContract
  14. inner join BillingPayerSource bps on bps.ContractID = bc.ID and bps.Name = pc.Payer
  15. where f.FacilityID = p.FacilityID
  16. and bc.EffectiveDate <= r.RUGDate
  17. order by bc.EffectiveDate desc) as bps
  18. where p.FacilityID = @FacID
  19. and (@UseBPSPayer = 0 or bps.Method = 'RUG')
  20. and (@UsePPSPayer = 0 or pc.Payer = 'A')
  21. group by left(r.RUG,2)
  22.  
  23. select r.RUGMod, COUNT(*) as RUGCount
  24. from DARPatient p
  25. inner join DARPPSCase pc on pc.DarPtID = p.DARPtID
  26. inner join DARRug r on r.DARPPSID = pc.DARPPSCaseID
  27. and r.RUGDate between @Start and @End
  28. cross apply (
  29. select top 1 bps.Method
  30. from Facility f
  31. inner join BillingContract bc on bc.Name = f.CurrentContract
  32. inner join BillingPayerSource bps on bps.ContractID = bc.ID and bps.Name = pc.Payer
  33. where f.FacilityID = p.FacilityID
  34. and bc.EffectiveDate <= r.RUGDate
  35. order by bc.EffectiveDate desc) as bps
  36. where p.FacilityID = @FacID
  37. and (@UseBPSPayer = 0 or bps.Method = 'RUG')
  38. and (@UsePPSPayer = 0 or pc.Payer = 'A')
  39. group by RUGMod
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement