“The Shrine” is episode six of season five of Stargate: Atlantis.
At the start of the episode, Rodney McKay is suffering from something that is destroying his intelligence and will soon take his life. His sister has been brought in to say goodbye.
The situation that caused it is then told in retrospect, with the current situation being interspersed with the past events. On a mission the team winds up stuck on top of the gate, which is almost completely covered with water. Rodney catches something that causes him to start losing his memory.
Ronon tells Rodney’s sister that there is somewhere that will give Rodney one more day as himself before he dies. A place that is now occupied by the Wraith.
The Shrine does show that there is a chance that Rodney can be permanently cured.