The Torah prohibits a Kohen from becoming Tameh (ritually impure) by contact with a corpse. Not only is a Kohen prohibited from touching a corpse, but he is also prohibited from being under the same roof with one as well. The Gemara in Masechet Nazir (p. 43), according to one version of the text, states that a Kohen is also prohibited from entering a building in which there is a "Gosess," someone on his deathbed. Even though he is still alive and is not Tameh, the restriction still applies because of his imminent death.
This prohibition is recorded by Maran in Shulhan Aruch (YD 370). However, Hacham Ovadia has a Chidush (novel interpretation) regarding this ruling. He says that Maran does not mean that it is a bona fide Halachic prohibition, but merely a Chumra-stringency. He bases this understanding on the many Rishonim (early authorities) who did not record this Halacha.
Even if this Halacha is just a stringency, one certainly must be scrupulous in observing it, like all the Halachot of the Shulhan Aruch. Nevertheless, the "Nafka Minah" (practical difference) whether it is a Torah prohibition or a stringency will be in a case in which a Kohen is resting in bed, and suddenly he is told that there is a "Gosess" in the building. If the Halacha in Shulhan Aruch would be a Torah prohibition, the Kohen would be obligated to immediately exit the building, without taking the time to get dressed. The concern of violating a Torah prohibition overrides his personal dignity. However, according to Hacham Ovadia that the Halacha is only a stringency, considerations of human dignity would be allowed. For that matter, according to Hacham Ovadia’s understanding, a Kohen would be permitted to enter a building, in which there was a Gosess if he had a good reason to do so. For example, if he wanted to join a Minyan in that building to perform Birkat Kohanim. It is understood that according to both approaches, a Kohen who is a doctor would be allowed to treat the Gosess to try and save his life.
If the Gosess is one of the immediate relatives to whom a Kohen may become Tameh after death, he may also be in contact with him while he is a Gosess.
A Kohen should not enter a building in which there is a "Gosess," someone whose death is imminent, unless he had significant reason to do so.