To develop a general method for using the alerting function of an electronic health record (EHR) system to warn prescribers when a drug order may be in conflict with the restrictions of a patient's research protocol. We examined a sample of clinical research protocols at the National Institutes of Health (NIH) to identify the frequency with which drugs were excluded by protocols. We analyzed two protocols and modeled the exclusions they contained. We then developed a data model to represent the exclusions, expanded the terminology in the NIH's Biomedical Translational Research Information System (BTRIS) to include relevant drug concepts, and wrote a medical logic module (MLM) for the EHR to match terms for ordered drugs with the drug concepts in the protocol. We found that 50% of protocols in our sample included drug exclusions. Our model represented exclusion concepts and also concepts related to exemptions from the exclusions. The MLM was deployed in a test environment where it successfully detected orders for excluded drugs and delivered messages to users explaining the exclusion, providing information about the clinical setting and timing where the exclusion applies. BTRIS reports using the same terminology information were able to identify instances where protocol exceptions occurred. Drug exclusions are frequent components of research protocols; nonadherenece to these exclusions could result in harm to subjects, erroneous study results or inefficiencies due to disqualification of research subjects. Our approach uses an MLM and a simple knowledge base, together with a controlled terminology, to provide a solution to the detection and prevention of possible protocol violations. Further work is needed to model additional aspects of the exclusions, such as timing and co-occurring conditions, to improve MLM accuracy.