DROP PROCEDURE IF EXISTS public.sp_UpdatePatientAddressFromGAR;

CREATE PROCEDURE public.sp_UpdatePatientAddressFromGAR
(
    addressid uuid,
	aoguid uuid default null::uuid,
	houseguid uuid default null::uuid
)
    language plpgsql
as
$$
DECLARE 
    p_addressid uuid := addressid;
    p_aoguid uuid := aoguid;
    p_houseguid uuid := houseguid;
Begin
	update akuz.t_patient_address aa 
	set 
		aoguid = Coalesce(p_aoguid,aa.aoguid), 
		houseguid = Coalesce(p_houseguid,aa.houseguid), 
		fiasupdatedate = current_date
	where aa.addressid = p_addressid;
End;
$$;