Hospitals told to cut out errors after figures showed 40,000 medication mistakes a year