public static ims.ocrr.orderingresults.domain.objects.OcsOrderSession extractOcsOrderSession(
      ims.domain.ILightweightDomainFactory domainFactory,
      ims.ocrr.vo.OcsOrderVo valueObject,
      HashMap domMap) {
    if (null == valueObject) {
      return null;
    }
    Integer id = valueObject.getID_OcsOrderSession();
    ims.ocrr.orderingresults.domain.objects.OcsOrderSession domainObject = null;
    if (null == id) {
      if (domMap.get(valueObject) != null) {
        return (ims.ocrr.orderingresults.domain.objects.OcsOrderSession) domMap.get(valueObject);
      }
      // ims.ocrr.vo.OcsOrderVo ID_OcsOrderSession field is unknown
      domainObject = new ims.ocrr.orderingresults.domain.objects.OcsOrderSession();
      domMap.put(valueObject, domainObject);
    } else {
      String key = (valueObject.getClass().getName() + "__" + valueObject.getID_OcsOrderSession());
      if (domMap.get(key) != null) {
        return (ims.ocrr.orderingresults.domain.objects.OcsOrderSession) domMap.get(key);
      }
      domainObject =
          (ims.ocrr.orderingresults.domain.objects.OcsOrderSession)
              domainFactory.getDomainObject(
                  ims.ocrr.orderingresults.domain.objects.OcsOrderSession.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_OcsOrderSession());

    domainObject.setClinicalTrial(valueObject.getClinicalTrial());
    // 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.getClinicalTrialTxt() != null && valueObject.getClinicalTrialTxt().equals("")) {
      valueObject.setClinicalTrialTxt(null);
    }
    domainObject.setClinicalTrialTxt(valueObject.getClinicalTrialTxt());
    // create LookupInstance from vo LookupType
    ims.domain.lookups.LookupInstance value3 = null;
    if (null != valueObject.getPatMobility()) {
      value3 = domainFactory.getLookupInstance(valueObject.getPatMobility().getID());
    }
    domainObject.setPatMobility(value3);
    // create LookupInstance from vo LookupType
    ims.domain.lookups.LookupInstance value4 = null;
    if (null != valueObject.getOrderCategory()) {
      value4 = domainFactory.getLookupInstance(valueObject.getOrderCategory().getID());
    }
    domainObject.setOrderCategory(value4);
    domainObject.setSpecimens(
        ims.ocrr.vo.domain.OrderSpecimenVoAssembler.extractOrderSpecimenSet(
            domainFactory, valueObject.getSpecimens(), domainObject.getSpecimens(), domMap));
    domainObject.setInvestigations(
        ims.ocrr.vo.domain.OrderInvestigationVoAssembler.extractOrderInvestigationSet(
            domainFactory,
            valueObject.getInvestigations(),
            domainObject.getInvestigations(),
            domMap));
    domainObject.setWasProcessed(valueObject.getWasProcessed());
    domainObject.setClinicalInfo(
        ims.ocrr.vo.domain.OcsQASessionVoAssembler.extractOcsQASession(
            domainFactory, valueObject.getClinicalInfo(), domMap));
    domainObject.setReportTo(
        ims.ocrr.vo.domain.OcsReportToVoAssembler.extractOcsReportToList(
            domainFactory, valueObject.getReportTo(), domainObject.getReportTo(), 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.getSummaryClinicalInformation() != null
        && valueObject.getSummaryClinicalInformation().equals("")) {
      valueObject.setSummaryClinicalInformation(null);
    }
    domainObject.setSummaryClinicalInformation(valueObject.getSummaryClinicalInformation());
    // 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.getBleepExtNumber() != null && valueObject.getBleepExtNumber().equals("")) {
      valueObject.setBleepExtNumber(null);
    }
    domainObject.setBleepExtNumber(valueObject.getBleepExtNumber());
    ims.core.admin.domain.objects.ClinicalContact value12 = null;
    if (null != valueObject.getClinicalContact()) {
      if (valueObject.getClinicalContact().getBoId() == null) {
        if (domMap.get(valueObject.getClinicalContact()) != null) {
          value12 =
              (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
      {
        value12 = domainObject.getClinicalContact();
      } else {
        value12 =
            (ims.core.admin.domain.objects.ClinicalContact)
                domainFactory.getDomainObject(
                    ims.core.admin.domain.objects.ClinicalContact.class,
                    valueObject.getClinicalContact().getBoId());
      }
    }
    domainObject.setClinicalContact(value12);
    // SaveAsRefVO - treated as a refVo in extract methods
    ims.core.patient.domain.objects.Patient value13 = null;
    if (null != valueObject.getPatient()) {
      if (valueObject.getPatient().getBoId() == null) {
        if (domMap.get(valueObject.getPatient()) != null) {
          value13 = (ims.core.patient.domain.objects.Patient) domMap.get(valueObject.getPatient());
        }
      } else {
        value13 =
            (ims.core.patient.domain.objects.Patient)
                domainFactory.getDomainObject(
                    ims.core.patient.domain.objects.Patient.class,
                    valueObject.getPatient().getBoId());
      }
    }
    domainObject.setPatient(value13);
    // SaveAsRefVO - treated as a refVo in extract methods
    ims.core.resource.people.domain.objects.MemberOfStaff value14 = null;
    if (null != valueObject.getOrderedBy()) {
      if (valueObject.getOrderedBy().getBoId() == null) {
        if (domMap.get(valueObject.getOrderedBy()) != null) {
          value14 =
              (ims.core.resource.people.domain.objects.MemberOfStaff)
                  domMap.get(valueObject.getOrderedBy());
        }
      } else {
        value14 =
            (ims.core.resource.people.domain.objects.MemberOfStaff)
                domainFactory.getDomainObject(
                    ims.core.resource.people.domain.objects.MemberOfStaff.class,
                    valueObject.getOrderedBy().getBoId());
      }
    }
    domainObject.setOrderedBy(value14);
    // SaveAsRefVO - treated as a refVo in extract methods
    ims.core.resource.people.domain.objects.Hcp value15 = null;
    if (null != valueObject.getResponsibleClinician()) {
      if (valueObject.getResponsibleClinician().getBoId() == null) {
        if (domMap.get(valueObject.getResponsibleClinician()) != null) {
          value15 =
              (ims.core.resource.people.domain.objects.Hcp)
                  domMap.get(valueObject.getResponsibleClinician());
        }
      } else {
        value15 =
            (ims.core.resource.people.domain.objects.Hcp)
                domainFactory.getDomainObject(
                    ims.core.resource.people.domain.objects.Hcp.class,
                    valueObject.getResponsibleClinician().getBoId());
      }
    }
    domainObject.setResponsibleClinician(value15);
    // SaveAsRefVO - treated as a refVo in extract methods
    ims.core.resource.people.domain.objects.Gp value16 = null;
    if (null != valueObject.getResponsibleGp()) {
      if (valueObject.getResponsibleGp().getBoId() == null) {
        if (domMap.get(valueObject.getResponsibleGp()) != null) {
          value16 =
              (ims.core.resource.people.domain.objects.Gp)
                  domMap.get(valueObject.getResponsibleGp());
        }
      } else {
        value16 =
            (ims.core.resource.people.domain.objects.Gp)
                domainFactory.getDomainObject(
                    ims.core.resource.people.domain.objects.Gp.class,
                    valueObject.getResponsibleGp().getBoId());
      }
    }
    domainObject.setResponsibleGp(value16);
    // SaveAsRefVO - treated as a refVo in extract methods
    ims.core.resource.place.domain.objects.Location value17 = null;
    if (null != valueObject.getPatientLocation()) {
      if (valueObject.getPatientLocation().getBoId() == null) {
        if (domMap.get(valueObject.getPatientLocation()) != null) {
          value17 =
              (ims.core.resource.place.domain.objects.Location)
                  domMap.get(valueObject.getPatientLocation());
        }
      } else {
        value17 =
            (ims.core.resource.place.domain.objects.Location)
                domainFactory.getDomainObject(
                    ims.core.resource.place.domain.objects.Location.class,
                    valueObject.getPatientLocation().getBoId());
      }
    }
    domainObject.setPatientLocation(value17);
    // SaveAsRefVO - treated as a refVo in extract methods
    ims.core.resource.place.domain.objects.Clinic value18 = null;
    if (null != valueObject.getPatientClinic()) {
      if (valueObject.getPatientClinic().getBoId() == null) {
        if (domMap.get(valueObject.getPatientClinic()) != null) {
          value18 =
              (ims.core.resource.place.domain.objects.Clinic)
                  domMap.get(valueObject.getPatientClinic());
        }
      } else {
        value18 =
            (ims.core.resource.place.domain.objects.Clinic)
                domainFactory.getDomainObject(
                    ims.core.resource.place.domain.objects.Clinic.class,
                    valueObject.getPatientClinic().getBoId());
      }
    }
    domainObject.setPatientClinic(value18);
    // 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.getAdditClinNotes() != null && valueObject.getAdditClinNotes().equals("")) {
      valueObject.setAdditClinNotes(null);
    }
    domainObject.setAdditClinNotes(valueObject.getAdditClinNotes());
    // SaveAsRefVO - treated as a refVo in extract methods
    ims.core.admin.domain.objects.CareContext value21 = null;
    if (null != valueObject.getCareContext()) {
      if (valueObject.getCareContext().getBoId() == null) {
        if (domMap.get(valueObject.getCareContext()) != null) {
          value21 =
              (ims.core.admin.domain.objects.CareContext) domMap.get(valueObject.getCareContext());
        }
      } else {
        value21 =
            (ims.core.admin.domain.objects.CareContext)
                domainFactory.getDomainObject(
                    ims.core.admin.domain.objects.CareContext.class,
                    valueObject.getCareContext().getBoId());
      }
    }
    domainObject.setCareContext(value21);
    ims.core.resource.place.domain.objects.LocSite value22 = null;
    if (null != valueObject.getOrderingHospital()) {
      if (valueObject.getOrderingHospital().getBoId() == null) {
        if (domMap.get(valueObject.getOrderingHospital()) != null) {
          value22 =
              (ims.core.resource.place.domain.objects.LocSite)
                  domMap.get(valueObject.getOrderingHospital());
        }
      } else if (valueObject.getBoVersion()
          == -1) // RefVo was not modified since obtained from the Assembler, no need to update the
                 // BO field
      {
        value22 = domainObject.getOrderingHospital();
      } else {
        value22 =
            (ims.core.resource.place.domain.objects.LocSite)
                domainFactory.getDomainObject(
                    ims.core.resource.place.domain.objects.LocSite.class,
                    valueObject.getOrderingHospital().getBoId());
      }
    }
    domainObject.setOrderingHospital(value22);
    // SaveAsRefVO - treated as a refVo in extract methods
    ims.core.resource.place.domain.objects.Location value23 = null;
    if (null != valueObject.getOutpatientDept()) {
      if (valueObject.getOutpatientDept().getBoId() == null) {
        if (domMap.get(valueObject.getOutpatientDept()) != null) {
          value23 =
              (ims.core.resource.place.domain.objects.Location)
                  domMap.get(valueObject.getOutpatientDept());
        }
      } else {
        value23 =
            (ims.core.resource.place.domain.objects.Location)
                domainFactory.getDomainObject(
                    ims.core.resource.place.domain.objects.Location.class,
                    valueObject.getOutpatientDept().getBoId());
      }
    }
    domainObject.setOutpatientDept(value23);
    // create LookupInstance from vo LookupType
    ims.domain.lookups.LookupInstance value24 = null;
    if (null != valueObject.getAuthorisationOrderStatus()) {
      value24 = domainFactory.getLookupInstance(valueObject.getAuthorisationOrderStatus().getID());
    }
    domainObject.setAuthorisationOrderStatus(value24);

    return domainObject;
  }
  public static ims.ocrr.orderingresults.domain.objects.OcsOrderSession extractOcsOrderSession(
      ims.domain.ILightweightDomainFactory domainFactory,
      ims.ocs_if.vo.IfOcsOrderShortVo valueObject,
      HashMap domMap) {
    if (null == valueObject) {
      return null;
    }
    Integer id = valueObject.getID_OcsOrderSession();
    ims.ocrr.orderingresults.domain.objects.OcsOrderSession domainObject = null;
    if (null == id) {
      if (domMap.get(valueObject) != null) {
        return (ims.ocrr.orderingresults.domain.objects.OcsOrderSession) domMap.get(valueObject);
      }
      // ims.ocs_if.vo.IfOcsOrderShortVo ID_OcsOrderSession field is unknown
      domainObject = new ims.ocrr.orderingresults.domain.objects.OcsOrderSession();
      domMap.put(valueObject, domainObject);
    } else {
      String key = (valueObject.getClass().getName() + "__" + valueObject.getID_OcsOrderSession());
      if (domMap.get(key) != null) {
        return (ims.ocrr.orderingresults.domain.objects.OcsOrderSession) domMap.get(key);
      }
      domainObject =
          (ims.ocrr.orderingresults.domain.objects.OcsOrderSession)
              domainFactory.getDomainObject(
                  ims.ocrr.orderingresults.domain.objects.OcsOrderSession.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_OcsOrderSession());

    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);
    // SaveAsRefVO - treated as a refVo in extract methods
    ims.core.resource.people.domain.objects.MemberOfStaff value2 = null;
    if (null != valueObject.getOrderedBy()) {
      if (valueObject.getOrderedBy().getBoId() == null) {
        if (domMap.get(valueObject.getOrderedBy()) != null) {
          value2 =
              (ims.core.resource.people.domain.objects.MemberOfStaff)
                  domMap.get(valueObject.getOrderedBy());
        }
      } else {
        value2 =
            (ims.core.resource.people.domain.objects.MemberOfStaff)
                domainFactory.getDomainObject(
                    ims.core.resource.people.domain.objects.MemberOfStaff.class,
                    valueObject.getOrderedBy().getBoId());
      }
    }
    domainObject.setOrderedBy(value2);
    // SaveAsRefVO - treated as a refVo in extract methods
    ims.core.resource.people.domain.objects.Hcp value3 = null;
    if (null != valueObject.getResponsibleClinician()) {
      if (valueObject.getResponsibleClinician().getBoId() == null) {
        if (domMap.get(valueObject.getResponsibleClinician()) != null) {
          value3 =
              (ims.core.resource.people.domain.objects.Hcp)
                  domMap.get(valueObject.getResponsibleClinician());
        }
      } else {
        value3 =
            (ims.core.resource.people.domain.objects.Hcp)
                domainFactory.getDomainObject(
                    ims.core.resource.people.domain.objects.Hcp.class,
                    valueObject.getResponsibleClinician().getBoId());
      }
    }
    domainObject.setResponsibleClinician(value3);
    // SaveAsRefVO - treated as a refVo in extract methods
    ims.core.resource.people.domain.objects.Gp value4 = null;
    if (null != valueObject.getResponsibleGp()) {
      if (valueObject.getResponsibleGp().getBoId() == null) {
        if (domMap.get(valueObject.getResponsibleGp()) != null) {
          value4 =
              (ims.core.resource.people.domain.objects.Gp)
                  domMap.get(valueObject.getResponsibleGp());
        }
      } else {
        value4 =
            (ims.core.resource.people.domain.objects.Gp)
                domainFactory.getDomainObject(
                    ims.core.resource.people.domain.objects.Gp.class,
                    valueObject.getResponsibleGp().getBoId());
      }
    }
    domainObject.setResponsibleGp(value4);
    ims.core.resource.place.domain.objects.Location value5 = null;
    if (null != valueObject.getPatientLocation()) {
      if (valueObject.getPatientLocation().getBoId() == null) {
        if (domMap.get(valueObject.getPatientLocation()) != null) {
          value5 =
              (ims.core.resource.place.domain.objects.Location)
                  domMap.get(valueObject.getPatientLocation());
        }
      } else if (valueObject.getBoVersion()
          == -1) // RefVo was not modified since obtained from the Assembler, no need to update the
                 // BO field
      {
        value5 = domainObject.getPatientLocation();
      } else {
        value5 =
            (ims.core.resource.place.domain.objects.Location)
                domainFactory.getDomainObject(
                    ims.core.resource.place.domain.objects.Location.class,
                    valueObject.getPatientLocation().getBoId());
      }
    }
    domainObject.setPatientLocation(value5);
    ims.core.resource.place.domain.objects.Clinic value6 = null;
    if (null != valueObject.getPatientClinic()) {
      if (valueObject.getPatientClinic().getBoId() == null) {
        if (domMap.get(valueObject.getPatientClinic()) != null) {
          value6 =
              (ims.core.resource.place.domain.objects.Clinic)
                  domMap.get(valueObject.getPatientClinic());
        }
      } else if (valueObject.getBoVersion()
          == -1) // RefVo was not modified since obtained from the Assembler, no need to update the
                 // BO field
      {
        value6 = domainObject.getPatientClinic();
      } else {
        value6 =
            (ims.core.resource.place.domain.objects.Clinic)
                domainFactory.getDomainObject(
                    ims.core.resource.place.domain.objects.Clinic.class,
                    valueObject.getPatientClinic().getBoId());
      }
    }
    domainObject.setPatientClinic(value6);
    // 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.getAdditClinNotes() != null && valueObject.getAdditClinNotes().equals("")) {
      valueObject.setAdditClinNotes(null);
    }
    domainObject.setAdditClinNotes(valueObject.getAdditClinNotes());
    domainObject.setSendNumber(valueObject.getSendNumber());

    return domainObject;
  }