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;
  }