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

      valueObject = insert(map, valueObject, domainObject);
    }
    return valueObject;
  }
  public static ims.nursing.careplans.domain.objects.CarePlanTemplate extractCarePlanTemplate(
      ims.domain.ILightweightDomainFactory domainFactory,
      ims.nursing.vo.CarePlanTemplateTitle valueObject,
      HashMap domMap) {
    if (null == valueObject) {
      return null;
    }
    Integer id = valueObject.getID_CarePlanTemplate();
    ims.nursing.careplans.domain.objects.CarePlanTemplate domainObject = null;
    if (null == id) {
      if (domMap.get(valueObject) != null) {
        return (ims.nursing.careplans.domain.objects.CarePlanTemplate) domMap.get(valueObject);
      }
      // ims.nursing.vo.CarePlanTemplateTitle ID_CarePlanTemplate field is unknown
      domainObject = new ims.nursing.careplans.domain.objects.CarePlanTemplate();
      domMap.put(valueObject, domainObject);
    } else {
      String key = (valueObject.getClass().getName() + "__" + valueObject.getID_CarePlanTemplate());
      if (domMap.get(key) != null) {
        return (ims.nursing.careplans.domain.objects.CarePlanTemplate) domMap.get(key);
      }
      domainObject =
          (ims.nursing.careplans.domain.objects.CarePlanTemplate)
              domainFactory.getDomainObject(
                  ims.nursing.careplans.domain.objects.CarePlanTemplate.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_CarePlanTemplate());

    java.util.Date value1 = null;
    ims.framework.utils.Date date1 = valueObject.getCreationDate();
    if (date1 != null) {
      value1 = date1.getDate();
    }
    domainObject.setCreationDate(value1);
    // create LookupInstance from vo LookupType
    ims.domain.lookups.LookupInstance value2 = null;
    if (null != valueObject.getAssessmentComponent()) {
      value2 = domainFactory.getLookupInstance(valueObject.getAssessmentComponent().getID());
    }
    domainObject.setAssessmentComponent(value2);
    // 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.getTitle() != null && valueObject.getTitle().equals("")) {
      valueObject.setTitle(null);
    }
    domainObject.setTitle(valueObject.getTitle());
    domainObject.setActive(valueObject.getActive());

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

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

    // CreationDate
    java.util.Date CreationDate = domainObject.getCreationDate();
    if (null != CreationDate) {
      valueObject.setCreationDate(new ims.framework.utils.Date(CreationDate));
    }
    // AssessmentComponent
    ims.domain.lookups.LookupInstance instance2 = domainObject.getAssessmentComponent();
    if (null != instance2) {
      ims.framework.utils.ImagePath img = null;
      ims.framework.utils.Color color = null;
      img = null;
      if (instance2.getImage() != null) {
        img =
            new ims.framework.utils.ImagePath(
                instance2.getImage().getImageId(), instance2.getImage().getImagePath());
      }
      color = instance2.getColor();
      if (color != null) color.getValue();

      ims.nursing.vo.lookups.AssessmentComponentType voLookup2 =
          new ims.nursing.vo.lookups.AssessmentComponentType(
              instance2.getId(), instance2.getText(), instance2.isActive(), null, img, color);
      ims.nursing.vo.lookups.AssessmentComponentType parentVoLookup2 = voLookup2;
      ims.domain.lookups.LookupInstance parent2 = instance2.getParent();
      while (parent2 != null) {
        if (parent2.getImage() != null) {
          img =
              new ims.framework.utils.ImagePath(
                  parent2.getImage().getImageId(), parent2.getImage().getImagePath());
        } else {
          img = null;
        }
        color = parent2.getColor();
        if (color != null) color.getValue();
        parentVoLookup2.setParent(
            new ims.nursing.vo.lookups.AssessmentComponentType(
                parent2.getId(), parent2.getText(), parent2.isActive(), null, img, color));
        parentVoLookup2 = parentVoLookup2.getParent();
        parent2 = parent2.getParent();
      }
      valueObject.setAssessmentComponent(voLookup2);
    }
    // Title
    valueObject.setTitle(domainObject.getTitle());
    // Active
    valueObject.setActive(domainObject.isActive());
    return valueObject;
  }