/**
   * Create the ValueObject collection to hold the set of DomainObjects.
   *
   * @param map - maps DomainObjects to created ValueObjects
   * @param domainObjectSet - Set of
   *     ims.assessment.configuration.domain.objects.PatientAssessmentFolder objects.
   */
  public static ims.assessment.vo.PatientAssessmentFolderVoCollection
      createPatientAssessmentFolderVoCollectionFromPatientAssessmentFolder(
          DomainObjectMap map, java.util.Set domainObjectSet) {
    ims.assessment.vo.PatientAssessmentFolderVoCollection voList =
        new ims.assessment.vo.PatientAssessmentFolderVoCollection();
    if (null == domainObjectSet) {
      return voList;
    }
    int rieCount = 0;
    int activeCount = 0;
    java.util.Iterator iterator = domainObjectSet.iterator();
    while (iterator.hasNext()) {
      ims.assessment.configuration.domain.objects.PatientAssessmentFolder domainObject =
          (ims.assessment.configuration.domain.objects.PatientAssessmentFolder) iterator.next();
      ims.assessment.vo.PatientAssessmentFolderVo 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.assessment.configuration.domain.objects.PatientAssessmentFolder objects.
   */
  public static ims.assessment.vo.PatientAssessmentFolderVoCollection
      createPatientAssessmentFolderVoCollectionFromPatientAssessmentFolder(
          DomainObjectMap map, java.util.List domainObjectList) {
    ims.assessment.vo.PatientAssessmentFolderVoCollection voList =
        new ims.assessment.vo.PatientAssessmentFolderVoCollection();
    if (null == domainObjectList) {
      return voList;
    }
    int rieCount = 0;
    int activeCount = 0;
    for (int i = 0; i < domainObjectList.size(); i++) {
      ims.assessment.configuration.domain.objects.PatientAssessmentFolder domainObject =
          (ims.assessment.configuration.domain.objects.PatientAssessmentFolder)
              domainObjectList.get(i);
      ims.assessment.vo.PatientAssessmentFolderVo 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 from the
   * ims.assessment.configuration.domain.objects.PatientAssessmentFolder object.
   *
   * @param map DomainObjectMap of DomainObjects to already created ValueObjects.
   * @param domainObject
   */
  public static ims.assessment.vo.PatientAssessmentFolderVo create(
      DomainObjectMap map,
      ims.assessment.configuration.domain.objects.PatientAssessmentFolder domainObject) {
    if (null == domainObject) {
      return null;
    }
    // check if the domainObject already has a valueObject created for it
    ims.assessment.vo.PatientAssessmentFolderVo valueObject =
        (ims.assessment.vo.PatientAssessmentFolderVo)
            map.getValueObject(domainObject, ims.assessment.vo.PatientAssessmentFolderVo.class);
    if (null == valueObject) {
      valueObject =
          new ims.assessment.vo.PatientAssessmentFolderVo(
              domainObject.getId(), domainObject.getVersion());
      map.addValueObject(domainObject, valueObject);

      valueObject = insert(map, valueObject, domainObject);
    }
    return valueObject;
  }
  /**
   * Update the ValueObject with the Domain Object.
   *
   * @param map DomainObjectMap of DomainObjects to already created ValueObjects.
   * @param valueObject to be updated
   * @param domainObject ims.assessment.configuration.domain.objects.PatientAssessmentFolder
   */
  public static ims.assessment.vo.PatientAssessmentFolderVo insert(
      DomainObjectMap map,
      ims.assessment.vo.PatientAssessmentFolderVo valueObject,
      ims.assessment.configuration.domain.objects.PatientAssessmentFolder domainObject) {
    if (null == domainObject) {
      return valueObject;
    }
    if (null == map) {
      map = new DomainObjectMap();
    }

    valueObject.setID_PatientAssessmentFolder(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;

    // FolderName
    valueObject.setFolderName(domainObject.getFolderName());
    // PatientAssessments
    valueObject.setPatientAssessments(
        ims.assessment.vo.domain.UserAssessmentShortVoAssembler
            .createUserAssessmentShortVoCollectionFromUserAssessment(
                map, domainObject.getPatientAssessments()));
    // GraphicAssessments
    valueObject.setGraphicAssessments(
        ims.assessment.vo.domain.GraphicAssessmentShortVoAssembler
            .createGraphicAssessmentShortVoCollectionFromGraphicAssessment(
                map, domainObject.getGraphicAssessments()));
    return valueObject;
  }
  public static ims.assessment.configuration.domain.objects.PatientAssessmentFolder
      extractPatientAssessmentFolder(
          ims.domain.ILightweightDomainFactory domainFactory,
          ims.assessment.vo.PatientAssessmentFolderVo valueObject,
          HashMap domMap) {
    if (null == valueObject) {
      return null;
    }
    Integer id = valueObject.getID_PatientAssessmentFolder();
    ims.assessment.configuration.domain.objects.PatientAssessmentFolder domainObject = null;
    if (null == id) {
      if (domMap.get(valueObject) != null) {
        return (ims.assessment.configuration.domain.objects.PatientAssessmentFolder)
            domMap.get(valueObject);
      }
      // ims.assessment.vo.PatientAssessmentFolderVo ID_PatientAssessmentFolder field is unknown
      domainObject = new ims.assessment.configuration.domain.objects.PatientAssessmentFolder();
      domMap.put(valueObject, domainObject);
    } else {
      String key =
          (valueObject.getClass().getName() + "__" + valueObject.getID_PatientAssessmentFolder());
      if (domMap.get(key) != null) {
        return (ims.assessment.configuration.domain.objects.PatientAssessmentFolder)
            domMap.get(key);
      }
      domainObject =
          (ims.assessment.configuration.domain.objects.PatientAssessmentFolder)
              domainFactory.getDomainObject(
                  ims.assessment.configuration.domain.objects.PatientAssessmentFolder.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_PatientAssessmentFolder());

    // 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.getFolderName() != null && valueObject.getFolderName().equals("")) {
      valueObject.setFolderName(null);
    }
    domainObject.setFolderName(valueObject.getFolderName());
    domainObject.setPatientAssessments(
        ims.assessment.vo.domain.UserAssessmentShortVoAssembler.extractUserAssessmentSet(
            domainFactory,
            valueObject.getPatientAssessments(),
            domainObject.getPatientAssessments(),
            domMap));
    domainObject.setGraphicAssessments(
        ims.assessment.vo.domain.GraphicAssessmentShortVoAssembler.extractGraphicAssessmentSet(
            domainFactory,
            valueObject.getGraphicAssessments(),
            domainObject.getGraphicAssessments(),
            domMap));

    return domainObject;
  }