The question that MUST be answered in all of the cases, except for the pediatric case, is whether or not the patient has the Capacity to understand their condition, the risks and benefits of treatment, and the risks of not have any treatment. This is especially important in patients who are elderly and have dementia or if there is a power of attorney or there is a living will.
According to PA law (where I practice medicine), as long as the patient has capacity to understand all of the above, there you are NOT allowed to look at the living will and anyone in the family, including the power of attorney cannot override what the patient says. If the patient does NOT have capacity, which you as a physician can determine, then you go to the power of attorney as long as you have NOT documented that the patient has a terminal condition. You cannot look at the living will as long as the patient is not documented to have a terminal condition. They can have one, but if you have not DOCUMENTED it in the chart, it does not exist. That being said, no one; power of attorney/family/physician etc can make the patient a DNR/DNI without that documented statement.
If the patient is documented to have a terminal condition (Failure to Thrive, Advanced Dementia, Metastatic Cancer) and as long as you have documented that in the chart then you can look at the living will. This document is the patient's voice and trumps everyone else. Family, POA, etc. If the patient states that they are DNR/DNI and the family threatens to sue you and you have documented a terminal condition and per the living will it clearly state DNR/DNI the family has no foot to stand on.
The key is documentation. All patients, with the exception of pediatrics, have full autonomy. And if they want to refuse any treatment being life saving or paliative, as long as they have the capacity as documented by you the physician they can do so. If you feel that the patient has no capacity to make decision, you must do everything you can to find a family member to make decisions for them. IF you cannot find any family member then a close friend, someone who knows the patient, is good enough to make decisions. If there is no friend or family, the hospital must petition the court for guardianship. But unless there is an emergent need such as surgery or any other invasive procedure, it can take some time.
Just remember, the key is determination of capacity and DOCUMENTATION. I am not a pediatrician so I cannot comment.