The Starfleet Code of Military Justice (aka SCMJ) is the foundation of military law for Starfleet.
One section of the SCMJ charges chief medical officers to not allow, either by action or omission of action, personnel under their medical charge to bring themselves to harm or death. These regulations further allow the medical officer to protect the patient, even from themselves if needed. In 2381, Doctor Shenti Yisec Eres Ree considered carrying out actions to protect Deanna Troi from the potential damage caused by her miscarried second pregnancy after she refused medical treatment to remove the fetus. (ST - Destiny novel: Gods of Night)