drop procedure if exists public.sp_SetRegisterMainItems;
CREATE procedure public.sp_SetRegisterMainItems
(
	"RegisterMain" UUID
)
AS
$$
BEGIN
	update akuz.T_VISIT t 
	set rim = t1.RegisterItemID
	from akuz.T_REGISTER_ITEM t1 
	where t1.Visit = t.VisitID 
	and t1.RegisterMain = "RegisterMain";
 
	update akuz.T_DIAGNOSTICS_RESULTS t 
	set rim = t1.RegisterItemID
	from akuz.T_REGISTER_ITEM t1 
	where t1.Service = t.MedicalRecordID 
	and t1.RegisterMain = "RegisterMain";
END;
$$ LANGUAGE plpgsql;