/**
  * Copy one ValueObject to another
  *
  * @param valueObjectDest to be updated
  * @param valueObjectSrc to copy values from
  */
 public static ims.icp.vo.PatientICPVo copy(
     ims.icp.vo.PatientICPVo valueObjectDest, ims.icp.vo.PatientICPVo valueObjectSrc) {
   if (null == valueObjectSrc) {
     return valueObjectSrc;
   }
   valueObjectDest.setID_PatientICP(valueObjectSrc.getID_PatientICP());
   valueObjectDest.setIsRIE(valueObjectSrc.getIsRIE());
   // Patient
   valueObjectDest.setPatient(valueObjectSrc.getPatient());
   // CareContext
   valueObjectDest.setCareContext(valueObjectSrc.getCareContext());
   // ClinicalContact
   valueObjectDest.setClinicalContact(valueObjectSrc.getClinicalContact());
   // PasEvent
   valueObjectDest.setPasEvent(valueObjectSrc.getPasEvent());
   // ICP
   valueObjectDest.setICP(valueObjectSrc.getICP());
   // AuthoringInformation
   valueObjectDest.setAuthoringInformation(valueObjectSrc.getAuthoringInformation());
   // Stages
   valueObjectDest.setStages(valueObjectSrc.getStages());
   // hasOutstandingAdminActions
   valueObjectDest.setHasOutstandingAdminActions(valueObjectSrc.getHasOutstandingAdminActions());
   // hasOutstandingNursingActions
   valueObjectDest.setHasOutstandingNursingActions(
       valueObjectSrc.getHasOutstandingNursingActions());
   // hasOutstandingPhysioActions
   valueObjectDest.setHasOutstandingPhysioActions(valueObjectSrc.getHasOutstandingPhysioActions());
   // hasOutstandingClinicalActions
   valueObjectDest.setHasOutstandingClinicalActions(
       valueObjectSrc.getHasOutstandingClinicalActions());
   // Appointments
   valueObjectDest.setAppointments(valueObjectSrc.getAppointments());
   // CriticalEvents
   valueObjectDest.setCriticalEvents(valueObjectSrc.getCriticalEvents());
   // StartedDateTime
   valueObjectDest.setStartedDateTime(valueObjectSrc.getStartedDateTime());
   // CompletedDateTime
   valueObjectDest.setCompletedDateTime(valueObjectSrc.getCompletedDateTime());
   // EvaluationNotes
   valueObjectDest.setEvaluationNotes(valueObjectSrc.getEvaluationNotes());
   return valueObjectDest;
 }
  public static ims.icps.instantiation.domain.objects.PatientICP extractPatientICP(
      ims.domain.ILightweightDomainFactory domainFactory,
      ims.icp.vo.PatientICPVo valueObject,
      HashMap domMap) {
    if (null == valueObject) {
      return null;
    }
    Integer id = valueObject.getID_PatientICP();
    ims.icps.instantiation.domain.objects.PatientICP domainObject = null;
    if (null == id) {
      if (domMap.get(valueObject) != null) {
        return (ims.icps.instantiation.domain.objects.PatientICP) domMap.get(valueObject);
      }
      // ims.icp.vo.PatientICPVo ID_PatientICP field is unknown
      domainObject = new ims.icps.instantiation.domain.objects.PatientICP();
      domMap.put(valueObject, domainObject);
    } else {
      String key = (valueObject.getClass().getName() + "__" + valueObject.getID_PatientICP());
      if (domMap.get(key) != null) {
        return (ims.icps.instantiation.domain.objects.PatientICP) domMap.get(key);
      }
      domainObject =
          (ims.icps.instantiation.domain.objects.PatientICP)
              domainFactory.getDomainObject(
                  ims.icps.instantiation.domain.objects.PatientICP.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_PatientICP());

    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);
    ims.core.admin.domain.objects.CareContext value2 = null;
    if (null != valueObject.getCareContext()) {
      if (valueObject.getCareContext().getBoId() == null) {
        if (domMap.get(valueObject.getCareContext()) != null) {
          value2 =
              (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
      {
        value2 = domainObject.getCareContext();
      } else {
        value2 =
            (ims.core.admin.domain.objects.CareContext)
                domainFactory.getDomainObject(
                    ims.core.admin.domain.objects.CareContext.class,
                    valueObject.getCareContext().getBoId());
      }
    }
    domainObject.setCareContext(value2);
    ims.core.admin.domain.objects.ClinicalContact value3 = null;
    if (null != valueObject.getClinicalContact()) {
      if (valueObject.getClinicalContact().getBoId() == null) {
        if (domMap.get(valueObject.getClinicalContact()) != null) {
          value3 =
              (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
      {
        value3 = domainObject.getClinicalContact();
      } else {
        value3 =
            (ims.core.admin.domain.objects.ClinicalContact)
                domainFactory.getDomainObject(
                    ims.core.admin.domain.objects.ClinicalContact.class,
                    valueObject.getClinicalContact().getBoId());
      }
    }
    domainObject.setClinicalContact(value3);
    ims.core.admin.pas.domain.objects.PASEvent value4 = null;
    if (null != valueObject.getPasEvent()) {
      if (valueObject.getPasEvent().getBoId() == null) {
        if (domMap.get(valueObject.getPasEvent()) != null) {
          value4 =
              (ims.core.admin.pas.domain.objects.PASEvent) domMap.get(valueObject.getPasEvent());
        }
      } else if (valueObject.getBoVersion()
          == -1) // RefVo was not modified since obtained from the Assembler, no need to update the
                 // BO field
      {
        value4 = domainObject.getPasEvent();
      } else {
        value4 =
            (ims.core.admin.pas.domain.objects.PASEvent)
                domainFactory.getDomainObject(
                    ims.core.admin.pas.domain.objects.PASEvent.class,
                    valueObject.getPasEvent().getBoId());
      }
    }
    domainObject.setPasEvent(value4);
    // SaveAsRefVO - treated as a refVo in extract methods
    ims.icps.configuration.domain.objects.ICP value5 = null;
    if (null != valueObject.getICP()) {
      if (valueObject.getICP().getBoId() == null) {
        if (domMap.get(valueObject.getICP()) != null) {
          value5 = (ims.icps.configuration.domain.objects.ICP) domMap.get(valueObject.getICP());
        }
      } else {
        value5 =
            (ims.icps.configuration.domain.objects.ICP)
                domainFactory.getDomainObject(
                    ims.icps.configuration.domain.objects.ICP.class,
                    valueObject.getICP().getBoId());
      }
    }
    domainObject.setICP(value5);
    // SaveAsRefVO - treated as a refVo in extract methods
    ims.core.clinical.domain.objects.AuthoringInformation value6 = null;
    if (null != valueObject.getAuthoringInformation()) {
      if (valueObject.getAuthoringInformation().getBoId() == null) {
        if (domMap.get(valueObject.getAuthoringInformation()) != null) {
          value6 =
              (ims.core.clinical.domain.objects.AuthoringInformation)
                  domMap.get(valueObject.getAuthoringInformation());
        }
      } else {
        value6 =
            (ims.core.clinical.domain.objects.AuthoringInformation)
                domainFactory.getDomainObject(
                    ims.core.clinical.domain.objects.AuthoringInformation.class,
                    valueObject.getAuthoringInformation().getBoId());
      }
    }
    domainObject.setAuthoringInformation(value6);

    // SaveAsRefVO treated as RefValueObject
    ims.icps.instantiation.vo.PatientICPStageRefVoCollection refCollection7 =
        new ims.icps.instantiation.vo.PatientICPStageRefVoCollection();
    if (valueObject.getStages() != null) {
      for (int i7 = 0; i7 < valueObject.getStages().size(); i7++) {
        ims.icps.instantiation.vo.PatientICPStageRefVo ref7 =
            (ims.icps.instantiation.vo.PatientICPStageRefVo) valueObject.getStages().get(i7);
        refCollection7.add(ref7);
      }
    }
    int size7 = (null == refCollection7) ? 0 : refCollection7.size();
    java.util.Set domainStages7 = domainObject.getStages();
    if (domainStages7 == null) {
      domainStages7 = new java.util.HashSet();
    }
    java.util.Set newSet7 = new java.util.HashSet();
    for (int i = 0; i < size7; i++) {
      ims.icps.instantiation.vo.PatientICPStageRefVo vo = refCollection7.get(i);
      ims.icps.instantiation.domain.objects.PatientICPStage dom = null;
      if (null != vo) {
        if (vo.getBoId() == null) {
          if (domMap.get(vo) != null) {
            dom = (ims.icps.instantiation.domain.objects.PatientICPStage) domMap.get(vo);
          }
        } else {
          dom =
              (ims.icps.instantiation.domain.objects.PatientICPStage)
                  domainFactory.getDomainObject(
                      ims.icps.instantiation.domain.objects.PatientICPStage.class, vo.getBoId());
        }
      }

      // Trying to avoid the hibernate collection being marked as dirty via its public interface
      // methods. (like add)
      if (!domainStages7.contains(dom)) {
        domainStages7.add(dom);
      }
      newSet7.add(dom);
    }
    java.util.Set removedSet7 = new java.util.HashSet();
    java.util.Iterator iter7 = domainStages7.iterator();
    // Find out which objects need to be removed
    while (iter7.hasNext()) {
      ims.domain.DomainObject o = (ims.domain.DomainObject) iter7.next();
      if ((o == null || o.getIsRIE() == null || !o.getIsRIE().booleanValue())
          && !newSet7.contains(o)) {
        removedSet7.add(o);
      }
    }
    iter7 = removedSet7.iterator();
    // Remove the unwanted objects
    while (iter7.hasNext()) {
      domainStages7.remove(iter7.next());
    }

    domainObject.setStages(domainStages7);
    domainObject.setHasOutstandingAdminActions(valueObject.getHasOutstandingAdminActions());
    domainObject.setHasOutstandingNursingActions(valueObject.getHasOutstandingNursingActions());
    domainObject.setHasOutstandingPhysioActions(valueObject.getHasOutstandingPhysioActions());
    domainObject.setHasOutstandingClinicalActions(valueObject.getHasOutstandingClinicalActions());

    ims.scheduling.vo.Booking_AppointmentRefVoCollection refCollection12 =
        valueObject.getAppointments();
    int size12 = (null == refCollection12) ? 0 : refCollection12.size();
    java.util.Set domainAppointments12 = domainObject.getAppointments();
    if (domainAppointments12 == null) {
      domainAppointments12 = new java.util.HashSet();
    }
    java.util.Set newSet12 = new java.util.HashSet();
    for (int i = 0; i < size12; i++) {
      ims.scheduling.vo.Booking_AppointmentRefVo vo = refCollection12.get(i);
      ims.scheduling.domain.objects.Booking_Appointment dom = null;
      if (null != vo) {
        if (vo.getBoId() == null) {
          if (domMap.get(vo) != null) {
            dom = (ims.scheduling.domain.objects.Booking_Appointment) domMap.get(vo);
          }
        } else {
          dom =
              (ims.scheduling.domain.objects.Booking_Appointment)
                  domainFactory.getDomainObject(
                      ims.scheduling.domain.objects.Booking_Appointment.class, vo.getBoId());
        }
      }

      // Trying to avoid the hibernate collection being marked as dirty via its public interface
      // methods. (like add)
      if (!domainAppointments12.contains(dom)) {
        domainAppointments12.add(dom);
      }
      newSet12.add(dom);
    }
    java.util.Set removedSet12 = new java.util.HashSet();
    java.util.Iterator iter12 = domainAppointments12.iterator();
    // Find out which objects need to be removed
    while (iter12.hasNext()) {
      ims.domain.DomainObject o = (ims.domain.DomainObject) iter12.next();
      if ((o == null || o.getIsRIE() == null || !o.getIsRIE().booleanValue())
          && !newSet12.contains(o)) {
        removedSet12.add(o);
      }
    }
    iter12 = removedSet12.iterator();
    // Remove the unwanted objects
    while (iter12.hasNext()) {
      domainAppointments12.remove(iter12.next());
    }

    domainObject.setAppointments(domainAppointments12);

    ims.icps.instantiation.vo.PatientCriticalEventsRefVoCollection refCollection13 =
        valueObject.getCriticalEvents();
    int size13 = (null == refCollection13) ? 0 : refCollection13.size();
    java.util.Set domainCriticalEvents13 = domainObject.getCriticalEvents();
    if (domainCriticalEvents13 == null) {
      domainCriticalEvents13 = new java.util.HashSet();
    }
    java.util.Set newSet13 = new java.util.HashSet();
    for (int i = 0; i < size13; i++) {
      ims.icps.instantiation.vo.PatientCriticalEventsRefVo vo = refCollection13.get(i);
      ims.icps.instantiation.domain.objects.PatientCriticalEvents dom = null;
      if (null != vo) {
        if (vo.getBoId() == null) {
          if (domMap.get(vo) != null) {
            dom = (ims.icps.instantiation.domain.objects.PatientCriticalEvents) domMap.get(vo);
          }
        } else {
          dom =
              (ims.icps.instantiation.domain.objects.PatientCriticalEvents)
                  domainFactory.getDomainObject(
                      ims.icps.instantiation.domain.objects.PatientCriticalEvents.class,
                      vo.getBoId());
        }
      }

      // Trying to avoid the hibernate collection being marked as dirty via its public interface
      // methods. (like add)
      if (!domainCriticalEvents13.contains(dom)) {
        domainCriticalEvents13.add(dom);
      }
      newSet13.add(dom);
    }
    java.util.Set removedSet13 = new java.util.HashSet();
    java.util.Iterator iter13 = domainCriticalEvents13.iterator();
    // Find out which objects need to be removed
    while (iter13.hasNext()) {
      ims.domain.DomainObject o = (ims.domain.DomainObject) iter13.next();
      if ((o == null || o.getIsRIE() == null || !o.getIsRIE().booleanValue())
          && !newSet13.contains(o)) {
        removedSet13.add(o);
      }
    }
    iter13 = removedSet13.iterator();
    // Remove the unwanted objects
    while (iter13.hasNext()) {
      domainCriticalEvents13.remove(iter13.next());
    }

    domainObject.setCriticalEvents(domainCriticalEvents13);
    ims.framework.utils.DateTime dateTime14 = valueObject.getStartedDateTime();
    java.util.Date value14 = null;
    if (dateTime14 != null) {
      value14 = dateTime14.getJavaDate();
    }
    domainObject.setStartedDateTime(value14);
    ims.framework.utils.DateTime dateTime15 = valueObject.getCompletedDateTime();
    java.util.Date value15 = null;
    if (dateTime15 != null) {
      value15 = dateTime15.getJavaDate();
    }
    domainObject.setCompletedDateTime(value15);

    ims.icps.instantiation.vo.PatientICPEvaluationNoteRefVoCollection refCollection16 =
        valueObject.getEvaluationNotes();
    int size16 = (null == refCollection16) ? 0 : refCollection16.size();
    java.util.Set domainEvaluationNotes16 = domainObject.getEvaluationNotes();
    if (domainEvaluationNotes16 == null) {
      domainEvaluationNotes16 = new java.util.HashSet();
    }
    java.util.Set newSet16 = new java.util.HashSet();
    for (int i = 0; i < size16; i++) {
      ims.icps.instantiation.vo.PatientICPEvaluationNoteRefVo vo = refCollection16.get(i);
      ims.icps.instantiation.domain.objects.PatientICPEvaluationNote dom = null;
      if (null != vo) {
        if (vo.getBoId() == null) {
          if (domMap.get(vo) != null) {
            dom = (ims.icps.instantiation.domain.objects.PatientICPEvaluationNote) domMap.get(vo);
          }
        } else {
          dom =
              (ims.icps.instantiation.domain.objects.PatientICPEvaluationNote)
                  domainFactory.getDomainObject(
                      ims.icps.instantiation.domain.objects.PatientICPEvaluationNote.class,
                      vo.getBoId());
        }
      }

      // Trying to avoid the hibernate collection being marked as dirty via its public interface
      // methods. (like add)
      if (!domainEvaluationNotes16.contains(dom)) {
        domainEvaluationNotes16.add(dom);
      }
      newSet16.add(dom);
    }
    java.util.Set removedSet16 = new java.util.HashSet();
    java.util.Iterator iter16 = domainEvaluationNotes16.iterator();
    // Find out which objects need to be removed
    while (iter16.hasNext()) {
      ims.domain.DomainObject o = (ims.domain.DomainObject) iter16.next();
      if ((o == null || o.getIsRIE() == null || !o.getIsRIE().booleanValue())
          && !newSet16.contains(o)) {
        removedSet16.add(o);
      }
    }
    iter16 = removedSet16.iterator();
    // Remove the unwanted objects
    while (iter16.hasNext()) {
      domainEvaluationNotes16.remove(iter16.next());
    }

    domainObject.setEvaluationNotes(domainEvaluationNotes16);

    return domainObject;
  }