 -- this groups comorbidities together for a single patient admission
 , eligrp as
 (
-  select hadm_id
+  select hadm_id, subject_id
   , max(chf) as chf
   , max(arythm) as arythm
   , max(valve) as valve

  , max(psych) as psych
  , max(depress) as depress
from eliflg
group by hadm_id
)

-- DRG FILTER --
, msdrg as
(
select
  hadm_id
/**** V29 MS-DRG Formats ****/

/* Cardiac */


from
(
  select hadm_id, subject_id, drg_type, cast(drg_code as numeric) as drg_code from mimiciii.drgcodes where drg_type = 'MS'
) d

)
, hcfadrg as
(
select
  hadm_id, subject_id

  /** V24 DRG Formats  **/

