Identifying the gender of the foetus in order to choose a male because of a hereditary disease that affects females
Question

                I am married to my maternal cousin (daughter of my maternal aunt), and because of a hereditary disease that doctors cannot identify precisely, three daughters have been born to me, but each one was born sick with problems in the respiratory system, and died after a short time despite staying in the hospital, as the doctors were unable to treat them. Four years ago, Allah blessed me with a boy who was born naturally and does not suffer from any health problems, praise be to Allah. The doctors said that this hereditary disease affects females only and does not affect males. Is it permissible for me to try to choose the gender of the foetus and opt to have boys only who will not be affected by this disease? If pregnancy occurs and the foetus is found to be female, is it permissible to abort it?.
Praise be to Allah.If what the doctors said about this is confirmed, that this is because of a hereditary disease that affects females but not males, and it is not just speculation, then in this case there is nothing wrong with aborting the foetus if it is female, on condition that this happens before the soul is blown into it. The soul is blown into it after one hundred and twenty days from the beginning of the pregnancy. But if the soul has already been blown into it, then it is not permissible to abort it for this reason, because now it has become a human being whose life is sacred and it is not permissible to transgress against it. 
This has been discussed in the answer to question number 12289. 
With regard to choosing the gender of the foetus and opting for a male, there is nothing wrong with that in this case, if the words of the doctors are confirmed, as stated above. There is nothing wrong with medical intervention and choosing the gender of the foetus (male), hoping that he will be free from this disease. 
The Islamic Fiqh Council has issued a statement concerning the subject of choosing the sex of the foetus, the text of which is as follows: 
alone, and blessings and peace be upon the one after whom there is no Prophet, our Prophet Muhammad, and upon his family and Companions. To proceed: 
The Islamic Fiqh Council belonging to the Muslim World League, in its nineteenth session held in Makkah al-Mukarramah, 22-27 Shawwaal 1428 AH/3-8 November 2007 CE, examined the issue of choosing the gender of the foetus. After listening to the research that was presented, consulting specialists and a great deal of discussion, 
The Council affirms that the basic principle for the Muslim is to accept the will and the decree of Allah and to be content with whatever children Allah blesses him with, whether they are male or female, and he should praise Allah for that, as the choice of the Creator is best for us, may He be glorified and exalted, chooses. 
In the Holy Qur’aan there is criticism of the people of the Jaahiliyyah for not accepting and being content with the child if it was female. Allah says (interpretation of the meaning):
“And when the news of (the birth of) a female (child) is brought to any of them, his face becomes dark, and he is filled with inward grief!
59. He hides himself from the people because of the evil of that whereof he has been informed. Shall he keep her with dishonour or bury her in the earth? Certainly, evil is their decision”
[al-Nahl 16:58]. 
There is nothing wrong with a person wanting a child to be male or female, based on the fact that the Holy Qur'aan refers to the supplication of some of the Prophets asking that they be blessed with a male child.  
In the light of that, the Council has determined the following: 
Firstly:
It is permissible to choose the gender of the foetus by natural means, such as following a certain nutrition plan, chemical washes, and choosing times for intercourse according to the time of ovulation, because these are permissible means and there are no reservations about them. 
Secondly:
It is not permissible to use any kind of medical intervention to choose the gender of the foetus, except in cases of medical necessity with regard to hereditary diseases which affect males but not females or vice versa. In that case intervention is permissible, subject to established shar‘i guidelines, so long as that is done on the basis of a committee of specialist doctors consisting of no less than three doctors of good character, who produce a medical report stating that the case calls for medical intervention so that the foetus will not be affected by the hereditary disease. Then after that, this medical report should be submitted to the Department for Issuing Fatwas so that they may issue a ruling as they see fit in that case. 
Thirdly:
It is essential to establish “watchdog” committees that will keep a close watch on hospitals and medical centres which carry out such procedures in Muslim countries, so as to prevent any practices that may go against the content of the report. In Muslim countries official bodies should set up systems and guidelines to achieve this. 
May Allah send blessings and peace upon our Prophet Muhammad and his family and Companions. End quote. 
[Link to the fatwa (in Arabic):  http://www.themwl.org/Fatwa/default.aspx?d=1&cidi=168&l=AR&cid=12]
And Allah knows best.