The closest to perfect solution in my mind would include all the details to make the medicine in the patent itself (I'm not sure how detailed patents has to be today). This would make it easy for other companies to create a competition once the patent expires and essentially would create a free market.
In the scenarios when it happens that there is only a single player in the market for one or another reason, things get a little trickier. I guess one of the solutions could be a commitment by government to buy/prescribe certain amount of medicine. The price of a unit should be predetermined in such cases to avoid exploitation.
Overall the actual knowledge of how to make a medicine and having a market for it, should make such situation pretty rare when only a single player is left in the market.