In order for them to find out about the drugs, they must do a toxicology screening. This is not done on routine checkups; it's done when there is some form of already existing suspicion, or to rule out drug use.
If you have a prescription, that positive on the drug test will not count against you in any way. If you have been prescribed opiates by a doctor (face-to-face) previously, then there is your excuse. Maybe a bad cough warranted codeine cough syrup, maybe you had some sort of dental work that was painful and you got a small prescription, etc.