There are pretty good databases of known harmful drug interactions available from vendors like Wolters Kluwer. Those are generally already integrated with the eRx features of most modern EHRs and pharmacy systems, and will pop up an alert.
The problem is that patient charts are often incomplete, or lacking proper RxNorm or NDC codes for the current medication list. So competent clinicians have to prevent problems from slipping through the cracks using their judgment and intuition. This is not something which can ever be automated (short of a true AGI).