Created reusable function for error passing in patients controller