DO
$$
BEGIN
	IF EXISTS 
	(
		SELECT * 
        FROM   pg_proc p
		WHERE  p.proname = 'sp_SyncMedicalExamination'
	)
	THEN
		DROP FUNCTION akuz.sp_SyncMedicalExamination(UUID, UUID);
	END IF;
END;
$$ 
LANGUAGE plpgsql;

-- =============================================
-- Author:  Michael Panin
-- Create date: 2023/08/08
-- Description: Обновление ссылок на DOCTOR_WARD_EXAMINATION
-- =============================================

CREATE OR REPLACE FUNCTION public.sp_SyncMedicalExamination
(
	"newDweId" UUID -- Идентификатор нового DOCTOR_WARD_EXAMINATION
,	"oldDweId" UUID -- Идентификатор старого DOCTOR_WARD_EXAMINATION
)
RETURNS void
AS
$$ 
BEGIN

    UPDATE AKUZ.T_MEDICAL_EXAMINATION_RE
    SET    MedicalExaminationMain = "newDweId"
    WHERE  MedicalExaminationMain = "oldDweId";

END;
$$ 
LANGUAGE plpgsql;
