/**
  * Copy one ValueObject to another
  *
  * @param valueObjectDest to be updated
  * @param valueObjectSrc to copy values from
  */
 public static ims.ocrr.vo.SpecimenWorkListItemListVo copy(
     ims.ocrr.vo.SpecimenWorkListItemListVo valueObjectDest,
     ims.ocrr.vo.SpecimenWorkListItemListVo valueObjectSrc) {
   if (null == valueObjectSrc) {
     return valueObjectSrc;
   }
   valueObjectDest.setID_SpecimenWorkListItem(valueObjectSrc.getID_SpecimenWorkListItem());
   valueObjectDest.setIsRIE(valueObjectSrc.getIsRIE());
   // Specimen
   valueObjectDest.setSpecimen(valueObjectSrc.getSpecimen());
   // ListType
   valueObjectDest.setListType(valueObjectSrc.getListType());
   // DateToCollect
   valueObjectDest.setDateToCollect(valueObjectSrc.getDateToCollect());
   // RoundToCollect
   valueObjectDest.setRoundToCollect(valueObjectSrc.getRoundToCollect());
   // TimeToCollect
   valueObjectDest.setTimeToCollect(valueObjectSrc.getTimeToCollect());
   // CollectionStatus
   valueObjectDest.setCollectionStatus(valueObjectSrc.getCollectionStatus());
   // Printed
   valueObjectDest.setPrinted(valueObjectSrc.getPrinted());
   // DFTOrderInvestigation
   valueObjectDest.setDFTOrderInvestigation(valueObjectSrc.getDFTOrderInvestigation());
   // Ward
   valueObjectDest.setWard(valueObjectSrc.getWard());
   return valueObjectDest;
 }
  public static ims.ocrr.orderingresults.domain.objects.SpecimenWorkListItem
      extractSpecimenWorkListItem(
          ims.domain.ILightweightDomainFactory domainFactory,
          ims.ocrr.vo.SpecimenWorkListItemListVo valueObject,
          HashMap domMap) {
    if (null == valueObject) {
      return null;
    }
    Integer id = valueObject.getID_SpecimenWorkListItem();
    ims.ocrr.orderingresults.domain.objects.SpecimenWorkListItem domainObject = null;
    if (null == id) {
      if (domMap.get(valueObject) != null) {
        return (ims.ocrr.orderingresults.domain.objects.SpecimenWorkListItem)
            domMap.get(valueObject);
      }
      // ims.ocrr.vo.SpecimenWorkListItemListVo ID_SpecimenWorkListItem field is unknown
      domainObject = new ims.ocrr.orderingresults.domain.objects.SpecimenWorkListItem();
      domMap.put(valueObject, domainObject);
    } else {
      String key =
          (valueObject.getClass().getName() + "__" + valueObject.getID_SpecimenWorkListItem());
      if (domMap.get(key) != null) {
        return (ims.ocrr.orderingresults.domain.objects.SpecimenWorkListItem) domMap.get(key);
      }
      domainObject =
          (ims.ocrr.orderingresults.domain.objects.SpecimenWorkListItem)
              domainFactory.getDomainObject(
                  ims.ocrr.orderingresults.domain.objects.SpecimenWorkListItem.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_SpecimenWorkListItem());

    domainObject.setSpecimen(
        ims.ocrr.vo.domain.OrderSpecimenListVoAssembler.extractOrderSpecimen(
            domainFactory, valueObject.getSpecimen(), domMap));
    // create LookupInstance from vo LookupType
    ims.domain.lookups.LookupInstance value2 = null;
    if (null != valueObject.getListType()) {
      value2 = domainFactory.getLookupInstance(valueObject.getListType().getID());
    }
    domainObject.setListType(value2);
    java.util.Date value3 = null;
    ims.framework.utils.Date date3 = valueObject.getDateToCollect();
    if (date3 != null) {
      value3 = date3.getDate();
    }
    domainObject.setDateToCollect(value3);
    // create LookupInstance from vo LookupType
    ims.domain.lookups.LookupInstance value4 = null;
    if (null != valueObject.getRoundToCollect()) {
      value4 = domainFactory.getLookupInstance(valueObject.getRoundToCollect().getID());
    }
    domainObject.setRoundToCollect(value4);
    ims.framework.utils.Time time5 = valueObject.getTimeToCollect();
    String value5 = null;
    if (time5 != null) {
      value5 = time5.toString();
    }
    domainObject.setTimeToCollect(value5);
    // create LookupInstance from vo LookupType
    ims.domain.lookups.LookupInstance value6 = null;
    if (null != valueObject.getCollectionStatus()) {
      value6 = domainFactory.getLookupInstance(valueObject.getCollectionStatus().getID());
    }
    domainObject.setCollectionStatus(value6);
    domainObject.setPrinted(valueObject.getPrinted());
    // SaveAsRefVO - treated as a refVo in extract methods
    ims.ocrr.orderingresults.domain.objects.OrderInvestigation value8 = null;
    if (null != valueObject.getDFTOrderInvestigation()) {
      if (valueObject.getDFTOrderInvestigation().getBoId() == null) {
        if (domMap.get(valueObject.getDFTOrderInvestigation()) != null) {
          value8 =
              (ims.ocrr.orderingresults.domain.objects.OrderInvestigation)
                  domMap.get(valueObject.getDFTOrderInvestigation());
        }
      } else {
        value8 =
            (ims.ocrr.orderingresults.domain.objects.OrderInvestigation)
                domainFactory.getDomainObject(
                    ims.ocrr.orderingresults.domain.objects.OrderInvestigation.class,
                    valueObject.getDFTOrderInvestigation().getBoId());
      }
    }
    domainObject.setDFTOrderInvestigation(value8);
    ims.core.resource.place.domain.objects.Location value9 = null;
    if (null != valueObject.getWard()) {
      if (valueObject.getWard().getBoId() == null) {
        if (domMap.get(valueObject.getWard()) != null) {
          value9 =
              (ims.core.resource.place.domain.objects.Location) domMap.get(valueObject.getWard());
        }
      } else if (valueObject.getBoVersion()
          == -1) // RefVo was not modified since obtained from the Assembler, no need to update the
                 // BO field
      {
        value9 = domainObject.getWard();
      } else {
        value9 =
            (ims.core.resource.place.domain.objects.Location)
                domainFactory.getDomainObject(
                    ims.core.resource.place.domain.objects.Location.class,
                    valueObject.getWard().getBoId());
      }
    }
    domainObject.setWard(value9);

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

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

    // Specimen
    valueObject.setSpecimen(
        ims.ocrr.vo.domain.OrderSpecimenListVoAssembler.create(map, domainObject.getSpecimen()));
    // ListType
    ims.domain.lookups.LookupInstance instance2 = domainObject.getListType();
    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.ocrr.vo.lookups.SpecimenCollectionMethod voLookup2 =
          new ims.ocrr.vo.lookups.SpecimenCollectionMethod(
              instance2.getId(), instance2.getText(), instance2.isActive(), null, img, color);
      ims.ocrr.vo.lookups.SpecimenCollectionMethod 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.ocrr.vo.lookups.SpecimenCollectionMethod(
                parent2.getId(), parent2.getText(), parent2.isActive(), null, img, color));
        parentVoLookup2 = parentVoLookup2.getParent();
        parent2 = parent2.getParent();
      }
      valueObject.setListType(voLookup2);
    }
    // DateToCollect
    java.util.Date DateToCollect = domainObject.getDateToCollect();
    if (null != DateToCollect) {
      valueObject.setDateToCollect(new ims.framework.utils.Date(DateToCollect));
    }
    // RoundToCollect
    ims.domain.lookups.LookupInstance instance4 = domainObject.getRoundToCollect();
    if (null != instance4) {
      ims.framework.utils.ImagePath img = null;
      ims.framework.utils.Color color = null;
      img = null;
      if (instance4.getImage() != null) {
        img =
            new ims.framework.utils.ImagePath(
                instance4.getImage().getImageId(), instance4.getImage().getImagePath());
      }
      color = instance4.getColor();
      if (color != null) color.getValue();

      ims.ocrr.vo.lookups.SpecimenCollectionTime voLookup4 =
          new ims.ocrr.vo.lookups.SpecimenCollectionTime(
              instance4.getId(), instance4.getText(), instance4.isActive(), null, img, color);
      ims.ocrr.vo.lookups.SpecimenCollectionTime parentVoLookup4 = voLookup4;
      ims.domain.lookups.LookupInstance parent4 = instance4.getParent();
      while (parent4 != null) {
        if (parent4.getImage() != null) {
          img =
              new ims.framework.utils.ImagePath(
                  parent4.getImage().getImageId(), parent4.getImage().getImagePath());
        } else {
          img = null;
        }
        color = parent4.getColor();
        if (color != null) color.getValue();
        parentVoLookup4.setParent(
            new ims.ocrr.vo.lookups.SpecimenCollectionTime(
                parent4.getId(), parent4.getText(), parent4.isActive(), null, img, color));
        parentVoLookup4 = parentVoLookup4.getParent();
        parent4 = parent4.getParent();
      }
      valueObject.setRoundToCollect(voLookup4);
    }
    // TimeToCollect
    String TimeToCollect = domainObject.getTimeToCollect();
    if (null != TimeToCollect) {
      valueObject.setTimeToCollect(new ims.framework.utils.Time(TimeToCollect));
    }
    // CollectionStatus
    ims.domain.lookups.LookupInstance instance6 = domainObject.getCollectionStatus();
    if (null != instance6) {
      ims.framework.utils.ImagePath img = null;
      ims.framework.utils.Color color = null;
      img = null;
      if (instance6.getImage() != null) {
        img =
            new ims.framework.utils.ImagePath(
                instance6.getImage().getImageId(), instance6.getImage().getImagePath());
      }
      color = instance6.getColor();
      if (color != null) color.getValue();

      ims.ocrr.vo.lookups.SpecimenCollectionStatus voLookup6 =
          new ims.ocrr.vo.lookups.SpecimenCollectionStatus(
              instance6.getId(), instance6.getText(), instance6.isActive(), null, img, color);
      ims.ocrr.vo.lookups.SpecimenCollectionStatus parentVoLookup6 = voLookup6;
      ims.domain.lookups.LookupInstance parent6 = instance6.getParent();
      while (parent6 != null) {
        if (parent6.getImage() != null) {
          img =
              new ims.framework.utils.ImagePath(
                  parent6.getImage().getImageId(), parent6.getImage().getImagePath());
        } else {
          img = null;
        }
        color = parent6.getColor();
        if (color != null) color.getValue();
        parentVoLookup6.setParent(
            new ims.ocrr.vo.lookups.SpecimenCollectionStatus(
                parent6.getId(), parent6.getText(), parent6.isActive(), null, img, color));
        parentVoLookup6 = parentVoLookup6.getParent();
        parent6 = parent6.getParent();
      }
      valueObject.setCollectionStatus(voLookup6);
    }
    // Printed
    valueObject.setPrinted(domainObject.isPrinted());
    // DFTOrderInvestigation
    valueObject.setDFTOrderInvestigation(
        ims.ocrr.vo.domain.DftOrderInvestigationVoAssembler.create(
            map, domainObject.getDFTOrderInvestigation()));
    // Ward
    if (domainObject.getWard() != null) {
      if (domainObject.getWard()
          instanceof
          HibernateProxy) // If the proxy is set, there is no need to lazy load, the proxy knows the
                          // id already.
      {
        HibernateProxy p = (HibernateProxy) domainObject.getWard();
        int id = Integer.parseInt(p.getHibernateLazyInitializer().getIdentifier().toString());
        valueObject.setWard(new ims.core.resource.place.vo.LocationRefVo(id, -1));
      } else {
        valueObject.setWard(
            new ims.core.resource.place.vo.LocationRefVo(
                domainObject.getWard().getId(), domainObject.getWard().getVersion()));
      }
    }
    return valueObject;
  }