code: def to_er7(self, encoding_chars=None, trailing_children=False):
          
          if encoding_chars is None:
              encoding_chars = self.encoding_chars
  
          separator = encoding_chars.get('FIELD')
          repetition = encoding_chars.get('REPETITION')
          s = [self.name]
          for child in self._get_children(trailing_children):
              if child is not None:
                  s.append(repetition.join(item.to_er7(encoding_chars, trailing_children) for item in child))
              else:
                  try:
                      s.append(self._handle_empty_children(encoding_chars))
                  except NotImplementedError:
                      pass
  
          if self.name == 'MSH' and len(s) > 1:
              s.pop(1)
  
          return separator.join(s)
docs: Return the ER7-encoded string
  
          :type encoding_chars: ``dict``
          :param encoding_chars: a dictionary containing the encoding chars or None to use the default
              (see :func:`get_default_encoding_chars <hl7apy.get_default_encoding_chars>`)
  
          :type trailing_children: ``bool``
          :param trailing_children: if ``True``, trailing children will be added even if their value is None
  
          :return: the ER7-encoded string
  
          >>> pid = Segment("PID")
          >>> pid.pid_1 = '1'
          >>> pid.pid_5 = "EVERYMAN^ADAM"
          >>> print(pid.to_er7())
          PID|1||||EVERYMAN^ADAM