Walgreens was within its rights to fire a pharmacist who had moral objections to administering flu vaccines, a federal judge has ruled.

Rodney Prewitt, a 66-year-old pharmacist who had worked at the company’s Oxford store for about five years, sued Walgreens after the pharmacy started a program in 2010 offering 20 vaccines, including one for the flu, to customers in its stores nationwide. It required pharmacists to complete a training program in order to administer the vaccines and immunize customers who asked for the service.