DO $$
	DECLARE ent integer;
			cnent integer;
	BEGIN
		select entityid into ent from vclib.t_entities where entname = 'CN_PDF' limit 1;
		select entityid into cnent from vclib.t_entities where entname = 'CARD_NOTE' limit 1;
		update AKUZ.T_MEDICAL_RECORD mr
		set type_ = ent
		from AKUZ.T_CARD_NOTE cn
			left join AKUZ.T_EMDR_DOC_TYPE edt on cn.EmdrDocType = edt.EmdrDocTypeID
		where 
			mr.medicalrecordid = cn.medicalrecordid	
			and
				type_ = cnent 
			and 
				(edt.IsSemd = false or edt.IsSemd is null );
	END 
$$