My mom has Alzheimer's, and recently started hallucinating. After several (!) trips to the ER and doctor, someone finally thought to do a blood test, and found that she had a severe sodium|potassium deficiency (now I don't remember which). Turns out she was thirsty due to the dry climate and it being winter, and she kept drinking water, forgetting that she had just finished a glass, which led to the mineral deficiency, which caused the hallucinations.
I can't imagine how hard it would to control be if she was taking painkillers on an as-needed basis for a long time. People with dementia are often surprisingly clever and resourceful, considering the disease.