<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def insert(self, index, child, by_name_index=-1):
 """ Add the child at the given index :type index: ``int`` :param index: child position :type child: :class:`Element <hl7apy.core.Element>` :param child: an instance of an :class:`Element <hl7apy.core.Element>` subclass """

        if self._can_add_child(child):
            try:
                if by_name_index == -1:
                    self.indexes[child.name].append(child)
                else:
                    self.indexes[child.name].insert(by_name_index, child)
            except KeyError:
                self.indexes[child.name] = [child]
            self.list.insert(index, child)