Pure MDMA really does not put much strain on the heart because it doesn't release that much adrenaline.
If your doctor said you should avoid exercise than that might be a problem because you might not be able to dance so much.
But if you can jog for 10-20 minutes without a problem, you can definitely take MDMA and dance.
If you take MDMA and you don't do physical activity (like dancing) your heart rate should only be around 110-120, which is really not much at all.
You should ask your doctor if it's safe for you to run for extensive periods of time, drink coffee, and go to the gym for weightlifting.
If he says it's ok to run, drink coffee and go to the gym, then you're ok to take MDMA because it's really not as bad as other stimulants like speed & shit in terms of its strain on the heart.
But either way, make sure you get some good crystal, big rocks, don't buy pills. Those things can have speed and other nasty stuff in them.