What is an HSG test and why is it done?

Claire
What is an HSG test and how is it performed? What does it diagnose and what are some of the risks and side effects associated with the procedure?