As pointed out in the previous answer, the second sentence is correct; there is no need to capitalize 'doctor' in 'the doctor', but the same word is capitalized (usually in its abbreviated form) when it comes as a title before the doctor's name. Doctor is also capitalized in direct speech (but not reported speech) when used as a form of addressing a doctor.
I visited Dan, the doctor.
I visited Dr. Dan, the physician. (can also write Doctor Dan, but uncommonly used in full form)
"I can see now, Doctor!" the patient said.
The patient told the doctor that he could see now.
It is general convention not to capitalize occupational nouns like doctor, teacher, engineer, plumber, tailor and priest when used in sentences. HOWEVER, capitalization is used for the official titles of heads of state such as President and Prime Minister, and specialised titles of exceeding respect such as His Holiness, Holy Father, and (in countries that are monarchies) King or Queen.
The Prime Minister of India met with the President of the USA.
Pilgrims waited to meet the Holy Father.
There were more than 70 visitors, but His Holiness spoke a few words to each of them.
They made high quality stationery for the Queen.