Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- declare @FacID varchar(max) = 'HW', @Start datetime = '10/1/2014', @End datetime = '10/31/2014',
- @UsePPSPayer bit = 0, @UseBPSPayer bit = 1;
- select left(r.RUG,2) as LetterRUG, COUNT(*) as RUGCount
- from DARPatient p
- inner join DARPPSCase pc on pc.DarPtID = p.DARPtID
- inner join DARRug r on r.DARPPSID = pc.DARPPSCaseID
- and r.RUGDate between @Start and @End
- cross apply (
- select top 1 bps.Method
- from Facility f
- inner join BillingContract bc on bc.Name = f.CurrentContract
- inner join BillingPayerSource bps on bps.ContractID = bc.ID and bps.Name = pc.Payer
- where f.FacilityID = p.FacilityID
- and bc.EffectiveDate <= r.RUGDate
- order by bc.EffectiveDate desc) as bps
- where p.FacilityID = @FacID
- and (@UseBPSPayer = 0 or bps.Method = 'RUG')
- and (@UsePPSPayer = 0 or pc.Payer = 'A')
- group by left(r.RUG,2)
- select r.RUGMod, COUNT(*) as RUGCount
- from DARPatient p
- inner join DARPPSCase pc on pc.DarPtID = p.DARPtID
- inner join DARRug r on r.DARPPSID = pc.DARPPSCaseID
- and r.RUGDate between @Start and @End
- cross apply (
- select top 1 bps.Method
- from Facility f
- inner join BillingContract bc on bc.Name = f.CurrentContract
- inner join BillingPayerSource bps on bps.ContractID = bc.ID and bps.Name = pc.Payer
- where f.FacilityID = p.FacilityID
- and bc.EffectiveDate <= r.RUGDate
- order by bc.EffectiveDate desc) as bps
- where p.FacilityID = @FacID
- and (@UseBPSPayer = 0 or bps.Method = 'RUG')
- and (@UsePPSPayer = 0 or pc.Payer = 'A')
- group by RUGMod
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement