/**
  * Copy one ValueObject to another
  *
  * @param valueObjectDest to be updated
  * @param valueObjectSrc to copy values from
  */
 public static ims.core.vo.CatsReferralRepatriationRequestVo copy(
     ims.core.vo.CatsReferralRepatriationRequestVo valueObjectDest,
     ims.core.vo.CatsReferralRepatriationRequestVo valueObjectSrc) {
   if (null == valueObjectSrc) {
     return valueObjectSrc;
   }
   valueObjectDest.setID_CatsReferral(valueObjectSrc.getID_CatsReferral());
   valueObjectDest.setIsRIE(valueObjectSrc.getIsRIE());
   // Patient
   valueObjectDest.setPatient(valueObjectSrc.getPatient());
   // ReferralDetails
   valueObjectDest.setReferralDetails(valueObjectSrc.getReferralDetails());
   // EpisodeOfCare
   valueObjectDest.setEpisodeOfCare(valueObjectSrc.getEpisodeOfCare());
   // CareContext
   valueObjectDest.setCareContext(valueObjectSrc.getCareContext());
   // CurrentStatus
   valueObjectDest.setCurrentStatus(valueObjectSrc.getCurrentStatus());
   // StatusHistory
   valueObjectDest.setStatusHistory(valueObjectSrc.getStatusHistory());
   // Contract
   valueObjectDest.setContract(valueObjectSrc.getContract());
   // Urgency
   valueObjectDest.setUrgency(valueObjectSrc.getUrgency());
   // Journey
   valueObjectDest.setJourney(valueObjectSrc.getJourney());
   // PathwayID
   valueObjectDest.setPathwayID(valueObjectSrc.getPathwayID());
   // RTTClockImpact
   valueObjectDest.setRTTClockImpact(valueObjectSrc.getRTTClockImpact());
   // CurrentRTTStatus
   valueObjectDest.setCurrentRTTStatus(valueObjectSrc.getCurrentRTTStatus());
   // RepatriationRequest
   valueObjectDest.setRepatriationRequest(valueObjectSrc.getRepatriationRequest());
   // PatientCategory
   valueObjectDest.setPatientCategory(valueObjectSrc.getPatientCategory());
   // IsEmergencyReferral
   valueObjectDest.setIsEmergencyReferral(valueObjectSrc.getIsEmergencyReferral());
   return valueObjectDest;
 }
  public static ims.RefMan.domain.objects.CatsReferral extractCatsReferral(
      ims.domain.ILightweightDomainFactory domainFactory,
      ims.core.vo.CatsReferralRepatriationRequestVo valueObject,
      HashMap domMap) {
    if (null == valueObject) {
      return null;
    }
    Integer id = valueObject.getID_CatsReferral();
    ims.RefMan.domain.objects.CatsReferral domainObject = null;
    if (null == id) {
      if (domMap.get(valueObject) != null) {
        return (ims.RefMan.domain.objects.CatsReferral) domMap.get(valueObject);
      }
      // ims.core.vo.CatsReferralRepatriationRequestVo ID_CatsReferral field is unknown
      domainObject = new ims.RefMan.domain.objects.CatsReferral();
      domMap.put(valueObject, domainObject);
    } else {
      String key = (valueObject.getClass().getName() + "__" + valueObject.getID_CatsReferral());
      if (domMap.get(key) != null) {
        return (ims.RefMan.domain.objects.CatsReferral) domMap.get(key);
      }
      domainObject =
          (ims.RefMan.domain.objects.CatsReferral)
              domainFactory.getDomainObject(ims.RefMan.domain.objects.CatsReferral.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_CatsReferral());

    ims.core.patient.domain.objects.Patient value1 = null;
    if (null != valueObject.getPatient()) {
      if (valueObject.getPatient().getBoId() == null) {
        if (domMap.get(valueObject.getPatient()) != null) {
          value1 = (ims.core.patient.domain.objects.Patient) domMap.get(valueObject.getPatient());
        }
      } else if (valueObject.getBoVersion()
          == -1) // RefVo was not modified since obtained from the Assembler, no need to update the
                 // BO field
      {
        value1 = domainObject.getPatient();
      } else {
        value1 =
            (ims.core.patient.domain.objects.Patient)
                domainFactory.getDomainObject(
                    ims.core.patient.domain.objects.Patient.class,
                    valueObject.getPatient().getBoId());
      }
    }
    domainObject.setPatient(value1);
    domainObject.setReferralDetails(
        ims.core.vo.domain.CatsReferralDetailsRepatriationRequestVoAssembler
            .extractReferralLetterDetails(domainFactory, valueObject.getReferralDetails(), domMap));
    ims.core.admin.domain.objects.EpisodeOfCare value3 = null;
    if (null != valueObject.getEpisodeOfCare()) {
      if (valueObject.getEpisodeOfCare().getBoId() == null) {
        if (domMap.get(valueObject.getEpisodeOfCare()) != null) {
          value3 =
              (ims.core.admin.domain.objects.EpisodeOfCare)
                  domMap.get(valueObject.getEpisodeOfCare());
        }
      } else if (valueObject.getBoVersion()
          == -1) // RefVo was not modified since obtained from the Assembler, no need to update the
                 // BO field
      {
        value3 = domainObject.getEpisodeOfCare();
      } else {
        value3 =
            (ims.core.admin.domain.objects.EpisodeOfCare)
                domainFactory.getDomainObject(
                    ims.core.admin.domain.objects.EpisodeOfCare.class,
                    valueObject.getEpisodeOfCare().getBoId());
      }
    }
    domainObject.setEpisodeOfCare(value3);
    ims.core.admin.domain.objects.CareContext value4 = null;
    if (null != valueObject.getCareContext()) {
      if (valueObject.getCareContext().getBoId() == null) {
        if (domMap.get(valueObject.getCareContext()) != null) {
          value4 =
              (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
      {
        value4 = domainObject.getCareContext();
      } else {
        value4 =
            (ims.core.admin.domain.objects.CareContext)
                domainFactory.getDomainObject(
                    ims.core.admin.domain.objects.CareContext.class,
                    valueObject.getCareContext().getBoId());
      }
    }
    domainObject.setCareContext(value4);
    domainObject.setCurrentStatus(
        ims.RefMan.vo.domain.CatsReferralStatusVoAssembler.extractCATSReferralStatus(
            domainFactory, valueObject.getCurrentStatus(), domMap));
    domainObject.setStatusHistory(
        ims.RefMan.vo.domain.CatsReferralStatusVoAssembler.extractCATSReferralStatusSet(
            domainFactory,
            valueObject.getStatusHistory(),
            domainObject.getStatusHistory(),
            domMap));
    ims.core.configuration.domain.objects.ContractConfig value7 = null;
    if (null != valueObject.getContract()) {
      if (valueObject.getContract().getBoId() == null) {
        if (domMap.get(valueObject.getContract()) != null) {
          value7 =
              (ims.core.configuration.domain.objects.ContractConfig)
                  domMap.get(valueObject.getContract());
        }
      } else if (valueObject.getBoVersion()
          == -1) // RefVo was not modified since obtained from the Assembler, no need to update the
                 // BO field
      {
        value7 = domainObject.getContract();
      } else {
        value7 =
            (ims.core.configuration.domain.objects.ContractConfig)
                domainFactory.getDomainObject(
                    ims.core.configuration.domain.objects.ContractConfig.class,
                    valueObject.getContract().getBoId());
      }
    }
    domainObject.setContract(value7);
    // create LookupInstance from vo LookupType
    ims.domain.lookups.LookupInstance value8 = null;
    if (null != valueObject.getUrgency()) {
      value8 = domainFactory.getLookupInstance(valueObject.getUrgency().getID());
    }
    domainObject.setUrgency(value8);
    ims.pathways.domain.objects.PatientPathwayJourney value9 = null;
    if (null != valueObject.getJourney()) {
      if (valueObject.getJourney().getBoId() == null) {
        if (domMap.get(valueObject.getJourney()) != null) {
          value9 =
              (ims.pathways.domain.objects.PatientPathwayJourney)
                  domMap.get(valueObject.getJourney());
        }
      } else if (valueObject.getBoVersion()
          == -1) // RefVo was not modified since obtained from the Assembler, no need to update the
                 // BO field
      {
        value9 = domainObject.getJourney();
      } else {
        value9 =
            (ims.pathways.domain.objects.PatientPathwayJourney)
                domainFactory.getDomainObject(
                    ims.pathways.domain.objects.PatientPathwayJourney.class,
                    valueObject.getJourney().getBoId());
      }
    }
    domainObject.setJourney(value9);
    // This is to overcome a bug in both Sybase and Oracle which prevents them from storing an empty
    // string correctly
    // Sybase stores it as a single space, Oracle stores it as NULL. This fix will make them
    // consistent at least.
    if (valueObject.getPathwayID() != null && valueObject.getPathwayID().equals("")) {
      valueObject.setPathwayID(null);
    }
    domainObject.setPathwayID(valueObject.getPathwayID());
    domainObject.setRTTClockImpact(valueObject.getRTTClockImpact());
    // SaveAsRefVO - treated as a refVo in extract methods
    ims.pathways.domain.objects.PathwayRTTStatus value12 = null;
    if (null != valueObject.getCurrentRTTStatus()) {
      if (valueObject.getCurrentRTTStatus().getBoId() == null) {
        if (domMap.get(valueObject.getCurrentRTTStatus()) != null) {
          value12 =
              (ims.pathways.domain.objects.PathwayRTTStatus)
                  domMap.get(valueObject.getCurrentRTTStatus());
        }
      } else {
        value12 =
            (ims.pathways.domain.objects.PathwayRTTStatus)
                domainFactory.getDomainObject(
                    ims.pathways.domain.objects.PathwayRTTStatus.class,
                    valueObject.getCurrentRTTStatus().getBoId());
      }
    }
    domainObject.setCurrentRTTStatus(value12);
    domainObject.setRepatriationRequest(
        ims.core.vo.domain.PendingEmergencyAdmissionRepatriationVoAssembler
            .extractPendingNoEDEmergencyAdmit(
                domainFactory, valueObject.getRepatriationRequest(), domMap));
    // create LookupInstance from vo LookupType
    ims.domain.lookups.LookupInstance value14 = null;
    if (null != valueObject.getPatientCategory()) {
      value14 = domainFactory.getLookupInstance(valueObject.getPatientCategory().getID());
    }
    domainObject.setPatientCategory(value14);
    domainObject.setIsEmergencyReferral(valueObject.getIsEmergencyReferral());

    return domainObject;
  }