A device, system and method for diagnosing and treating a patient is provided where a functional device is attached to a stomach wall. The device in one embodiment provides electrical stimulation of the stomach wall. The device may also have other functional aspects such as a sensor for sensing various parameters of the stomach or stomach environment, or a substance delivery device. The implant may be programmed to respond to sensed information or signals. The device may be modular with a portion of the device accessible for removal and replacement. In one embodiment, an endoscopic delivery system delivers the functional device through the esophagus and into the stomach where it is attached the stomach wall with the assistance of a suction used to stabilize the tissue of the stomach wall. The device includes a chamber for receiving tissue of the stomach wall for attachment where a vacuum pressure is applied through the chamber to draw the tissue into the chamber.