Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.73 KB | None | 0 0
  1. with hassgn as (
  2. select 'A2740'::text as org_id, 'cms_mssp|'::text || "HICN" as fk_patient_id,
  3. "First Name" as src_bene_first_name, "Last Name" as src_bene_last_name,
  4. case when "CMS-HCC Risk Score for ESRD Status8" <> '' then 'esrd'
  5. when "CMS-HCC Risk Score for Disabled Status8" <> '' then 'disabled'
  6. when "CMS-HCC Risk Score for Aged/Dual Status8" <> '' then 'aged/dual'
  7. when "CMS-HCC Risk Score for Aged/Non-dual Status8" <> '' then 'aged/non-dual'
  8. end as cohort_type,
  9. case when "CMS-HCC Risk Score for ESRD Status8" <> '' then "CMS-HCC Risk Score for ESRD Status8"
  10. when "CMS-HCC Risk Score for Disabled Status8" <> '' then "CMS-HCC Risk Score for Disabled Status8"
  11. when "CMS-HCC Risk Score for Aged/Dual Status8" <> '' then "CMS-HCC Risk Score for Aged/Dual Status8"
  12. when "CMS-HCC Risk Score for Aged/Non-dual Status8" <> '' then "CMS-HCC Risk Score for Aged/Non-dual Status8"
  13. end as hcc_score,
  14. case when "Monthly Eligibility Flag 16" > 0 then 1 else 0 end as month_1_cd,
  15. case when "Monthly Eligibility Flag 26" > 0 then 1 else 0 end as month_2_cd,
  16. case when "Monthly Eligibility Flag 36" > 0 then 1 else 0 end as month_3_cd,
  17. case when "Monthly Eligibility Flag 46" > 0 then 1 else 0 end as month_4_cd,
  18. case when "Monthly Eligibility Flag 56" > 0 then 1 else 0 end as month_5_cd,
  19. case when "Monthly Eligibility Flag 66" > 0 then 1 else 0 end as month_6_cd,
  20. case when "Monthly Eligibility Flag 76" > 0 then 1 else 0 end as month_7_cd,
  21. case when "Monthly Eligibility Flag 86" > 0 then 1 else 0 end as month_8_cd,
  22. case when "Monthly Eligibility Flag 96" > 0 then 1 else 0 end as month_9_cd,
  23. case when "Monthly Eligibility Flag 106" > 0 then 1 else 0 end as month_10_cd,
  24. case when "Monthly Eligibility Flag 116" > 0 then 1 else 0 end as month_11_cd,
  25. case when "Monthly Eligibility Flag 126" > 0 then 1 else 0 end as month_12_cd
  26. from sndbx."P.2740.ACO.HASSGN.Y2016"
  27. -- where "Newly Assigned Beneficiary Flag5" = '1'
  28. ),
  29.  
  30. pat_pmpy_mm as (
  31. select org_id, fk_patient_id,
  32. sum(case when month_cd = 'm-2016-01' then paid_amt else 0 end) as month_1_pmpy,
  33. sum(case when month_cd = 'm-2016-02' then paid_amt else 0 end) as month_2_pmpy,
  34. sum(case when month_cd = 'm-2016-03' then paid_amt else 0 end) as month_3_pmpy,
  35. sum(case when month_cd = 'm-2016-04' then paid_amt else 0 end) as month_4_pmpy,
  36. sum(case when month_cd = 'm-2016-05' then paid_amt else 0 end) as month_5_pmpy,
  37. sum(case when month_cd = 'm-2016-06' then paid_amt else 0 end) as month_6_pmpy,
  38. sum(case when month_cd = 'm-2016-07' then paid_amt else 0 end) as month_7_pmpy,
  39. sum(case when month_cd = 'm-2016-08' then paid_amt else 0 end) as month_8_pmpy,
  40. sum(case when month_cd = 'm-2016-09' then paid_amt else 0 end) as month_9_pmpy,
  41. sum(case when month_cd = 'm-2016-10' then paid_amt else 0 end) as month_10_pmpy,
  42. sum(case when month_cd = 'm-2016-11' then paid_amt else 0 end) as month_11_pmpy,
  43. sum(case when month_cd = 'm-2016-12' then paid_amt else 0 end) as month_12_pmpy
  44. from wkbk2.metric_value_qexpu
  45. where org_id = 'A2740' and month_cd between 'm-2016-01' and 'm-2016-12'
  46. group by 1,2),
  47.  
  48.  
  49. pat_pmpy as (
  50. select ha.org_id, ha.fk_patient_id,
  51. sum(pp.month_1_pmpy * ha.month_1_cd + pp.month_2_pmpy * ha.month_2_cd + pp.month_3_pmpy * ha.month_3_cd
  52. + pp.month_4_pmpy * ha.month_4_cd + pp.month_5_pmpy * ha.month_5_cd + pp.month_6_pmpy * ha.month_6_cd
  53. + pp.month_7_pmpy * ha.month_7_cd + pp.month_8_pmpy * ha.month_8_cd + pp.month_9_pmpy * ha.month_9_cd
  54. + pp.month_10_pmpy * ha.month_10_cd + pp.month_11_pmpy * ha.month_11_cd + pp.month_12_pmpy * ha.month_12_cd) as pmpy
  55. from hassgn ha
  56. inner join pat_pmpy_mm pp
  57. on ha.fk_patient_id = pp.fk_patient_id
  58. and ha.org_id = pp.org_id
  59. group by 1,2)
  60.  
  61. select sum(pmpy) from pat_pmpy
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement