alter table examematcoleta add emc_loinc varchar(20); insert into atualizacoes(atu_nome) values ('v23000001_101122.sql'); alter table filiais_postocoleta drop fil_pushhoraaniversario, drop fil_pushhorainicial, drop fil_pushhorafinal, drop fil_pushhorariodiasagendamento; alter table filiais_postocoleta add fil_pushhoraaniversario time, add fil_pushhorainicial time, add fil_pushhorafinal time, add fil_pushhorariodiasagendamento time; insert into atualizacoes(atu_nome) values ('v23000002_171122.sql'); set session_replication_role=replica; alter table paciente add pac_bloquearpushapp boolean default false; alter table convenios add con_bloquearpushexamepronto boolean default false, add con_bloquearpushrecoleta boolean default false, add con_bloquearpushaniversario boolean default false; alter table medico add med_bloquearpushexamepronto boolean default false, add med_bloquearpushrecoleta boolean default false; alter table requisicao add req_pushresultadoenviado timestamp; set session_replication_role=origin; alter table logpushapp add lpa_token varchar(200); alter table logpushapp add lpa_origem varchar(1); --drop sequence logpushapp_1_sequence; do $$ declare s varchar; begin for s in SELECT sequence_name FROM information_schema.sequences where sequence_name ilike 'logpushapp_%' loop execute 'drop sequence ' || s; raise notice '%', s; end loop; end $$; select criasequencia('logpushapp'); insert into atualizacoes(atu_nome) values ('v23000003_181122.sql'); set session_replication_role=replica; alter table destino add des_bloquearpushexamepronto boolean default false, add des_bloquearpushrecoleta boolean default false; set session_replication_role=origin; insert into atualizacoes(atu_nome) values ('v23000004_211122.sql'); alter table configuracoesservicos add cfg_servidorpush text; insert into atualizacoes(atu_nome) values ('v23000005_221122.sql'); alter table filiais_postocoleta add fil_titulopushaniversario varchar(300), add fil_titulopushresultados varchar(300), add fil_titulopushrecoleta varchar(300), add fil_titulopushrequisicao varchar(300), add fil_titulopushagendamento varchar(300); alter table logpushapp add lpa_titulo varchar(300); insert into atualizacoes(atu_nome) values ('v23000006_221122.sql'); alter table fraseagendamentopush add fpu_titulo varchar(300); create table requisicaolabexternopendencia ( fil_codigo integer not null, req_codigo integer not null, lae_codigo integer not null, rlp_codigo serial not null, rlp_datahoraconsulta timestamp, rlp_pendencia varchar(8000), usr_codigo varchar(20) ); create unique index xpkrequisicaolabexternopendenci on requisicaolabexternopendencia ( fil_codigo, req_codigo, lae_codigo, rlp_codigo ); create index xif1requisicaolabexternopendenc on requisicaolabexternopendencia ( fil_codigo, req_codigo ); create index xif2requisicaolabexternopendenc on requisicaolabexternopendencia ( fil_codigo, lae_codigo ); create index xif3requisicaolabexternopendenc on requisicaolabexternopendencia ( usr_codigo ); alter table requisicaolabexternopendencia add primary key (fil_codigo, req_codigo, lae_codigo, rlp_codigo); drop function fn_td_labexterno() cascade; create function fn_td_labexterno() returns opaque as ' declare numrows integer; begin select count(*) into numrows from requisicaolabexternopendencia where requisicaolabexternopendencia.fil_codigo = old.fil_codigo and requisicaolabexternopendencia.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaolabexternopendencia.''; end if; delete from examesindlab where examesindlab.fil_codigo = old.fil_codigo and examesindlab.lae_codigo = old.lae_codigo; select count(*) into numrows from convenios where convenios.fil_codigo = old.fil_codigo and convenios.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela convenios.''; end if; select count(*) into numrows from materialalvaro where materialalvaro.fil_codigo = old.fil_codigo and materialalvaro.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materialalvaro.''; end if; delete from labexternolotepardini where labexternolotepardini.fil_codigo = old.fil_codigo and labexternolotepardini.lae_codigo = old.lae_codigo; delete from labexternologintegracao where labexternologintegracao.fil_codigo = old.fil_codigo and labexternologintegracao.lae_codigo = old.lae_codigo; delete from labexternoversaotermo where labexternoversaotermo.fil_codigo = old.fil_codigo and labexternoversaotermo.lae_codigo = old.lae_codigo; select count(*) into numrows from examessaomarcos where examessaomarcos.fil_codigo = old.fil_codigo and examessaomarcos.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examessaomarcos.''; end if; delete from examessyslab where examessyslab.fil_codigo = old.fil_codigo and examessyslab.lae_codigo = old.lae_codigo; delete from examesunilab where examesunilab.fil_codigo = old.fil_codigo and examesunilab.lae_codigo = old.lae_codigo; select count(*) into numrows from filiais_postocoleta where filiais_postocoleta.fil_codigo = old.fil_codigo and filiais_postocoleta.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela filiais_postocoleta.''; end if; delete from logimportacaolabexterno where logimportacaolabexterno.fil_codigo = old.fil_codigo and logimportacaolabexterno.lae_codigo = old.lae_codigo; select count(*) into numrows from examessolucao where examessolucao.fil_codigo = old.fil_codigo and examessolucao.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examessolucao.''; end if; select count(*) into numrows from examesdb where examesdb.fil_codigo = old.fil_codigo and examesdb.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examesdb.''; end if; delete from examesatitude where examesatitude.fil_codigo = old.fil_codigo and examesatitude.lae_codigo = old.lae_codigo; delete from examesbalague where examesbalague.fil_codigo = old.fil_codigo and examesbalague.lae_codigo = old.lae_codigo; delete from examesdelta where examesdelta.fil_codigo = old.fil_codigo and examesdelta.lae_codigo = old.lae_codigo; select count(*) into numrows from examematcoletalabexterno where examematcoletalabexterno.fil_codigo = old.fil_codigo and examematcoletalabexterno.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examematcoletalabexterno.''; end if; select count(*) into numrows from examesmatrix where examesmatrix.fil_codigo = old.fil_codigo and examesmatrix.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examesmatrix.''; end if; select count(*) into numrows from examesrede where examesrede.fil_codigo = old.fil_codigo and examesrede.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examesrede.''; end if; delete from examesreacao where examesreacao.fil_codigo = old.fil_codigo and examesreacao.lae_codigo = old.lae_codigo; select count(*) into numrows from pacientelabexterno where pacientelabexterno.fil_codigo = old.fil_codigo and pacientelabexterno.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela pacientelabexterno.''; end if; select count(*) into numrows from requisicaolabexterno where requisicaolabexterno.fil_codigo = old.fil_codigo and requisicaolabexterno.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaolabexterno.''; end if; delete from examessergiofranco where examessergiofranco.fil_codigo = old.fil_codigo and examessergiofranco.lae_codigo = old.lae_codigo; delete from examesalvaro where examesalvaro.fil_codigo = old.fil_codigo and examesalvaro.lae_codigo = old.lae_codigo; select count(*) into numrows from examesjalis where examesjalis.fil_codigo = old.fil_codigo and examesjalis.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examesjalis.''; end if; delete from examespardini where examespardini.fil_codigo = old.fil_codigo and examespardini.lae_codigo = old.lae_codigo; select count(*) into numrows from loteexterno where loteexterno.fil_codigo = old.fil_codigo and loteexterno.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteexterno.''; end if; return old; end;' language 'plpgsql'; create trigger td_labexterno after delete on labexterno for each row execute procedure fn_td_labexterno(); drop function fn_ti_labexterno() cascade; create function fn_ti_labexterno() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from prazoentrega where new.fil_codigo = prazoentrega.fil_codigo and new.prz_codigo = prazoentrega.prz_codigo; tmp:=''prazoentrega|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''prz_codigo='' || new.prz_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.prz_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela prazoentrega. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from metodologia where new.fil_codigo = metodologia.fil_codigo and new.met_codigo = metodologia.met_codigo; tmp:=''metodologia|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''met_codigo='' || new.met_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.met_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela metodologia. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from setores where new.fil_codigo = setores.fil_codigo and new.set_codigo = setores.set_codigo; tmp:=''setores|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''set_codigo='' || new.set_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.set_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela setores. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codconferir = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codconferir || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codconferir is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from filiais_postocoleta where new.fil_codigo = filiais_postocoleta.fil_codigo; tmp:=''filiais_postocoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela filiais_postocoleta. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; return new; end;' language 'plpgsql'; create trigger ti_labexterno after insert on labexterno for each row execute procedure fn_ti_labexterno(); drop function fn_tu_labexterno() cascade; create function fn_tu_labexterno() returns opaque as ' declare numrows integer; tmp varchar; begin if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from requisicaolabexternopendencia where requisicaolabexternopendencia.fil_codigo = old.fil_codigo and requisicaolabexternopendencia.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaolabexternopendencia.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesindlab where examesindlab.fil_codigo = old.fil_codigo and examesindlab.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesindlab.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from convenios where convenios.fil_codigo = old.fil_codigo and convenios.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela convenios.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from materialalvaro where materialalvaro.fil_codigo = old.fil_codigo and materialalvaro.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materialalvaro.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from labexternolotepardini where labexternolotepardini.fil_codigo = old.fil_codigo and labexternolotepardini.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela labexternolotepardini.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from labexternologintegracao where labexternologintegracao.fil_codigo = old.fil_codigo and labexternologintegracao.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela labexternologintegracao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from labexternoversaotermo where labexternoversaotermo.fil_codigo = old.fil_codigo and labexternoversaotermo.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela labexternoversaotermo.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examessaomarcos where examessaomarcos.fil_codigo = old.fil_codigo and examessaomarcos.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examessaomarcos.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examessyslab where examessyslab.fil_codigo = old.fil_codigo and examessyslab.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examessyslab.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesunilab where examesunilab.fil_codigo = old.fil_codigo and examesunilab.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesunilab.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from filiais_postocoleta where filiais_postocoleta.fil_codigo = old.fil_codigo and filiais_postocoleta.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela filiais_postocoleta.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from logimportacaolabexterno where logimportacaolabexterno.fil_codigo = old.fil_codigo and logimportacaolabexterno.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logimportacaolabexterno.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examessolucao where examessolucao.fil_codigo = old.fil_codigo and examessolucao.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examessolucao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesdb where examesdb.fil_codigo = old.fil_codigo and examesdb.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesdb.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesatitude where examesatitude.fil_codigo = old.fil_codigo and examesatitude.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesatitude.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesbalague where examesbalague.fil_codigo = old.fil_codigo and examesbalague.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesbalague.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesdelta where examesdelta.fil_codigo = old.fil_codigo and examesdelta.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesdelta.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examematcoletalabexterno where examematcoletalabexterno.fil_codigo = old.fil_codigo and examematcoletalabexterno.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examematcoletalabexterno.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesmatrix where examesmatrix.fil_codigo = old.fil_codigo and examesmatrix.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesmatrix.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesrede where examesrede.fil_codigo = old.fil_codigo and examesrede.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesrede.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesreacao where examesreacao.fil_codigo = old.fil_codigo and examesreacao.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesreacao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from pacientelabexterno where pacientelabexterno.fil_codigo = old.fil_codigo and pacientelabexterno.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela pacientelabexterno.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from requisicaolabexterno where requisicaolabexterno.fil_codigo = old.fil_codigo and requisicaolabexterno.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaolabexterno.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examessergiofranco where examessergiofranco.fil_codigo = old.fil_codigo and examessergiofranco.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examessergiofranco.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesalvaro where examesalvaro.fil_codigo = old.fil_codigo and examesalvaro.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesalvaro.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesjalis where examesjalis.fil_codigo = old.fil_codigo and examesjalis.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesjalis.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examespardini where examespardini.fil_codigo = old.fil_codigo and examespardini.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examespardini.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from loteexterno where loteexterno.fil_codigo = old.fil_codigo and loteexterno.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteexterno.''; end if; end if; select count(*) into numrows from prazoentrega where new.fil_codigo = prazoentrega.fil_codigo and new.prz_codigo = prazoentrega.prz_codigo; tmp:=''prazoentrega|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''prz_codigo='' || new.prz_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.prz_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela prazoentrega. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from metodologia where new.fil_codigo = metodologia.fil_codigo and new.met_codigo = metodologia.met_codigo; tmp:=''metodologia|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''met_codigo='' || new.met_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.met_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela metodologia. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from setores where new.fil_codigo = setores.fil_codigo and new.set_codigo = setores.set_codigo; tmp:=''setores|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''set_codigo='' || new.set_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.set_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela setores. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codconferir = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codconferir || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codconferir is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from filiais_postocoleta where new.fil_codigo = filiais_postocoleta.fil_codigo; tmp:=''filiais_postocoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela filiais_postocoleta. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; return old; end;' language 'plpgsql'; create trigger tu_labexterno after update on labexterno for each row execute procedure fn_tu_labexterno(); drop function fn_td_requisicao() cascade; create function fn_td_requisicao() returns opaque as ' declare numrows integer; begin select count(*) into numrows from requisicaolabexternopendencia where requisicaolabexternopendencia.fil_codigo = old.fil_codigo and requisicaolabexternopendencia.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaolabexternopendencia.''; end if; select count(*) into numrows from historicoregistrocontato where historicoregistrocontato.fil_codigo = old.fil_codigo and historicoregistrocontato.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela historicoregistrocontato.''; end if; select count(*) into numrows from requisicaotermoconsentimento where requisicaotermoconsentimento.fil_codigo = old.fil_codigo and requisicaotermoconsentimento.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaotermoconsentimento.''; end if; delete from logpushapp where logpushapp.fil_codigo = old.fil_codigo and logpushapp.req_codigo = old.req_codigo; select count(*) into numrows from requisicaopaginasimpressas where requisicaopaginasimpressas.fil_codigo = old.fil_codigo and requisicaopaginasimpressas.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaopaginasimpressas.''; end if; select count(*) into numrows from exportaintegracaohospital where exportaintegracaohospital.fil_codigo = old.fil_codigo and exportaintegracaohospital.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela exportaintegracaohospital.''; end if; select count(*) into numrows from logemail where logemail.fil_codigo = old.fil_codigo and logemail.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela logemail.''; end if; delete from requisicaovisualizada where requisicaovisualizada.fil_codigo = old.fil_codigo and requisicaovisualizada.req_codigo = old.req_codigo; delete from exportaintegracaooperadora where exportaintegracaooperadora.fil_codigo = old.fil_codigo and exportaintegracaooperadora.req_codigo = old.req_codigo; delete from requisicaoimagens where requisicaoimagens.fil_codigo = old.fil_codigo and requisicaoimagens.req_codigo = old.req_codigo; delete from logsms where logsms.fil_codigo = old.fil_codigo and logsms.req_codigo = old.req_codigo; select count(*) into numrows from requisicaotaxa where requisicaotaxa.fil_codigo = old.fil_codigo and requisicaotaxa.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaotaxa.''; end if; select count(*) into numrows from lotefilialrequisicao where lotefilialrequisicao.fil_codigo = old.fil_codigo and lotefilialrequisicao.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lotefilialrequisicao.''; end if; select count(*) into numrows from requisicaonaoconformidade where requisicaonaoconformidade.fil_codigo = old.fil_codigo and requisicaonaoconformidade.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaonaoconformidade.''; end if; select count(*) into numrows from requisicaolog where requisicaolog.fil_codigo = old.fil_codigo and requisicaolog.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaolog.''; end if; select count(*) into numrows from agendamento where agendamento.fil_codigo = old.fil_codigo and agendamento.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from requisicaoweb where requisicaoweb.fil_codigo = old.fil_codigo and requisicaoweb.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaoweb.''; end if; select count(*) into numrows from requisicaonotafiscal where requisicaonotafiscal.fil_codigo = old.fil_codigo and requisicaonotafiscal.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaonotafiscal.''; end if; select count(*) into numrows from requisicaolabexterno where requisicaolabexterno.fil_codigo = old.fil_codigo and requisicaolabexterno.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaolabexterno.''; end if; delete from requisicaocid10 where requisicaocid10.fil_codigo = old.fil_codigo and requisicaocid10.req_codigo = old.req_codigo; select count(*) into numrows from loteexternorequisicao where loteexternorequisicao.fil_kodigo = old.fil_codigo and loteexternorequisicao.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteexternorequisicao.''; end if; select count(*) into numrows from loteapoiorequisicao where loteapoiorequisicao.fil_codigo = old.fil_codigo and loteapoiorequisicao.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteapoiorequisicao.''; end if; delete from requisicaousuario where requisicaousuario.fil_codigo = old.fil_codigo and requisicaousuario.req_codigo = old.req_codigo; delete from requisicaolanctocaixa where requisicaolanctocaixa.fil_codigo = old.fil_codigo and requisicaolanctocaixa.req_codigo = old.req_codigo; delete from examescontrole where examescontrole.fil_codigo = old.fil_codigo and examescontrole.req_codigo = old.req_codigo; select count(*) into numrows from requisicaorequisicao where requisicaorequisicao.fil_codigo = old.fil_codigo and requisicaorequisicao.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaorequisicao.''; end if; delete from requisicaomedicamento where requisicaomedicamento.fil_codigo = old.fil_codigo and requisicaomedicamento.req_codigo = old.req_codigo; select count(*) into numrows from faturarequisicao where faturarequisicao.fil_kodigo = old.fil_codigo and faturarequisicao.req_codigo = old.req_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela faturarequisicao.''; end if; delete from requisicaorequisicao where requisicaorequisicao.fil_codigo = old.fil_codigo and requisicaorequisicao.req_kodigo = old.req_codigo; delete from examerequisicao where examerequisicao.fil_codigo = old.fil_codigo and examerequisicao.req_codigo = old.req_codigo; return old; end;' language 'plpgsql'; create trigger td_requisicao after delete on requisicao for each row execute procedure fn_td_requisicao(); drop function fn_ti_requisicao() cascade; create function fn_ti_requisicao() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from entidade where new.fil_codigo = entidade.fil_codigo and new.ent_codempresa = entidade.ent_codigo; tmp:=''entidade|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''ent_codigo='' || new.ent_codempresa || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.ent_codempresa is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela entidade. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from produtoalimentos where new.fil_codigo = produtoalimentos.fil_codigo and new.cpl_codigo = produtoalimentos.cpl_codigo and new.pal_codigo = produtoalimentos.pal_codigo; tmp:=''produtoalimentos|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''cpl_codigo='' || new.cpl_codigo || ''|''; tmp:=tmp || ''pal_codigo='' || new.pal_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.cpl_codigo is not null and new.pal_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela produtoalimentos. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_coddesconto = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_coddesconto || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_coddesconto is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codelegibilidade = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codelegibilidade || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codelegibilidade is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from formapagto where new.fpg_codigo = formapagto.fpg_codigo and new.fil_codigo = formapagto.fil_codigo; tmp:=''formapagto|''; tmp:=tmp || ''fpg_codigo='' || new.fpg_codigo || ''|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fpg_codigo is not null and new.fil_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela formapagto. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from pais where new.fil_codigo = pais.fil_codigo and new.pai_codigo = pais.pai_codigo; tmp:=''pais|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''pai_codigo='' || new.pai_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.pai_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela pais. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codguiarepasse = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codguiarepasse || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codguiarepasse is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from convenios where new.fil_codigo = convenios.fil_codigo and new.con_codrepasse = convenios.con_codigo; tmp:=''convenios|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''con_codigo='' || new.con_codrepasse || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.con_codrepasse is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela convenios. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from orcamento where new.fil_codigo = orcamento.fil_codigo and new.orc_codigo = orcamento.orc_codigo; tmp:=''orcamento|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''orc_codigo='' || new.orc_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.orc_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela orcamento. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from unidadesaude where new.fil_codigo = unidadesaude.fil_codigo and new.uns_codigo = unidadesaude.uns_codigo; tmp:=''unidadesaude|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''uns_codigo='' || new.uns_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.uns_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela unidadesaude. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codexcluida = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codexcluida || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codexcluida is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from entidade where new.fil_codigo = entidade.fil_codigo and new.ent_codigo = entidade.ent_codigo; tmp:=''entidade|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''ent_codigo='' || new.ent_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.ent_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela entidade. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from embalagemproduto where new.fil_codigo = embalagemproduto.fil_codigo and new.emb_codigo = embalagemproduto.emb_codigo; tmp:=''embalagemproduto|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''emb_codigo='' || new.emb_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.emb_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela embalagemproduto. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from unidademedida where new.fil_codigo = unidademedida.fil_codigo and new.unm_codigo = unidademedida.unm_codigo; tmp:=''unidademedida|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''unm_codigo='' || new.unm_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.unm_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela unidademedida. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from situacao where new.fil_codigo = situacao.fil_codigo and new.sit_codigo = situacao.sit_codigo; tmp:=''situacao|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''sit_codigo='' || new.sit_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.sit_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela situacao. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from alahospital where new.fil_codigo = alahospital.fil_codigo and new.ala_codigo = alahospital.ala_codigo; tmp:=''alahospital|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''ala_codigo='' || new.ala_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.ala_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela alahospital. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from filiais_postocoleta where new.fil_codcopia = filiais_postocoleta.fil_codigo; tmp:=''filiais_postocoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codcopia || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codcopia is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela filiais_postocoleta. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codabertura = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codabertura || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codabertura is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from estacoes where new.est_codigo = estacoes.est_codigo; tmp:=''estacoes|''; tmp:=tmp || ''est_codigo='' || new.est_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.est_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela estacoes. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codigo = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from filiais_postocoleta where new.fil_codigo = filiais_postocoleta.fil_codigo; tmp:=''filiais_postocoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela filiais_postocoleta. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from coletas where new.fil_codigo = coletas.fil_codigo and new.col_codigo = coletas.col_codigo; tmp:=''coletas|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''col_codigo='' || new.col_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.col_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela coletas. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from destino where new.fil_codigo = destino.fil_codigo and new.des_codigo = destino.des_codigo; tmp:=''destino|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''des_codigo='' || new.des_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.des_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela destino. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from convenios where new.fil_codigo = convenios.fil_codigo and new.con_codigo = convenios.con_codigo; tmp:=''convenios|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''con_codigo='' || new.con_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.con_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela convenios. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from medico where new.fil_codigo = medico.fil_codigo and new.med_conselho = medico.med_conselho and new.med_crm = medico.med_crm and new.med_uf = medico.med_uf; tmp:=''medico|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''med_conselho='' || new.med_conselho || ''|''; tmp:=tmp || ''med_crm='' || new.med_crm || ''|''; tmp:=tmp || ''med_uf='' || new.med_uf || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.med_conselho is not null and new.med_crm is not null and new.med_uf is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela medico. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from paciente where new.fil_codigo = paciente.fil_codigo and new.pac_codigo = paciente.pac_codigo; tmp:=''paciente|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''pac_codigo='' || new.pac_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela paciente. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; return new; end;' language 'plpgsql'; create trigger ti_requisicao after insert on requisicao for each row execute procedure fn_ti_requisicao(); drop function fn_tu_requisicao() cascade; create function fn_tu_requisicao() returns opaque as ' declare numrows integer; tmp varchar; begin if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from requisicaolabexternopendencia where requisicaolabexternopendencia.fil_codigo = old.fil_codigo and requisicaolabexternopendencia.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaolabexternopendencia.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from historicoregistrocontato where historicoregistrocontato.fil_codigo = old.fil_codigo and historicoregistrocontato.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela historicoregistrocontato.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from requisicaotermoconsentimento where requisicaotermoconsentimento.fil_codigo = old.fil_codigo and requisicaotermoconsentimento.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaotermoconsentimento.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from logpushapp where logpushapp.fil_codigo = old.fil_codigo and logpushapp.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logpushapp.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from requisicaopaginasimpressas where requisicaopaginasimpressas.fil_codigo = old.fil_codigo and requisicaopaginasimpressas.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaopaginasimpressas.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from exportaintegracaohospital where exportaintegracaohospital.fil_codigo = old.fil_codigo and exportaintegracaohospital.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela exportaintegracaohospital.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from logemail where logemail.fil_codigo = old.fil_codigo and logemail.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logemail.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from requisicaovisualizada where requisicaovisualizada.fil_codigo = old.fil_codigo and requisicaovisualizada.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaovisualizada.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from exportaintegracaooperadora where exportaintegracaooperadora.fil_codigo = old.fil_codigo and exportaintegracaooperadora.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela exportaintegracaooperadora.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from requisicaoimagens where requisicaoimagens.fil_codigo = old.fil_codigo and requisicaoimagens.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaoimagens.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from logsms where logsms.fil_codigo = old.fil_codigo and logsms.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logsms.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from requisicaotaxa where requisicaotaxa.fil_codigo = old.fil_codigo and requisicaotaxa.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaotaxa.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from lotefilialrequisicao where lotefilialrequisicao.fil_codigo = old.fil_codigo and lotefilialrequisicao.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lotefilialrequisicao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from requisicaonaoconformidade where requisicaonaoconformidade.fil_codigo = old.fil_codigo and requisicaonaoconformidade.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaonaoconformidade.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from requisicaolog where requisicaolog.fil_codigo = old.fil_codigo and requisicaolog.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaolog.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from agendamento where agendamento.fil_codigo = old.fil_codigo and agendamento.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from requisicaoweb where requisicaoweb.fil_codigo = old.fil_codigo and requisicaoweb.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaoweb.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from requisicaonotafiscal where requisicaonotafiscal.fil_codigo = old.fil_codigo and requisicaonotafiscal.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaonotafiscal.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from requisicaolabexterno where requisicaolabexterno.fil_codigo = old.fil_codigo and requisicaolabexterno.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaolabexterno.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from requisicaocid10 where requisicaocid10.fil_codigo = old.fil_codigo and requisicaocid10.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaocid10.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from loteexternorequisicao where loteexternorequisicao.fil_kodigo = old.fil_codigo and loteexternorequisicao.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteexternorequisicao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from loteapoiorequisicao where loteapoiorequisicao.fil_codigo = old.fil_codigo and loteapoiorequisicao.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteapoiorequisicao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from requisicaousuario where requisicaousuario.fil_codigo = old.fil_codigo and requisicaousuario.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaousuario.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from requisicaolanctocaixa where requisicaolanctocaixa.fil_codigo = old.fil_codigo and requisicaolanctocaixa.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaolanctocaixa.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from examescontrole where examescontrole.fil_codigo = old.fil_codigo and examescontrole.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examescontrole.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from requisicaorequisicao where requisicaorequisicao.fil_codigo = old.fil_codigo and requisicaorequisicao.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaorequisicao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from requisicaomedicamento where requisicaomedicamento.fil_codigo = old.fil_codigo and requisicaomedicamento.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaomedicamento.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from faturarequisicao where faturarequisicao.fil_kodigo = old.fil_codigo and faturarequisicao.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela faturarequisicao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from requisicaorequisicao where requisicaorequisicao.fil_codigo = old.fil_codigo and requisicaorequisicao.req_kodigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaorequisicao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.req_codigo <> new.req_codigo) then select count(*) from examerequisicao where examerequisicao.fil_codigo = old.fil_codigo and examerequisicao.req_codigo = old.req_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; select count(*) into numrows from entidade where new.fil_codigo = entidade.fil_codigo and new.ent_codempresa = entidade.ent_codigo; tmp:=''entidade|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''ent_codigo='' || new.ent_codempresa || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.ent_codempresa is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela entidade. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from produtoalimentos where new.fil_codigo = produtoalimentos.fil_codigo and new.cpl_codigo = produtoalimentos.cpl_codigo and new.pal_codigo = produtoalimentos.pal_codigo; tmp:=''produtoalimentos|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''cpl_codigo='' || new.cpl_codigo || ''|''; tmp:=tmp || ''pal_codigo='' || new.pal_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.cpl_codigo is not null and new.pal_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela produtoalimentos. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_coddesconto = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_coddesconto || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_coddesconto is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codelegibilidade = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codelegibilidade || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codelegibilidade is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from formapagto where new.fpg_codigo = formapagto.fpg_codigo and new.fil_codigo = formapagto.fil_codigo; tmp:=''formapagto|''; tmp:=tmp || ''fpg_codigo='' || new.fpg_codigo || ''|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fpg_codigo is not null and new.fil_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela formapagto. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from pais where new.fil_codigo = pais.fil_codigo and new.pai_codigo = pais.pai_codigo; tmp:=''pais|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''pai_codigo='' || new.pai_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.pai_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela pais. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codguiarepasse = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codguiarepasse || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codguiarepasse is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from convenios where new.fil_codigo = convenios.fil_codigo and new.con_codrepasse = convenios.con_codigo; tmp:=''convenios|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''con_codigo='' || new.con_codrepasse || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.con_codrepasse is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela convenios. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from orcamento where new.fil_codigo = orcamento.fil_codigo and new.orc_codigo = orcamento.orc_codigo; tmp:=''orcamento|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''orc_codigo='' || new.orc_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.orc_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela orcamento. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from unidadesaude where new.fil_codigo = unidadesaude.fil_codigo and new.uns_codigo = unidadesaude.uns_codigo; tmp:=''unidadesaude|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''uns_codigo='' || new.uns_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.uns_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela unidadesaude. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codexcluida = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codexcluida || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codexcluida is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from entidade where new.fil_codigo = entidade.fil_codigo and new.ent_codigo = entidade.ent_codigo; tmp:=''entidade|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''ent_codigo='' || new.ent_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.ent_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela entidade. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from embalagemproduto where new.fil_codigo = embalagemproduto.fil_codigo and new.emb_codigo = embalagemproduto.emb_codigo; tmp:=''embalagemproduto|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''emb_codigo='' || new.emb_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.emb_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela embalagemproduto. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from unidademedida where new.fil_codigo = unidademedida.fil_codigo and new.unm_codigo = unidademedida.unm_codigo; tmp:=''unidademedida|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''unm_codigo='' || new.unm_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.unm_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela unidademedida. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from situacao where new.fil_codigo = situacao.fil_codigo and new.sit_codigo = situacao.sit_codigo; tmp:=''situacao|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''sit_codigo='' || new.sit_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.sit_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela situacao. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from alahospital where new.fil_codigo = alahospital.fil_codigo and new.ala_codigo = alahospital.ala_codigo; tmp:=''alahospital|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''ala_codigo='' || new.ala_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.ala_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela alahospital. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from filiais_postocoleta where new.fil_codcopia = filiais_postocoleta.fil_codigo; tmp:=''filiais_postocoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codcopia || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codcopia is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela filiais_postocoleta. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codabertura = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codabertura || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codabertura is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from estacoes where new.est_codigo = estacoes.est_codigo; tmp:=''estacoes|''; tmp:=tmp || ''est_codigo='' || new.est_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.est_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela estacoes. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codigo = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from filiais_postocoleta where new.fil_codigo = filiais_postocoleta.fil_codigo; tmp:=''filiais_postocoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela filiais_postocoleta. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from coletas where new.fil_codigo = coletas.fil_codigo and new.col_codigo = coletas.col_codigo; tmp:=''coletas|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''col_codigo='' || new.col_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.col_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela coletas. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from destino where new.fil_codigo = destino.fil_codigo and new.des_codigo = destino.des_codigo; tmp:=''destino|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''des_codigo='' || new.des_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.des_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela destino. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from convenios where new.fil_codigo = convenios.fil_codigo and new.con_codigo = convenios.con_codigo; tmp:=''convenios|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''con_codigo='' || new.con_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.con_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela convenios. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from medico where new.fil_codigo = medico.fil_codigo and new.med_conselho = medico.med_conselho and new.med_crm = medico.med_crm and new.med_uf = medico.med_uf; tmp:=''medico|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''med_conselho='' || new.med_conselho || ''|''; tmp:=tmp || ''med_crm='' || new.med_crm || ''|''; tmp:=tmp || ''med_uf='' || new.med_uf || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.med_conselho is not null and new.med_crm is not null and new.med_uf is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela medico. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from paciente where new.fil_codigo = paciente.fil_codigo and new.pac_codigo = paciente.pac_codigo; tmp:=''paciente|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''pac_codigo='' || new.pac_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela paciente. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; return old; end;' language 'plpgsql'; create trigger tu_requisicao after update on requisicao for each row execute procedure fn_tu_requisicao(); --drop function fn_ti_requisicaolabexternopendencia() cascade; create function fn_ti_requisicaolabexternopendencia() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from usuario where new.usr_codigo = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from labexterno where new.fil_codigo = labexterno.fil_codigo and new.lae_codigo = labexterno.lae_codigo; tmp:=''labexterno|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''lae_codigo='' || new.lae_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela labexterno. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from requisicao where new.fil_codigo = requisicao.fil_codigo and new.req_codigo = requisicao.req_codigo; tmp:=''requisicao|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''req_codigo='' || new.req_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela requisicao. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; return new; end;' language 'plpgsql'; create trigger ti_requisicaolabexternopendencia after insert on requisicaolabexternopendencia for each row execute procedure fn_ti_requisicaolabexternopendencia(); --drop function fn_tu_requisicaolabexternopendencia() cascade; create function fn_tu_requisicaolabexternopendencia() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from usuario where new.usr_codigo = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from labexterno where new.fil_codigo = labexterno.fil_codigo and new.lae_codigo = labexterno.lae_codigo; tmp:=''labexterno|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''lae_codigo='' || new.lae_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela labexterno. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from requisicao where new.fil_codigo = requisicao.fil_codigo and new.req_codigo = requisicao.req_codigo; tmp:=''requisicao|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''req_codigo='' || new.req_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela requisicao. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; return old; end;' language 'plpgsql'; create trigger tu_requisicaolabexternopendencia after update on requisicaolabexternopendencia for each row execute procedure fn_tu_requisicaolabexternopendencia(); drop function fn_td_usuario() cascade; create function fn_td_usuario() returns opaque as ' declare numrows integer; begin select count(*) into numrows from requisicaolabexternopendencia where requisicaolabexternopendencia.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaolabexternopendencia.''; end if; select count(*) into numrows from setoresusuario where setoresusuario.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela setoresusuario.''; end if; select count(*) into numrows from historicoregistrocontato where historicoregistrocontato.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela historicoregistrocontato.''; end if; select count(*) into numrows from loteexternoexamerequisicao where loteexternoexamerequisicao.usr_codestorno = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteexternoexamerequisicao.''; end if; select count(*) into numrows from requisicaotermoconsentimento where requisicaotermoconsentimento.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaotermoconsentimento.''; end if; select count(*) into numrows from lotefilialexamerequisicao where lotefilialexamerequisicao.usr_codtransportechegada = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lotefilialexamerequisicao.''; end if; select count(*) into numrows from lotefilialexamerequisicao where lotefilialexamerequisicao.usr_codtransportesaida = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lotefilialexamerequisicao.''; end if; select count(*) into numrows from historicopoliticaweb where historicopoliticaweb.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela historicopoliticaweb.''; end if; select count(*) into numrows from preagendamentoevento where preagendamentoevento.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela preagendamentoevento.''; end if; select count(*) into numrows from labexternologintegracao where labexternologintegracao.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela labexternologintegracao.''; end if; select count(*) into numrows from labexternoversaotermo where labexternoversaotermo.usr_codaceite = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela labexternoversaotermo.''; end if; select count(*) into numrows from preagendamento where preagendamento.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela preagendamento.''; end if; select count(*) into numrows from preagendamento where preagendamento.usr_codagendou = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela preagendamento.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_coddialsist = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from integracaosave where integracaosave.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela integracaosave.''; end if; select count(*) into numrows from interfaceexamereagente where interfaceexamereagente.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela interfaceexamereagente.''; end if; select count(*) into numrows from examerequisicaohistoricoentrega where examerequisicaohistoricoentrega.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaohistoricoentrega.''; end if; select count(*) into numrows from requisicaopaginasimpressas where requisicaopaginasimpressas.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaopaginasimpressas.''; end if; select count(*) into numrows from tabelaprecoexamesusuario where tabelaprecoexamesusuario.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela tabelaprecoexamesusuario.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codenvioemail = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from materialusuario where materialusuario.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materialusuario.''; end if; select count(*) into numrows from logids where logids.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela logids.''; end if; select count(*) into numrows from logvalidalotematerial where logvalidalotematerial.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela logvalidalotematerial.''; end if; select count(*) into numrows from material where material.usr_codavisolote = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela material.''; end if; delete from usuariosenhas where usuariosenhas.usr_codigo = old.usr_codigo; select count(*) into numrows from pacienteimagens where pacienteimagens.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela pacienteimagens.''; end if; select count(*) into numrows from requisicaoimagens where requisicaoimagens.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaoimagens.''; end if; select count(*) into numrows from orcamentoconvenio where orcamentoconvenio.usr_coddesconto = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela orcamentoconvenio.''; end if; select count(*) into numrows from requisicao where requisicao.usr_coddesconto = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicao.''; end if; select count(*) into numrows from examerequisicaoetiquetas where examerequisicaoetiquetas.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaoetiquetas.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codduplaconferencia = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from loteexternorequisicao where loteexternorequisicao.usr_codestorno = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteexternorequisicao.''; end if; select count(*) into numrows from loteexterno where loteexterno.usr_codestorno = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteexterno.''; end if; select count(*) into numrows from materiallotehistorico where materiallotehistorico.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materiallotehistorico.''; end if; select count(*) into numrows from materiallote where materiallote.usr_codaberturainicial = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materiallote.''; end if; select count(*) into numrows from materiallote where materiallote.usr_codfechado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materiallote.''; end if; select count(*) into numrows from materiallote where materiallote.usr_codaberto = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materiallote.''; end if; delete from responsavelcertificado where responsavelcertificado.usr_codigo = old.usr_codigo; select count(*) into numrows from requisicao where requisicao.usr_codelegibilidade = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codsolicitadotiss = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codcoletar = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from transfestoquematerial where transfestoquematerial.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela transfestoquematerial.''; end if; select count(*) into numrows from transfestoque where transfestoque.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela transfestoque.''; end if; select count(*) into numrows from examerequisicaodadosbrutos where examerequisicaodadosbrutos.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaodadosbrutos.''; end if; select count(*) into numrows from examerequisicaoincerteza where examerequisicaoincerteza.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaoincerteza.''; end if; select count(*) into numrows from setoresnaoconformidadeusuario where setoresnaoconformidadeusuario.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela setoresnaoconformidadeusuario.''; end if; select count(*) into numrows from setoresnaoconformidade where setoresnaoconformidade.usr_codresponsavelsetor = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela setoresnaoconformidade.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codtransportechegada = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codtransportesaida = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from lotefilial where lotefilial.usr_codrecebeu = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lotefilial.''; end if; select count(*) into numrows from lotefilial where lotefilial.usr_codenviou = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lotefilial.''; end if; select count(*) into numrows from logoffline where logoffline.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela logoffline.''; end if; select count(*) into numrows from usuariologin where usuariologin.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela usuariologin.''; end if; select count(*) into numrows from acoesnaoconformidade where acoesnaoconformidade.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela acoesnaoconformidade.''; end if; select count(*) into numrows from orcamentolog where orcamentolog.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela orcamentolog.''; end if; select count(*) into numrows from orcamento where orcamento.usr_codaprovado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela orcamento.''; end if; select count(*) into numrows from naoconformidade where naoconformidade.usr_codconclusao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela naoconformidade.''; end if; select count(*) into numrows from naoconformidade where naoconformidade.usr_codanalise = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela naoconformidade.''; end if; select count(*) into numrows from naoconformidade where naoconformidade.usr_codregistro = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela naoconformidade.''; end if; select count(*) into numrows from naoconformidade where naoconformidade.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela naoconformidade.''; end if; select count(*) into numrows from labexterno where labexterno.usr_codconferir = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela labexterno.''; end if; select count(*) into numrows from banhomariatemperatura where banhomariatemperatura.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela banhomariatemperatura.''; end if; select count(*) into numrows from banhomaria where banhomaria.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela banhomaria.''; end if; select count(*) into numrows from filiais_postocoleta where filiais_postocoleta.usr_codcompras = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela filiais_postocoleta.''; end if; select count(*) into numrows from filiais_postocoleta where filiais_postocoleta.usr_codestoque = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela filiais_postocoleta.''; end if; select count(*) into numrows from examerequisicaolaminas where examerequisicaolaminas.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaolaminas.''; end if; select count(*) into numrows from agendamento where agendamento.usr_codhorarioanexado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from agendamento where agendamento.usr_codbloqueado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from materiallote where materiallote.usr_codremovido = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materiallote.''; end if; select count(*) into numrows from materiallote where materiallote.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materiallote.''; end if; select count(*) into numrows from examerequisicaohash where examerequisicaohash.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaohash.''; end if; select count(*) into numrows from agendamento where agendamento.usr_codfinalizado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from agendamento where agendamento.usr_codemcoleta = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from agendamento where agendamento.usr_codremarcado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from requisicaolog where requisicaolog.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaolog.''; end if; select count(*) into numrows from convenioshistoricocota where convenioshistoricocota.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela convenioshistoricocota.''; end if; select count(*) into numrows from agendamento where agendamento.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from agendamento where agendamento.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela agendamento.''; end if; select count(*) into numrows from examerequisicaotrocas where examerequisicaotrocas.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaotrocas.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codtrocalayout = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codalteracaopreco = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; delete from usuariocompromisso where usuariocompromisso.usr_codigo = old.usr_codigo; select count(*) into numrows from examerequisicaohistoricolaudo where examerequisicaohistoricolaudo.usr_codsituacao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaohistoricolaudo.''; end if; select count(*) into numrows from contrassenharequisicao where contrassenharequisicao.usr_codgerada = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela contrassenharequisicao.''; end if; select count(*) into numrows from contrassenharequisicao where contrassenharequisicao.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela contrassenharequisicao.''; end if; select count(*) into numrows from solicitarsoroteca where solicitarsoroteca.usr_codentrega = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela solicitarsoroteca.''; end if; select count(*) into numrows from solicitarsoroteca where solicitarsoroteca.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela solicitarsoroteca.''; end if; select count(*) into numrows from solicitarsoroteca where solicitarsoroteca.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela solicitarsoroteca.''; end if; select count(*) into numrows from convenioignorarecebimento where convenioignorarecebimento.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela convenioignorarecebimento.''; end if; select count(*) into numrows from examerequisicaohistoricolaudo where examerequisicaohistoricolaudo.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaohistoricolaudo.''; end if; select count(*) into numrows from examerequisicaosetor where examerequisicaosetor.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaosetor.''; end if; select count(*) into numrows from paciente where paciente.usr_codimpressaocarteira = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela paciente.''; end if; select count(*) into numrows from materialenviado where materialenviado.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materialenviado.''; end if; select count(*) into numrows from materialidentificado where materialidentificado.usr_codretorno = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materialidentificado.''; end if; select count(*) into numrows from materialidentificado where materialidentificado.usr_codenvio = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materialidentificado.''; end if; select count(*) into numrows from loteapoio where loteapoio.usr_codrecebeucaixa = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteapoio.''; end if; select count(*) into numrows from examerequisicaosoroteca where examerequisicaosoroteca.usr_coddescarte = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaosoroteca.''; end if; select count(*) into numrows from examerequisicaosoroteca where examerequisicaosoroteca.usr_codsoroteca = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaosoroteca.''; end if; select count(*) into numrows from requisicao where requisicao.usr_codguiarepasse = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codrecoleta = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codfaturarepasse = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from receberpagar where receberpagar.usr_codcomissao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela receberpagar.''; end if; select count(*) into numrows from montagemkit where montagemkit.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela montagemkit.''; end if; select count(*) into numrows from transfestoque where transfestoque.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela transfestoque.''; end if; select count(*) into numrows from orcamento where orcamento.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela orcamento.''; end if; select count(*) into numrows from estoquemanual where estoquemanual.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela estoquemanual.''; end if; select count(*) into numrows from requisicaoestoque where requisicaoestoque.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaoestoque.''; end if; select count(*) into numrows from requisicaoestoque where requisicaoestoque.usr_codalmoxarife = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaoestoque.''; end if; select count(*) into numrows from requisicaoestoque where requisicaoestoque.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaoestoque.''; end if; select count(*) into numrows from notafiscal where notafiscal.usr_codautorizafinanceira = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela notafiscal.''; end if; select count(*) into numrows from conferenciaestoque where conferenciaestoque.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela conferenciaestoque.''; end if; select count(*) into numrows from lanctoestoque where lanctoestoque.usr_codconciliacao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctoestoque.''; end if; select count(*) into numrows from lanctoestoque where lanctoestoque.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctoestoque.''; end if; select count(*) into numrows from lanctoestoque where lanctoestoque.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctoestoque.''; end if; select count(*) into numrows from conferenciaentrada where conferenciaentrada.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela conferenciaentrada.''; end if; select count(*) into numrows from conferenciaentrada where conferenciaentrada.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela conferenciaentrada.''; end if; select count(*) into numrows from pedido where pedido.usr_codexclusao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela pedido.''; end if; select count(*) into numrows from fatura where fatura.usr_codcomissao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela fatura.''; end if; select count(*) into numrows from pedido where pedido.usr_codautorizacao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela pedido.''; end if; select count(*) into numrows from pedido where pedido.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela pedido.''; end if; select count(*) into numrows from cotacao where cotacao.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela cotacao.''; end if; select count(*) into numrows from material where material.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela material.''; end if; select count(*) into numrows from receberpagar where receberpagar.usr_codprotestocobranca = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela receberpagar.''; end if; select count(*) into numrows from receberpagar where receberpagar.usr_codcartoriocobranca = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela receberpagar.''; end if; select count(*) into numrows from receberpagar where receberpagar.usr_codavisocobranca = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela receberpagar.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codrepeticao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from paciente where paciente.usr_codalteracao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela paciente.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codguia = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicaosituacoes where examerequisicaosituacoes.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaosituacoes.''; end if; select count(*) into numrows from exames where exames.usr_codassinaweb = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela exames.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codexcluido = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from requisicao where requisicao.usr_codexcluida = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicao.''; end if; select count(*) into numrows from fatura where fatura.usr_codcancelamento = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela fatura.''; end if; select count(*) into numrows from convenios where convenios.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela convenios.''; end if; select count(*) into numrows from notafiscal where notafiscal.usr_codreimpressao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela notafiscal.''; end if; select count(*) into numrows from geladeirastemperaturas where geladeirastemperaturas.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela geladeirastemperaturas.''; end if; select count(*) into numrows from geladeiras where geladeiras.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela geladeiras.''; end if; delete from usuariofilial where usuariofilial.usr_codigo = old.usr_codigo; select count(*) into numrows from notafiscal where notafiscal.usr_codimpressao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela notafiscal.''; end if; select count(*) into numrows from notafiscal where notafiscal.usr_codcancelada = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela notafiscal.''; end if; select count(*) into numrows from notafiscal where notafiscal.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela notafiscal.''; end if; select count(*) into numrows from baixa where baixa.usr_codcancelado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela baixa.''; end if; select count(*) into numrows from baixa where baixa.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela baixa.''; end if; select count(*) into numrows from receberpagar where receberpagar.usr_codcancelado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela receberpagar.''; end if; select count(*) into numrows from receberpagar where receberpagar.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela receberpagar.''; end if; select count(*) into numrows from lanctocaixa where lanctocaixa.usr_codcancelado = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctocaixa.''; end if; select count(*) into numrows from requisicaocid10 where requisicaocid10.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaocid10.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codmaterialsetor = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codloteexterno = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from loteexterno where loteexterno.usr_codenvio = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteexterno.''; end if; select count(*) into numrows from loteexterno where loteexterno.usr_codcriacao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteexterno.''; end if; select count(*) into numrows from log where log.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela log.''; end if; select count(*) into numrows from usuariomensagem where usuariomensagem.usr_codorigem = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela usuariomensagem.''; end if; delete from usuariomensagem where usuariomensagem.usr_coddestino = old.usr_codigo; select count(*) into numrows from conveniomensagem where conveniomensagem.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela conveniomensagem.''; end if; select count(*) into numrows from examerequisicaorecipiente where examerequisicaorecipiente.usr_codtriagem = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicaorecipiente.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codetqtriagem = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codetqcoleta = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from loteapoio where loteapoio.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteapoio.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codtriagem = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from fatura where fatura.usr_codconferencia = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela fatura.''; end if; select count(*) into numrows from fatura where fatura.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela fatura.''; end if; select count(*) into numrows from contrasenha where contrasenha.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela contrasenha.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codnaofaturar = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from requisicaousuario where requisicaousuario.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaousuario.''; end if; select count(*) into numrows from requisicao where requisicao.usr_codabertura = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codcortesia = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codmapa = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from interfaceexamerequisicao where interfaceexamerequisicao.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela interfaceexamerequisicao.''; end if; select count(*) into numrows from usuarioparametro where usuarioparametro.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela usuarioparametro.''; end if; select count(*) into numrows from lanctocaixa where lanctocaixa.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela lanctocaixa.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from requisicao where requisicao.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codimpressao = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codentrega = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codfatura = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codmaterial = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_coddigitador = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; select count(*) into numrows from examerequisicao where examerequisicao.usr_codassina = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examerequisicao.''; end if; delete from usuarioacesso where usuarioacesso.usr_codigo = old.usr_codigo; select count(*) into numrows from setores where setores.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela setores.''; end if; select count(*) into numrows from paciente where paciente.usr_codigo = old.usr_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela paciente.''; end if; return old; end;' language 'plpgsql'; create trigger td_usuario after delete on usuario for each row execute procedure fn_td_usuario(); drop function fn_ti_usuario() cascade; create function fn_ti_usuario() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from tipousuario where new.tpu_codigo = tipousuario.tpu_codigo; tmp:=''tipousuario|''; tmp:=tmp || ''tpu_codigo='' || new.tpu_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.tpu_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela tipousuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; return new; end;' language 'plpgsql'; create trigger ti_usuario after insert on usuario for each row execute procedure fn_ti_usuario(); drop function fn_tu_usuario() cascade; create function fn_tu_usuario() returns opaque as ' declare numrows integer; tmp varchar; begin if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaolabexternopendencia where requisicaolabexternopendencia.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaolabexternopendencia.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from setoresusuario where setoresusuario.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela setoresusuario.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from historicoregistrocontato where historicoregistrocontato.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela historicoregistrocontato.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from loteexternoexamerequisicao where loteexternoexamerequisicao.usr_codestorno = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteexternoexamerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaotermoconsentimento where requisicaotermoconsentimento.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaotermoconsentimento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lotefilialexamerequisicao where lotefilialexamerequisicao.usr_codtransportechegada = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lotefilialexamerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lotefilialexamerequisicao where lotefilialexamerequisicao.usr_codtransportesaida = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lotefilialexamerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from historicopoliticaweb where historicopoliticaweb.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela historicopoliticaweb.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from preagendamentoevento where preagendamentoevento.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela preagendamentoevento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from labexternologintegracao where labexternologintegracao.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela labexternologintegracao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from labexternoversaotermo where labexternoversaotermo.usr_codaceite = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela labexternoversaotermo.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from preagendamento where preagendamento.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela preagendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from preagendamento where preagendamento.usr_codagendou = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela preagendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_coddialsist = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from integracaosave where integracaosave.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela integracaosave.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from interfaceexamereagente where interfaceexamereagente.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela interfaceexamereagente.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaohistoricoentrega where examerequisicaohistoricoentrega.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaohistoricoentrega.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaopaginasimpressas where requisicaopaginasimpressas.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaopaginasimpressas.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from tabelaprecoexamesusuario where tabelaprecoexamesusuario.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela tabelaprecoexamesusuario.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codenvioemail = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materialusuario where materialusuario.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materialusuario.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from logids where logids.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logids.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from logvalidalotematerial where logvalidalotematerial.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logvalidalotematerial.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from material where material.usr_codavisolote = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela material.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuariosenhas where usuariosenhas.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuariosenhas.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from pacienteimagens where pacienteimagens.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela pacienteimagens.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaoimagens where requisicaoimagens.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaoimagens.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from orcamentoconvenio where orcamentoconvenio.usr_coddesconto = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela orcamentoconvenio.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicao where requisicao.usr_coddesconto = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaoetiquetas where examerequisicaoetiquetas.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaoetiquetas.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codduplaconferencia = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from loteexternorequisicao where loteexternorequisicao.usr_codestorno = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteexternorequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from loteexterno where loteexterno.usr_codestorno = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteexterno.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materiallotehistorico where materiallotehistorico.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materiallotehistorico.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materiallote where materiallote.usr_codaberturainicial = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materiallote.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materiallote where materiallote.usr_codfechado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materiallote.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materiallote where materiallote.usr_codaberto = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materiallote.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from responsavelcertificado where responsavelcertificado.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela responsavelcertificado.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicao where requisicao.usr_codelegibilidade = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codsolicitadotiss = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codcoletar = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from transfestoquematerial where transfestoquematerial.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela transfestoquematerial.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from transfestoque where transfestoque.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela transfestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaodadosbrutos where examerequisicaodadosbrutos.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaodadosbrutos.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaoincerteza where examerequisicaoincerteza.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaoincerteza.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from setoresnaoconformidadeusuario where setoresnaoconformidadeusuario.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela setoresnaoconformidadeusuario.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from setoresnaoconformidade where setoresnaoconformidade.usr_codresponsavelsetor = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela setoresnaoconformidade.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codtransportechegada = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codtransportesaida = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lotefilial where lotefilial.usr_codrecebeu = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lotefilial.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lotefilial where lotefilial.usr_codenviou = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lotefilial.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from logoffline where logoffline.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logoffline.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuariologin where usuariologin.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuariologin.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from acoesnaoconformidade where acoesnaoconformidade.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela acoesnaoconformidade.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from orcamentolog where orcamentolog.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela orcamentolog.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from orcamento where orcamento.usr_codaprovado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela orcamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from naoconformidade where naoconformidade.usr_codconclusao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela naoconformidade.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from naoconformidade where naoconformidade.usr_codanalise = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela naoconformidade.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from naoconformidade where naoconformidade.usr_codregistro = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela naoconformidade.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from naoconformidade where naoconformidade.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela naoconformidade.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from labexterno where labexterno.usr_codconferir = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela labexterno.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from banhomariatemperatura where banhomariatemperatura.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela banhomariatemperatura.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from banhomaria where banhomaria.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela banhomaria.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from filiais_postocoleta where filiais_postocoleta.usr_codcompras = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela filiais_postocoleta.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from filiais_postocoleta where filiais_postocoleta.usr_codestoque = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela filiais_postocoleta.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaolaminas where examerequisicaolaminas.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaolaminas.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from agendamento where agendamento.usr_codhorarioanexado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from agendamento where agendamento.usr_codbloqueado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materiallote where materiallote.usr_codremovido = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materiallote.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materiallote where materiallote.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materiallote.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaohash where examerequisicaohash.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaohash.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from agendamento where agendamento.usr_codfinalizado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from agendamento where agendamento.usr_codemcoleta = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from agendamento where agendamento.usr_codremarcado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaolog where requisicaolog.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaolog.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from convenioshistoricocota where convenioshistoricocota.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela convenioshistoricocota.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from agendamento where agendamento.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from agendamento where agendamento.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela agendamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaotrocas where examerequisicaotrocas.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaotrocas.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codtrocalayout = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codalteracaopreco = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuariocompromisso where usuariocompromisso.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuariocompromisso.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaohistoricolaudo where examerequisicaohistoricolaudo.usr_codsituacao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaohistoricolaudo.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from contrassenharequisicao where contrassenharequisicao.usr_codgerada = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela contrassenharequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from contrassenharequisicao where contrassenharequisicao.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela contrassenharequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from solicitarsoroteca where solicitarsoroteca.usr_codentrega = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela solicitarsoroteca.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from solicitarsoroteca where solicitarsoroteca.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela solicitarsoroteca.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from solicitarsoroteca where solicitarsoroteca.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela solicitarsoroteca.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from convenioignorarecebimento where convenioignorarecebimento.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela convenioignorarecebimento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaohistoricolaudo where examerequisicaohistoricolaudo.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaohistoricolaudo.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaosetor where examerequisicaosetor.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaosetor.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from paciente where paciente.usr_codimpressaocarteira = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela paciente.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materialenviado where materialenviado.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materialenviado.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materialidentificado where materialidentificado.usr_codretorno = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materialidentificado.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from materialidentificado where materialidentificado.usr_codenvio = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materialidentificado.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from loteapoio where loteapoio.usr_codrecebeucaixa = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteapoio.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaosoroteca where examerequisicaosoroteca.usr_coddescarte = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaosoroteca.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaosoroteca where examerequisicaosoroteca.usr_codsoroteca = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaosoroteca.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicao where requisicao.usr_codguiarepasse = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codrecoleta = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codfaturarepasse = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from receberpagar where receberpagar.usr_codcomissao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela receberpagar.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from montagemkit where montagemkit.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela montagemkit.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from transfestoque where transfestoque.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela transfestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from orcamento where orcamento.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela orcamento.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from estoquemanual where estoquemanual.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela estoquemanual.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaoestoque where requisicaoestoque.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaoestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaoestoque where requisicaoestoque.usr_codalmoxarife = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaoestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaoestoque where requisicaoestoque.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaoestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from notafiscal where notafiscal.usr_codautorizafinanceira = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela notafiscal.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from conferenciaestoque where conferenciaestoque.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela conferenciaestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lanctoestoque where lanctoestoque.usr_codconciliacao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctoestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lanctoestoque where lanctoestoque.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctoestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lanctoestoque where lanctoestoque.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctoestoque.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from conferenciaentrada where conferenciaentrada.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela conferenciaentrada.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from conferenciaentrada where conferenciaentrada.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela conferenciaentrada.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from pedido where pedido.usr_codexclusao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela pedido.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from fatura where fatura.usr_codcomissao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela fatura.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from pedido where pedido.usr_codautorizacao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela pedido.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from pedido where pedido.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela pedido.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from cotacao where cotacao.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela cotacao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from material where material.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela material.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from receberpagar where receberpagar.usr_codprotestocobranca = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela receberpagar.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from receberpagar where receberpagar.usr_codcartoriocobranca = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela receberpagar.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from receberpagar where receberpagar.usr_codavisocobranca = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela receberpagar.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codrepeticao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from paciente where paciente.usr_codalteracao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela paciente.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codguia = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaosituacoes where examerequisicaosituacoes.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaosituacoes.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from exames where exames.usr_codassinaweb = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela exames.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codexcluido = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicao where requisicao.usr_codexcluida = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from fatura where fatura.usr_codcancelamento = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela fatura.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from convenios where convenios.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela convenios.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from notafiscal where notafiscal.usr_codreimpressao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela notafiscal.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from geladeirastemperaturas where geladeirastemperaturas.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela geladeirastemperaturas.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from geladeiras where geladeiras.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela geladeiras.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuariofilial where usuariofilial.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuariofilial.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from notafiscal where notafiscal.usr_codimpressao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela notafiscal.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from notafiscal where notafiscal.usr_codcancelada = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela notafiscal.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from notafiscal where notafiscal.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela notafiscal.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from baixa where baixa.usr_codcancelado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela baixa.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from baixa where baixa.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela baixa.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from receberpagar where receberpagar.usr_codcancelado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela receberpagar.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from receberpagar where receberpagar.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela receberpagar.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lanctocaixa where lanctocaixa.usr_codcancelado = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctocaixa.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaocid10 where requisicaocid10.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaocid10.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codmaterialsetor = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codloteexterno = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from loteexterno where loteexterno.usr_codenvio = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteexterno.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from loteexterno where loteexterno.usr_codcriacao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteexterno.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from log where log.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela log.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuariomensagem where usuariomensagem.usr_codorigem = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuariomensagem.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuariomensagem where usuariomensagem.usr_coddestino = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuariomensagem.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from conveniomensagem where conveniomensagem.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela conveniomensagem.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicaorecipiente where examerequisicaorecipiente.usr_codtriagem = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicaorecipiente.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codetqtriagem = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codetqcoleta = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from loteapoio where loteapoio.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteapoio.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codtriagem = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from fatura where fatura.usr_codconferencia = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela fatura.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from fatura where fatura.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela fatura.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from contrasenha where contrasenha.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela contrasenha.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codnaofaturar = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicaousuario where requisicaousuario.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaousuario.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicao where requisicao.usr_codabertura = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codcortesia = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codmapa = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from interfaceexamerequisicao where interfaceexamerequisicao.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela interfaceexamerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuarioparametro where usuarioparametro.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuarioparametro.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from lanctocaixa where lanctocaixa.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela lanctocaixa.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from requisicao where requisicao.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codimpressao = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codentrega = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codfatura = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codmaterial = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_coddigitador = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from examerequisicao where examerequisicao.usr_codassina = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examerequisicao.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from usuarioacesso where usuarioacesso.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela usuarioacesso.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from setores where setores.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela setores.''; end if; end if; if (old.usr_codigo <> new.usr_codigo) then select count(*) from paciente where paciente.usr_codigo = old.usr_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela paciente.''; end if; end if; select count(*) into numrows from tipousuario where new.tpu_codigo = tipousuario.tpu_codigo; tmp:=''tipousuario|''; tmp:=tmp || ''tpu_codigo='' || new.tpu_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.tpu_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela tipousuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; return old; end;' language 'plpgsql'; create trigger tu_usuario after update on usuario for each row execute procedure fn_tu_usuario(); select configurageralog('requisicaolabexternopendencia'); insert into atualizacoes(atu_nome) values ('v23000007_231122.sql'); set session_replication_role=replica; alter table convenios add con_cancelartiss boolean default false, add con_configcancelartiss varchar(1000); set session_replication_role=origin;insert into atualizacoes(atu_nome) values ('v23000008_051222.sql'); alter table parametros add par_replicarresultadosmultiguia boolean default false; insert into atualizacoes(atu_nome) values ('v23000009_061222.sql'); alter table aparelhosinterface add apa_ultimoacesso timestamp; insert into atualizacoes(atu_nome) values ('v23000010_071222.sql'); create table examesmercolab ( fil_codigo integer not null, lae_codigo integer not null, eml_codexame varchar(40) not null, eml_descricaoexame varchar(100), eml_xml text ); create unique index xpkexamesmercolab on examesmercolab ( fil_codigo, lae_codigo, eml_codexame ); create index xif1examesmercolab on examesmercolab ( fil_codigo, lae_codigo ); alter table examesmercolab add primary key (fil_codigo, lae_codigo, eml_codexame); --drop function fn_ti_examesmercolab() cascade; create function fn_ti_examesmercolab() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from labexterno where new.fil_codigo = labexterno.fil_codigo and new.lae_codigo = labexterno.lae_codigo; tmp:=''labexterno|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''lae_codigo='' || new.lae_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela labexterno. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; return new; end;' language 'plpgsql'; create trigger ti_examesmercolab after insert on examesmercolab for each row execute procedure fn_ti_examesmercolab(); --drop function fn_tu_examesmercolab() cascade; create function fn_tu_examesmercolab() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from labexterno where new.fil_codigo = labexterno.fil_codigo and new.lae_codigo = labexterno.lae_codigo; tmp:=''labexterno|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''lae_codigo='' || new.lae_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela labexterno. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; return old; end;' language 'plpgsql'; create trigger tu_examesmercolab after update on examesmercolab for each row execute procedure fn_tu_examesmercolab(); drop function fn_td_labexterno() cascade; create function fn_td_labexterno() returns opaque as ' declare numrows integer; begin select count(*) into numrows from examesmercolab where examesmercolab.fil_codigo = old.fil_codigo and examesmercolab.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examesmercolab.''; end if; select count(*) into numrows from requisicaolabexternopendencia where requisicaolabexternopendencia.fil_codigo = old.fil_codigo and requisicaolabexternopendencia.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaolabexternopendencia.''; end if; delete from examesindlab where examesindlab.fil_codigo = old.fil_codigo and examesindlab.lae_codigo = old.lae_codigo; select count(*) into numrows from convenios where convenios.fil_codigo = old.fil_codigo and convenios.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela convenios.''; end if; select count(*) into numrows from materialalvaro where materialalvaro.fil_codigo = old.fil_codigo and materialalvaro.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela materialalvaro.''; end if; delete from labexternolotepardini where labexternolotepardini.fil_codigo = old.fil_codigo and labexternolotepardini.lae_codigo = old.lae_codigo; delete from labexternologintegracao where labexternologintegracao.fil_codigo = old.fil_codigo and labexternologintegracao.lae_codigo = old.lae_codigo; delete from labexternoversaotermo where labexternoversaotermo.fil_codigo = old.fil_codigo and labexternoversaotermo.lae_codigo = old.lae_codigo; select count(*) into numrows from examessaomarcos where examessaomarcos.fil_codigo = old.fil_codigo and examessaomarcos.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examessaomarcos.''; end if; delete from examessyslab where examessyslab.fil_codigo = old.fil_codigo and examessyslab.lae_codigo = old.lae_codigo; delete from examesunilab where examesunilab.fil_codigo = old.fil_codigo and examesunilab.lae_codigo = old.lae_codigo; select count(*) into numrows from filiais_postocoleta where filiais_postocoleta.fil_codigo = old.fil_codigo and filiais_postocoleta.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela filiais_postocoleta.''; end if; delete from logimportacaolabexterno where logimportacaolabexterno.fil_codigo = old.fil_codigo and logimportacaolabexterno.lae_codigo = old.lae_codigo; select count(*) into numrows from examessolucao where examessolucao.fil_codigo = old.fil_codigo and examessolucao.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examessolucao.''; end if; select count(*) into numrows from examesdb where examesdb.fil_codigo = old.fil_codigo and examesdb.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examesdb.''; end if; delete from examesatitude where examesatitude.fil_codigo = old.fil_codigo and examesatitude.lae_codigo = old.lae_codigo; delete from examesbalague where examesbalague.fil_codigo = old.fil_codigo and examesbalague.lae_codigo = old.lae_codigo; delete from examesdelta where examesdelta.fil_codigo = old.fil_codigo and examesdelta.lae_codigo = old.lae_codigo; select count(*) into numrows from examematcoletalabexterno where examematcoletalabexterno.fil_codigo = old.fil_codigo and examematcoletalabexterno.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examematcoletalabexterno.''; end if; select count(*) into numrows from examesmatrix where examesmatrix.fil_codigo = old.fil_codigo and examesmatrix.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examesmatrix.''; end if; select count(*) into numrows from examesrede where examesrede.fil_codigo = old.fil_codigo and examesrede.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examesrede.''; end if; delete from examesreacao where examesreacao.fil_codigo = old.fil_codigo and examesreacao.lae_codigo = old.lae_codigo; select count(*) into numrows from pacientelabexterno where pacientelabexterno.fil_codigo = old.fil_codigo and pacientelabexterno.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela pacientelabexterno.''; end if; select count(*) into numrows from requisicaolabexterno where requisicaolabexterno.fil_codigo = old.fil_codigo and requisicaolabexterno.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela requisicaolabexterno.''; end if; delete from examessergiofranco where examessergiofranco.fil_codigo = old.fil_codigo and examessergiofranco.lae_codigo = old.lae_codigo; delete from examesalvaro where examesalvaro.fil_codigo = old.fil_codigo and examesalvaro.lae_codigo = old.lae_codigo; select count(*) into numrows from examesjalis where examesjalis.fil_codigo = old.fil_codigo and examesjalis.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela examesjalis.''; end if; delete from examespardini where examespardini.fil_codigo = old.fil_codigo and examespardini.lae_codigo = old.lae_codigo; select count(*) into numrows from loteexterno where loteexterno.fil_codigo = old.fil_codigo and loteexterno.lae_codigo = old.lae_codigo; if (numrows > 0) then raise exception ''o registro nao pode ser excluido, por estar sendo utilizado na tabela loteexterno.''; end if; return old; end;' language 'plpgsql'; create trigger td_labexterno after delete on labexterno for each row execute procedure fn_td_labexterno(); drop function fn_ti_labexterno() cascade; create function fn_ti_labexterno() returns opaque as ' declare numrows integer; tmp varchar; begin select count(*) into numrows from prazoentrega where new.fil_codigo = prazoentrega.fil_codigo and new.prz_codigo = prazoentrega.prz_codigo; tmp:=''prazoentrega|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''prz_codigo='' || new.prz_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.prz_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela prazoentrega. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from metodologia where new.fil_codigo = metodologia.fil_codigo and new.met_codigo = metodologia.met_codigo; tmp:=''metodologia|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''met_codigo='' || new.met_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.met_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela metodologia. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from setores where new.fil_codigo = setores.fil_codigo and new.set_codigo = setores.set_codigo; tmp:=''setores|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''set_codigo='' || new.set_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.set_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela setores. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from usuario where new.usr_codconferir = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codconferir || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codconferir is not null and numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; select count(*) into numrows from filiais_postocoleta where new.fil_codigo = filiais_postocoleta.fil_codigo; tmp:=''filiais_postocoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser inserido, pois um valor informado nao existe na tabela filiais_postocoleta. chave para consulta:[%]'',tmp using errcode=upper(''ifkne''); end if; return new; end;' language 'plpgsql'; create trigger ti_labexterno after insert on labexterno for each row execute procedure fn_ti_labexterno(); drop function fn_tu_labexterno() cascade; create function fn_tu_labexterno() returns opaque as ' declare numrows integer; tmp varchar; begin if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesmercolab where examesmercolab.fil_codigo = old.fil_codigo and examesmercolab.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesmercolab.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from requisicaolabexternopendencia where requisicaolabexternopendencia.fil_codigo = old.fil_codigo and requisicaolabexternopendencia.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaolabexternopendencia.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesindlab where examesindlab.fil_codigo = old.fil_codigo and examesindlab.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesindlab.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from convenios where convenios.fil_codigo = old.fil_codigo and convenios.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela convenios.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from materialalvaro where materialalvaro.fil_codigo = old.fil_codigo and materialalvaro.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela materialalvaro.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from labexternolotepardini where labexternolotepardini.fil_codigo = old.fil_codigo and labexternolotepardini.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela labexternolotepardini.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from labexternologintegracao where labexternologintegracao.fil_codigo = old.fil_codigo and labexternologintegracao.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela labexternologintegracao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from labexternoversaotermo where labexternoversaotermo.fil_codigo = old.fil_codigo and labexternoversaotermo.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela labexternoversaotermo.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examessaomarcos where examessaomarcos.fil_codigo = old.fil_codigo and examessaomarcos.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examessaomarcos.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examessyslab where examessyslab.fil_codigo = old.fil_codigo and examessyslab.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examessyslab.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesunilab where examesunilab.fil_codigo = old.fil_codigo and examesunilab.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesunilab.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from filiais_postocoleta where filiais_postocoleta.fil_codigo = old.fil_codigo and filiais_postocoleta.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela filiais_postocoleta.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from logimportacaolabexterno where logimportacaolabexterno.fil_codigo = old.fil_codigo and logimportacaolabexterno.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela logimportacaolabexterno.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examessolucao where examessolucao.fil_codigo = old.fil_codigo and examessolucao.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examessolucao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesdb where examesdb.fil_codigo = old.fil_codigo and examesdb.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesdb.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesatitude where examesatitude.fil_codigo = old.fil_codigo and examesatitude.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesatitude.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesbalague where examesbalague.fil_codigo = old.fil_codigo and examesbalague.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesbalague.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesdelta where examesdelta.fil_codigo = old.fil_codigo and examesdelta.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesdelta.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examematcoletalabexterno where examematcoletalabexterno.fil_codigo = old.fil_codigo and examematcoletalabexterno.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examematcoletalabexterno.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesmatrix where examesmatrix.fil_codigo = old.fil_codigo and examesmatrix.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesmatrix.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesrede where examesrede.fil_codigo = old.fil_codigo and examesrede.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesrede.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesreacao where examesreacao.fil_codigo = old.fil_codigo and examesreacao.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesreacao.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from pacientelabexterno where pacientelabexterno.fil_codigo = old.fil_codigo and pacientelabexterno.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela pacientelabexterno.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from requisicaolabexterno where requisicaolabexterno.fil_codigo = old.fil_codigo and requisicaolabexterno.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela requisicaolabexterno.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examessergiofranco where examessergiofranco.fil_codigo = old.fil_codigo and examessergiofranco.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examessergiofranco.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesalvaro where examesalvaro.fil_codigo = old.fil_codigo and examesalvaro.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesalvaro.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examesjalis where examesjalis.fil_codigo = old.fil_codigo and examesjalis.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examesjalis.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from examespardini where examespardini.fil_codigo = old.fil_codigo and examespardini.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela examespardini.''; end if; end if; if (old.fil_codigo <> new.fil_codigo or old.lae_codigo <> new.lae_codigo) then select count(*) from loteexterno where loteexterno.fil_codigo = old.fil_codigo and loteexterno.lae_codigo = old.lae_codigo into numrows; if (numrows > 0) then raise exception ''o registro nao pode ser alterado, pois um valor esta sendo utilizado na tabela loteexterno.''; end if; end if; select count(*) into numrows from prazoentrega where new.fil_codigo = prazoentrega.fil_codigo and new.prz_codigo = prazoentrega.prz_codigo; tmp:=''prazoentrega|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''prz_codigo='' || new.prz_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.prz_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela prazoentrega. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from metodologia where new.fil_codigo = metodologia.fil_codigo and new.met_codigo = metodologia.met_codigo; tmp:=''metodologia|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''met_codigo='' || new.met_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.met_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela metodologia. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from setores where new.fil_codigo = setores.fil_codigo and new.set_codigo = setores.set_codigo; tmp:=''setores|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=tmp || ''set_codigo='' || new.set_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.fil_codigo is not null and new.set_codigo is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela setores. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from usuario where new.usr_codconferir = usuario.usr_codigo; tmp:=''usuario|''; tmp:=tmp || ''usr_codigo='' || new.usr_codconferir || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( new.usr_codconferir is not null and numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela usuario. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; select count(*) into numrows from filiais_postocoleta where new.fil_codigo = filiais_postocoleta.fil_codigo; tmp:=''filiais_postocoleta|''; tmp:=tmp || ''fil_codigo='' || new.fil_codigo || ''|''; tmp:=substring(tmp,1,length(tmp)-1); if ( numrows = 0 ) then raise exception ''o registro nao pode ser alterado, pois um valor nao existe na tabela filiais_postocoleta. chave para consulta:[%]'',tmp using errcode=upper(''ufkne''); end if; return old; end;' language 'plpgsql'; create trigger tu_labexterno after update on labexterno for each row execute procedure fn_tu_labexterno(); insert into atualizacoes(atu_nome) values ('v23000011_141222.sql'); set session_replication_role=replica; alter table convenios add con_respostafatura boolean default false; set session_replication_role=origin; insert into atualizacoes(atu_nome) values ('v23000012_100123.sql'); alter table configuracaoweb add cwe_ocultarpersonalizado boolean default false; insert into atualizacoes(atu_nome) values ('v23000013_120123.sql');