Patient Group Snippets

/*This provides a dropdown box for patient groups.*/

/*
<PARAMETERS>

<PATIENT_GROUP
  STATEMENT="select pg.grp_desc
                  , pg.pat_grp_no
             from pat_group pg
             join pat_group_type pgt on pg.pat_grp_type_no = pgt.pat_grp_type_no
               and pgt.sys_code <> 'STA'
             where pg.grp_enabled = 'T'
             union
             select cast('<No Patient Group>' as VarChar(40)) grp_desc
                  , cast(-2 as integer) pat_grp_no
             from rdb$database
             union
             select cast('<All>' as VarChar(40)) grp_desc
                  , cast(-1 as integer) pat_grp_no
             from rdb$database"
  DEFAULT="<All>"
>
</PATIENT_GROUP>

</PARAMETERS>
*/

...
left outer join (pat_group_member pgm
join pat_group pg on pg.pat_grp_no = pgm.pat_grp_no
join pat_group_type pgt on pgt.pat_grp_type_no = pg.pat_grp_type_no
  and pgt.sys_code <> 'STA'
  and pg.grp_enabled = 'T'
  and pg.pat_grp_no = :Patient_Group) on pgm.pat_id = p.pat_id
...
where ((((pgm.pat_grp_no = :Patient_Group)
    and (pgm.join_date <= :Reference_date)
    and ((pgm.exit_date > :Reference_date)
      or (pgm.exit_date is null)))
  or (Cast(-1 as integer) = :Patient_Group))
  or (pgm.pat_grp_no is null
    and :Patient_Group = -2))
...