As the other poster said, best to do this under the direction of your parish or diocese. Here’s my personal experience:
Our deacon started a volunteer ministry for interested parishioners to visit those in the parish who hadn’t been to Mass in some time due to illness or unknown reasons. About 20 people turned out and were teamed up into partners. Each partnership received several names of people to visit. In our case, my partner and I visited about a half-dozen people, mostly elderly and home-bound. Of those, eventually I ended up being a long-time visitor to a woman in her 80’s who was in a retirement facility and eventually in a foster home for her last year or so. I brought her Holy Communion, prayed with her and visited. Over the course of several years, her ability to visit and understand things diminished, but she always looked forward to seeing me. I received so much spiritual benefit, myself, for doing this. It is something I will always treasure. Whenever I say the “Our Father”, I think of her and how, in her last half year, she struggled to remember the words to this prayer and questioned me about their meaning.
Certain members of our ministry were assigned to visit the hospital and they had to be checked out and signed up with the hospital, specifically. You can’t just go into a hospital or nursing home without pre-approval from the institution, for privacy and protection reasons.