If you are applying for adjustment of status (a green card) in the United States, you will need to have a medical exam done and submit the results to U.S. Citizenship and Immigration Services (USCIS). People applying for immigrant visas from overseas must also have a medical exam done, though the process is slightly different.
Exceptions to the exam requirement are made for some people who had the exam done before they entered the United States, such as entrants on a K-1 fiancé visa; they can use the results of their earlier medical exam, which should already be in the local USCIS office's files.
Your medical exam can be conducted only by a government-approved doctor.
If you're in the U.S., the doctor is known as a "civil surgeon." A list of these doctors is available on the Find a Doctor page of the USCIS website. You can also get this information by calling the USCIS Contact Center at 800-375-5283.
The U.S. doctor must fill out a USCIS Form called an I-693 in order to report the results of your exam. The doctor will give you your results in a sealed envelope. Do not open the report envelope—doing so will invalidate the results.
If you're overseas, the doctor is known as a "panel physician." To find one, go to the State Department's immigrant visa processing web page for medical examinations and follow the instructions. The fee varies among doctors, so you might want to call a few before choosing one. Overseas doctors fill out a form called DS-2054, and either put it in a sealed envelope or send your results directly to the consulate.
Timing is important. If you're overseas, you will be instructed to go for the medical exam shortly before your visa interview.
If you're adjusting status from within the U.S., USCIS requires (as of an October, 2018 policy announcement) that your medical exam be no more than two months old when you submit it to USCIS, most likely along with your adjustment of status application.
The results will then normally be good for two years after that, though in light of the COVID-19 pandemic, USCIS announced in August of 2021 that it will temporarily extend this to a four-year validity period.
Also realize that USCIS can always order you to have a later exam done if it suspects you've since developed a medical ground of inadmissibility.
It is possible to file an adjustment application before getting the medical exam, and then bring the results of the exam to your adjustment interview, or submit them by mail if USCIS sends you a Request for Evidence (RFE). This can be a safer approach to avoid the possibility that you'll get the exam done in anticipation of filing your adjustment application but the actual filing gets delayed.
For what happens during the exam, and the purpose of the exam, see What the Medical Exam for a U.S. Green Card Involves.