In the first place, we would like to stress that Islam encourages Muslims to seek knowledge—whether worldly or religious—in its broad sense of the word, and makes seeking knowledge one of the great acts a Muslim can do to benefit himself and his Ummah. Seeking knowledge is a key to gaining Allah’s pleasure in the Hereafter. Mu`adh ibn Jabal (may Allah be pleased with him) said, “Seek knowledge, for seeking it for the sake of Allah is a sign of consciousness of Allah; acquiring it is an act of worship; studying it is a glorification (of Allah); and searching for it is (a kind of) jihad (striving in Allah’s cause)…”
Indeed, there are some branches of knowledge that Muslims must learn; they are even considered sinful by deserting them. These branches of knowledge cover all fields of our life. Examples are medicine, engineering, accounting, technology, management, military, economic, and political sciences, and craftwork. These are some of the disciplines that must be studied, and, further, there has to be a considerable number of specialists in such disciplines within the Muslim community. Since Islam has come with a universal message, Muslims should be acquainted with all worldly branches of knowledge.
Thus, there is nothing wrong with studying sonography as a branch of medicine as doctors are able to know the gender of the fetus only through x-rays and ultrasound scans. The absolute knowledge of the fetus and his gender, while in his mother’s womb, lies wholly in the hands of Allah Alone.
Moreover, doctors can only perform sonographic investigations after the elapse of a certain number of weeks of pregnancy, and not before. Even if they know if the fetus is male or female, they do not know whether it will be miscarried or carried to full-term, or born alive or stillborn. They do not know the precise length of time that it will stay in its mother’s womb.