Yes, your comprehension is correct. And there is a subtle difference between these two sentences, although they basically mean the same. 你吃了药没有 is like a present perfect tense: Have you taken medicine? While 你吃没吃药 is just a past tense: Did you take medicine?
And about those four questions, they mean the same, however there are some tiny differences in their affirmative/negative responses:
你吃药了吗? -吃了(Yes) -没吃(No)
你吃没吃药? -吃了(Yes) -没吃(No)
你有没有吃药? -有(Yes) -没有(No)
你吃药了没有? -吃了(Yes) -没有(No)