/**
   * Create the ValueObject from the ims.core.clinical.domain.objects.PatientDiagnosis object.
   *
   * @param map DomainObjectMap of DomainObjects to already created ValueObjects.
   * @param domainObject
   */
  public static ims.core.vo.PatientDiagnosisEDischargeVo create(
      DomainObjectMap map, ims.core.clinical.domain.objects.PatientDiagnosis domainObject) {
    if (null == domainObject) {
      return null;
    }
    // check if the domainObject already has a valueObject created for it
    ims.core.vo.PatientDiagnosisEDischargeVo valueObject =
        (ims.core.vo.PatientDiagnosisEDischargeVo)
            map.getValueObject(domainObject, ims.core.vo.PatientDiagnosisEDischargeVo.class);
    if (null == valueObject) {
      valueObject =
          new ims.core.vo.PatientDiagnosisEDischargeVo(
              domainObject.getId(), domainObject.getVersion());
      map.addValueObject(domainObject, valueObject);

      valueObject = insert(map, valueObject, domainObject);
    }
    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.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;
  }