If a person leaves the hospital ward, for example for an x-ray, they’ll usually take their medical notes with them. Many hospitals have a system whereby a sticker on the outside of the medical notes indicates that CPR should not be attempted. This is to ensure that all healthcare professionals are aware of the person's resuscitation status.
As well as the sticker system, hospitals aim to have good communication so that staff in other departments are aware if CPR is not to be attempted. This covers the situation where a person leaves the ward but doesn't have their notes with them.