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;
  }