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

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

    // Patient
    if (domainObject.getPatient() != null) {
      if (domainObject.getPatient()
          instanceof
          HibernateProxy) // If the proxy is set, there is no need to lazy load, the proxy knows the
                          // id already.
      {
        HibernateProxy p = (HibernateProxy) domainObject.getPatient();
        int id = Integer.parseInt(p.getHibernateLazyInitializer().getIdentifier().toString());
        valueObject.setPatient(new ims.core.patient.vo.PatientRefVo(id, -1));
      } else {
        valueObject.setPatient(
            new ims.core.patient.vo.PatientRefVo(
                domainObject.getPatient().getId(), domainObject.getPatient().getVersion()));
      }
    }
    // ReferralDetails
    valueObject.setReferralDetails(
        ims.core.vo.domain.CatsReferralDetailsRepatriationRequestVoAssembler.create(
            map, domainObject.getReferralDetails()));
    // EpisodeOfCare
    if (domainObject.getEpisodeOfCare() != null) {
      if (domainObject.getEpisodeOfCare()
          instanceof
          HibernateProxy) // If the proxy is set, there is no need to lazy load, the proxy knows the
                          // id already.
      {
        HibernateProxy p = (HibernateProxy) domainObject.getEpisodeOfCare();
        int id = Integer.parseInt(p.getHibernateLazyInitializer().getIdentifier().toString());
        valueObject.setEpisodeOfCare(new ims.core.admin.vo.EpisodeOfCareRefVo(id, -1));
      } else {
        valueObject.setEpisodeOfCare(
            new ims.core.admin.vo.EpisodeOfCareRefVo(
                domainObject.getEpisodeOfCare().getId(),
                domainObject.getEpisodeOfCare().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()));
      }
    }
    // CurrentStatus
    valueObject.setCurrentStatus(
        ims.RefMan.vo.domain.CatsReferralStatusVoAssembler.create(
            map, domainObject.getCurrentStatus()));
    // StatusHistory
    valueObject.setStatusHistory(
        ims.RefMan.vo.domain.CatsReferralStatusVoAssembler
            .createCatsReferralStatusVoCollectionFromCATSReferralStatus(
                map, domainObject.getStatusHistory()));
    // Contract
    if (domainObject.getContract() != null) {
      if (domainObject.getContract()
          instanceof
          HibernateProxy) // If the proxy is set, there is no need to lazy load, the proxy knows the
                          // id already.
      {
        HibernateProxy p = (HibernateProxy) domainObject.getContract();
        int id = Integer.parseInt(p.getHibernateLazyInitializer().getIdentifier().toString());
        valueObject.setContract(new ims.core.configuration.vo.ContractConfigRefVo(id, -1));
      } else {
        valueObject.setContract(
            new ims.core.configuration.vo.ContractConfigRefVo(
                domainObject.getContract().getId(), domainObject.getContract().getVersion()));
      }
    }
    // Urgency
    ims.domain.lookups.LookupInstance instance8 = domainObject.getUrgency();
    if (null != instance8) {
      ims.framework.utils.ImagePath img = null;
      ims.framework.utils.Color color = null;
      img = null;
      if (instance8.getImage() != null) {
        img =
            new ims.framework.utils.ImagePath(
                instance8.getImage().getImageId(), instance8.getImage().getImagePath());
      }
      color = instance8.getColor();
      if (color != null) color.getValue();

      ims.RefMan.vo.lookups.ReferralUrgency voLookup8 =
          new ims.RefMan.vo.lookups.ReferralUrgency(
              instance8.getId(), instance8.getText(), instance8.isActive(), null, img, color);
      ims.RefMan.vo.lookups.ReferralUrgency parentVoLookup8 = voLookup8;
      ims.domain.lookups.LookupInstance parent8 = instance8.getParent();
      while (parent8 != null) {
        if (parent8.getImage() != null) {
          img =
              new ims.framework.utils.ImagePath(
                  parent8.getImage().getImageId(), parent8.getImage().getImagePath());
        } else {
          img = null;
        }
        color = parent8.getColor();
        if (color != null) color.getValue();
        parentVoLookup8.setParent(
            new ims.RefMan.vo.lookups.ReferralUrgency(
                parent8.getId(), parent8.getText(), parent8.isActive(), null, img, color));
        parentVoLookup8 = parentVoLookup8.getParent();
        parent8 = parent8.getParent();
      }
      valueObject.setUrgency(voLookup8);
    }
    // Journey
    if (domainObject.getJourney() != null) {
      if (domainObject.getJourney()
          instanceof
          HibernateProxy) // If the proxy is set, there is no need to lazy load, the proxy knows the
                          // id already.
      {
        HibernateProxy p = (HibernateProxy) domainObject.getJourney();
        int id = Integer.parseInt(p.getHibernateLazyInitializer().getIdentifier().toString());
        valueObject.setJourney(new ims.pathways.vo.PatientPathwayJourneyRefVo(id, -1));
      } else {
        valueObject.setJourney(
            new ims.pathways.vo.PatientPathwayJourneyRefVo(
                domainObject.getJourney().getId(), domainObject.getJourney().getVersion()));
      }
    }
    // PathwayID
    valueObject.setPathwayID(domainObject.getPathwayID());
    // RTTClockImpact
    valueObject.setRTTClockImpact(domainObject.isRTTClockImpact());
    // CurrentRTTStatus
    valueObject.setCurrentRTTStatus(
        ims.pathways.vo.domain.PathwayRTTStatusVoAssembler.create(
            map, domainObject.getCurrentRTTStatus()));
    // RepatriationRequest
    valueObject.setRepatriationRequest(
        ims.core.vo.domain.PendingEmergencyAdmissionRepatriationVoAssembler.create(
            map, domainObject.getRepatriationRequest()));
    // PatientCategory
    ims.domain.lookups.LookupInstance instance14 = domainObject.getPatientCategory();
    if (null != instance14) {
      ims.framework.utils.ImagePath img = null;
      ims.framework.utils.Color color = null;
      img = null;
      if (instance14.getImage() != null) {
        img =
            new ims.framework.utils.ImagePath(
                instance14.getImage().getImageId(), instance14.getImage().getImagePath());
      }
      color = instance14.getColor();
      if (color != null) color.getValue();

      ims.core.vo.lookups.PatientStatus voLookup14 =
          new ims.core.vo.lookups.PatientStatus(
              instance14.getId(), instance14.getText(), instance14.isActive(), null, img, color);
      ims.core.vo.lookups.PatientStatus parentVoLookup14 = voLookup14;
      ims.domain.lookups.LookupInstance parent14 = instance14.getParent();
      while (parent14 != null) {
        if (parent14.getImage() != null) {
          img =
              new ims.framework.utils.ImagePath(
                  parent14.getImage().getImageId(), parent14.getImage().getImagePath());
        } else {
          img = null;
        }
        color = parent14.getColor();
        if (color != null) color.getValue();
        parentVoLookup14.setParent(
            new ims.core.vo.lookups.PatientStatus(
                parent14.getId(), parent14.getText(), parent14.isActive(), null, img, color));
        parentVoLookup14 = parentVoLookup14.getParent();
        parent14 = parent14.getParent();
      }
      valueObject.setPatientCategory(voLookup14);
    }
    // IsEmergencyReferral
    valueObject.setIsEmergencyReferral(domainObject.isIsEmergencyReferral());
    return valueObject;
  }
  /**
   * Update the ValueObject with the Domain Object.
   *
   * @param map DomainObjectMap of DomainObjects to already created ValueObjects.
   * @param valueObject to be updated
   * @param domainObject ims.core.admin.pas.domain.objects.ConsultantStay
   */
  public static ims.core.vo.ConsultantStayMinVo insert(
      DomainObjectMap map,
      ims.core.vo.ConsultantStayMinVo valueObject,
      ims.core.admin.pas.domain.objects.ConsultantStay domainObject) {
    if (null == domainObject) {
      return valueObject;
    }
    if (null == map) {
      map = new DomainObjectMap();
    }

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

    // transferDateTime
    java.util.Date transferDateTime = domainObject.getTransferDateTime();
    if (null != transferDateTime) {
      valueObject.setTransferDateTime(new ims.framework.utils.DateTime(transferDateTime));
    }
    // endDateTime
    java.util.Date endDateTime = domainObject.getEndDateTime();
    if (null != endDateTime) {
      valueObject.setEndDateTime(new ims.framework.utils.DateTime(endDateTime));
    }
    // PatientStatus
    ims.domain.lookups.LookupInstance instance3 = domainObject.getPatientStatus();
    if (null != instance3) {
      ims.framework.utils.ImagePath img = null;
      ims.framework.utils.Color color = null;
      img = null;
      if (instance3.getImage() != null) {
        img =
            new ims.framework.utils.ImagePath(
                instance3.getImage().getImageId(), instance3.getImage().getImagePath());
      }
      color = instance3.getColor();
      if (color != null) color.getValue();

      ims.core.vo.lookups.PatientStatus voLookup3 =
          new ims.core.vo.lookups.PatientStatus(
              instance3.getId(), instance3.getText(), instance3.isActive(), null, img, color);
      ims.core.vo.lookups.PatientStatus parentVoLookup3 = voLookup3;
      ims.domain.lookups.LookupInstance parent3 = instance3.getParent();
      while (parent3 != null) {
        if (parent3.getImage() != null) {
          img =
              new ims.framework.utils.ImagePath(
                  parent3.getImage().getImageId(), parent3.getImage().getImagePath());
        } else {
          img = null;
        }
        color = parent3.getColor();
        if (color != null) color.getValue();
        parentVoLookup3.setParent(
            new ims.core.vo.lookups.PatientStatus(
                parent3.getId(), parent3.getText(), parent3.isActive(), null, img, color));
        parentVoLookup3 = parentVoLookup3.getParent();
        parent3 = parent3.getParent();
      }
      valueObject.setPatientStatus(voLookup3);
    }
    return valueObject;
  }