Apparently, the mistake stems from:
MedicalElements[NavigatedIndex]
when the value of
NavigatedIndex
is greater than the number of items in
MedicalElements
minus one, not to forget indices in a collection like array start from zero. To prevent this, use
Count [
^].