Who decides on behalf of the patient if the patient is determined to lack competency

Who decides on behalf of the patient if the patient is determined to lack competency? How should a surrogate decision maker proceed on behalf of a patient? How can a healthcare administrator ensure that the patient’s autonomy is ensured and competency is established? How do the facility’s standards and regulations affect how competency is determined?