Usually they used randomized controlled trials for this sort of thing, which in a well designed study will account for this sort of bias
Whether the population in the trial generalized to the population at large is a bit different question and I think is where the bias you’re highlighting could come into part