Thank you for your query on Healthcare Magic,
I think you might have developed gastritis due to drug induced or due to the typhoid infection.
And for this you have to use proton pump inhibitor like Rabeprazole
and gastric mucosal protectant like sucralfate.
The second episode developed along with fever, diarrhea with associated severe gastritis.
For this you take precautions to decrease drug induced gastritis.
For recurrent gastritis consult a Gastroenterologist
for the need for endoscopy to look for any reflux esophagitis
, erosive gastritis, or signs of acid peptic disease
which may require prolonged proton pump inhibitor treatmment.
Hope I have answered your query.