Check out the OMOP library of methods developed for the OMOP Common Data Model. Go to http://omop.fnih.org/MethodsLibrary.