public static ims.core.clinical.domain.objects.Service extractService(
      ims.domain.ILightweightDomainFactory domainFactory,
      ims.admin.vo.ServiceForElectiveListConfigVo valueObject,
      HashMap domMap) {
    if (null == valueObject) {
      return null;
    }
    Integer id = valueObject.getID_Service();
    ims.core.clinical.domain.objects.Service domainObject = null;
    if (null == id) {
      if (domMap.get(valueObject) != null) {
        return (ims.core.clinical.domain.objects.Service) domMap.get(valueObject);
      }
      // ims.admin.vo.ServiceForElectiveListConfigVo ID_Service field is unknown
      domainObject = new ims.core.clinical.domain.objects.Service();
      domMap.put(valueObject, domainObject);
    } else {
      String key = (valueObject.getClass().getName() + "__" + valueObject.getID_Service());
      if (domMap.get(key) != null) {
        return (ims.core.clinical.domain.objects.Service) domMap.get(key);
      }
      domainObject =
          (ims.core.clinical.domain.objects.Service)
              domainFactory.getDomainObject(ims.core.clinical.domain.objects.Service.class, id);

      // TODO: Not sure how this should be handled. Effectively it must be a staleobject exception,
      // but maybe should be handled as that further up.
      if (domainObject == null) return null;

      domMap.put(key, domainObject);
    }
    domainObject.setVersion(valueObject.getVersion_Service());

    // This is to overcome a bug in both Sybase and Oracle which prevents them from storing an empty
    // string correctly
    // Sybase stores it as a single space, Oracle stores it as NULL. This fix will make them
    // consistent at least.
    if (valueObject.getServiceName() != null && valueObject.getServiceName().equals("")) {
      valueObject.setServiceName(null);
    }
    domainObject.setServiceName(valueObject.getServiceName());
    // This is to overcome a bug in both Sybase and Oracle which prevents them from storing an empty
    // string correctly
    // Sybase stores it as a single space, Oracle stores it as NULL. This fix will make them
    // consistent at least.
    if (valueObject.getServiceDescription() != null
        && valueObject.getServiceDescription().equals("")) {
      valueObject.setServiceDescription(null);
    }
    domainObject.setServiceDescription(valueObject.getServiceDescription());
    // create LookupInstance from vo LookupType
    ims.domain.lookups.LookupInstance value3 = null;
    if (null != valueObject.getServiceCategory()) {
      value3 = domainFactory.getLookupInstance(valueObject.getServiceCategory().getID());
    }
    domainObject.setServiceCategory(value3);
    // create LookupInstance from vo LookupType
    ims.domain.lookups.LookupInstance value4 = null;
    if (null != valueObject.getSpecialty()) {
      value4 = domainFactory.getLookupInstance(valueObject.getSpecialty().getID());
    }
    domainObject.setSpecialty(value4);
    domainObject.setIsActive(valueObject.getIsActive());
    // This is to overcome a bug in both Sybase and Oracle which prevents them from storing an empty
    // string correctly
    // Sybase stores it as a single space, Oracle stores it as NULL. This fix will make them
    // consistent at least.
    if (valueObject.getUpperName() != null && valueObject.getUpperName().equals("")) {
      valueObject.setUpperName(null);
    }
    domainObject.setUpperName(valueObject.getUpperName());

    return domainObject;
  }