If a friend wasn't informed of a STD they had for over 3 years and they ended up passing that STD to me, can I sue the hospital/doctor?
No, you cannot sue the hospital or doctor because you were not the hospital's or doctor's patient, and the hospital or doctor had no duty or obligation to warn you: hospitals and doctors are not required to take action to protect third parties with whom they have no relationship from potential infection. Not having a duty to you, you cannot hold them liable: there is no liability without some duty of care imposed by law or by contract, and in this case, there was no such duty.
Furthermore, if the doctor or hospital did not even know of your existence and/or relationship with your friend, they could not possibly be liable to you, even if there had been a duty, since someone is only liable for the reasonably foreseeable harm their actions or inaction may cause--and you cannot foresee harm to someone whom you don't know exists (or if you know they exist, do not know that they have such sort of relationship with their patient that they might be exposed to the patient's STD).
No you can't sue the hospital or the doctor since they owed you no duty of care; you were not their patient; you were a unrelated 3rd party. Further, how would they even know of your existence regarding informing you of the situation? That having been said, if the person who gave you the STD was aware of their condition but did not disclose it to you and then had sexual relations with you, then you might have a claim against them. However, this was not the case in this situation. Bottom line, you can't take any legal action.