If one had a worm, there are ways to determine that, and yes the doctor should be able to diagnose that based on symptoms. A doctor may not consider that if he/she does not expect one to be exposed to an environment in which worms reside. One should inform the doctor if one suspects one has been exposed to worms, e.g. if one visited an area where worms or other parasites are common.
What makes one suspect that something is wrong with one's health? Aside from diet (nutrition) and exercise, or deficiencies therein, and aside from illness (cancer, an auto-immune disease, . . . .), one's illness could be psychological.
Certainly if one has stomach distress, it could be related to stress, or an ulcer.
If one's symptoms are related to one stomach or digestive system, then one should see a specialist - a gastroenterologist - in addition to one's doctor, who is likely a general practitioner.