I like your idea, but it seems like then the government (or somebody) would have to have a guaranteed way to detect whether or not you're drinking soda, smoking, etc. Seems invasive.
After all, someone who drinks soda and does a lot of exercise or hard work might not impose any cost on the health system - and someone who eats a lot of bacon or home-baked cakes might get obese without drinking any soda.
As for the tax, it doesn't need to be applied at the point of sale, but can be further back in the chain.