do it before filing I-485
I recommend doing it before you file your I-485. Generally speaking, it is better if your application package is complete so that INS can adjudicate your case faster. If you file I-485 without the medical report INS will send you a letter asking you to do it. But that will definitely add a few months to your processing time!!!
The medical exam is valid for 1 year. So if you want to file I-485 withing the next few months you can already do the medical exam if you want. By the way, by 1 year I mean until you file your application. If your green card takes more than 1 year to be approved, you\'re still fine as long as the medical exam is not older than 1 year from your filing date.
Remember that the medical exam might take a week or two if you test positive to the tubercolosis skin test (and many people do, like me, even if they have never had TB). In that case, you will have to take chest x-rays to verify that you\'re healthy.