code: def date_factory(value, datatype_cls, validation_level=None):
      
  
      dt_value, fmt = get_date_info(value)
      return datatype_cls(dt_value, fmt)
docs: Creates a :class:`DT <hl7apy.base_datatypes.DT>` object
  
      The value in input must be a string parsable with :meth:`datetime.strptime`.
      The date format is chosen according to the length of the value as stated in this table:
  
      +-------+-----------+
      |Length |Format     |
      +=======+===========+
      |4      |``%Y``     |
      |       |           |
      +-------+-----------+
      |6      |``%Y%m``   |
      |       |           |
      +-------+-----------+
      |8      |``%Y%m%d`` |
      |       |           |
      +-------+-----------+
  
      Some examples that work are:
  
      >>> from hl7apy.base_datatypes import DT
      >>> date_factory("1974", DT) #doctest: +ELLIPSIS
      <hl7apy.base_datatypes.DT object at 0x...>
      >>> date_factory("198302", DT) #doctest: +ELLIPSIS
      <hl7apy.base_datatypes.DT object at 0x...>
      >>> date_factory("19880312", DT) #doctest: +ELLIPSIS
      <hl7apy.base_datatypes.DT object at 0x...>
  
      If the value does not match one of the valid format it raises :exc:`ValueError`
  
      :type value: ``str``
      :param value: the value to assign the date object
  
      :type datatype_cls: `class`
      :param value: the :class:`DT <hl7apy.base_datatypes.DT>` class to use. It has to be one implementation of
          the different version modules
  
      :type validation_level: ``int``
      :param validation_level: It must be a value from class :attr:`validation_level`
          :class:`VALIDATION_LEVEL hl7apy.consts.VALIDATION_LEVEL` or ``None`` to use the default value
  
      :rtype: :class:`hl7apy.base_datatypes.DT`