/**
  * Copy one ValueObject to another
  *
  * @param valueObjectDest to be updated
  * @param valueObjectSrc to copy values from
  */
 public static ims.core.vo.IncludeDiagnosisInDischargeReportVo copy(
     ims.core.vo.IncludeDiagnosisInDischargeReportVo valueObjectDest,
     ims.core.vo.IncludeDiagnosisInDischargeReportVo valueObjectSrc) {
   if (null == valueObjectSrc) {
     return valueObjectSrc;
   }
   valueObjectDest.setID_IncludeDiagnosisInDischargeReport(
       valueObjectSrc.getID_IncludeDiagnosisInDischargeReport());
   valueObjectDest.setIsRIE(valueObjectSrc.getIsRIE());
   // CareContext
   valueObjectDest.setCareContext(valueObjectSrc.getCareContext());
   // Diagnosis
   valueObjectDest.setDiagnosis(valueObjectSrc.getDiagnosis());
   // IncludeInReport
   valueObjectDest.setIncludeInReport(valueObjectSrc.getIncludeInReport());
   return valueObjectDest;
 }
  public static ims.core.clinical.domain.objects.IncludeDiagnosisInDischargeReport
      extractIncludeDiagnosisInDischargeReport(
          ims.domain.ILightweightDomainFactory domainFactory,
          ims.core.vo.IncludeDiagnosisInDischargeReportVo valueObject,
          HashMap domMap) {
    if (null == valueObject) {
      return null;
    }
    Integer id = valueObject.getID_IncludeDiagnosisInDischargeReport();
    ims.core.clinical.domain.objects.IncludeDiagnosisInDischargeReport domainObject = null;
    if (null == id) {
      if (domMap.get(valueObject) != null) {
        return (ims.core.clinical.domain.objects.IncludeDiagnosisInDischargeReport)
            domMap.get(valueObject);
      }
      // ims.core.vo.IncludeDiagnosisInDischargeReportVo ID_IncludeDiagnosisInDischargeReport field
      // is unknown
      domainObject = new ims.core.clinical.domain.objects.IncludeDiagnosisInDischargeReport();
      domMap.put(valueObject, domainObject);
    } else {
      String key =
          (valueObject.getClass().getName()
              + "__"
              + valueObject.getID_IncludeDiagnosisInDischargeReport());
      if (domMap.get(key) != null) {
        return (ims.core.clinical.domain.objects.IncludeDiagnosisInDischargeReport) domMap.get(key);
      }
      domainObject =
          (ims.core.clinical.domain.objects.IncludeDiagnosisInDischargeReport)
              domainFactory.getDomainObject(
                  ims.core.clinical.domain.objects.IncludeDiagnosisInDischargeReport.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_IncludeDiagnosisInDischargeReport());

    ims.core.admin.domain.objects.CareContext value1 = null;
    if (null != valueObject.getCareContext()) {
      if (valueObject.getCareContext().getBoId() == null) {
        if (domMap.get(valueObject.getCareContext()) != null) {
          value1 =
              (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
      {
        value1 = domainObject.getCareContext();
      } else {
        value1 =
            (ims.core.admin.domain.objects.CareContext)
                domainFactory.getDomainObject(
                    ims.core.admin.domain.objects.CareContext.class,
                    valueObject.getCareContext().getBoId());
      }
    }
    domainObject.setCareContext(value1);
    ims.core.clinical.domain.objects.PatientDiagnosis value2 = null;
    if (null != valueObject.getDiagnosis()) {
      if (valueObject.getDiagnosis().getBoId() == null) {
        if (domMap.get(valueObject.getDiagnosis()) != null) {
          value2 =
              (ims.core.clinical.domain.objects.PatientDiagnosis)
                  domMap.get(valueObject.getDiagnosis());
        }
      } else if (valueObject.getBoVersion()
          == -1) // RefVo was not modified since obtained from the Assembler, no need to update the
      // BO field
      {
        value2 = domainObject.getDiagnosis();
      } else {
        value2 =
            (ims.core.clinical.domain.objects.PatientDiagnosis)
                domainFactory.getDomainObject(
                    ims.core.clinical.domain.objects.PatientDiagnosis.class,
                    valueObject.getDiagnosis().getBoId());
      }
    }
    domainObject.setDiagnosis(value2);
    domainObject.setIncludeInReport(valueObject.getIncludeInReport());

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

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

    // 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()));
      }
    }
    // Diagnosis
    if (domainObject.getDiagnosis() != null) {
      if (domainObject.getDiagnosis()
          instanceof
          HibernateProxy) // If the proxy is set, there is no need to lazy load, the proxy knows the
      // id already.
      {
        HibernateProxy p = (HibernateProxy) domainObject.getDiagnosis();
        int id = Integer.parseInt(p.getHibernateLazyInitializer().getIdentifier().toString());
        valueObject.setDiagnosis(new ims.core.clinical.vo.PatientDiagnosisRefVo(id, -1));
      } else {
        valueObject.setDiagnosis(
            new ims.core.clinical.vo.PatientDiagnosisRefVo(
                domainObject.getDiagnosis().getId(), domainObject.getDiagnosis().getVersion()));
      }
    }
    // IncludeInReport
    valueObject.setIncludeInReport(domainObject.isIncludeInReport());
    return valueObject;
  }