A program intended to help poor and uninsured patients get prescription drugs has become an unexpected windfall for hospitals. The program at the center of a new study in the journal Health Affairs was started more than 20 years ago to allow some hospitals to buy medications from drug companies at steep discounts. The intent was to help hospitals care for people who could not afford the drugs or had no insurance to pay for them. But critics say hospitals have taken advantage of the program by selling the drugs they obtain at discounts to insured patients whose health plans reimburse the medicines’ normal prices.