Europe's top court ruled on Wednesday that banning gay men from donating blood may be justified, but only if there are no alternatives.

The European Court of Justice (ECJ) ruled that doctors should maximize all resources first prior to accepting blood donations from gay men. This is to ensure that HIV transmission will not occur in the process. Gay donors can undergo screening to determine if they are HIV-free and should be allowed to donate once proven clear, according to BBC News.

"The Strasbourg administrative tribunal will have to ascertain whether there are less onerous methods of ensuring a high level of health protection for recipients other than permanent deferral from blood donation," the court said in a statement.

The issue of banning blood donations from gay men began in 2009 after a doctor refused a blood donation from Frenchman Geoffrey Leger because he had sex with another man. The incident sparked uproar from gay men who felt that banning them from donating blood due to their sexual orientation is a form of discrimination. The current French law excludes blood donations from gay men to prevent the transmission of HIV.

"Discrimination of donors based on their sexual orientation is unacceptable and only the security of recipient can justify limitations on blood donation," French Health Minister Marisol Touraine said, according to The Wall Street Journal. Touraine has been actively supporting the removal of all references to sexual orientation in the questionnaires given to blood donors.

The French officials, in response to the EU's decision, is considering limiting the ban on gay men who had unprotected sex for the past one year, according to the New York Times.

The ECJ said that France still has the highest rate of HIV infections among gay men in Europe and Central Asia. Half of the newly infected people between 2003 and 2008 are men who had sexual relationships with other men.