THE PURPOSE OF BIKUR CHOLIM AND WHEN TO VISIT [Bikur Cholim: purpose]
Gemara
39b: Rav Kahana announced 'Rav Chelbo is sick. Will no one come?!
Once, a Talmid of R. Akiva fell sick, and Chachamim did not visit him. R. Akiva visited him and commanded to sweep and clean the premises. The Talmid recovered, and attributed this to R. Akiva.'
R. Akiva: Anyone who does not visit the sick is like one who murders.
(Rav Dimi): One who visits a sick person causes him to live. One who does not visit him causes him to die.
He means that one who does not visit him does not pray, not that he should live, nor that he should die.
40a: Rava fell sick. The first day, he asked not to publicize the matter, lest his Mazel turn bad. After this, he asked them to announce it.
He reasoned - whoever hates me will rejoice, and it says "do not rejoice in the fall of your enemy (lest Hash-m... turn His anger away from him)". Whoever loves me will request mercy for me.
(Rav Shisha brei d'Rav Idi): One should not visit the sick in the first three or last three hours of the day, lest he refrain from requesting mercy for him.
In the first three hours, the patient looks well. In the last three hours, he is very weak.
Shabbos 12a (R. Chanina): With difficulty, Chachamim permitted Bikur Cholim and consolation of mourners on Shabbos (for these sadden people).
Rishonim
The Rif and Rosh (4:8) bring the episode with R. Akiva's Talmid, and that one who does not visit him does not pray, not that he should live, nor that he should die. They bring the hours not to visit a Choleh.
The Rif brings why Rava asked to publicize his illness only after the first day.
Rambam (Hilchos Evel 14:5): We visit only from the third day and onwards. If the sickness intensifies, all visit immediately. We do not visit in the first three or last three hours of the day, for then they engage in the Choleh's needs.
Kesef Mishneh: Why did the Rambam omit that relatives and friends visit immediately? Why did he give a different reason than the Gemara for not visiting in the first and last three hours?
Poskim
Shulchan Aruch (YD 335:1): It is a Mitzvah to visit the sick. Relatives and friends visit immediately. Strangers visit after three days. If the sickness intensifies, all visit immediately.
Source (Beis Yosef DH veha'Krovim): Maseches Semachos (this is not in our version) and the Yerushalmi (3:9) make this distinction.
Bach (DH u'Mah she'Chosav v'Kivan): When someone is sick, we should visit immediately, just like Hash-m visited Avraham immediately on the third day from the Bris, when it is most painful. The Yerushalmi says that strangers wait until the third day. It seems that this is to avoid establishing him to be sick. Relatives and friends are normally around, so they can visit immediately. If the sickness intensifies, he is already established, so everyone visits immediately.
Me'iri (40a DH Kol): If the sickness intensified he could die suddenly, therefore everyone visits immediately.
Einayim l'Mishpat (40a DH Lo Tiglu): Rava said not to publicize his illness on the first day. This implies that people visit on the second day! The Me'iri (40a DH Kol) says that we do not visit until the third day, when he is Muchzak to be ill.
Shulchan Aruch (4): One should not visit the sick in the first three hours of the day, for then the Choleh looks well, and one will not be concerned to pray for him. We do not visit in the last three hours, for then he is so weak that one will despair and not pray.
Rema: If one visited and did not pray, he did not fulfill the Mitzvah.
Beis Yosef (DH u'Mitzvah): The Ramban (Toras ha'Adam 17) says that we learn from here that the Mitzvah of Bikur Cholim is in order that they will sweep and wash the floor and do his needs, and also so he will request mercy for him. One who visited and did not request mercy did not fulfill the Mitzvah.
Source (Gra 7): Rav Shisha brei d'Rav Idi taught that one should not visit the sick in the first three or last three hours of the day, lest he refrain from requesting mercy for him.
Note: Sedei Eliyahu explains that if one would fulfill the Mitzvah without praying, there would be a Mitzvah to visit at these times! Seemingly, at any time it should be a Mitzvah (even if it is not Bikur Cholim) to go to investigate the needs of the Choleh! Perhaps this is the Rambam's source to say that at these times others are engaged in the Choleh's needs! It is difficult to say that every Choleh is so weak in the last three hours that the visitor will despair and not pray. Presumably, the visitor has seen sick people in his own family at this time, and they recovered! Rather, there is a minority who look so weak that one might despair, and Chachamim were concerned for the minority. If one were Yotzei without praying, surely we would not decree not to visit at these times lest one not pray!
Shulchan Aruch (OC 287:1): We may console mourners and visit the sick on Shabbos.
Magen Avraham (1): Bikur Cholim on Shabbos was permitted with difficulty, so it is improper to go only on Shabbos.
Kaf ha'Chayim (6): Chachamei ha'Musar say that the Ikar Bikur Cholim is for the poor, to investigate their needs. If one can, he should go during the week and help them as much as he can. If one is busy all week and can go only on Shabbos, he should not refrain, unless his nature is to feel pain over others' afflictions. Shabbos is for pleasure, to for pain.
Kaf ha'Chayim (5): Sefer Chasidim (110) says that one should not discuss pain of his friends, lest this cause anguish. Certainly, if one does not know that his relative or close friend is sick or in pain, others should not tell him on Shabbos.
Shulchan Aruch (7): We tell the Choleh to think about his monetary affairs, e.g. if he lent or deposited something or took a loan or deposit, lest he fear death due to this.
Gra (8): The Ramban (Toras ha'Adam) cites this from Maseches Semachos. It is in our text of Maseches Semachos.