Thank you for the additional information.
The most likely cause of several months of right abdominal pain associated with alternating periods of constipation and diarrhea would be irritable bowel syndrome, or IBS. IBS is due to altered muscular activity of the bowels, both an increase and a decrease in muscular activity at various times. When material does not pass through the bowels because of the altered muscular activity, it can cause pain as the bowel has to push harder to move the material downstream and can cause bloating and distension at various times.
There is no test that can prove that IBS is the cause of symptoms, but it is by far the most common cause of pain that also causes both constipation and diarrhea. The formal method for diagnosis of IBS is to exclude all other possible causes of pain, but when the symptoms are typical, another option is to manage it as IBS to see if the symptoms improve.
The usual first line intervention
for IBS is to significantly increase the intake of fiber, either in the diet or via a fiber supplement. The goal is to achieve at least a fiber intake of 25-35 grams per day. In addition, it is necessary to be drinking 64 oz. of water per day, as the fiber needs to absorb the water to be effective in controlling the muscular activity of the bowels.
Some people do not tolerate a sudden increase in the amount of fiber, so it is generally better to increase the fiber intake gradually.
If the fiber is not sufficient, an antispasmodic may be helpful for the pain, but that would require seeing your doctor.
If I can provide any further information, please let me know.