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

      valueObject = insert(map, valueObject, domainObject);
    }
    return valueObject;
  }
  public static ims.clinical.configuration.domain.objects.WorkflowInternalReferrals
      extractWorkflowInternalReferrals(
          ims.domain.ILightweightDomainFactory domainFactory,
          ims.clinicaladmin.vo.WorkflowInternalReferralsVo valueObject,
          HashMap domMap) {
    if (null == valueObject) {
      return null;
    }
    Integer id = valueObject.getID_WorkflowInternalReferrals();
    ims.clinical.configuration.domain.objects.WorkflowInternalReferrals domainObject = null;
    if (null == id) {
      if (domMap.get(valueObject) != null) {
        return (ims.clinical.configuration.domain.objects.WorkflowInternalReferrals)
            domMap.get(valueObject);
      }
      // ims.clinicaladmin.vo.WorkflowInternalReferralsVo ID_WorkflowInternalReferrals field is
      // unknown
      domainObject = new ims.clinical.configuration.domain.objects.WorkflowInternalReferrals();
      domMap.put(valueObject, domainObject);
    } else {
      String key =
          (valueObject.getClass().getName() + "__" + valueObject.getID_WorkflowInternalReferrals());
      if (domMap.get(key) != null) {
        return (ims.clinical.configuration.domain.objects.WorkflowInternalReferrals)
            domMap.get(key);
      }
      domainObject =
          (ims.clinical.configuration.domain.objects.WorkflowInternalReferrals)
              domainFactory.getDomainObject(
                  ims.clinical.configuration.domain.objects.WorkflowInternalReferrals.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_WorkflowInternalReferrals());

    domainObject.setInpatientActions(
        ims.clinicaladmin.vo.domain.WorkflowActionInternalReferalVoAssembler
            .extractWorkflowActionInternalRefList(
                domainFactory,
                valueObject.getInpatientActions(),
                domainObject.getInpatientActions(),
                domMap));
    domainObject.setOutpatientActions(
        ims.clinicaladmin.vo.domain.WorkflowActionInternalReferalVoAssembler
            .extractWorkflowActionInternalRefList(
                domainFactory,
                valueObject.getOutpatientActions(),
                domainObject.getOutpatientActions(),
                domMap));

    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.clinical.configuration.domain.objects.WorkflowInternalReferrals
   */
  public static ims.clinicaladmin.vo.WorkflowInternalReferralsVo insert(
      DomainObjectMap map,
      ims.clinicaladmin.vo.WorkflowInternalReferralsVo valueObject,
      ims.clinical.configuration.domain.objects.WorkflowInternalReferrals domainObject) {
    if (null == domainObject) {
      return valueObject;
    }
    if (null == map) {
      map = new DomainObjectMap();
    }

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

    // InpatientActions
    valueObject.setInpatientActions(
        ims.clinicaladmin.vo.domain.WorkflowActionInternalReferalVoAssembler
            .createWorkflowActionInternalReferalVoCollectionFromWorkflowActionInternalRef(
                map, domainObject.getInpatientActions()));
    // OutpatientActions
    valueObject.setOutpatientActions(
        ims.clinicaladmin.vo.domain.WorkflowActionInternalReferalVoAssembler
            .createWorkflowActionInternalReferalVoCollectionFromWorkflowActionInternalRef(
                map, domainObject.getOutpatientActions()));
    return valueObject;
  }