Arzt = someone who has studied and practices medicine (after the necessary exams and permissions)
Doktor = someone who has received a doctoral degree, not necessarily in medicine (philosophy, chemistry, ...)
Because it's very common for an Arzt to have a doctoral degree too and because the title isn't very visible in public in other fields than medicine, "beim Doktor" is a common way to say "beim Arzt", though not strictly accurate.