All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad is His slave and Messenger.
We have already issued Fataawa 108142 and 106469 clarifying that it is forbidden to be treated with impurities, among which is being treated with any part of the pig. However, if there is a necessity for being treated with an impurity, then this becomes permissible provided that there is no permissible medicine that serves instead, and provided that a trustworthy doctor informs that this precise medicine is beneficial for the purpose which is mentioned and that there is no permissible alternative.
It appears to us –Allaah Knows best –that it is permissible to use such medicine which you mentioned in the question if these conditions are met. If having children is not a necessity, it is at least a dire need, and a dire need is considered on the level of a necessity in the field of treatment.
Allaah Knows best.