You can prevent complications from epididymitis by getting diagnosed early, and by treating any infections.
Your doctor may prescribe antibiotics before a surgery that increases the risk for epididymitis. Practicing safe sex (having intercourse with only one partner at a time, using condoms) may help prevent epididymitis caused by sexually-transmitted diseases.
Nickel JC. Inflammatory Conditions of the Male Genitourinary Tract: Prostatitis, and Related Conditions, Orchitis, Epididymitis. In: Wein AJ, ed. Campbell-Walsh Urology. 9th ed. Philadelphia, Pa: Saunders Elsevier; 2007:chap 9.