It is very easy to get advanced medical directives today. You can often get living wills and health care powers of attorney as part of the process of admission to a hospital. If you tell a doctor about your wishes, it is often good enough for the doctor to make a note of them in his or her notes. However, getting those documents at a hospital or by telling a doctor can be a problem.
The system of medical records used in the U.S. does not make it easy for doctors to know that you have expressed your wishes ahead of time, especially when they actually need the information as The New York Times reports in "You've Detailed Your Last Wishes, but Doctors May Not See Them."
There is a potential way to mitigate the possibility that this problem will happen to you. Get your living will and your health care power of attorney ahead of time, by going to an estate planning attorney. These documents are routinely created as part of the estate planning process.
Once you have created the documents, you should store them in a secure place. However, do not stop there. Make sure that someone you trust knows where to find the documents. That person can then get them when needed, to the doctors providing care for you.
This is not a perfect plan that will work all of the time, but it is better than relying on the current system of medical records.
Reference: New York Times (March 27, 2018) "You've Detailed Your Last Wishes, but Doctors May Not See Them."