public static ims.scheduling.domain.objects.Booking_Appointment extractBooking_Appointment(
      ims.domain.ILightweightDomainFactory domainFactory,
      ims.scheduling.vo.AppointmentForOutpatientClinicListManualCustomClassVo valueObject,
      HashMap domMap) {
    if (null == valueObject) {
      return null;
    }
    Integer id = valueObject.getID_Booking_Appointment();
    ims.scheduling.domain.objects.Booking_Appointment domainObject = null;
    if (null == id) {
      if (domMap.get(valueObject) != null) {
        return (ims.scheduling.domain.objects.Booking_Appointment) domMap.get(valueObject);
      }
      // ims.scheduling.vo.AppointmentForOutpatientClinicListManualCustomClassVo
      // ID_Booking_Appointment field is unknown
      domainObject = new ims.scheduling.domain.objects.Booking_Appointment();
      domMap.put(valueObject, domainObject);
    } else {
      String key =
          (valueObject.getClass().getName() + "__" + valueObject.getID_Booking_Appointment());
      if (domMap.get(key) != null) {
        return (ims.scheduling.domain.objects.Booking_Appointment) domMap.get(key);
      }
      domainObject =
          (ims.scheduling.domain.objects.Booking_Appointment)
              domainFactory.getDomainObject(
                  ims.scheduling.domain.objects.Booking_Appointment.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_Booking_Appointment());

    java.util.Date value1 = null;
    ims.framework.utils.Date date1 = valueObject.getAppointmentDate();
    if (date1 != null) {
      value1 = date1.getDate();
    }
    domainObject.setAppointmentDate(value1);
    ims.framework.utils.Time time2 = valueObject.getApptStartTime();
    String value2 = null;
    if (time2 != null) {
      value2 = time2.toString();
    }
    domainObject.setApptStartTime(value2);
    domainObject.setIsCABBooking(valueObject.getIsCABBooking());
    // SaveAsRefVO - treated as a refVo in extract methods
    ims.core.patient.domain.objects.Patient value4 = null;
    if (null != valueObject.getPatient()) {
      if (valueObject.getPatient().getBoId() == null) {
        if (domMap.get(valueObject.getPatient()) != null) {
          value4 = (ims.core.patient.domain.objects.Patient) domMap.get(valueObject.getPatient());
        }
      } else {
        value4 =
            (ims.core.patient.domain.objects.Patient)
                domainFactory.getDomainObject(
                    ims.core.patient.domain.objects.Patient.class,
                    valueObject.getPatient().getBoId());
      }
    }
    domainObject.setPatient(value4);
    // 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.getOutcomeComments() != null && valueObject.getOutcomeComments().equals("")) {
      valueObject.setOutcomeComments(null);
    }
    domainObject.setOutcomeComments(valueObject.getOutcomeComments());
    domainObject.setHasElectiveList(valueObject.getHasElectiveList());
    domainObject.setWasPrinted(valueObject.getWasPrinted());
    // 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.getComments() != null && valueObject.getComments().equals("")) {
      valueObject.setComments(null);
    }
    domainObject.setComments(valueObject.getComments());
    ims.RefMan.domain.objects.PatientElectiveList value9 = null;
    if (null != valueObject.getElectiveList()) {
      if (valueObject.getElectiveList().getBoId() == null) {
        if (domMap.get(valueObject.getElectiveList()) != null) {
          value9 =
              (ims.RefMan.domain.objects.PatientElectiveList)
                  domMap.get(valueObject.getElectiveList());
        }
      } else if (valueObject.getBoVersion()
          == -1) // RefVo was not modified since obtained from the Assembler, no need to update the
      // BO field
      {
        value9 = domainObject.getElectiveList();
      } else {
        value9 =
            (ims.RefMan.domain.objects.PatientElectiveList)
                domainFactory.getDomainObject(
                    ims.RefMan.domain.objects.PatientElectiveList.class,
                    valueObject.getElectiveList().getBoId());
      }
    }
    domainObject.setElectiveList(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.scheduling.domain.objects.Booking_Appointment
   */
  public static ims.scheduling.vo.AppointmentForOutpatientClinicListManualCustomClassVo insert(
      DomainObjectMap map,
      ims.scheduling.vo.AppointmentForOutpatientClinicListManualCustomClassVo valueObject,
      ims.scheduling.domain.objects.Booking_Appointment domainObject) {
    if (null == domainObject) {
      return valueObject;
    }
    if (null == map) {
      map = new DomainObjectMap();
    }

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

    // AppointmentDate
    java.util.Date AppointmentDate = domainObject.getAppointmentDate();
    if (null != AppointmentDate) {
      valueObject.setAppointmentDate(new ims.framework.utils.Date(AppointmentDate));
    }
    // ApptStartTime
    String ApptStartTime = domainObject.getApptStartTime();
    if (null != ApptStartTime) {
      valueObject.setApptStartTime(new ims.framework.utils.Time(ApptStartTime));
    }
    // isCABBooking
    valueObject.setIsCABBooking(domainObject.isIsCABBooking());
    // Patient
    valueObject.setPatient(
        ims.core.vo.domain.PatientManuallyAssembledVoAssembler.create(
            map, domainObject.getPatient()));
    // OutcomeComments
    valueObject.setOutcomeComments(domainObject.getOutcomeComments());
    // HasElectiveList
    valueObject.setHasElectiveList(domainObject.isHasElectiveList());
    // wasPrinted
    valueObject.setWasPrinted(domainObject.isWasPrinted());
    // Comments
    valueObject.setComments(domainObject.getComments());
    // ElectiveList
    if (domainObject.getElectiveList() != null) {
      if (domainObject.getElectiveList()
          instanceof
          HibernateProxy) // If the proxy is set, there is no need to lazy load, the proxy knows the
      // id already.
      {
        HibernateProxy p = (HibernateProxy) domainObject.getElectiveList();
        int id = Integer.parseInt(p.getHibernateLazyInitializer().getIdentifier().toString());
        valueObject.setElectiveList(new ims.RefMan.vo.PatientElectiveListRefVo(id, -1));
      } else {
        valueObject.setElectiveList(
            new ims.RefMan.vo.PatientElectiveListRefVo(
                domainObject.getElectiveList().getId(),
                domainObject.getElectiveList().getVersion()));
      }
    }
    return valueObject;
  }