Walgreens Boots Alliance (WBA 0.57%) stock hit a 12-year low after the company reported earnings last month. Not only were the recent results not great, but the company is expecting some challenges ahead. But investors knew that this wasn't going to be a smooth road ahead -- the company is facing a decline, with fewer people obtaining vaccinations and the business investing into a new healthcare segment.

Have investors overreacted to the company's earnings results, and is Walgreens a good contrarian buy?

How do profits compare with pre-pandemic earnings?

In recent years, Walgreens has been benefiting from rising traffic in its stores due to COVID vaccinations.  But as demand for that has come down, the company's financials have worsened. Walgreens is facing rising costs due to inflation, and the increase in sales hasn't been enough to offset that. Revenue of $35.4 billion for the period ended May 31 represented an increase of 8.6% year over year, but the company's operating loss grew by 49% to $477 million as it incurred higher selling, general, and administrative expenses.

For the current fiscal year (which ends in August), the company projects adjusted earnings per share to be between $4.00 and $4.05, down from a previous forecast of $4.45 to $4.65. A good comparable for Walgreens is where the company was before the pandemic, under more typical circumstances. In fiscal 2018 and 2019, its adjusted earnings per share were around $6.00. The revised forecast is significantly down from those numbers, but Walgreens has been dealing with higher labor costs, and the company has been spending money on expanding into healthcare.

The positive is that Walgreens is finding more ways to cut costs and has increased the target for its transformational cost management program to $4.1 billion in savings versus the $3.5 billion it was previously forecasting. The savings could help soften the blow from what is still a costly venture into primary care.

The new healthcare business was always a long-term play

Walgreens has been spending billions to expand into primary care with its investment in VillageMD. In the most recent quarter, the U.S. healthcare business generated $2 billion in revenue, which was 43% more than the $1.4 billion it reported a year ago.

The segment is showing good growth, but it's still in its early stages. By fiscal 2025, the company hopes to generate up to $16 billion in revenue from its healthcare operations. Profitability is still likely years away, however, as the segment incurred an operating loss of $522 million this past quarter.

That means that the new business unit will continue to weigh on Walgreens' bottom line for the foreseeable future.

Does the stock deserve to be trading at a 12-year low?

Walgreens isn't just trading at a 52-week low; the stock is around a 12-year low after what is just its latest sell-off. While the stock market as a whole has been rallying this year, shares of Walgreens are down 22% since January. And over the past five years the stock has lost more than half of its value.

Lack of growth has been a problem for Walgreens in the past. Ironically, its efforts to uncover more growth through its healthcare business may be doing more harm than good -- at least in the short term. The stock is trading at six times its estimated future earnings, and it's heavily discounted.

I think the latest reaction to the stock's earnings results is an overreaction, and that Walgreens could be a good buy, but it certainly does come with some risk and uncertainty. For most investors, this is still probably a stock to avoid -- but if you're willing to buy and hold and are comfortable with the risk, it has the potential to be a good contrarian investment.