Should we keep our grandparents or parents alive with drugs and other treatments when they are unhappy and unhealthy on their deathbeds?

This is a very, very complicated question. In general, it should be said Catholic theology offers wide freedom to valid decision-makers to remove even life-sustaining treatment. We are finite creatures and should not grasp for more life when it is unjust or when the burdens of medical treatment outweigh its benefits.

Still, human persons have has irreducible value and should never be radically reduced to some other end by aiming at their death—whether that reduction is by an act (say, giving an overdose of pain medication) or by refusing to act (say, by refusing to give food or fluids). One may do something (or refuse to do something) that results in death as long as one is aiming at something else—but one may never aim at the death of an innocent person. So it may be perfectly legit to stop chemotherapy if one is aiming, not at death, but at saving someone from the burden of this kind of treatment. But it would not be acceptable to, say, remove a feeding tube because one had decided that the patient was better off dead.

Another layer of complexity involves who gets to decide. Ideally, a patient (if they are rational) should make the decision either at the time of treatment or via an advanced directive, or a person close to the patient should make the decision based on what they believe the patient would have wanted. All of these matters are very complex, however, and the Church gives the benefit of the doubt to those making difficult decisions based on individual circumstances.