declare @typeId int := (select EntityID from vclib.T_ENTITIES WHERE EntName = 'ROUTE_MAP_REPRODUCTIVE' limit 1);
INSERT INTO AKUZ.T_ROUTE_MAP_REPRODUCTIVE (MedicalRecordID, FirstDiagnosis) 
select anketa.MedicalRecordID, 0 
    FROM AKUZ.T_ANKETA anketa
    JOIN AKUZ.T_MEDICAL_RECORD record ON record.MedicalRecordID = anketa.MedicalRecordID
WHERE record.type_ = @typeId
    AND NOT EXISTS 
    (
        SELECT 1 FROM AKUZ.T_ROUTE_MAP_REPRODUCTIVE repr
        WHERE repr.MedicalRecordID = anketa.MedicalRecordID
    );