Encounter Place, Mode and Program Snippets

/*This provides a search box of encounter places where multilevel hierarchical encounter places are used.
Both 'administrative' and 'service' places can be selected.*/

/*
<PARAMETERS>

<ENCOUNTER_PLACE
  FUNCTION="SELECT_ENCOUNTER_PLACE"
>
</ENCOUNTER_PLACE>

</PARAMETERS>
*/

...
where (enc_place_no in (select enc_place_no from GET_ENC_PLACE_AND_DESCENDANTS(:Encounter_Place))
or cast(-1 as integer) = :Encounter_Place)
...
/*This provides a search box of encounter places where multilevel hierarchical encounter places are used.
Only 'service' places can be selected, but the hierarchy is still displayed.*/

/*
<PARAMETERS>

<ENCOUNTER_PLACE
  FUNCTION="SELECT_SERVICE_ENCOUNTER_PLACE"
>
</ENCOUNTER_PLACE>

</PARAMETERS>
*/

...
where (enc_place_no = :Encounter_Place
  or Cast(-1 as integer) = :Encounter_Place)
...
/*This provides a dropdown box of encounter places.*/

/*
<PARAMETERS>

<ENCOUNTER_PLACE
  STATEMENT="select distinct trim(ep.enc_place_desc) || case
                      when mode.enabled = 'T' then ''
                      else ' (not used)'
                    end
                  , ep.enc_place_no
             from encounter_place ep
             left outer join (
             select emp.enc_place_no
                  , max(emp.mode_place_enabled) enabled
             from encounter_mode_place emp
             group by 1
             ) mode on mode.enc_place_no = ep.enc_place_no
             union
             select cast('<All Encounter Places>' as Char(40)) enc_place_desc
                  , cast(-1 as integer) enc_place_no
             from rdb$database"
  DEFAULT="<All Encounter Places>"
>
</ENCOUNTER_PLACE>

</PARAMETERS>
*/

...
where (enc_place_no = :Encounter_Place
  or Cast(-1 as integer) = :Encounter_Place)
...
/*This provides a dropdown box of encounter places with an option to show all encounter places together.*/

/*
<PARAMETERS>

<ENCOUNTER_PLACE
  STATEMENT="select enc_place_desc
                  , enc_place_no
             from encounter_place
             union
             select cast('<All Encounter Places Together>' as Char(40)) enc_place_desc
                  , cast(-1 as integer) enc_place_no
             from rdb$database
             union
             select cast('<All Separate Encounter Places>' as Char(40)) enc_place_desc
                  , cast(-2 as integer) enc_place_no
             from rdb$database"
  DEFAULT="<All Encounter Places Together>"
>
</ENCOUNTER_PLACE>

</PARAMETERS>
*/

...
case
  when Cast(-1 as integer) = :Encounter_Place then '<All Encounter Places Together>'
  else enc_place_desc
end Place
...
where (enc_place_no = :Encounter_Place
  or Cast(0 as integer) > :Encounter_Place)
...
/*This provides a dropdown box of encounter modes.*/

/*
<PARAMETERS>

<ENCOUNTER_MODE
  STATEMENT="select em.enc_mode_desc
                  , em.enc_mode_no
             from encounter_mode_place emp
             join encounter_mode em on emp.enc_mode_no = em.enc_mode_no
             union
             select cast('<All Encounter Modes>' as Char(50)) enc_mode_desc
                  , cast(-1 as integer) enc_mode_no
             from rdb$database"
  DEFAULT="<All Encounter Modes>"
>
</ENCOUNTER_MODE>

</PARAMETERS>
*/

...
where (enc_mode_no = :Encounter_Mode
  or Cast(-1 as integer) = :Encounter_Mode)
...
/*This provides a dropdown box of record storage sites.*/

/*
<PARAMETERS>

<RECORD_STORAGE_SITE
  STATEMENT="select enc_place_desc
                  , enc_place_no
             from encounter_place
             where record_storage = 'T'
             union
             select cast('<Any Record Storage Site>' as Char(40)) enc_place_desc
                  , cast(-1 as integer) enc_place_no
             from rdb$database
             union
             select cast('<All Patients>' as Char(40)) enc_place_desc
                  , cast(-2 as integer) enc_place_no
             from rdb$database
             union
             select cast('<No Record Storage Site>' as Char(40)) enc_place_desc
                  , cast(-3 as integer) enc_place_no
             from rdb$database"
  DEFAULT="<All Patients>"
>
</RECORD_STORAGE_SITE>

</PARAMETERS>
*/

...
where ( (p.record_storage_site_no = :Record_Storage_Site)
  or (cast(-1 as integer) = :Record_Storage_Site
    and p.record_storage_site_no is not null)
  or (cast(-2 as integer) = :Record_Storage_Site)
  or (cast(-3 as integer) = :Record_Storage_Site
    and p.record_storage_site_no is null) )
...
/*This provides a dropdown box of encounter programs.*/

/*
<PARAMETERS>

<ENCOUNTER_PROGRAM
  STATEMENT="select enc_program_desc
                  , enc_program_no
             from encounter_program
             union
             select cast('<All Encounter Programs>' as varChar(40)) enc_program_desc
                  , cast(-1 as integer) enc_program_no
             from rdb$database"
  DEFAULT="<All Encounter Programs>"
>
</ENCOUNTER_PROGRAM>

</PARAMETERS>
*/

...
where (enc_program_no = :Encounter_Program
  or Cast(-1 as integer) = :Encounter_Program)
...