This question is from a male. To test infertility problems, semen sample has to be provided to lab. It is allowed to masturbate and provide semen at the hospital lab as a very short time is available to submit the sample (max 30 mins).
In the name of Allah, Most Gracious, Most Merciful
Assalaamu `alaykum waRahmatullahi Wabarakatuh
One will be excused for doing so due to medical reasons.
And Allah knows best
Mufti Ebrahim Desai
Darul Iftaa, Madrassah In’aamiyyah