A procedure used to diagnose and sometimes remove gallstones blocking the common bile duct. It involves swallowing an endoscope, which the doctor gently moves through the gastrointestinal tract to the small intestine. A special dye is released into the small intestine so that gallstones can be seen on x-ray. This technique can be adapted for use in surgery to remove gallstones using a tiny basket attached to the end of the endoscope. Endoscopic retrograde cholangiopancreatography.