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

      valueObject = insert(map, valueObject, domainObject);
    }
    return valueObject;
  }
  public static ims.nursing.assessmenttools.domain.objects.NutritionalRiskAssessment
      extractNutritionalRiskAssessment(
          ims.domain.ILightweightDomainFactory domainFactory,
          ims.nursing.vo.NutritionalRiskAssessmentVo valueObject,
          HashMap domMap) {
    if (null == valueObject) {
      return null;
    }
    Integer id = valueObject.getID_Assessment();
    ims.nursing.assessmenttools.domain.objects.NutritionalRiskAssessment domainObject = null;
    if (null == id) {
      if (domMap.get(valueObject) != null) {
        return (ims.nursing.assessmenttools.domain.objects.NutritionalRiskAssessment)
            domMap.get(valueObject);
      }
      // ims.nursing.vo.NutritionalRiskAssessmentVo ID_NutritionalRiskAssessment field is unknown
      domainObject = new ims.nursing.assessmenttools.domain.objects.NutritionalRiskAssessment();
      domMap.put(valueObject, domainObject);
    } else {
      String key = (valueObject.getClass().getName() + "__" + valueObject.getID_Assessment());
      if (domMap.get(key) != null) {
        return (ims.nursing.assessmenttools.domain.objects.NutritionalRiskAssessment)
            domMap.get(key);
      }
      domainObject =
          (ims.nursing.assessmenttools.domain.objects.NutritionalRiskAssessment)
              domainFactory.getDomainObject(
                  ims.nursing.assessmenttools.domain.objects.NutritionalRiskAssessment.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_Assessment());

    domainObject.setAssessmentDetails(
        ims.nursing.vo.domain.NutritionalRiskAssessmentDetailsVoAssembler
            .extractNutritionalRiskAssessmentDetailsSet(
                domainFactory,
                valueObject.getAssessmentDetails(),
                domainObject.getAssessmentDetails(),
                domMap));
    // SaveAsRefVO - treated as a refVo in extract methods
    ims.core.resource.people.domain.objects.Hcp value2 = null;
    if (null != valueObject.getHcpInitiated()) {
      if (valueObject.getHcpInitiated().getBoId() == null) {
        if (domMap.get(valueObject.getHcpInitiated()) != null) {
          value2 =
              (ims.core.resource.people.domain.objects.Hcp)
                  domMap.get(valueObject.getHcpInitiated());
        }
      } else {
        value2 =
            (ims.core.resource.people.domain.objects.Hcp)
                domainFactory.getDomainObject(
                    ims.core.resource.people.domain.objects.Hcp.class,
                    valueObject.getHcpInitiated().getBoId());
      }
    }
    domainObject.setHcpInitiated(value2);
    ims.framework.utils.DateTime dateTime3 = valueObject.getDateTimeInitiated();
    java.util.Date value3 = null;
    if (dateTime3 != null) {
      value3 = dateTime3.getJavaDate();
    }
    domainObject.setDateTimeInitiated(value3);
    ims.core.admin.domain.objects.ClinicalContact value4 = null;
    if (null != valueObject.getClinicalContact()) {
      if (valueObject.getClinicalContact().getBoId() == null) {
        if (domMap.get(valueObject.getClinicalContact()) != null) {
          value4 =
              (ims.core.admin.domain.objects.ClinicalContact)
                  domMap.get(valueObject.getClinicalContact());
        }
      } else if (valueObject.getBoVersion()
          == -1) // RefVo was not modified since obtained from the Assembler, no need to update the
                 // BO field
      {
        value4 = domainObject.getClinicalContact();
      } else {
        value4 =
            (ims.core.admin.domain.objects.ClinicalContact)
                domainFactory.getDomainObject(
                    ims.core.admin.domain.objects.ClinicalContact.class,
                    valueObject.getClinicalContact().getBoId());
      }
    }
    domainObject.setClinicalContact(value4);
    ims.core.admin.domain.objects.CareContext value5 = null;
    if (null != valueObject.getCareContext()) {
      if (valueObject.getCareContext().getBoId() == null) {
        if (domMap.get(valueObject.getCareContext()) != null) {
          value5 =
              (ims.core.admin.domain.objects.CareContext) domMap.get(valueObject.getCareContext());
        }
      } else if (valueObject.getBoVersion()
          == -1) // RefVo was not modified since obtained from the Assembler, no need to update the
                 // BO field
      {
        value5 = domainObject.getCareContext();
      } else {
        value5 =
            (ims.core.admin.domain.objects.CareContext)
                domainFactory.getDomainObject(
                    ims.core.admin.domain.objects.CareContext.class,
                    valueObject.getCareContext().getBoId());
      }
    }
    domainObject.setCareContext(value5);

    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.assessmenttools.domain.objects.NutritionalRiskAssessment
   */
  public static ims.nursing.vo.NutritionalRiskAssessmentVo insert(
      DomainObjectMap map,
      ims.nursing.vo.NutritionalRiskAssessmentVo valueObject,
      ims.nursing.assessmenttools.domain.objects.NutritionalRiskAssessment domainObject) {
    if (null == domainObject) {
      return valueObject;
    }
    if (null == map) {
      map = new DomainObjectMap();
    }

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

    // AssessmentDetails
    valueObject.setAssessmentDetails(
        ims.nursing.vo.domain.NutritionalRiskAssessmentDetailsVoAssembler
            .createNutritionalRiskAssessmentDetailsVoCollectionFromNutritionalRiskAssessmentDetails(
                map, domainObject.getAssessmentDetails()));
    // HcpInitiated
    valueObject.setHcpInitiated(
        ims.core.vo.domain.HcpLiteVoAssembler.create(map, domainObject.getHcpInitiated()));
    // DateTimeInitiated
    java.util.Date DateTimeInitiated = domainObject.getDateTimeInitiated();
    if (null != DateTimeInitiated) {
      valueObject.setDateTimeInitiated(new ims.framework.utils.DateTime(DateTimeInitiated));
    }
    // ClinicalContact
    if (domainObject.getClinicalContact() != null) {
      if (domainObject.getClinicalContact()
          instanceof
          HibernateProxy) // If the proxy is set, there is no need to lazy load, the proxy knows the
                          // id already.
      {
        HibernateProxy p = (HibernateProxy) domainObject.getClinicalContact();
        int id = Integer.parseInt(p.getHibernateLazyInitializer().getIdentifier().toString());
        valueObject.setClinicalContact(new ims.core.admin.vo.ClinicalContactRefVo(id, -1));
      } else {
        valueObject.setClinicalContact(
            new ims.core.admin.vo.ClinicalContactRefVo(
                domainObject.getClinicalContact().getId(),
                domainObject.getClinicalContact().getVersion()));
      }
    }
    // CareContext
    if (domainObject.getCareContext() != null) {
      if (domainObject.getCareContext()
          instanceof
          HibernateProxy) // If the proxy is set, there is no need to lazy load, the proxy knows the
                          // id already.
      {
        HibernateProxy p = (HibernateProxy) domainObject.getCareContext();
        int id = Integer.parseInt(p.getHibernateLazyInitializer().getIdentifier().toString());
        valueObject.setCareContext(new ims.core.admin.vo.CareContextRefVo(id, -1));
      } else {
        valueObject.setCareContext(
            new ims.core.admin.vo.CareContextRefVo(
                domainObject.getCareContext().getId(), domainObject.getCareContext().getVersion()));
      }
    }
    return valueObject;
  }