Parshas Vayera and Chayey Sara contain exemplary acts of chessed which serve as models for all generations. Parshas Vayera begins as Hakadosh Baruch Hu appears to Avraham Avinu who is recuperating from his bris milah, Rav Chama b'rabi Chanina explains (Sotah 14).
"Hakadosh Baruch Hu bi-ker cholim...af atah ba-ker cholim - Hashem visited the sick, you too should visit the sick." Parshas Chayey Sara concludes as Hakadosh Baruch Hu appears to Yitzchak after the death of Avraham Avinu. Similarly, Rav Chama b'rabi Chanina comments "Hakadosh Baruch Hu nicheim aveilim...af atah nacheim aveilim - Hashem comforts mourners, you too should comfort mourners."
The Rambam explains (Hilchos Aveil 14:7) that nichum aveilim takes precedence over bikur cholim, for whereas through bikur cholim one services the needs of the living, nichum aveilim is a chessed for the living and the dead. The Ohr Sameach questions this view based on the Gemara (Succah 41) which describes the practice of anshei Yerushalayim who would hold the daled minim throughout Succos: "ho-lach l'vaker cholim u'l'nachem aveilim, lulavo b'yado". It seems from the order of the Gemara that the anshei Yerushalayim would first be mevaker cholim and only later be menachem aveilim. Interestingly, the Rosh cites the practice of anshei Yerushalayim in the reverse order - first nichum aveilim followed by bikur cholim. Yet the Rambam himself (Hilchos Lulav 7:24) cites our version of the Gemara. How can we reconcile the Rambam's view with the minhag of anshei Yerushalayim? The Rambam and the Rosh disagree regarding the focus of an aveil on yom tov. According to the Rambam (Aveil 10:7) "ain davar midivrei aveilus noheig b'yom tov - no aspect of aveilus applies on yom tov." The Rosh however maintains that principle elements of aveilus are observed even during yom tov. The mishna (Moed Kattan 27a) which states that the mitzvah of nichum aveilim can be fulfilled on yom tov seems, at first glance, to support the view of the Rosh, for according to the Rambam how can there be a mitzvah of nichum aveillim if aveilus has not yet begun! Rav Betzalel Zolte explains that nichum aveilim on yom tov must be understood based on the duel nature of this mitzvah. Although avielus only begins at the conclusion of yom tov, the element of nichum aveilim as chessed im hameis can be expressed even on yom tov. According to the Rambam, because nichum aveilim on yom tov is only a chessed im hameis, bikur cholim, which is a chessed im hachai, would take precedence over nichum aveilim on yom tov. This was the practice of anshei Yerushalayim. Generally, however, as the Rambam asserts, nichum aveilim kodem l'bikur cholim.
According to the Rosh, however, private aveilus is observed even on yom tov, allowing for both elements of nichum aveilim to be expressed. Thus, even on yom tov, nichum aveilim would precede bikur cholim, consistent with the Rosh's citation of the minhag of anshei Yerushalayim.