It seems like a calculi in the urinary system
anywhere from the kidneys upto the bladder and the urethra
. An X-ray of the KUB region along with a plain ultrasound
abdomen will help to find out the actual cause. In my suggestion you should get these investigations done.
If these are ruled out, then two other possibilities could be costochondritis
of the ribs or a peptic ulcer disease
To me, the first 2 things need to ruled out first.
Drink plenty of water in the meantime as it would flush out smaller calculi less than 4 mm in size by itself.
Get well soon.