====== pears.psHealthShowButton ======
Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace.
===== Original SQL =====
create function "pears"."psHealthShowButton"(
/* Application Maintained Function / Procedure - DO NOT EDIT*/
in "SourceID" char(20),in "IDType" char(2) )
returns integer
begin
if "sourceid" is null then
return 0
end if;
/* IDType R = recipient, S = temp shift, P = temp shift plan C = carer, V = vacancy */
if not exists(select * from "wpkglobalswitchsetting" where "wpkglobalswitchid" = 'PSHealth' and "value" = 'Y') then
return 0
end if;
/* in case some silly person turns switch on without tables installed (check person only) */
if not exists(select * from "sys"."systable" where "table_name" = 'PSHealthPerson') then
return 0
end if;
case "IDType"
when 'R' then if exists(select * from "pshealthperson" where "personid" = "sourceid" and "recipientflag" = 'R') then return 1
end if when 'C' then if exists(select * from "pshealthperson" where "personid" = "sourceid" and "recipientflag" = 'C') then return 1
end if when 'V' then if exists(select * from "pshealthvacancy" where "vacancyid" = "sourceid") then return 1
end if when 'S' then if exists(select * from "pshealthshift" where "tempshiftid" = "sourceid") then return 1
end if when 'P' then if exists(select * from "pshealthshift" where "tempshiftplanid" = "sourceid") then return 1
end if
end case;
return 0
end