The context of 繰り返し stands for "I had to go to the hospital many times (入院、退院、通院)". First, I don't know if （時間が）経つ means "to pass time (doing something)" or "the time passes". It looks like to be the latter based on the sentence above and other example sentences I read on the internet. But, the ～ようとする form means "to attempt doing something", and that contradicts the verb itself of being intransitive (I'm not sure about it). Further reading on the internet, I found out that this grammar can also mean "to be about to do something", even though strangely there wasn't any example sentence, but it also doesn't seem to fit here. So, does （時間が）経つ mean "to spend time doing something"? If that's the case, should I say that the sentence means "I was trying to repeatedly spend time (doing something) for several months"?