/**
   * Update the ValueObject with the Domain Object.
   *
   * @param map DomainObjectMap of DomainObjects to already created ValueObjects.
   * @param valueObject to be updated
   * @param domainObject ims.RefMan.domain.objects.ReportNote
   */
  public static ims.RefMan.vo.CorrespondenceNoteLiteVo insert(
      DomainObjectMap map,
      ims.RefMan.vo.CorrespondenceNoteLiteVo valueObject,
      ims.RefMan.domain.objects.ReportNote domainObject) {
    if (null == domainObject) {
      return valueObject;
    }
    if (null == map) {
      map = new DomainObjectMap();
    }

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

    // CatsReferral
    if (domainObject.getCatsReferral() != null) {
      if (domainObject.getCatsReferral()
          instanceof
          HibernateProxy) // If the proxy is set, there is no need to lazy load, the proxy knows the
                          // id already.
      {
        HibernateProxy p = (HibernateProxy) domainObject.getCatsReferral();
        int id = Integer.parseInt(p.getHibernateLazyInitializer().getIdentifier().toString());
        valueObject.setCatsReferral(new ims.RefMan.vo.CatsReferralRefVo(id, -1));
      } else {
        valueObject.setCatsReferral(
            new ims.RefMan.vo.CatsReferralRefVo(
                domainObject.getCatsReferral().getId(),
                domainObject.getCatsReferral().getVersion()));
      }
    }
    // AuthoringInformation
    valueObject.setAuthoringInformation(
        ims.core.vo.domain.AuthoringInformationVoAssembler.create(
            map, domainObject.getAuthoringInformation()));
    // RecordingInformation
    valueObject.setRecordingInformation(
        ims.core.vo.domain.AuthoringInformationVoAssembler.create(
            map, domainObject.getRecordingInformation()));
    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.clinical.domain.objects.PatientProcedureChecklist
   */
  public static ims.clinical.vo.PatientProcedureChecklistVo insert(
      DomainObjectMap map,
      ims.clinical.vo.PatientProcedureChecklistVo valueObject,
      ims.clinical.domain.objects.PatientProcedureChecklist domainObject) {
    if (null == domainObject) {
      return valueObject;
    }
    if (null == map) {
      map = new DomainObjectMap();
    }

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

    // 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()));
      }
    }
    // PresentProcedures
    valueObject.setPresentProcedures(
        ims.core.vo.domain.PatientProcedureVoAssembler
            .createPatientProcedureVoCollectionFromPatientProcedure(
                map, domainObject.getPresentProcedures()));
    // OtherProcedures
    valueObject.setOtherProcedures(
        ims.clinical.vo.domain.PatientAbsentProcedureVoAssembler
            .createPatientAbsentProcedureVoCollectionFromPatientAbsentProcedure(
                map, domainObject.getOtherProcedures()));
    // AuthoringInformation
    valueObject.setAuthoringInformation(
        ims.core.vo.domain.AuthoringInformationVoAssembler.create(
            map, domainObject.getAuthoringInformation()));
    return valueObject;
  }
  public static ims.core.clinical.domain.objects.PatientDiagnosis extractPatientDiagnosis(
      ims.domain.ILightweightDomainFactory domainFactory,
      ims.core.vo.PatientDiagnosisEDischargeVo valueObject,
      HashMap domMap) {
    if (null == valueObject) {
      return null;
    }
    Integer id = valueObject.getID_PatientDiagnosis();
    ims.core.clinical.domain.objects.PatientDiagnosis domainObject = null;
    if (null == id) {
      if (domMap.get(valueObject) != null) {
        return (ims.core.clinical.domain.objects.PatientDiagnosis) domMap.get(valueObject);
      }
      // ims.core.vo.PatientDiagnosisEDischargeVo ID_PatientDiagnosis field is unknown
      domainObject = new ims.core.clinical.domain.objects.PatientDiagnosis();
      domMap.put(valueObject, domainObject);
    } else {
      String key = (valueObject.getClass().getName() + "__" + valueObject.getID_PatientDiagnosis());
      if (domMap.get(key) != null) {
        return (ims.core.clinical.domain.objects.PatientDiagnosis) domMap.get(key);
      }
      domainObject =
          (ims.core.clinical.domain.objects.PatientDiagnosis)
              domainFactory.getDomainObject(
                  ims.core.clinical.domain.objects.PatientDiagnosis.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_PatientDiagnosis());

    domainObject.setStatusHistory(
        ims.clinical.vo.domain.PatientDiagnosisStatusVoAssembler.extractPatientDiagnosisStatusSet(
            domainFactory,
            valueObject.getStatusHistory(),
            domainObject.getStatusHistory(),
            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.getDiagnosisDescription() != null
        && valueObject.getDiagnosisDescription().equals("")) {
      valueObject.setDiagnosisDescription(null);
    }
    domainObject.setDiagnosisDescription(valueObject.getDiagnosisDescription());
    ims.framework.utils.PartialDate DiagnosedDate = valueObject.getDiagnosedDate();
    Integer value3 = null;
    if (null != DiagnosedDate) {
      value3 = DiagnosedDate.toInteger();
    }
    domainObject.setDiagnosedDate(value3);
    // SaveAsRefVO - treated as a refVo in extract methods
    ims.core.clinical.domain.objects.Diagnosis value4 = null;
    if (null != valueObject.getDiagnosis()) {
      if (valueObject.getDiagnosis().getBoId() == null) {
        if (domMap.get(valueObject.getDiagnosis()) != null) {
          value4 =
              (ims.core.clinical.domain.objects.Diagnosis) domMap.get(valueObject.getDiagnosis());
        }
      } else {
        value4 =
            (ims.core.clinical.domain.objects.Diagnosis)
                domainFactory.getDomainObject(
                    ims.core.clinical.domain.objects.Diagnosis.class,
                    valueObject.getDiagnosis().getBoId());
      }
    }
    domainObject.setDiagnosis(value4);
    // create LookupInstance from vo LookupType
    ims.domain.lookups.LookupInstance value5 = null;
    if (null != valueObject.getSourceofInformation()) {
      value5 = domainFactory.getLookupInstance(valueObject.getSourceofInformation().getID());
    }
    domainObject.setSourceofInformation(value5);
    domainObject.setIsComplication(valueObject.getIsComplication());
    domainObject.setIsComorbidity(valueObject.getIsComorbidity());
    java.util.Date value8 = null;
    ims.framework.utils.Date date8 = valueObject.getDateResolved();
    if (date8 != null) {
      value8 = date8.getDate();
    }
    domainObject.setDateResolved(value8);
    // SaveAsRefVO - treated as a refVo in extract methods
    ims.core.admin.domain.objects.CareContext value9 = null;
    if (null != valueObject.getCareContext()) {
      if (valueObject.getCareContext().getBoId() == null) {
        if (domMap.get(valueObject.getCareContext()) != null) {
          value9 =
              (ims.core.admin.domain.objects.CareContext) domMap.get(valueObject.getCareContext());
        }
      } else {
        value9 =
            (ims.core.admin.domain.objects.CareContext)
                domainFactory.getDomainObject(
                    ims.core.admin.domain.objects.CareContext.class,
                    valueObject.getCareContext().getBoId());
      }
    }
    domainObject.setCareContext(value9);
    // create LookupInstance from vo LookupType
    ims.domain.lookups.LookupInstance value10 = null;
    if (null != valueObject.getDiagLaterality()) {
      value10 = domainFactory.getLookupInstance(valueObject.getDiagLaterality().getID());
    }
    domainObject.setDiagLaterality(value10);
    // 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.getSiteText() != null && valueObject.getSiteText().equals("")) {
      valueObject.setSiteText(null);
    }
    domainObject.setSiteText(valueObject.getSiteText());
    domainObject.setAuthoringInfo(
        ims.core.vo.domain.AuthoringInformationVoAssembler.extractAuthoringInformation(
            domainFactory, valueObject.getAuthoringInfo(), domMap));
    domainObject.setIncludeDiagnosisInDiscReports(
        ims.core.vo.domain.IncludeDiagnosisInDischargeReportVoAssembler
            .extractIncludeDiagnosisInDischargeReportSet(
                domainFactory,
                valueObject.getIncludeDiagnosisInDiscReports(),
                domainObject.getIncludeDiagnosisInDiscReports(),
                domMap));
    domainObject.setIsPrevRelevantDiagnosis(valueObject.getIsPrevRelevantDiagnosis());
    java.util.Date value16 = null;
    ims.framework.utils.Date date16 = valueObject.getDateOnset();
    if (date16 != null) {
      value16 = date16.getDate();
    }
    domainObject.setDateOnset(value16);
    ims.core.admin.domain.objects.ClinicalContact value17 = null;
    if (null != valueObject.getClinicalContact()) {
      if (valueObject.getClinicalContact().getBoId() == null) {
        if (domMap.get(valueObject.getClinicalContact()) != null) {
          value17 =
              (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
      {
        value17 = domainObject.getClinicalContact();
      } else {
        value17 =
            (ims.core.admin.domain.objects.ClinicalContact)
                domainFactory.getDomainObject(
                    ims.core.admin.domain.objects.ClinicalContact.class,
                    valueObject.getClinicalContact().getBoId());
      }
    }
    domainObject.setClinicalContact(value17);
    domainObject.setPrimaryForCareSpells(
        ims.core.vo.domain.CSPrimaryDiagnosisVoAssembler.extractCsPrimaryDiagnosisSet(
            domainFactory,
            valueObject.getPrimaryForCareSpells(),
            domainObject.getPrimaryForCareSpells(),
            domMap));
    domainObject.setCoMorbidityForEpisodeOfCares(
        ims.core.vo.domain.EpisodeOfCareCoMorbidityVoAssembler.extractEpisodeOfCareCoMorbiditySet(
            domainFactory,
            valueObject.getCoMorbidityForEpisodeOfCares(),
            domainObject.getCoMorbidityForEpisodeOfCares(),
            domMap));
    ims.core.admin.domain.objects.EpisodeOfCare value20 = null;
    if (null != valueObject.getEpisodeOfCare()) {
      if (valueObject.getEpisodeOfCare().getBoId() == null) {
        if (domMap.get(valueObject.getEpisodeOfCare()) != null) {
          value20 =
              (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
      {
        value20 = domainObject.getEpisodeOfCare();
      } else {
        value20 =
            (ims.core.admin.domain.objects.EpisodeOfCare)
                domainFactory.getDomainObject(
                    ims.core.admin.domain.objects.EpisodeOfCare.class,
                    valueObject.getEpisodeOfCare().getBoId());
      }
    }
    domainObject.setEpisodeOfCare(value20);
    domainObject.setDiagnosedOnAdmission(valueObject.getDiagnosedOnAdmission());

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

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

    // StatusHistory
    valueObject.setStatusHistory(
        ims.clinical.vo.domain.PatientDiagnosisStatusVoAssembler
            .createPatientDiagnosisStatusVoCollectionFromPatientDiagnosisStatus(
                map, domainObject.getStatusHistory()));
    // DiagnosisDescription
    valueObject.setDiagnosisDescription(domainObject.getDiagnosisDescription());
    // DiagnosedDate
    Integer DiagnosedDate = domainObject.getDiagnosedDate();
    if (null != DiagnosedDate) {
      valueObject.setDiagnosedDate(new ims.framework.utils.PartialDate(DiagnosedDate));
    }
    // Diagnosis
    valueObject.setDiagnosis(
        ims.core.vo.domain.DiagLiteVoAssembler.create(map, domainObject.getDiagnosis()));
    // SourceofInformation
    ims.domain.lookups.LookupInstance instance5 = domainObject.getSourceofInformation();
    if (null != instance5) {
      ims.framework.utils.ImagePath img = null;
      ims.framework.utils.Color color = null;
      img = null;
      if (instance5.getImage() != null) {
        img =
            new ims.framework.utils.ImagePath(
                instance5.getImage().getImageId(), instance5.getImage().getImagePath());
      }
      color = instance5.getColor();
      if (color != null) color.getValue();

      ims.core.vo.lookups.SourceofInformation voLookup5 =
          new ims.core.vo.lookups.SourceofInformation(
              instance5.getId(), instance5.getText(), instance5.isActive(), null, img, color);
      ims.core.vo.lookups.SourceofInformation parentVoLookup5 = voLookup5;
      ims.domain.lookups.LookupInstance parent5 = instance5.getParent();
      while (parent5 != null) {
        if (parent5.getImage() != null) {
          img =
              new ims.framework.utils.ImagePath(
                  parent5.getImage().getImageId(), parent5.getImage().getImagePath());
        } else {
          img = null;
        }
        color = parent5.getColor();
        if (color != null) color.getValue();
        parentVoLookup5.setParent(
            new ims.core.vo.lookups.SourceofInformation(
                parent5.getId(), parent5.getText(), parent5.isActive(), null, img, color));
        parentVoLookup5 = parentVoLookup5.getParent();
        parent5 = parent5.getParent();
      }
      valueObject.setSourceofInformation(voLookup5);
    }
    // isComplication
    valueObject.setIsComplication(domainObject.isIsComplication());
    // isComorbidity
    valueObject.setIsComorbidity(domainObject.isIsComorbidity());
    // DateResolved
    java.util.Date DateResolved = domainObject.getDateResolved();
    if (null != DateResolved) {
      valueObject.setDateResolved(new ims.framework.utils.Date(DateResolved));
    }
    // CareContext
    valueObject.setCareContext(
        ims.core.vo.domain.CareContextForEdischargeDiagnosisVoAssembler.create(
            map, domainObject.getCareContext()));
    // DiagLaterality
    ims.domain.lookups.LookupInstance instance10 = domainObject.getDiagLaterality();
    if (null != instance10) {
      ims.framework.utils.ImagePath img = null;
      ims.framework.utils.Color color = null;
      img = null;
      if (instance10.getImage() != null) {
        img =
            new ims.framework.utils.ImagePath(
                instance10.getImage().getImageId(), instance10.getImage().getImagePath());
      }
      color = instance10.getColor();
      if (color != null) color.getValue();

      ims.core.vo.lookups.LateralityLRB voLookup10 =
          new ims.core.vo.lookups.LateralityLRB(
              instance10.getId(), instance10.getText(), instance10.isActive(), null, img, color);
      ims.core.vo.lookups.LateralityLRB parentVoLookup10 = voLookup10;
      ims.domain.lookups.LookupInstance parent10 = instance10.getParent();
      while (parent10 != null) {
        if (parent10.getImage() != null) {
          img =
              new ims.framework.utils.ImagePath(
                  parent10.getImage().getImageId(), parent10.getImage().getImagePath());
        } else {
          img = null;
        }
        color = parent10.getColor();
        if (color != null) color.getValue();
        parentVoLookup10.setParent(
            new ims.core.vo.lookups.LateralityLRB(
                parent10.getId(), parent10.getText(), parent10.isActive(), null, img, color));
        parentVoLookup10 = parentVoLookup10.getParent();
        parent10 = parent10.getParent();
      }
      valueObject.setDiagLaterality(voLookup10);
    }
    // SiteText
    valueObject.setSiteText(domainObject.getSiteText());
    // AuthoringInfo
    valueObject.setAuthoringInfo(
        ims.core.vo.domain.AuthoringInformationVoAssembler.create(
            map, domainObject.getAuthoringInfo()));
    // IncludeDiagnosisInDiscReports
    valueObject.setIncludeDiagnosisInDiscReports(
        ims.core.vo.domain.IncludeDiagnosisInDischargeReportVoAssembler
            .createIncludeDiagnosisInDischargeReportVoCollectionFromIncludeDiagnosisInDischargeReport(
                map, domainObject.getIncludeDiagnosisInDiscReports()));
    // isPrevRelevantDiagnosis
    valueObject.setIsPrevRelevantDiagnosis(domainObject.isIsPrevRelevantDiagnosis());
    // SysInfo
    // set system information
    valueObject.setSysInfo(
        ims.vo.domain.SystemInformationAssembler.create(domainObject.getSystemInformation()));
    // DateOnset
    java.util.Date DateOnset = domainObject.getDateOnset();
    if (null != DateOnset) {
      valueObject.setDateOnset(new ims.framework.utils.Date(DateOnset));
    }
    // 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()));
      }
    }
    // PrimaryForCareSpells
    valueObject.setPrimaryForCareSpells(
        ims.core.vo.domain.CSPrimaryDiagnosisVoAssembler
            .createCSPrimaryDiagnosisVoCollectionFromCsPrimaryDiagnosis(
                map, domainObject.getPrimaryForCareSpells()));
    // CoMorbidityForEpisodeOfCares
    valueObject.setCoMorbidityForEpisodeOfCares(
        ims.core.vo.domain.EpisodeOfCareCoMorbidityVoAssembler
            .createEpisodeOfCareCoMorbidityVoCollectionFromEpisodeOfCareCoMorbidity(
                map, domainObject.getCoMorbidityForEpisodeOfCares()));
    // EpisodeOfCare
    if (domainObject.getEpisodeOfCare() != null) {
      if (domainObject.getEpisodeOfCare()
          instanceof
          HibernateProxy) // If the proxy is set, there is no need to lazy load, the proxy knows the
      // id already.
      {
        HibernateProxy p = (HibernateProxy) domainObject.getEpisodeOfCare();
        int id = Integer.parseInt(p.getHibernateLazyInitializer().getIdentifier().toString());
        valueObject.setEpisodeOfCare(new ims.core.admin.vo.EpisodeOfCareRefVo(id, -1));
      } else {
        valueObject.setEpisodeOfCare(
            new ims.core.admin.vo.EpisodeOfCareRefVo(
                domainObject.getEpisodeOfCare().getId(),
                domainObject.getEpisodeOfCare().getVersion()));
      }
    }
    // diagnosedOnAdmission
    valueObject.setDiagnosedOnAdmission(domainObject.isDiagnosedOnAdmission());
    return valueObject;
  }
  public static ims.oncology.domain.objects.PathologyDetails extractPathologyDetails(
      ims.domain.ILightweightDomainFactory domainFactory,
      ims.clinicaladmin.vo.PathologyDetailsVo valueObject,
      HashMap domMap) {
    if (null == valueObject) {
      return null;
    }
    Integer id = valueObject.getID_PathologyDetails();
    ims.oncology.domain.objects.PathologyDetails domainObject = null;
    if (null == id) {
      if (domMap.get(valueObject) != null) {
        return (ims.oncology.domain.objects.PathologyDetails) domMap.get(valueObject);
      }
      // ims.clinicaladmin.vo.PathologyDetailsVo ID_PathologyDetails field is unknown
      domainObject = new ims.oncology.domain.objects.PathologyDetails();
      domMap.put(valueObject, domainObject);
    } else {
      String key = (valueObject.getClass().getName() + "__" + valueObject.getID_PathologyDetails());
      if (domMap.get(key) != null) {
        return (ims.oncology.domain.objects.PathologyDetails) domMap.get(key);
      }
      domainObject =
          (ims.oncology.domain.objects.PathologyDetails)
              domainFactory.getDomainObject(ims.oncology.domain.objects.PathologyDetails.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_PathologyDetails());

    domainObject.setInvasiveLesionSize(valueObject.getInvasiveLesionSize());
    // create LookupInstance from vo LookupType
    ims.domain.lookups.LookupInstance value2 = null;
    if (null != valueObject.getSynchronousTumourIndicator()) {
      value2 = domainFactory.getLookupInstance(valueObject.getSynchronousTumourIndicator().getID());
    }
    domainObject.setSynchronousTumourIndicator(value2);
    domainObject.setHistology(
        ims.clinicaladmin.vo.domain.TumourHistologyLiteVoAssembler.extractTumourHistologySet(
            domainFactory, valueObject.getHistology(), domainObject.getHistology(), domMap));
    // create LookupInstance from vo LookupType
    ims.domain.lookups.LookupInstance value4 = null;
    if (null != valueObject.getVascularLymphInvasion()) {
      value4 = domainFactory.getLookupInstance(valueObject.getVascularLymphInvasion().getID());
    }
    domainObject.setVascularLymphInvasion(value4);
    // create LookupInstance from vo LookupType
    ims.domain.lookups.LookupInstance value5 = null;
    if (null != valueObject.getExcisionMargin()) {
      value5 = domainFactory.getLookupInstance(valueObject.getExcisionMargin().getID());
    }
    domainObject.setExcisionMargin(value5);
    domainObject.setNumberNodesExamined(valueObject.getNumberNodesExamined());
    domainObject.setNodesPositiveNumber(valueObject.getNodesPositiveNumber());
    domainObject.setPathologicalTVal(
        ims.clinicaladmin.vo.domain.TumourGroupSiteTNMValueVoAssembler
            .extractTumourGroupSiteTNMValue(
                domainFactory, valueObject.getPathologicalTVal(), domMap));
    domainObject.setPathologicalNVal(
        ims.clinicaladmin.vo.domain.TumourGroupSiteTNMValueVoAssembler
            .extractTumourGroupSiteTNMValue(
                domainFactory, valueObject.getPathologicalNVal(), domMap));
    domainObject.setPathologicalMVal(
        ims.clinicaladmin.vo.domain.TumourGroupSiteTNMValueVoAssembler
            .extractTumourGroupSiteTNMValue(
                domainFactory, valueObject.getPathologicalMVal(), domMap));
    domainObject.setPathologicalOverall(
        ims.clinicaladmin.vo.domain.TumourGroupSiteOverallStagingVoAssembler
            .extractTumourGroupSiteOverallStaging(
                domainFactory, valueObject.getPathologicalOverall(), 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.getServiceReportId() != null && valueObject.getServiceReportId().equals("")) {
      valueObject.setServiceReportId(null);
    }
    domainObject.setServiceReportId(valueObject.getServiceReportId());
    // create LookupInstance from vo LookupType
    ims.domain.lookups.LookupInstance value13 = null;
    if (null != valueObject.getServiceReportStatus()) {
      value13 = domainFactory.getLookupInstance(valueObject.getServiceReportStatus().getID());
    }
    domainObject.setServiceReportStatus(value13);
    // create LookupInstance from vo LookupType
    ims.domain.lookups.LookupInstance value14 = null;
    if (null != valueObject.getSpecimenNature()) {
      value14 = domainFactory.getLookupInstance(valueObject.getSpecimenNature().getID());
    }
    domainObject.setSpecimenNature(value14);
    domainObject.setOrgaCodeRequester(
        ims.core.vo.domain.OrgLiteVoAssembler.extractOrganisation(
            domainFactory, valueObject.getOrgaCodeRequester(), domMap));
    domainObject.setCareProfCodeRequester(
        ims.core.vo.domain.HcpLiteVoAssembler.extractHcp(
            domainFactory, (ims.core.vo.HcpLiteVo) valueObject.getCareProfCodeRequester(), domMap));
    domainObject.setTCategoryExtended(
        ims.clinicaladmin.vo.domain.TumourGroupSiteTNMValueVoAssembler
            .extractTumourGroupSiteTNMValueSet(
                domainFactory,
                valueObject.getTCategoryExtended(),
                domainObject.getTCategoryExtended(),
                domMap));
    domainObject.setMCategoryExtended(
        ims.clinicaladmin.vo.domain.TumourGroupSiteTNMValueVoAssembler
            .extractTumourGroupSiteTNMValueSet(
                domainFactory,
                valueObject.getMCategoryExtended(),
                domainObject.getMCategoryExtended(),
                domMap));
    // create LookupInstance from vo LookupType
    ims.domain.lookups.LookupInstance value19 = null;
    if (null != valueObject.getStatus()) {
      value19 = domainFactory.getLookupInstance(valueObject.getStatus().getID());
    }
    domainObject.setStatus(value19);
    domainObject.setAuthoringInformation(
        ims.core.vo.domain.AuthoringInformationVoAssembler.extractAuthoringInformation(
            domainFactory, valueObject.getAuthoringInformation(), domMap));
    domainObject.setAssociatedQuestions(
        ims.assessment.vo.domain.PatientAssessmentVoAssembler.extractPatientAssessment(
            domainFactory, valueObject.getAssociatedQuestions(), domMap));
    domainObject.setAssociatiatedTumourDetails(
        ims.oncology.vo.domain.PrimaryTumourDetailsShortVoAssembler.extractPrimaryTumourDetails(
            domainFactory, valueObject.getAssociatiatedTumourDetails(), domMap));
    domainObject.setGradeOfDifferentation(
        ims.clinicaladmin.vo.domain.TumourGroupHistopathologyGradeVoAssembler
            .extractTumourGroupHistopathologicGrade(
                domainFactory, valueObject.getGradeOfDifferentation(), domMap));
    // create LookupInstance from vo LookupType
    ims.domain.lookups.LookupInstance value24 = null;
    if (null != valueObject.getInvestigationType()) {
      value24 = domainFactory.getLookupInstance(valueObject.getInvestigationType().getID());
    }
    domainObject.setInvestigationType(value24);
    java.util.Date value25 = null;
    ims.framework.utils.Date date25 = valueObject.getSampleReceiptDate();
    if (date25 != null) {
      value25 = date25.getDate();
    }
    domainObject.setSampleReceiptDate(value25);
    java.util.Date value26 = null;
    ims.framework.utils.Date date26 = valueObject.getInvestigationResultDate();
    if (date26 != null) {
      value26 = date26.getDate();
    }
    domainObject.setInvestigationResultDate(value26);
    domainObject.setReportingConsultantCode(
        ims.core.vo.domain.HcpLiteVoAssembler.extractHcp(
            domainFactory,
            (ims.core.vo.HcpLiteVo) valueObject.getReportingConsultantCode(),
            domMap));
    domainObject.setReportingOrganisation(
        ims.core.vo.domain.OrgLiteVoAssembler.extractOrganisation(
            domainFactory, valueObject.getReportingOrganisation(), domMap));
    ims.core.admin.domain.objects.CareContext value29 = null;
    if (null != valueObject.getCareContext()) {
      if (valueObject.getCareContext().getBoId() == null) {
        if (domMap.get(valueObject.getCareContext()) != null) {
          value29 =
              (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
      {
        value29 = domainObject.getCareContext();
      } else {
        value29 =
            (ims.core.admin.domain.objects.CareContext)
                domainFactory.getDomainObject(
                    ims.core.admin.domain.objects.CareContext.class,
                    valueObject.getCareContext().getBoId());
      }
    }
    domainObject.setCareContext(value29);
    ims.oncology.domain.objects.PathologyDetails value30 = null;
    if (null != valueObject.getPreviousVersion()) {
      if (valueObject.getPreviousVersion().getBoId() == null) {
        if (domMap.get(valueObject.getPreviousVersion()) != null) {
          value30 =
              (ims.oncology.domain.objects.PathologyDetails)
                  domMap.get(valueObject.getPreviousVersion());
        }
      } else if (valueObject.getBoVersion()
          == -1) // RefVo was not modified since obtained from the Assembler, no need to update the
                 // BO field
      {
        value30 = domainObject.getPreviousVersion();
      } else {
        value30 =
            (ims.oncology.domain.objects.PathologyDetails)
                domainFactory.getDomainObject(
                    ims.oncology.domain.objects.PathologyDetails.class,
                    valueObject.getPreviousVersion().getBoId());
      }
    }
    domainObject.setPreviousVersion(value30);

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

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

    // InvasiveLesionSize
    valueObject.setInvasiveLesionSize(domainObject.getInvasiveLesionSize());
    // SynchronousTumourIndicator
    ims.domain.lookups.LookupInstance instance2 = domainObject.getSynchronousTumourIndicator();
    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.oncology.vo.lookups.SynchronousTumourIndicator voLookup2 =
          new ims.oncology.vo.lookups.SynchronousTumourIndicator(
              instance2.getId(), instance2.getText(), instance2.isActive(), null, img, color);
      ims.oncology.vo.lookups.SynchronousTumourIndicator 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.oncology.vo.lookups.SynchronousTumourIndicator(
                parent2.getId(), parent2.getText(), parent2.isActive(), null, img, color));
        parentVoLookup2 = parentVoLookup2.getParent();
        parent2 = parent2.getParent();
      }
      valueObject.setSynchronousTumourIndicator(voLookup2);
    }
    // Histology
    valueObject.setHistology(
        ims.clinicaladmin.vo.domain.TumourHistologyLiteVoAssembler
            .createTumourHistologyLiteVoCollectionFromTumourHistology(
                map, domainObject.getHistology()));
    // VascularLymphInvasion
    ims.domain.lookups.LookupInstance instance4 = domainObject.getVascularLymphInvasion();
    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.oncology.vo.lookups.VascularLymphInvasion voLookup4 =
          new ims.oncology.vo.lookups.VascularLymphInvasion(
              instance4.getId(), instance4.getText(), instance4.isActive(), null, img, color);
      ims.oncology.vo.lookups.VascularLymphInvasion 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.oncology.vo.lookups.VascularLymphInvasion(
                parent4.getId(), parent4.getText(), parent4.isActive(), null, img, color));
        parentVoLookup4 = parentVoLookup4.getParent();
        parent4 = parent4.getParent();
      }
      valueObject.setVascularLymphInvasion(voLookup4);
    }
    // ExcisionMargin
    ims.domain.lookups.LookupInstance instance5 = domainObject.getExcisionMargin();
    if (null != instance5) {
      ims.framework.utils.ImagePath img = null;
      ims.framework.utils.Color color = null;
      img = null;
      if (instance5.getImage() != null) {
        img =
            new ims.framework.utils.ImagePath(
                instance5.getImage().getImageId(), instance5.getImage().getImagePath());
      }
      color = instance5.getColor();
      if (color != null) color.getValue();

      ims.oncology.vo.lookups.ExcisionMargin voLookup5 =
          new ims.oncology.vo.lookups.ExcisionMargin(
              instance5.getId(), instance5.getText(), instance5.isActive(), null, img, color);
      ims.oncology.vo.lookups.ExcisionMargin parentVoLookup5 = voLookup5;
      ims.domain.lookups.LookupInstance parent5 = instance5.getParent();
      while (parent5 != null) {
        if (parent5.getImage() != null) {
          img =
              new ims.framework.utils.ImagePath(
                  parent5.getImage().getImageId(), parent5.getImage().getImagePath());
        } else {
          img = null;
        }
        color = parent5.getColor();
        if (color != null) color.getValue();
        parentVoLookup5.setParent(
            new ims.oncology.vo.lookups.ExcisionMargin(
                parent5.getId(), parent5.getText(), parent5.isActive(), null, img, color));
        parentVoLookup5 = parentVoLookup5.getParent();
        parent5 = parent5.getParent();
      }
      valueObject.setExcisionMargin(voLookup5);
    }
    // NumberNodesExamined
    valueObject.setNumberNodesExamined(domainObject.getNumberNodesExamined());
    // NodesPositiveNumber
    valueObject.setNodesPositiveNumber(domainObject.getNodesPositiveNumber());
    // PathologicalTVal
    valueObject.setPathologicalTVal(
        ims.clinicaladmin.vo.domain.TumourGroupSiteTNMValueVoAssembler.create(
            map, domainObject.getPathologicalTVal()));
    // PathologicalNVal
    valueObject.setPathologicalNVal(
        ims.clinicaladmin.vo.domain.TumourGroupSiteTNMValueVoAssembler.create(
            map, domainObject.getPathologicalNVal()));
    // PathologicalMVal
    valueObject.setPathologicalMVal(
        ims.clinicaladmin.vo.domain.TumourGroupSiteTNMValueVoAssembler.create(
            map, domainObject.getPathologicalMVal()));
    // PathologicalOverall
    valueObject.setPathologicalOverall(
        ims.clinicaladmin.vo.domain.TumourGroupSiteOverallStagingVoAssembler.create(
            map, domainObject.getPathologicalOverall()));
    // ServiceReportId
    valueObject.setServiceReportId(domainObject.getServiceReportId());
    // ServiceReportStatus
    ims.domain.lookups.LookupInstance instance13 = domainObject.getServiceReportStatus();
    if (null != instance13) {
      ims.framework.utils.ImagePath img = null;
      ims.framework.utils.Color color = null;
      img = null;
      if (instance13.getImage() != null) {
        img =
            new ims.framework.utils.ImagePath(
                instance13.getImage().getImageId(), instance13.getImage().getImagePath());
      }
      color = instance13.getColor();
      if (color != null) color.getValue();

      ims.oncology.vo.lookups.ServiceReportStatus voLookup13 =
          new ims.oncology.vo.lookups.ServiceReportStatus(
              instance13.getId(), instance13.getText(), instance13.isActive(), null, img, color);
      ims.oncology.vo.lookups.ServiceReportStatus parentVoLookup13 = voLookup13;
      ims.domain.lookups.LookupInstance parent13 = instance13.getParent();
      while (parent13 != null) {
        if (parent13.getImage() != null) {
          img =
              new ims.framework.utils.ImagePath(
                  parent13.getImage().getImageId(), parent13.getImage().getImagePath());
        } else {
          img = null;
        }
        color = parent13.getColor();
        if (color != null) color.getValue();
        parentVoLookup13.setParent(
            new ims.oncology.vo.lookups.ServiceReportStatus(
                parent13.getId(), parent13.getText(), parent13.isActive(), null, img, color));
        parentVoLookup13 = parentVoLookup13.getParent();
        parent13 = parent13.getParent();
      }
      valueObject.setServiceReportStatus(voLookup13);
    }
    // SpecimenNature
    ims.domain.lookups.LookupInstance instance14 = domainObject.getSpecimenNature();
    if (null != instance14) {
      ims.framework.utils.ImagePath img = null;
      ims.framework.utils.Color color = null;
      img = null;
      if (instance14.getImage() != null) {
        img =
            new ims.framework.utils.ImagePath(
                instance14.getImage().getImageId(), instance14.getImage().getImagePath());
      }
      color = instance14.getColor();
      if (color != null) color.getValue();

      ims.oncology.vo.lookups.SpecimenNature voLookup14 =
          new ims.oncology.vo.lookups.SpecimenNature(
              instance14.getId(), instance14.getText(), instance14.isActive(), null, img, color);
      ims.oncology.vo.lookups.SpecimenNature parentVoLookup14 = voLookup14;
      ims.domain.lookups.LookupInstance parent14 = instance14.getParent();
      while (parent14 != null) {
        if (parent14.getImage() != null) {
          img =
              new ims.framework.utils.ImagePath(
                  parent14.getImage().getImageId(), parent14.getImage().getImagePath());
        } else {
          img = null;
        }
        color = parent14.getColor();
        if (color != null) color.getValue();
        parentVoLookup14.setParent(
            new ims.oncology.vo.lookups.SpecimenNature(
                parent14.getId(), parent14.getText(), parent14.isActive(), null, img, color));
        parentVoLookup14 = parentVoLookup14.getParent();
        parent14 = parent14.getParent();
      }
      valueObject.setSpecimenNature(voLookup14);
    }
    // OrgaCodeRequester
    valueObject.setOrgaCodeRequester(
        ims.core.vo.domain.OrgLiteVoAssembler.create(map, domainObject.getOrgaCodeRequester()));
    // CareProfCodeRequester
    valueObject.setCareProfCodeRequester(
        (ims.core.vo.HcpLiteVo)
            ims.core.vo.domain.HcpLiteVoAssembler.create(
                map, domainObject.getCareProfCodeRequester()));
    // TCategoryExtended
    valueObject.setTCategoryExtended(
        ims.clinicaladmin.vo.domain.TumourGroupSiteTNMValueVoAssembler
            .createTumourGroupSiteTNMValueVoCollectionFromTumourGroupSiteTNMValue(
                map, domainObject.getTCategoryExtended()));
    // MCategoryExtended
    valueObject.setMCategoryExtended(
        ims.clinicaladmin.vo.domain.TumourGroupSiteTNMValueVoAssembler
            .createTumourGroupSiteTNMValueVoCollectionFromTumourGroupSiteTNMValue(
                map, domainObject.getMCategoryExtended()));
    // Status
    ims.domain.lookups.LookupInstance instance19 = domainObject.getStatus();
    if (null != instance19) {
      ims.framework.utils.ImagePath img = null;
      ims.framework.utils.Color color = null;
      img = null;
      if (instance19.getImage() != null) {
        img =
            new ims.framework.utils.ImagePath(
                instance19.getImage().getImageId(), instance19.getImage().getImagePath());
      }
      color = instance19.getColor();
      if (color != null) color.getValue();

      ims.oncology.vo.lookups.HistopathologyReportStatus voLookup19 =
          new ims.oncology.vo.lookups.HistopathologyReportStatus(
              instance19.getId(), instance19.getText(), instance19.isActive(), null, img, color);
      ims.oncology.vo.lookups.HistopathologyReportStatus parentVoLookup19 = voLookup19;
      ims.domain.lookups.LookupInstance parent19 = instance19.getParent();
      while (parent19 != null) {
        if (parent19.getImage() != null) {
          img =
              new ims.framework.utils.ImagePath(
                  parent19.getImage().getImageId(), parent19.getImage().getImagePath());
        } else {
          img = null;
        }
        color = parent19.getColor();
        if (color != null) color.getValue();
        parentVoLookup19.setParent(
            new ims.oncology.vo.lookups.HistopathologyReportStatus(
                parent19.getId(), parent19.getText(), parent19.isActive(), null, img, color));
        parentVoLookup19 = parentVoLookup19.getParent();
        parent19 = parent19.getParent();
      }
      valueObject.setStatus(voLookup19);
    }
    // AuthoringInformation
    valueObject.setAuthoringInformation(
        ims.core.vo.domain.AuthoringInformationVoAssembler.create(
            map, domainObject.getAuthoringInformation()));
    // AssociatedQuestions
    valueObject.setAssociatedQuestions(
        ims.assessment.vo.domain.PatientAssessmentVoAssembler.create(
            map, domainObject.getAssociatedQuestions()));
    // AssociatiatedTumourDetails
    valueObject.setAssociatiatedTumourDetails(
        ims.oncology.vo.domain.PrimaryTumourDetailsShortVoAssembler.create(
            map, domainObject.getAssociatiatedTumourDetails()));
    // GradeOfDifferentation
    valueObject.setGradeOfDifferentation(
        ims.clinicaladmin.vo.domain.TumourGroupHistopathologyGradeVoAssembler.create(
            map, domainObject.getGradeOfDifferentation()));
    // InvestigationType
    ims.domain.lookups.LookupInstance instance24 = domainObject.getInvestigationType();
    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.oncology.vo.lookups.InvestigationType voLookup24 =
          new ims.oncology.vo.lookups.InvestigationType(
              instance24.getId(), instance24.getText(), instance24.isActive(), null, img, color);
      ims.oncology.vo.lookups.InvestigationType 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.oncology.vo.lookups.InvestigationType(
                parent24.getId(), parent24.getText(), parent24.isActive(), null, img, color));
        parentVoLookup24 = parentVoLookup24.getParent();
        parent24 = parent24.getParent();
      }
      valueObject.setInvestigationType(voLookup24);
    }
    // SampleReceiptDate
    java.util.Date SampleReceiptDate = domainObject.getSampleReceiptDate();
    if (null != SampleReceiptDate) {
      valueObject.setSampleReceiptDate(new ims.framework.utils.Date(SampleReceiptDate));
    }
    // InvestigationResultDate
    java.util.Date InvestigationResultDate = domainObject.getInvestigationResultDate();
    if (null != InvestigationResultDate) {
      valueObject.setInvestigationResultDate(new ims.framework.utils.Date(InvestigationResultDate));
    }
    // ReportingConsultantCode
    valueObject.setReportingConsultantCode(
        (ims.core.vo.HcpLiteVo)
            ims.core.vo.domain.HcpLiteVoAssembler.create(
                map, domainObject.getReportingConsultantCode()));
    // ReportingOrganisation
    valueObject.setReportingOrganisation(
        ims.core.vo.domain.OrgLiteVoAssembler.create(map, domainObject.getReportingOrganisation()));
    // CareContext
    if (domainObject.getCareContext() != null) {
      if (domainObject.getCareContext()
          instanceof
          HibernateProxy) // If the proxy is set, there is no need to lazy load, the proxy knows the
                          // id already.
      {
        HibernateProxy p = (HibernateProxy) domainObject.getCareContext();
        int id = Integer.parseInt(p.getHibernateLazyInitializer().getIdentifier().toString());
        valueObject.setCareContext(new ims.core.admin.vo.CareContextRefVo(id, -1));
      } else {
        valueObject.setCareContext(
            new ims.core.admin.vo.CareContextRefVo(
                domainObject.getCareContext().getId(), domainObject.getCareContext().getVersion()));
      }
    }
    // PreviousVersion
    if (domainObject.getPreviousVersion() != null) {
      if (domainObject.getPreviousVersion()
          instanceof
          HibernateProxy) // If the proxy is set, there is no need to lazy load, the proxy knows the
                          // id already.
      {
        HibernateProxy p = (HibernateProxy) domainObject.getPreviousVersion();
        int id = Integer.parseInt(p.getHibernateLazyInitializer().getIdentifier().toString());
        valueObject.setPreviousVersion(new ims.oncology.vo.PathologyDetailsRefVo(id, -1));
      } else {
        valueObject.setPreviousVersion(
            new ims.oncology.vo.PathologyDetailsRefVo(
                domainObject.getPreviousVersion().getId(),
                domainObject.getPreviousVersion().getVersion()));
      }
    }
    return valueObject;
  }
  public static ims.clinical.domain.objects.PatientProcedureChecklist
      extractPatientProcedureChecklist(
          ims.domain.ILightweightDomainFactory domainFactory,
          ims.clinical.vo.PatientProcedureChecklistVo valueObject,
          HashMap domMap) {
    if (null == valueObject) {
      return null;
    }
    Integer id = valueObject.getID_PatientProcedureChecklist();
    ims.clinical.domain.objects.PatientProcedureChecklist domainObject = null;
    if (null == id) {
      if (domMap.get(valueObject) != null) {
        return (ims.clinical.domain.objects.PatientProcedureChecklist) domMap.get(valueObject);
      }
      // ims.clinical.vo.PatientProcedureChecklistVo ID_PatientProcedureChecklist field is unknown
      domainObject = new ims.clinical.domain.objects.PatientProcedureChecklist();
      domMap.put(valueObject, domainObject);
    } else {
      String key =
          (valueObject.getClass().getName() + "__" + valueObject.getID_PatientProcedureChecklist());
      if (domMap.get(key) != null) {
        return (ims.clinical.domain.objects.PatientProcedureChecklist) domMap.get(key);
      }
      domainObject =
          (ims.clinical.domain.objects.PatientProcedureChecklist)
              domainFactory.getDomainObject(
                  ims.clinical.domain.objects.PatientProcedureChecklist.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_PatientProcedureChecklist());

    ims.core.admin.domain.objects.ClinicalContact value1 = null;
    if (null != valueObject.getClinicalContact()) {
      if (valueObject.getClinicalContact().getBoId() == null) {
        if (domMap.get(valueObject.getClinicalContact()) != null) {
          value1 =
              (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
      {
        value1 = domainObject.getClinicalContact();
      } else {
        value1 =
            (ims.core.admin.domain.objects.ClinicalContact)
                domainFactory.getDomainObject(
                    ims.core.admin.domain.objects.ClinicalContact.class,
                    valueObject.getClinicalContact().getBoId());
      }
    }
    domainObject.setClinicalContact(value1);
    domainObject.setPresentProcedures(
        ims.core.vo.domain.PatientProcedureVoAssembler.extractPatientProcedureSet(
            domainFactory,
            valueObject.getPresentProcedures(),
            domainObject.getPresentProcedures(),
            domMap));
    domainObject.setOtherProcedures(
        ims.clinical.vo.domain.PatientAbsentProcedureVoAssembler.extractPatientAbsentProcedureSet(
            domainFactory,
            valueObject.getOtherProcedures(),
            domainObject.getOtherProcedures(),
            domMap));
    domainObject.setAuthoringInformation(
        ims.core.vo.domain.AuthoringInformationVoAssembler.extractAuthoringInformation(
            domainFactory, valueObject.getAuthoringInformation(), domMap));

    return domainObject;
  }
  public static ims.RefMan.domain.objects.ConsultationClinicalNotes
      extractConsultationClinicalNotes(
          ims.domain.ILightweightDomainFactory domainFactory,
          ims.RefMan.vo.ConsultationClinicalNotesVo valueObject,
          HashMap domMap) {
    if (null == valueObject) {
      return null;
    }
    Integer id = valueObject.getID_ConsultationClinicalNotes();
    ims.RefMan.domain.objects.ConsultationClinicalNotes domainObject = null;
    if (null == id) {
      if (domMap.get(valueObject) != null) {
        return (ims.RefMan.domain.objects.ConsultationClinicalNotes) domMap.get(valueObject);
      }
      // ims.RefMan.vo.ConsultationClinicalNotesVo ID_ConsultationClinicalNotes field is unknown
      domainObject = new ims.RefMan.domain.objects.ConsultationClinicalNotes();
      domMap.put(valueObject, domainObject);
    } else {
      String key =
          (valueObject.getClass().getName() + "__" + valueObject.getID_ConsultationClinicalNotes());
      if (domMap.get(key) != null) {
        return (ims.RefMan.domain.objects.ConsultationClinicalNotes) domMap.get(key);
      }
      domainObject =
          (ims.RefMan.domain.objects.ConsultationClinicalNotes)
              domainFactory.getDomainObject(
                  ims.RefMan.domain.objects.ConsultationClinicalNotes.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_ConsultationClinicalNotes());

    // 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.getHistoryPresentingComplaint() != null
        && valueObject.getHistoryPresentingComplaint().equals("")) {
      valueObject.setHistoryPresentingComplaint(null);
    }
    domainObject.setHistoryPresentingComplaint(valueObject.getHistoryPresentingComplaint());
    // 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.getRelevantPMH() != null && valueObject.getRelevantPMH().equals("")) {
      valueObject.setRelevantPMH(null);
    }
    domainObject.setRelevantPMH(valueObject.getRelevantPMH());
    // 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.getOtherRelevantHistory() != null
        && valueObject.getOtherRelevantHistory().equals("")) {
      valueObject.setOtherRelevantHistory(null);
    }
    domainObject.setOtherRelevantHistory(valueObject.getOtherRelevantHistory());
    // 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.getRelevantMedication() != null
        && valueObject.getRelevantMedication().equals("")) {
      valueObject.setRelevantMedication(null);
    }
    domainObject.setRelevantMedication(valueObject.getRelevantMedication());
    // 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.getExamination() != null && valueObject.getExamination().equals("")) {
      valueObject.setExamination(null);
    }
    domainObject.setExamination(valueObject.getExamination());
    domainObject.setHasNoKnownAllergies(valueObject.getHasNoKnownAllergies());
    domainObject.setAllergies(
        ims.core.vo.domain.PatientAllergyAssembler.extractPatientAllergySet(
            domainFactory, valueObject.getAllergies(), domainObject.getAllergies(), domMap));
    domainObject.setSeeScannedNotes(valueObject.getSeeScannedNotes());
    domainObject.setNotesDictated(valueObject.getNotesDictated());
    domainObject.setIncludeNotesInGpReport(valueObject.getIncludeNotesInGpReport());
    // 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.getClinicalImpression() != null
        && valueObject.getClinicalImpression().equals("")) {
      valueObject.setClinicalImpression(null);
    }
    domainObject.setClinicalImpression(valueObject.getClinicalImpression());
    domainObject.setHealthQuestionnaireCompleted(valueObject.getHealthQuestionnaireCompleted());
    ims.RefMan.domain.objects.CatsReferral value13 = null;
    if (null != valueObject.getCatsReferral()) {
      if (valueObject.getCatsReferral().getBoId() == null) {
        if (domMap.get(valueObject.getCatsReferral()) != null) {
          value13 =
              (ims.RefMan.domain.objects.CatsReferral) domMap.get(valueObject.getCatsReferral());
        }
      } else if (valueObject.getBoVersion()
          == -1) // RefVo was not modified since obtained from the Assembler, no need to update the
                 // BO field
      {
        value13 = domainObject.getCatsReferral();
      } else {
        value13 =
            (ims.RefMan.domain.objects.CatsReferral)
                domainFactory.getDomainObject(
                    ims.RefMan.domain.objects.CatsReferral.class,
                    valueObject.getCatsReferral().getBoId());
      }
    }
    domainObject.setCatsReferral(value13);
    domainObject.setRecordingInformation(
        ims.core.vo.domain.AuthoringInformationVoAssembler.extractAuthoringInformation(
            domainFactory, valueObject.getRecordingInformation(), domMap));
    domainObject.setLastUpdatingHCP(
        ims.core.vo.domain.AuthoringInformationVoAssembler.extractAuthoringInformation(
            domainFactory, valueObject.getLastUpdatingHCP(), domMap));
    domainObject.setInitiallySeenBy(
        ims.core.vo.domain.AuthoringInformationVoAssembler.extractAuthoringInformation(
            domainFactory, valueObject.getInitiallySeenBy(), domMap));

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

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

    // HistoryPresentingComplaint
    valueObject.setHistoryPresentingComplaint(domainObject.getHistoryPresentingComplaint());
    // RelevantPMH
    valueObject.setRelevantPMH(domainObject.getRelevantPMH());
    // OtherRelevantHistory
    valueObject.setOtherRelevantHistory(domainObject.getOtherRelevantHistory());
    // RelevantMedication
    valueObject.setRelevantMedication(domainObject.getRelevantMedication());
    // Examination
    valueObject.setExamination(domainObject.getExamination());
    // hasNoKnownAllergies
    valueObject.setHasNoKnownAllergies(domainObject.isHasNoKnownAllergies());
    // Allergies
    valueObject.setAllergies(
        ims.core.vo.domain.PatientAllergyAssembler.createPatientAllergyCollectionFromPatientAllergy(
            map, domainObject.getAllergies()));
    // seeScannedNotes
    valueObject.setSeeScannedNotes(domainObject.isSeeScannedNotes());
    // NotesDictated
    valueObject.setNotesDictated(domainObject.isNotesDictated());
    // IncludeNotesInGpReport
    valueObject.setIncludeNotesInGpReport(domainObject.isIncludeNotesInGpReport());
    // ClinicalImpression
    valueObject.setClinicalImpression(domainObject.getClinicalImpression());
    // HealthQuestionnaireCompleted
    valueObject.setHealthQuestionnaireCompleted(domainObject.isHealthQuestionnaireCompleted());
    // CatsReferral
    if (domainObject.getCatsReferral() != null) {
      if (domainObject.getCatsReferral()
          instanceof
          HibernateProxy) // If the proxy is set, there is no need to lazy load, the proxy knows the
                          // id already.
      {
        HibernateProxy p = (HibernateProxy) domainObject.getCatsReferral();
        int id = Integer.parseInt(p.getHibernateLazyInitializer().getIdentifier().toString());
        valueObject.setCatsReferral(new ims.RefMan.vo.CatsReferralRefVo(id, -1));
      } else {
        valueObject.setCatsReferral(
            new ims.RefMan.vo.CatsReferralRefVo(
                domainObject.getCatsReferral().getId(),
                domainObject.getCatsReferral().getVersion()));
      }
    }
    // RecordingInformation
    valueObject.setRecordingInformation(
        ims.core.vo.domain.AuthoringInformationVoAssembler.create(
            map, domainObject.getRecordingInformation()));
    // LastUpdatingHCP
    valueObject.setLastUpdatingHCP(
        ims.core.vo.domain.AuthoringInformationVoAssembler.create(
            map, domainObject.getLastUpdatingHCP()));
    // InitiallySeenBy
    valueObject.setInitiallySeenBy(
        ims.core.vo.domain.AuthoringInformationVoAssembler.create(
            map, domainObject.getInitiallySeenBy()));
    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.icps.instantiation.domain.objects.PatientICP
   */
  public static ims.icp.vo.PatientICPVo insert(
      DomainObjectMap map,
      ims.icp.vo.PatientICPVo valueObject,
      ims.icps.instantiation.domain.objects.PatientICP domainObject) {
    if (null == domainObject) {
      return valueObject;
    }
    if (null == map) {
      map = new DomainObjectMap();
    }

    valueObject.setID_PatientICP(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()));
      }
    }
    // CareContext
    if (domainObject.getCareContext() != null) {
      if (domainObject.getCareContext()
          instanceof
          HibernateProxy) // If the proxy is set, there is no need to lazy load, the proxy knows the
                          // id already.
      {
        HibernateProxy p = (HibernateProxy) domainObject.getCareContext();
        int id = Integer.parseInt(p.getHibernateLazyInitializer().getIdentifier().toString());
        valueObject.setCareContext(new ims.core.admin.vo.CareContextRefVo(id, -1));
      } else {
        valueObject.setCareContext(
            new ims.core.admin.vo.CareContextRefVo(
                domainObject.getCareContext().getId(), domainObject.getCareContext().getVersion()));
      }
    }
    // 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()));
      }
    }
    // 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()));
      }
    }
    // ICP
    valueObject.setICP(ims.icp.vo.domain.ICPLiteVoAssembler.create(map, domainObject.getICP()));
    // AuthoringInformation
    valueObject.setAuthoringInformation(
        ims.core.vo.domain.AuthoringInformationVoAssembler.create(
            map, domainObject.getAuthoringInformation()));
    // Stages
    valueObject.setStages(
        ims.icp.vo.domain.PatientICPStageVoAssembler
            .createPatientICPStageVoCollectionFromPatientICPStage(map, domainObject.getStages()));
    // hasOutstandingAdminActions
    valueObject.setHasOutstandingAdminActions(domainObject.isHasOutstandingAdminActions());
    // hasOutstandingNursingActions
    valueObject.setHasOutstandingNursingActions(domainObject.isHasOutstandingNursingActions());
    // hasOutstandingPhysioActions
    valueObject.setHasOutstandingPhysioActions(domainObject.isHasOutstandingPhysioActions());
    // hasOutstandingClinicalActions
    valueObject.setHasOutstandingClinicalActions(domainObject.isHasOutstandingClinicalActions());
    // Appointments
    ims.scheduling.vo.Booking_AppointmentRefVoCollection Appointments =
        new ims.scheduling.vo.Booking_AppointmentRefVoCollection();
    for (java.util.Iterator iterator = domainObject.getAppointments().iterator();
        iterator.hasNext(); ) {
      ims.scheduling.domain.objects.Booking_Appointment tmp =
          (ims.scheduling.domain.objects.Booking_Appointment) iterator.next();
      if (tmp != null)
        Appointments.add(
            new ims.scheduling.vo.Booking_AppointmentRefVo(tmp.getId(), tmp.getVersion()));
    }
    valueObject.setAppointments(Appointments);
    // CriticalEvents
    ims.icps.instantiation.vo.PatientCriticalEventsRefVoCollection CriticalEvents =
        new ims.icps.instantiation.vo.PatientCriticalEventsRefVoCollection();
    for (java.util.Iterator iterator = domainObject.getCriticalEvents().iterator();
        iterator.hasNext(); ) {
      ims.icps.instantiation.domain.objects.PatientCriticalEvents tmp =
          (ims.icps.instantiation.domain.objects.PatientCriticalEvents) iterator.next();
      if (tmp != null)
        CriticalEvents.add(
            new ims.icps.instantiation.vo.PatientCriticalEventsRefVo(
                tmp.getId(), tmp.getVersion()));
    }
    valueObject.setCriticalEvents(CriticalEvents);
    // StartedDateTime
    java.util.Date StartedDateTime = domainObject.getStartedDateTime();
    if (null != StartedDateTime) {
      valueObject.setStartedDateTime(new ims.framework.utils.DateTime(StartedDateTime));
    }
    // CompletedDateTime
    java.util.Date CompletedDateTime = domainObject.getCompletedDateTime();
    if (null != CompletedDateTime) {
      valueObject.setCompletedDateTime(new ims.framework.utils.DateTime(CompletedDateTime));
    }
    // EvaluationNotes
    ims.icps.instantiation.vo.PatientICPEvaluationNoteRefVoCollection EvaluationNotes =
        new ims.icps.instantiation.vo.PatientICPEvaluationNoteRefVoCollection();
    for (java.util.Iterator iterator = domainObject.getEvaluationNotes().iterator();
        iterator.hasNext(); ) {
      ims.icps.instantiation.domain.objects.PatientICPEvaluationNote tmp =
          (ims.icps.instantiation.domain.objects.PatientICPEvaluationNote) iterator.next();
      if (tmp != null)
        EvaluationNotes.add(
            new ims.icps.instantiation.vo.PatientICPEvaluationNoteRefVo(
                tmp.getId(), tmp.getVersion()));
    }
    valueObject.setEvaluationNotes(EvaluationNotes);
    return valueObject;
  }
  public static ims.medical.domain.objects.OPDSpasticityAssessTreat extractOPDSpasticityAssessTreat(
      ims.domain.ILightweightDomainFactory domainFactory,
      ims.generalmedical.vo.OPDSpasticityAssessTreatVo valueObject,
      HashMap domMap) {
    if (null == valueObject) {
      return null;
    }
    Integer id = valueObject.getID_OPDSpasticityAssessTreat();
    ims.medical.domain.objects.OPDSpasticityAssessTreat domainObject = null;
    if (null == id) {
      if (domMap.get(valueObject) != null) {
        return (ims.medical.domain.objects.OPDSpasticityAssessTreat) domMap.get(valueObject);
      }
      // ims.generalmedical.vo.OPDSpasticityAssessTreatVo ID_OPDSpasticityAssessTreat field is
      // unknown
      domainObject = new ims.medical.domain.objects.OPDSpasticityAssessTreat();
      domMap.put(valueObject, domainObject);
    } else {
      String key =
          (valueObject.getClass().getName() + "__" + valueObject.getID_OPDSpasticityAssessTreat());
      if (domMap.get(key) != null) {
        return (ims.medical.domain.objects.OPDSpasticityAssessTreat) domMap.get(key);
      }
      domainObject =
          (ims.medical.domain.objects.OPDSpasticityAssessTreat)
              domainFactory.getDomainObject(
                  ims.medical.domain.objects.OPDSpasticityAssessTreat.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_OPDSpasticityAssessTreat());

    domainObject.setTreatGoals(
        ims.generalmedical.vo.domain.OPDSpasticityAssessTreatGoalVoAssembler
            .extractOPDSpasAssessTreatGoalSet(
                domainFactory, valueObject.getTreatGoals(), domainObject.getTreatGoals(), domMap));
    ims.spinalinjuries.vo.lookups.SATreatmentPlanCollection collection2 =
        valueObject.getTreatmentPlan();
    java.util.List domainTreatmentPlan = domainObject.getTreatmentPlan();
    ;
    int collection2Size = 0;
    if (collection2 == null) {
      domainTreatmentPlan = new java.util.ArrayList(0);
    } else {
      collection2Size = collection2.size();
    }

    for (int i = 0; i < collection2Size; i++) {
      int instanceId = collection2.get(i).getID();
      ims.domain.lookups.LookupInstanceRef dom =
          new ims.domain.lookups.LookupInstanceRef(domainFactory.getLookupInstance(instanceId));

      int domIdx = domainTreatmentPlan.indexOf(dom);
      if (domIdx == -1) {
        domainTreatmentPlan.add(i, dom);
      } else if (i != domIdx && i < domainTreatmentPlan.size()) {
        Object tmp = domainTreatmentPlan.get(i);
        domainTreatmentPlan.set(i, domainTreatmentPlan.get(domIdx));
        domainTreatmentPlan.set(domIdx, tmp);
      }
    }

    // Remove all ones in domList where index > voCollection.size() as these should
    // now represent the ones removed from the VO collection. No longer referenced.
    int j2 = domainTreatmentPlan.size();
    while (j2 > collection2Size) {
      domainTreatmentPlan.remove(j2 - 1);
      j2 = domainTreatmentPlan.size();
    }

    domainObject.setTreatmentPlan(domainTreatmentPlan);
    ims.spinalinjuries.vo.lookups.SABotulinmCollection collection3 =
        valueObject.getBotulismTreatment();
    java.util.List domainBotulismTreatment = domainObject.getBotulismTreatment();
    ;
    int collection3Size = 0;
    if (collection3 == null) {
      domainBotulismTreatment = new java.util.ArrayList(0);
    } else {
      collection3Size = collection3.size();
    }

    for (int i = 0; i < collection3Size; i++) {
      int instanceId = collection3.get(i).getID();
      ims.domain.lookups.LookupInstanceRef dom =
          new ims.domain.lookups.LookupInstanceRef(domainFactory.getLookupInstance(instanceId));

      int domIdx = domainBotulismTreatment.indexOf(dom);
      if (domIdx == -1) {
        domainBotulismTreatment.add(i, dom);
      } else if (i != domIdx && i < domainBotulismTreatment.size()) {
        Object tmp = domainBotulismTreatment.get(i);
        domainBotulismTreatment.set(i, domainBotulismTreatment.get(domIdx));
        domainBotulismTreatment.set(domIdx, tmp);
      }
    }

    // Remove all ones in domList where index > voCollection.size() as these should
    // now represent the ones removed from the VO collection. No longer referenced.
    int j3 = domainBotulismTreatment.size();
    while (j3 > collection3Size) {
      domainBotulismTreatment.remove(j3 - 1);
      j3 = domainBotulismTreatment.size();
    }

    domainObject.setBotulismTreatment(domainBotulismTreatment);
    // 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.getJointContracture() != null && valueObject.getJointContracture().equals("")) {
      valueObject.setJointContracture(null);
    }
    domainObject.setJointContracture(valueObject.getJointContracture());
    domainObject.setLimbFinding(
        ims.generalmedical.vo.domain.OPDSpasAssLimbsVoAssembler.extractOPDSpasAssLimbsSet(
            domainFactory, valueObject.getLimbFinding(), domainObject.getLimbFinding(), domMap));
    // SaveAsRefVO - treated as a refVo in extract methods
    ims.core.admin.domain.objects.CareContext value6 = null;
    if (null != valueObject.getCareContext()) {
      if (valueObject.getCareContext().getBoId() == null) {
        if (domMap.get(valueObject.getCareContext()) != null) {
          value6 =
              (ims.core.admin.domain.objects.CareContext) domMap.get(valueObject.getCareContext());
        }
      } else {
        value6 =
            (ims.core.admin.domain.objects.CareContext)
                domainFactory.getDomainObject(
                    ims.core.admin.domain.objects.CareContext.class,
                    valueObject.getCareContext().getBoId());
      }
    }
    domainObject.setCareContext(value6);
    domainObject.setAuthoringInformation(
        ims.core.vo.domain.AuthoringInformationVoAssembler.extractAuthoringInformation(
            domainFactory, valueObject.getAuthoringInformation(), domMap));

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

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

    // TreatGoals
    valueObject.setTreatGoals(
        ims.generalmedical.vo.domain.OPDSpasticityAssessTreatGoalVoAssembler
            .createOPDSpasticityAssessTreatGoalVoCollectionFromOPDSpasAssessTreatGoal(
                map, domainObject.getTreatGoals()));
    // TreatmentPlan
    java.util.List listTreatmentPlan = domainObject.getTreatmentPlan();
    ims.spinalinjuries.vo.lookups.SATreatmentPlanCollection TreatmentPlan =
        new ims.spinalinjuries.vo.lookups.SATreatmentPlanCollection();
    for (java.util.Iterator iterator = listTreatmentPlan.iterator(); iterator.hasNext(); ) {
      ims.framework.utils.ImagePath img = null;
      ims.framework.utils.Color color = null;

      ims.domain.lookups.LookupInstance instance =
          (ims.domain.lookups.LookupInstance) iterator.next();
      if (instance.getImage() != null) {
        img =
            new ims.framework.utils.ImagePath(
                instance.getImage().getImageId(), instance.getImage().getImagePath());
      } else {
        img = null;
      }
      color = instance.getColor();
      if (color != null) color.getValue();
      ims.spinalinjuries.vo.lookups.SATreatmentPlan voInstance =
          new ims.spinalinjuries.vo.lookups.SATreatmentPlan(
              instance.getId(), instance.getText(), instance.isActive(), null, img, color);
      ims.spinalinjuries.vo.lookups.SATreatmentPlan parentVoInstance = voInstance;
      ims.domain.lookups.LookupInstance parent = instance.getParent();
      while (parent != null) {
        if (parent.getImage() != null) {
          img =
              new ims.framework.utils.ImagePath(
                  parent.getImage().getImageId(), parent.getImage().getImagePath());
        } else {
          img = null;
        }
        color = parent.getColor();
        if (color != null) color.getValue();
        parentVoInstance.setParent(
            new ims.spinalinjuries.vo.lookups.SATreatmentPlan(
                parent.getId(), parent.getText(), parent.isActive(), null, img, color));
        parentVoInstance = parentVoInstance.getParent();
        parent = parent.getParent();
      }
      TreatmentPlan.add(voInstance);
    }
    valueObject.setTreatmentPlan(TreatmentPlan);
    // BotulismTreatment
    java.util.List listBotulismTreatment = domainObject.getBotulismTreatment();
    ims.spinalinjuries.vo.lookups.SABotulinmCollection BotulismTreatment =
        new ims.spinalinjuries.vo.lookups.SABotulinmCollection();
    for (java.util.Iterator iterator = listBotulismTreatment.iterator(); iterator.hasNext(); ) {
      ims.framework.utils.ImagePath img = null;
      ims.framework.utils.Color color = null;

      ims.domain.lookups.LookupInstance instance =
          (ims.domain.lookups.LookupInstance) iterator.next();
      if (instance.getImage() != null) {
        img =
            new ims.framework.utils.ImagePath(
                instance.getImage().getImageId(), instance.getImage().getImagePath());
      } else {
        img = null;
      }
      color = instance.getColor();
      if (color != null) color.getValue();
      ims.spinalinjuries.vo.lookups.SABotulinm voInstance =
          new ims.spinalinjuries.vo.lookups.SABotulinm(
              instance.getId(), instance.getText(), instance.isActive(), null, img, color);
      ims.spinalinjuries.vo.lookups.SABotulinm parentVoInstance = voInstance;
      ims.domain.lookups.LookupInstance parent = instance.getParent();
      while (parent != null) {
        if (parent.getImage() != null) {
          img =
              new ims.framework.utils.ImagePath(
                  parent.getImage().getImageId(), parent.getImage().getImagePath());
        } else {
          img = null;
        }
        color = parent.getColor();
        if (color != null) color.getValue();
        parentVoInstance.setParent(
            new ims.spinalinjuries.vo.lookups.SABotulinm(
                parent.getId(), parent.getText(), parent.isActive(), null, img, color));
        parentVoInstance = parentVoInstance.getParent();
        parent = parent.getParent();
      }
      BotulismTreatment.add(voInstance);
    }
    valueObject.setBotulismTreatment(BotulismTreatment);
    // JointContracture
    valueObject.setJointContracture(domainObject.getJointContracture());
    // LimbFinding
    valueObject.setLimbFinding(
        ims.generalmedical.vo.domain.OPDSpasAssLimbsVoAssembler
            .createOPDSpasAssLimbsVoCollectionFromOPDSpasAssLimbs(
                map, domainObject.getLimbFinding()));
    // CareContext
    valueObject.setCareContext(
        ims.core.vo.domain.CareContextShortVoAssembler.create(map, domainObject.getCareContext()));
    // AuthoringInformation
    valueObject.setAuthoringInformation(
        ims.core.vo.domain.AuthoringInformationVoAssembler.create(
            map, domainObject.getAuthoringInformation()));
    return valueObject;
  }
  public static ims.RefMan.domain.objects.ReportNote extractReportNote(
      ims.domain.ILightweightDomainFactory domainFactory,
      ims.RefMan.vo.CorrespondenceNoteLiteVo valueObject,
      HashMap domMap) {
    if (null == valueObject) {
      return null;
    }
    Integer id = valueObject.getID_ReportNote();
    ims.RefMan.domain.objects.ReportNote domainObject = null;
    if (null == id) {
      if (domMap.get(valueObject) != null) {
        return (ims.RefMan.domain.objects.ReportNote) domMap.get(valueObject);
      }
      // ims.RefMan.vo.CorrespondenceNoteLiteVo ID_ReportNote field is unknown
      domainObject = new ims.RefMan.domain.objects.ReportNote();
      domMap.put(valueObject, domainObject);
    } else {
      String key = (valueObject.getClass().getName() + "__" + valueObject.getID_ReportNote());
      if (domMap.get(key) != null) {
        return (ims.RefMan.domain.objects.ReportNote) domMap.get(key);
      }
      domainObject =
          (ims.RefMan.domain.objects.ReportNote)
              domainFactory.getDomainObject(ims.RefMan.domain.objects.ReportNote.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_ReportNote());

    ims.RefMan.domain.objects.CatsReferral value1 = null;
    if (null != valueObject.getCatsReferral()) {
      if (valueObject.getCatsReferral().getBoId() == null) {
        if (domMap.get(valueObject.getCatsReferral()) != null) {
          value1 =
              (ims.RefMan.domain.objects.CatsReferral) domMap.get(valueObject.getCatsReferral());
        }
      } else if (valueObject.getBoVersion()
          == -1) // RefVo was not modified since obtained from the Assembler, no need to update the
                 // BO field
      {
        value1 = domainObject.getCatsReferral();
      } else {
        value1 =
            (ims.RefMan.domain.objects.CatsReferral)
                domainFactory.getDomainObject(
                    ims.RefMan.domain.objects.CatsReferral.class,
                    valueObject.getCatsReferral().getBoId());
      }
    }
    domainObject.setCatsReferral(value1);
    domainObject.setAuthoringInformation(
        ims.core.vo.domain.AuthoringInformationVoAssembler.extractAuthoringInformation(
            domainFactory, valueObject.getAuthoringInformation(), domMap));
    domainObject.setRecordingInformation(
        ims.core.vo.domain.AuthoringInformationVoAssembler.extractAuthoringInformation(
            domainFactory, valueObject.getRecordingInformation(), domMap));

    return domainObject;
  }