A system for controlling an implantable medical device (e.g., a drug delivery device) susceptible to malfunctioning during exposure to a magnetic field and/or Radio Frequency field (e.g., during a magnetic resonance imaging procedure) and a method for operating the same. Exposure of the implantable device to the magnetic field and/or the Radio Frequency field is detected using the sensing device. When the detected magnetic field and/or Radio Frequency field exceeds a corresponding predetermined threshold level, an input signal is generated at the microcontroller. In response to the generated input signal, the microcontroller automatically triggers (i) a safety mode enabling a predetermined safety mode operation that alters some operation, without ceasing all operation, of the implantable medical device and/or (ii) after expiration of a predetermined safety mode time interval when the at least one field being detected falls below its corresponding predetermined threshold level or a predetermined period of time elapses, a self testing mode enabling a predetermined self testing operation to verify proper operation of the implantable medical device. Preferably, both the safety and self testing modes are automatically triggered.