The capitalist profit system usually works, except in a few cases. The courts have held, for instance, that you cannot charge an outrageous price for a drink of water for a man dying of thirst or for a crust of bread for a starving man. Similarly, there are laws against ticket scalping, and no matter what the underlying economic theory (communist, capitalist, libertarian) there are always subsidies given to farmers to avoid a famine, which subsidies are NEVER provided for or explained in the original theory, but is rather based upon thousands of years of experience with farmers, food crops and famines. That is probably why there has never been a killing famine in a democracy---the voters would never stand for it.
When it comes to drug prices, however, the economic and politico-legal landscape becomes murkier. About 10 years ago, Lilly and Lederle got so tired of being sued by parents who claimed that their children were permanently damaged by the MMR (measles, mumps, rubella) vaccine, that Lilly threatened to institute the default position that only Lederle of Canada would manufacture the MMR vaccine, and it would never be sold in the USA so as to avoid tort claims of damage in the US courts. The US government, faced with this possibility, passed a law that the government would reimburse any parents who sued and could prove a case.
Similarly, the morning sickness of pregnancy with horrendous vomiting and secondary severe dehydration can prove fatal, as it did to the novelist Charlotte Bronte, sister of Emily. Merrill-Dow had a drug that treated and reduced the severity of morning sickness, called Bendectin. Now historically one out of 2500 children born has some sort of birth defect. One year, seven of the parents of such children sued Merrill-Dow, claiming that the Bendectin the pregnant mothers had taken had caused the birth defect. Merrill-Dow won all seven cases, but the legal fees far exceeded their profit from making Bendectin, so they ceased production. Their final words on the subject were: "If you are pregnant and suffer from morning sickness, call a malpractice lawyer".
Now we come to generic drugs. When a new drug is patented, there are virtually no limits on the price that the manufacturing pharmaceutical company can charge, and it is impossible to calculate what a "fair" price should be, after you try to amortize the years of studies needed to produce the drug as well as those drugs that were tested and never made it to market. It's somewhat similar to the fact that most movies never show a "net" profit, so a smart actor/producer takes a percentage of the gross, which is readily measured. If I am not mistaken, the film company that produced "The Producers" claimed that there was no net profit, and Mel Brooks had to sue them for his share of the net profits. (Caveat: if it was not "The Producers", it was a similarly successful film that generated huge grosses.) In order to encourage the production of a generic substitute, the US government will grant a six month exclusive license to the first generic company to bring a generic product to market when the patent on the brand name wears off.
Now what do the brand name drug manufacturers do when the patent for the parent, patented drug nears an end? The simplest practice was done by Roche, who put a hollow "v" in their brand name Valium, so patients could complain to their doctors that the generic valium tablet looked different, which it had to, by law. Similarly, the makers of Ativan converted the basic shape to a pentagon, again uniquely and memorably different in appearance from the generic lorazepam. Another solution is to take Prilosec, which is a mixture of right-handed and left-handed molecules (and there IS a difference in their chemical action) and start to make only (purple) Nexium, which is the isolated right-handed form of the basic patent and therefore is entitled to a new patent. Similarly Floxin is the brand name for ofloxacin, which is also a 50-50 mixture of right and left-handed molecules, and the company went on to patent and market only the L-form , called Levaquin, heavily and successfully. A final chemical "trick" was done with the anti-histamine Seldane, which was patented as the first non-sedating anti-histamine. This pro-drug was converted into its active form Allegra, in the liver. As Seldane neared the end of its patent life, the company merely stopped producing it and started to produce the newly patented and tested Allegra. None of these practices is illegal or dangerous to the patient. It just increases the cost of medicine to the patient and the profits of the drug company.
Now, however, things get a little murkier. Let us say that the generic maker "first on the scene" stands to make a profit of $200,000,000 in the first 6 months of sole production of the generic drug. The brand name producer makes $4,000,000,000 in the same six months, or 20 times the profit. The brand name company simply offers the generic company $400,000,000 free and clear,if the generic company does NOT make the generic drug, i.e. buys up their six-month rights, so the generic company makes double the profit without tying up their production lines, and the brand name company makes an additional $4B, and the consumers pay more. Just good old free enterprise in action. Or, the brand name company can (and this has happened) buy up all the basic chemical from which Xanax is made, so the generic manufacturers have to buy their base
product from them.
But the most egregious, albeit legal events have occurred in generic drugs that treat breast and other common cancers such as the drug adriamycin. Generic drugs yield the least profit, so few companies want to manufacture them or devote a lot of their production line to them, For this reason there has been a severe shortage of many cancer-treating drugs, and many patients have to wait to start their treatment. A few even had to halt their weekly treatment in the middle. A weekly bulletin of the drug shortages can be found at the FDA web site. There is at present absolutely no legal method whereby the federal government can compel any generic manufacturer to make any drug, whether the drug is used to treat cancer, heart failure, or warts, and there seem no solutions on the horizon.