Successfully addressing patient safety requires detecting medical events effectively. Given the volume of patients seen at medical centers, detecting events automatically from data that are already available electronically would greatly facilitate patient safety work. We have created a framework for electronic detection. Key steps include: selecting target events, assessing what information is available electronically, transforming raw data such as narrative notes into a coded format, querying the transformed data, verifying the accuracy of event detection, characterizing the events using systems and cognitive approaches, and using what is learned to improve detection.