/**
   * Create the ValueObject collection to hold the set of DomainObjects.
   *
   * @param map - maps DomainObjects to created ValueObjects
   * @param domainObjectSet - Set of ims.core.configuration.domain.objects.ElectiveListConfiguration
   *     objects.
   */
  public static ims.admin.vo.ElectiveListConfigForElectiveListDetailsVoCollection
      createElectiveListConfigForElectiveListDetailsVoCollectionFromElectiveListConfiguration(
          DomainObjectMap map, java.util.Set domainObjectSet) {
    ims.admin.vo.ElectiveListConfigForElectiveListDetailsVoCollection voList =
        new ims.admin.vo.ElectiveListConfigForElectiveListDetailsVoCollection();
    if (null == domainObjectSet) {
      return voList;
    }
    int rieCount = 0;
    int activeCount = 0;
    java.util.Iterator iterator = domainObjectSet.iterator();
    while (iterator.hasNext()) {
      ims.core.configuration.domain.objects.ElectiveListConfiguration domainObject =
          (ims.core.configuration.domain.objects.ElectiveListConfiguration) iterator.next();
      ims.admin.vo.ElectiveListConfigForElectiveListDetailsVo vo = create(map, domainObject);

      if (vo != null) voList.add(vo);

      if (domainObject != null) {
        if (domainObject.getIsRIE() != null && domainObject.getIsRIE().booleanValue() == true)
          rieCount++;
        else activeCount++;
      }
    }
    voList.setRieCount(rieCount);
    voList.setActiveCount(activeCount);
    return voList;
  }
  /**
   * Create the ValueObject collection to hold the list of DomainObjects.
   *
   * @param map - maps DomainObjects to created ValueObjects
   * @param domainObjectList - List of
   *     ims.core.configuration.domain.objects.ElectiveListConfiguration objects.
   */
  public static ims.admin.vo.ElectiveListConfigForElectiveListDetailsVoCollection
      createElectiveListConfigForElectiveListDetailsVoCollectionFromElectiveListConfiguration(
          DomainObjectMap map, java.util.List domainObjectList) {
    ims.admin.vo.ElectiveListConfigForElectiveListDetailsVoCollection voList =
        new ims.admin.vo.ElectiveListConfigForElectiveListDetailsVoCollection();
    if (null == domainObjectList) {
      return voList;
    }
    int rieCount = 0;
    int activeCount = 0;
    for (int i = 0; i < domainObjectList.size(); i++) {
      ims.core.configuration.domain.objects.ElectiveListConfiguration domainObject =
          (ims.core.configuration.domain.objects.ElectiveListConfiguration) domainObjectList.get(i);
      ims.admin.vo.ElectiveListConfigForElectiveListDetailsVo vo = create(map, domainObject);

      if (vo != null) voList.add(vo);

      if (domainObject != null) {
        if (domainObject.getIsRIE() != null && domainObject.getIsRIE().booleanValue() == true)
          rieCount++;
        else activeCount++;
      }
    }

    voList.setRieCount(rieCount);
    voList.setActiveCount(activeCount);
    return voList;
  }
  /**
   * Update the ValueObject with the Domain Object.
   *
   * @param map DomainObjectMap of DomainObjects to already created ValueObjects.
   * @param valueObject to be updated
   * @param domainObject ims.core.configuration.domain.objects.ElectiveListConfiguration
   */
  public static ims.admin.vo.ElectiveListConfigForElectiveListDetailsVo insert(
      DomainObjectMap map,
      ims.admin.vo.ElectiveListConfigForElectiveListDetailsVo valueObject,
      ims.core.configuration.domain.objects.ElectiveListConfiguration domainObject) {
    if (null == domainObject) {
      return valueObject;
    }
    if (null == map) {
      map = new DomainObjectMap();
    }

    valueObject.setID_ElectiveListConfiguration(domainObject.getId());
    valueObject.setIsRIE(domainObject.getIsRIE());

    // If this is a recordedInError record, and the domainObject
    // value isIncludeRecord has not been set, then we return null and
    // not the value object
    if (valueObject.getIsRIE() != null
        && valueObject.getIsRIE().booleanValue() == true
        && !domainObject.isIncludeRecord()) return null;

    // If this is not a recordedInError record, and the domainObject
    // value isIncludeRecord has been set, then we return null and
    // not the value object
    if ((valueObject.getIsRIE() == null || valueObject.getIsRIE().booleanValue() == false)
        && domainObject.isIncludeRecord()) return null;

    // ListLocations
    valueObject.setListLocations(
        ims.RefMan.vo.domain.ElectiveListHospitalConfigurationWLVoAssembler
            .createElectiveListHospitalConfigurationWLVoCollectionFromElectiveListHospitalConfiguration(
                map, domainObject.getListLocations()));
    // WaitingListName
    valueObject.setWaitingListName(domainObject.getWaitingListName());
    // StartDate
    java.util.Date StartDate = domainObject.getStartDate();
    if (null != StartDate) {
      valueObject.setStartDate(new ims.framework.utils.Date(StartDate));
    }
    // EndDate
    java.util.Date EndDate = domainObject.getEndDate();
    if (null != EndDate) {
      valueObject.setEndDate(new ims.framework.utils.Date(EndDate));
    }
    // WaitingListCode
    valueObject.setWaitingListCode(domainObject.getWaitingListCode());
    // IsActive
    valueObject.setIsActive(domainObject.isIsActive());
    return valueObject;
  }
  /**
   * Create the ValueObject from the ims.core.configuration.domain.objects.ElectiveListConfiguration
   * object.
   *
   * @param map DomainObjectMap of DomainObjects to already created ValueObjects.
   * @param domainObject
   */
  public static ims.admin.vo.ElectiveListConfigForElectiveListDetailsVo create(
      DomainObjectMap map,
      ims.core.configuration.domain.objects.ElectiveListConfiguration domainObject) {
    if (null == domainObject) {
      return null;
    }
    // check if the domainObject already has a valueObject created for it
    ims.admin.vo.ElectiveListConfigForElectiveListDetailsVo valueObject =
        (ims.admin.vo.ElectiveListConfigForElectiveListDetailsVo)
            map.getValueObject(
                domainObject, ims.admin.vo.ElectiveListConfigForElectiveListDetailsVo.class);
    if (null == valueObject) {
      valueObject =
          new ims.admin.vo.ElectiveListConfigForElectiveListDetailsVo(
              domainObject.getId(), domainObject.getVersion());
      map.addValueObject(domainObject, valueObject);

      valueObject = insert(map, valueObject, domainObject);
    }
    return valueObject;
  }
  public static ims.core.configuration.domain.objects.ElectiveListConfiguration
      extractElectiveListConfiguration(
          ims.domain.ILightweightDomainFactory domainFactory,
          ims.admin.vo.ElectiveListConfigForElectiveListDetailsVo valueObject,
          HashMap domMap) {
    if (null == valueObject) {
      return null;
    }
    Integer id = valueObject.getID_ElectiveListConfiguration();
    ims.core.configuration.domain.objects.ElectiveListConfiguration domainObject = null;
    if (null == id) {
      if (domMap.get(valueObject) != null) {
        return (ims.core.configuration.domain.objects.ElectiveListConfiguration)
            domMap.get(valueObject);
      }
      // ims.admin.vo.ElectiveListConfigForElectiveListDetailsVo ID_ElectiveListConfiguration field
      // is unknown
      domainObject = new ims.core.configuration.domain.objects.ElectiveListConfiguration();
      domMap.put(valueObject, domainObject);
    } else {
      String key =
          (valueObject.getClass().getName() + "__" + valueObject.getID_ElectiveListConfiguration());
      if (domMap.get(key) != null) {
        return (ims.core.configuration.domain.objects.ElectiveListConfiguration) domMap.get(key);
      }
      domainObject =
          (ims.core.configuration.domain.objects.ElectiveListConfiguration)
              domainFactory.getDomainObject(
                  ims.core.configuration.domain.objects.ElectiveListConfiguration.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_ElectiveListConfiguration());

    // SaveAsRefVO treated as RefValueObject
    ims.core.configuration.vo.ElectiveListHospitalConfigurationRefVoCollection refCollection1 =
        new ims.core.configuration.vo.ElectiveListHospitalConfigurationRefVoCollection();
    if (valueObject.getListLocations() != null) {
      for (int i1 = 0; i1 < valueObject.getListLocations().size(); i1++) {
        ims.core.configuration.vo.ElectiveListHospitalConfigurationRefVo ref1 =
            (ims.core.configuration.vo.ElectiveListHospitalConfigurationRefVo)
                valueObject.getListLocations().get(i1);
        refCollection1.add(ref1);
      }
    }
    int size1 = (null == refCollection1) ? 0 : refCollection1.size();
    java.util.List domainListLocations1 = domainObject.getListLocations();
    if (domainListLocations1 == null) {
      domainListLocations1 = new java.util.ArrayList();
    }
    for (int i = 0; i < size1; i++) {
      ims.core.configuration.vo.ElectiveListHospitalConfigurationRefVo vo = refCollection1.get(i);
      ims.core.configuration.domain.objects.ElectiveListHospitalConfiguration dom = null;
      if (null != vo) {
        if (vo.getBoId() == null) {
          if (domMap.get(vo) != null) {
            dom =
                (ims.core.configuration.domain.objects.ElectiveListHospitalConfiguration)
                    domMap.get(vo);
          }
        } else {
          dom =
              (ims.core.configuration.domain.objects.ElectiveListHospitalConfiguration)
                  domainFactory.getDomainObject(
                      ims.core.configuration.domain.objects.ElectiveListHospitalConfiguration.class,
                      vo.getBoId());
        }
      }

      int domIdx = domainListLocations1.indexOf(dom);
      if (domIdx == -1) {
        domainListLocations1.add(i, dom);
      } else if (i != domIdx && i < domainListLocations1.size()) {
        Object tmp = domainListLocations1.get(i);
        domainListLocations1.set(i, domainListLocations1.get(domIdx));
        domainListLocations1.set(domIdx, tmp);
      }
    }

    // Remove all ones in domList where index > voCollection.size() as these should
    // now represent the ones removed from the VO collection. No longer referenced.
    int i1 = domainListLocations1.size();
    while (i1 > size1) {
      domainListLocations1.remove(i1 - 1);
      i1 = domainListLocations1.size();
    }

    domainObject.setListLocations(domainListLocations1);
    // 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.getWaitingListName() != null && valueObject.getWaitingListName().equals("")) {
      valueObject.setWaitingListName(null);
    }
    domainObject.setWaitingListName(valueObject.getWaitingListName());
    java.util.Date value3 = null;
    ims.framework.utils.Date date3 = valueObject.getStartDate();
    if (date3 != null) {
      value3 = date3.getDate();
    }
    domainObject.setStartDate(value3);
    java.util.Date value4 = null;
    ims.framework.utils.Date date4 = valueObject.getEndDate();
    if (date4 != null) {
      value4 = date4.getDate();
    }
    domainObject.setEndDate(value4);
    // 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.getWaitingListCode() != null && valueObject.getWaitingListCode().equals("")) {
      valueObject.setWaitingListCode(null);
    }
    domainObject.setWaitingListCode(valueObject.getWaitingListCode());
    domainObject.setIsActive(valueObject.getIsActive());

    return domainObject;
  }