The core source for a physician's prayer is Berakhot 60a:28-30, where Rav Aḥa teaches that one entering to let blood recites that this enterprise be for healing, addressing God as a faithful healer whose healing is truth; Abaye adds that the one performing the procedure should instead say 'Blessed... rofei chinam,' since the Torah grants the physician permission to heal, derived from 've-rapo yerapei' (Shemot 21:19).
This same formula is codified practically in Shulchan Arukh, Orach Chayim 230:3-4, which directs one entering to be bled to say that this enterprise be for healing because God is a free healer, and afterward to bless God as healer of the sick.
The permission and duty to heal that undergirds these prayers is grounded halachically in Shulchan Arukh, Yoreh De'ah 336:1 and Arukh HaShulchan, Yoreh De'ah 336:1, both of which root the physician's license in 've-rapo yerapei' and treat healing as a mitzvah bound up with pikuach nefesh, such that one who withholds treatment is considered a shedder of blood.
Modern poskim extend this into an actual prayer text for the practicing physician: Tzitz Eliezer 9:17 holds that one compelled by his livelihood to practice medicine should recite a prayer for himself, and that it is highly desirable for the physician to offer a similar prayer to the רופא כל בשר, while Tzitz Eliezer 8:15 urges the physician to pray continually to God, the Healer of all flesh, for wisdom and clear insight in treating patients and to trust that his actions will be beneficial.
Tzitz Eliezer 17:2 holds that one should pray to the Creator for healing, recognizing Him as the free healer, and that physicians, like patients, must place their trust in Him and kindle the light of faith.
Igros Moshe YD 4:8 holds that because physicians can err, one should pray that the physician not make a mistake and that the treatment prove healing, noting that the Gemara records people consulting non-Jewish physicians and heretics where there was no concern they would kill the patient.
Contemporary codifications supply concrete wording: Rav Mordechai Eliyahu (Shut HaRav HaRashi 42:3) and Rav Mordechai Eliyahu (Maamar Mordechai Hilchot Shabbat, Chelek 2 38:8) both give the text 'yehi ratzon... sheyehei esek zeh li lirfuah u-terapeini refuah sheleimah, baruch rofei cholim ki El rofei chinam ve-ne'eman atah,' to be said before going to a doctor or taking medicine, reciting God's name only in thought rather than aloud, and bearing in mind that the physician and medicine are only agents of God's healing; Shaarei Halacha uMinhag 5:23 likewise holds that one should say only 'yehi ratzon sheyihyeh li refuah' rather than a formal blessing, while intending it with the seriousness of a brachah.
Kitzur Shulchan Arukh Yalkut Yosef, Orach Chaim 116:6 gives an expanded personal petition to insert within the brachah of Refa'einu, asking for complete healing of body and soul, and also provides language for praying on behalf of another ill person; Tzitz Eliezer 11:4 clarifies that this Refa'einu blessing is the proper vehicle for such petition, distinguishing it from Asher Yatzar, which praises the wise creation of the human body in health and in illness alike.
These prayers continue a biblical pattern of turning to God for healing, as when Abraham prays for Abimelech's household in Bereishit 20:17, Moses cries out 'E-l na refa na lah' for Miriam in Bamidbar 12:13, and the Tehillim praise God as the healer of the brokenhearted in Tehillim 147:3 and as the One who forgives iniquity and heals all disease in Tehillim 103:2-3; the Gemara further records that one who recovers from illness must offer public thanks with the blessing of 'Gomel chasadim tovim,' as in Berakhot 54b:12, and that a private individual rescued from danger recites a blessing of thanks at the site of the miracle, as in Berakhot 54a:11-13.
The ethical foundation for the physician's engagement with the patient's welfare is articulated in Mesillat Yesharim 19:4-5, which describes the duty of chesed to exert oneself to prevent or remove bodily harm from one's fellow wherever possible.