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

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

    // ClinicalTrial
    valueObject.setClinicalTrial(domainObject.isClinicalTrial());
    // ClinicalTrialTxt
    valueObject.setClinicalTrialTxt(domainObject.getClinicalTrialTxt());
    // PatMobility
    ims.domain.lookups.LookupInstance instance3 = domainObject.getPatMobility();
    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.ocrr.vo.lookups.OrderPatMobility voLookup3 =
          new ims.ocrr.vo.lookups.OrderPatMobility(
              instance3.getId(), instance3.getText(), instance3.isActive(), null, img, color);
      ims.ocrr.vo.lookups.OrderPatMobility 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.ocrr.vo.lookups.OrderPatMobility(
                parent3.getId(), parent3.getText(), parent3.isActive(), null, img, color));
        parentVoLookup3 = parentVoLookup3.getParent();
        parent3 = parent3.getParent();
      }
      valueObject.setPatMobility(voLookup3);
    }
    // OrderCategory
    ims.domain.lookups.LookupInstance instance4 = domainObject.getOrderCategory();
    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.OrderCategory voLookup4 =
          new ims.ocrr.vo.lookups.OrderCategory(
              instance4.getId(), instance4.getText(), instance4.isActive(), null, img, color);
      ims.ocrr.vo.lookups.OrderCategory 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.OrderCategory(
                parent4.getId(), parent4.getText(), parent4.isActive(), null, img, color));
        parentVoLookup4 = parentVoLookup4.getParent();
        parent4 = parent4.getParent();
      }
      valueObject.setOrderCategory(voLookup4);
    }
    // specimens
    valueObject.setSpecimens(
        ims.ocrr.vo.domain.OrderSpecimenVoAssembler
            .createOrderSpecimenVoCollectionFromOrderSpecimen(map, domainObject.getSpecimens()));
    // Investigations
    valueObject.setInvestigations(
        ims.ocrr.vo.domain.OrderInvestigationVoAssembler
            .createOrderInvestigationVoCollectionFromOrderInvestigation(
                map, domainObject.getInvestigations()));
    // wasProcessed
    valueObject.setWasProcessed(domainObject.isWasProcessed());
    // ClinicalInfo
    valueObject.setClinicalInfo(
        ims.ocrr.vo.domain.OcsQASessionVoAssembler.create(map, domainObject.getClinicalInfo()));
    // ReportTo
    valueObject.setReportTo(
        ims.ocrr.vo.domain.OcsReportToVoAssembler.createOcsReportToVoCollectionFromOcsReportTo(
            map, domainObject.getReportTo()));
    // SummaryClinicalInformation
    valueObject.setSummaryClinicalInformation(domainObject.getSummaryClinicalInformation());
    // BleepExtNumber
    valueObject.setBleepExtNumber(domainObject.getBleepExtNumber());
    // ClinicalContact
    if (domainObject.getClinicalContact() != null) {
      if (domainObject.getClinicalContact()
          instanceof
          HibernateProxy) // If the proxy is set, there is no need to lazy load, the proxy knows the
                          // id already.
      {
        HibernateProxy p = (HibernateProxy) domainObject.getClinicalContact();
        int id = Integer.parseInt(p.getHibernateLazyInitializer().getIdentifier().toString());
        valueObject.setClinicalContact(new ims.core.admin.vo.ClinicalContactRefVo(id, -1));
      } else {
        valueObject.setClinicalContact(
            new ims.core.admin.vo.ClinicalContactRefVo(
                domainObject.getClinicalContact().getId(),
                domainObject.getClinicalContact().getVersion()));
      }
    }
    // Patient
    valueObject.setPatient(
        ims.core.vo.domain.PatientShortAssembler.create(map, domainObject.getPatient()));
    // OrderedBy
    valueObject.setOrderedBy(
        ims.core.vo.domain.MemberOfStaffLiteVoAssembler.create(map, domainObject.getOrderedBy()));
    // ResponsibleClinician
    valueObject.setResponsibleClinician(
        ims.core.vo.domain.HcpLiteVoAssembler.create(map, domainObject.getResponsibleClinician()));
    // ResponsibleGp
    valueObject.setResponsibleGp(
        ims.core.vo.domain.GpLiteVoAssembler.create(map, domainObject.getResponsibleGp()));
    // PatientLocation
    valueObject.setPatientLocation(
        ims.core.vo.domain.LocationLiteVoAssembler.create(map, domainObject.getPatientLocation()));
    // PatientClinic
    valueObject.setPatientClinic(
        ims.core.vo.domain.ClinicLiteVoAssembler.create(map, domainObject.getPatientClinic()));
    // AdditClinNotes
    valueObject.setAdditClinNotes(domainObject.getAdditClinNotes());
    // SysInfo
    // set system information
    valueObject.setSysInfo(
        ims.vo.domain.SystemInformationAssembler.create(domainObject.getSystemInformation()));
    // CareContext
    valueObject.setCareContext(
        ims.core.vo.domain.CareContextPasVoAssembler.create(map, domainObject.getCareContext()));
    // OrderingHospital
    if (domainObject.getOrderingHospital() != null) {
      if (domainObject.getOrderingHospital()
          instanceof
          HibernateProxy) // If the proxy is set, there is no need to lazy load, the proxy knows the
                          // id already.
      {
        HibernateProxy p = (HibernateProxy) domainObject.getOrderingHospital();
        int id = Integer.parseInt(p.getHibernateLazyInitializer().getIdentifier().toString());
        valueObject.setOrderingHospital(new ims.core.resource.place.vo.LocSiteRefVo(id, -1));
      } else {
        valueObject.setOrderingHospital(
            new ims.core.resource.place.vo.LocSiteRefVo(
                domainObject.getOrderingHospital().getId(),
                domainObject.getOrderingHospital().getVersion()));
      }
    }
    // OutpatientDept
    valueObject.setOutpatientDept(
        ims.core.vo.domain.LocationLiteVoAssembler.create(map, domainObject.getOutpatientDept()));
    // AuthorisationOrderStatus
    ims.domain.lookups.LookupInstance instance24 = domainObject.getAuthorisationOrderStatus();
    if (null != instance24) {
      ims.framework.utils.ImagePath img = null;
      ims.framework.utils.Color color = null;
      img = null;
      if (instance24.getImage() != null) {
        img =
            new ims.framework.utils.ImagePath(
                instance24.getImage().getImageId(), instance24.getImage().getImagePath());
      }
      color = instance24.getColor();
      if (color != null) color.getValue();

      ims.ocrr.vo.lookups.AuthorisationOrderStatus voLookup24 =
          new ims.ocrr.vo.lookups.AuthorisationOrderStatus(
              instance24.getId(), instance24.getText(), instance24.isActive(), null, img, color);
      ims.ocrr.vo.lookups.AuthorisationOrderStatus parentVoLookup24 = voLookup24;
      ims.domain.lookups.LookupInstance parent24 = instance24.getParent();
      while (parent24 != null) {
        if (parent24.getImage() != null) {
          img =
              new ims.framework.utils.ImagePath(
                  parent24.getImage().getImageId(), parent24.getImage().getImagePath());
        } else {
          img = null;
        }
        color = parent24.getColor();
        if (color != null) color.getValue();
        parentVoLookup24.setParent(
            new ims.ocrr.vo.lookups.AuthorisationOrderStatus(
                parent24.getId(), parent24.getText(), parent24.isActive(), null, img, color));
        parentVoLookup24 = parentVoLookup24.getParent();
        parent24 = parent24.getParent();
      }
      valueObject.setAuthorisationOrderStatus(voLookup24);
    }
    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.correspondence.domain.objects.CorrespondenceDetails
   */
  public static ims.correspondence.vo.CorrespondenceDetailsVo insert(
      DomainObjectMap map,
      ims.correspondence.vo.CorrespondenceDetailsVo valueObject,
      ims.correspondence.domain.objects.CorrespondenceDetails domainObject) {
    if (null == domainObject) {
      return valueObject;
    }
    if (null == map) {
      map = new DomainObjectMap();
    }

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

    // pasEvent
    if (domainObject.getPasEvent() != null) {
      if (domainObject.getPasEvent()
          instanceof
          HibernateProxy) // If the proxy is set, there is no need to lazy load, the proxy knows the
                          // id already.
      {
        HibernateProxy p = (HibernateProxy) domainObject.getPasEvent();
        int id = Integer.parseInt(p.getHibernateLazyInitializer().getIdentifier().toString());
        valueObject.setPasEvent(new ims.core.admin.pas.vo.PASEventRefVo(id, -1));
      } else {
        valueObject.setPasEvent(
            new ims.core.admin.pas.vo.PASEventRefVo(
                domainObject.getPasEvent().getId(), domainObject.getPasEvent().getVersion()));
      }
    }
    // currentStatus
    ims.domain.lookups.LookupInstance instance2 = domainObject.getCurrentStatus();
    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.core.vo.lookups.DocumentStatus voLookup2 =
          new ims.core.vo.lookups.DocumentStatus(
              instance2.getId(), instance2.getText(), instance2.isActive(), null, img, color);
      ims.core.vo.lookups.DocumentStatus 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.core.vo.lookups.DocumentStatus(
                parent2.getId(), parent2.getText(), parent2.isActive(), null, img, color));
        parentVoLookup2 = parentVoLookup2.getParent();
        parent2 = parent2.getParent();
      }
      valueObject.setCurrentStatus(voLookup2);
    }
    // CspStatusHistory
    valueObject.setCspStatusHistory(
        ims.correspondence.vo.domain.CorrespondenceStatusHistoryVoAssembler
            .createCorrespondenceStatusHistoryVoCollectionFromCorrespondenceStatusHistory(
                map, domainObject.getCspStatusHistory()));
    // categories
    valueObject.setCategories(
        ims.correspondence.vo.domain.CategoryNotesVoAssembler
            .createCategoryNotesVoCollectionFromCategoryNotes(map, domainObject.getCategories()));
    // recipients
    valueObject.setRecipients(
        ims.correspondence.vo.domain.RecipientVoAssembler.createRecipientVoCollectionFromRecipient(
            map, domainObject.getRecipients()));
    // currentDocument
    valueObject.setCurrentDocument(
        ims.core.vo.domain.DocumentVoAssembler.create(map, domainObject.getCurrentDocument()));
    // signedBy
    valueObject.setSignedBy(
        ims.core.vo.domain.MedicLiteVoAssembler.create(map, domainObject.getSignedBy()));
    // specialInterest
    ims.domain.lookups.LookupInstance instance8 = domainObject.getSpecialInterest();
    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.correspondence.vo.lookups.SpecialInterestType voLookup8 =
          new ims.correspondence.vo.lookups.SpecialInterestType(
              instance8.getId(), instance8.getText(), instance8.isActive(), null, img, color);
      ims.correspondence.vo.lookups.SpecialInterestType 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.correspondence.vo.lookups.SpecialInterestType(
                parent8.getId(), parent8.getText(), parent8.isActive(), null, img, color));
        parentVoLookup8 = parentVoLookup8.getParent();
        parent8 = parent8.getParent();
      }
      valueObject.setSpecialInterest(voLookup8);
    }
    // DateOfClinic
    java.util.Date DateOfClinic = domainObject.getDateOfClinic();
    if (null != DateOfClinic) {
      valueObject.setDateOfClinic(new ims.framework.utils.Date(DateOfClinic));
    }
    // AdmissionDate
    java.util.Date AdmissionDate = domainObject.getAdmissionDate();
    if (null != AdmissionDate) {
      valueObject.setAdmissionDate(new ims.framework.utils.Date(AdmissionDate));
    }
    // DischargeDate
    java.util.Date DischargeDate = domainObject.getDischargeDate();
    if (null != DischargeDate) {
      valueObject.setDischargeDate(new ims.framework.utils.Date(DischargeDate));
    }
    // DictatedBy
    valueObject.setDictatedBy(
        ims.core.vo.domain.MemberOfStaffLiteVoAssembler.create(map, domainObject.getDictatedBy()));
    // DictatedByInitials
    valueObject.setDictatedByInitials(domainObject.getDictatedByInitials());
    // TypedBy
    valueObject.setTypedBy(
        ims.core.vo.domain.MemberOfStaffLiteVoAssembler.create(map, domainObject.getTypedBy()));
    // TypedByInitials
    valueObject.setTypedByInitials(domainObject.getTypedByInitials());
    // EnquiriesTo
    valueObject.setEnquiriesTo(
        ims.core.vo.domain.MemberOfStaffLiteVoAssembler.create(map, domainObject.getEnquiriesTo()));
    // WasTypedWithoutCaseNotes
    valueObject.setWasTypedWithoutCaseNotes(domainObject.isWasTypedWithoutCaseNotes());
    return valueObject;
  }
  public static ims.correspondence.domain.objects.CorrespondenceDetails
      extractCorrespondenceDetails(
          ims.domain.ILightweightDomainFactory domainFactory,
          ims.correspondence.vo.CorrespondenceDetailsVo valueObject,
          HashMap domMap) {
    if (null == valueObject) {
      return null;
    }
    Integer id = valueObject.getID_CorrespondenceDetails();
    ims.correspondence.domain.objects.CorrespondenceDetails domainObject = null;
    if (null == id) {
      if (domMap.get(valueObject) != null) {
        return (ims.correspondence.domain.objects.CorrespondenceDetails) domMap.get(valueObject);
      }
      // ims.correspondence.vo.CorrespondenceDetailsVo ID_CorrespondenceDetails field is unknown
      domainObject = new ims.correspondence.domain.objects.CorrespondenceDetails();
      domMap.put(valueObject, domainObject);
    } else {
      String key =
          (valueObject.getClass().getName() + "__" + valueObject.getID_CorrespondenceDetails());
      if (domMap.get(key) != null) {
        return (ims.correspondence.domain.objects.CorrespondenceDetails) domMap.get(key);
      }
      domainObject =
          (ims.correspondence.domain.objects.CorrespondenceDetails)
              domainFactory.getDomainObject(
                  ims.correspondence.domain.objects.CorrespondenceDetails.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_CorrespondenceDetails());

    ims.core.admin.pas.domain.objects.PASEvent value1 = null;
    if (null != valueObject.getPasEvent()) {
      if (valueObject.getPasEvent().getBoId() == null) {
        if (domMap.get(valueObject.getPasEvent()) != null) {
          value1 =
              (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
      {
        value1 = domainObject.getPasEvent();
      } else {
        value1 =
            (ims.core.admin.pas.domain.objects.PASEvent)
                domainFactory.getDomainObject(
                    ims.core.admin.pas.domain.objects.PASEvent.class,
                    valueObject.getPasEvent().getBoId());
      }
    }
    domainObject.setPasEvent(value1);
    // create LookupInstance from vo LookupType
    ims.domain.lookups.LookupInstance value2 = null;
    if (null != valueObject.getCurrentStatus()) {
      value2 = domainFactory.getLookupInstance(valueObject.getCurrentStatus().getID());
    }
    domainObject.setCurrentStatus(value2);
    domainObject.setCspStatusHistory(
        ims.correspondence.vo.domain.CorrespondenceStatusHistoryVoAssembler
            .extractCorrespondenceStatusHistorySet(
                domainFactory,
                valueObject.getCspStatusHistory(),
                domainObject.getCspStatusHistory(),
                domMap));
    domainObject.setCategories(
        ims.correspondence.vo.domain.CategoryNotesVoAssembler.extractCategoryNotesList(
            domainFactory, valueObject.getCategories(), domainObject.getCategories(), domMap));
    domainObject.setRecipients(
        ims.correspondence.vo.domain.RecipientVoAssembler.extractRecipientList(
            domainFactory, valueObject.getRecipients(), domainObject.getRecipients(), domMap));
    domainObject.setCurrentDocument(
        ims.core.vo.domain.DocumentVoAssembler.extractDocument(
            domainFactory, valueObject.getCurrentDocument(), domMap));
    domainObject.setSignedBy(
        ims.core.vo.domain.MedicLiteVoAssembler.extractMedic(
            domainFactory, valueObject.getSignedBy(), domMap));
    // create LookupInstance from vo LookupType
    ims.domain.lookups.LookupInstance value8 = null;
    if (null != valueObject.getSpecialInterest()) {
      value8 = domainFactory.getLookupInstance(valueObject.getSpecialInterest().getID());
    }
    domainObject.setSpecialInterest(value8);
    java.util.Date value9 = null;
    ims.framework.utils.Date date9 = valueObject.getDateOfClinic();
    if (date9 != null) {
      value9 = date9.getDate();
    }
    domainObject.setDateOfClinic(value9);
    java.util.Date value10 = null;
    ims.framework.utils.Date date10 = valueObject.getAdmissionDate();
    if (date10 != null) {
      value10 = date10.getDate();
    }
    domainObject.setAdmissionDate(value10);
    java.util.Date value11 = null;
    ims.framework.utils.Date date11 = valueObject.getDischargeDate();
    if (date11 != null) {
      value11 = date11.getDate();
    }
    domainObject.setDischargeDate(value11);
    domainObject.setDictatedBy(
        ims.core.vo.domain.MemberOfStaffLiteVoAssembler.extractMemberOfStaff(
            domainFactory, valueObject.getDictatedBy(), domMap));
    // 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.getDictatedByInitials() != null
        && valueObject.getDictatedByInitials().equals("")) {
      valueObject.setDictatedByInitials(null);
    }
    domainObject.setDictatedByInitials(valueObject.getDictatedByInitials());
    domainObject.setTypedBy(
        ims.core.vo.domain.MemberOfStaffLiteVoAssembler.extractMemberOfStaff(
            domainFactory, valueObject.getTypedBy(), domMap));
    // 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.getTypedByInitials() != null && valueObject.getTypedByInitials().equals("")) {
      valueObject.setTypedByInitials(null);
    }
    domainObject.setTypedByInitials(valueObject.getTypedByInitials());
    domainObject.setEnquiriesTo(
        ims.core.vo.domain.MemberOfStaffLiteVoAssembler.extractMemberOfStaff(
            domainFactory, valueObject.getEnquiriesTo(), domMap));
    domainObject.setWasTypedWithoutCaseNotes(valueObject.getWasTypedWithoutCaseNotes());

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

    valueObject.setID_OcsOrderSession(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()));
      }
    }
    // OrderedBy
    valueObject.setOrderedBy(
        ims.core.vo.domain.MemberOfStaffLiteVoAssembler.create(map, domainObject.getOrderedBy()));
    // ResponsibleClinician
    valueObject.setResponsibleClinician(
        ims.core.vo.domain.HcpLiteVoAssembler.create(map, domainObject.getResponsibleClinician()));
    // ResponsibleGp
    valueObject.setResponsibleGp(
        ims.core.vo.domain.GpLiteVoAssembler.create(map, domainObject.getResponsibleGp()));
    // PatientLocation
    if (domainObject.getPatientLocation() != null) {
      if (domainObject.getPatientLocation()
          instanceof
          HibernateProxy) // If the proxy is set, there is no need to lazy load, the proxy knows the
                          // id already.
      {
        HibernateProxy p = (HibernateProxy) domainObject.getPatientLocation();
        int id = Integer.parseInt(p.getHibernateLazyInitializer().getIdentifier().toString());
        valueObject.setPatientLocation(new ims.core.resource.place.vo.LocationRefVo(id, -1));
      } else {
        valueObject.setPatientLocation(
            new ims.core.resource.place.vo.LocationRefVo(
                domainObject.getPatientLocation().getId(),
                domainObject.getPatientLocation().getVersion()));
      }
    }
    // PatientClinic
    if (domainObject.getPatientClinic() != null) {
      if (domainObject.getPatientClinic()
          instanceof
          HibernateProxy) // If the proxy is set, there is no need to lazy load, the proxy knows the
                          // id already.
      {
        HibernateProxy p = (HibernateProxy) domainObject.getPatientClinic();
        int id = Integer.parseInt(p.getHibernateLazyInitializer().getIdentifier().toString());
        valueObject.setPatientClinic(new ims.core.resource.place.vo.ClinicRefVo(id, -1));
      } else {
        valueObject.setPatientClinic(
            new ims.core.resource.place.vo.ClinicRefVo(
                domainObject.getPatientClinic().getId(),
                domainObject.getPatientClinic().getVersion()));
      }
    }
    // AdditClinNotes
    valueObject.setAdditClinNotes(domainObject.getAdditClinNotes());
    // SendNumber
    valueObject.setSendNumber(domainObject.isSendNumber());
    return valueObject;
  }