/**
   * Create the ValueObject collection to hold the list of DomainObjects.
   *
   * @param map - maps DomainObjects to created ValueObjects
   * @param domainObjectList - List of ims.emergency.domain.objects.Tracking objects.
   */
  public static ims.emergency.vo.TrackingforDecisionToAdmitDialogVoCollection
      createTrackingforDecisionToAdmitDialogVoCollectionFromTracking(
          DomainObjectMap map, java.util.List domainObjectList) {
    ims.emergency.vo.TrackingforDecisionToAdmitDialogVoCollection voList =
        new ims.emergency.vo.TrackingforDecisionToAdmitDialogVoCollection();
    if (null == domainObjectList) {
      return voList;
    }
    int rieCount = 0;
    int activeCount = 0;
    for (int i = 0; i < domainObjectList.size(); i++) {
      ims.emergency.domain.objects.Tracking domainObject =
          (ims.emergency.domain.objects.Tracking) domainObjectList.get(i);
      ims.emergency.vo.TrackingforDecisionToAdmitDialogVo vo = create(map, domainObject);

      if (vo != null) voList.add(vo);

      if (domainObject != null) {
        if (domainObject.getIsRIE() != null && domainObject.getIsRIE().booleanValue() == true)
          rieCount++;
        else activeCount++;
      }
    }

    voList.setRieCount(rieCount);
    voList.setActiveCount(activeCount);
    return voList;
  }
  /**
   * Create the ValueObject collection to hold the set of DomainObjects.
   *
   * @param map - maps DomainObjects to created ValueObjects
   * @param domainObjectSet - Set of ims.emergency.domain.objects.Tracking objects.
   */
  public static ims.emergency.vo.TrackingforDecisionToAdmitDialogVoCollection
      createTrackingforDecisionToAdmitDialogVoCollectionFromTracking(
          DomainObjectMap map, java.util.Set domainObjectSet) {
    ims.emergency.vo.TrackingforDecisionToAdmitDialogVoCollection voList =
        new ims.emergency.vo.TrackingforDecisionToAdmitDialogVoCollection();
    if (null == domainObjectSet) {
      return voList;
    }
    int rieCount = 0;
    int activeCount = 0;
    java.util.Iterator iterator = domainObjectSet.iterator();
    while (iterator.hasNext()) {
      ims.emergency.domain.objects.Tracking domainObject =
          (ims.emergency.domain.objects.Tracking) iterator.next();
      ims.emergency.vo.TrackingforDecisionToAdmitDialogVo vo = create(map, domainObject);

      if (vo != null) voList.add(vo);

      if (domainObject != null) {
        if (domainObject.getIsRIE() != null && domainObject.getIsRIE().booleanValue() == true)
          rieCount++;
        else activeCount++;
      }
    }
    voList.setRieCount(rieCount);
    voList.setActiveCount(activeCount);
    return voList;
  }
  /**
   * Create the ValueObject from the ims.emergency.domain.objects.Tracking object.
   *
   * @param map DomainObjectMap of DomainObjects to already created ValueObjects.
   * @param domainObject
   */
  public static ims.emergency.vo.TrackingForSeenByHCPVo create(
      DomainObjectMap map, ims.emergency.domain.objects.Tracking domainObject) {
    if (null == domainObject) {
      return null;
    }
    // check if the domainObject already has a valueObject created for it
    ims.emergency.vo.TrackingForSeenByHCPVo valueObject =
        (ims.emergency.vo.TrackingForSeenByHCPVo)
            map.getValueObject(domainObject, ims.emergency.vo.TrackingForSeenByHCPVo.class);
    if (null == valueObject) {
      valueObject =
          new ims.emergency.vo.TrackingForSeenByHCPVo(
              domainObject.getId(), domainObject.getVersion());
      map.addValueObject(domainObject, valueObject);

      valueObject = insert(map, valueObject, domainObject);
    }
    return valueObject;
  }
  public static ims.emergency.domain.objects.Tracking extractTracking(
      ims.domain.ILightweightDomainFactory domainFactory,
      ims.emergency.vo.TrackingforDecisionToAdmitDialogVo valueObject,
      HashMap domMap) {
    if (null == valueObject) {
      return null;
    }
    Integer id = valueObject.getID_Tracking();
    ims.emergency.domain.objects.Tracking domainObject = null;
    if (null == id) {
      if (domMap.get(valueObject) != null) {
        return (ims.emergency.domain.objects.Tracking) domMap.get(valueObject);
      }
      // ims.emergency.vo.TrackingforDecisionToAdmitDialogVo ID_Tracking field is unknown
      domainObject = new ims.emergency.domain.objects.Tracking();
      domMap.put(valueObject, domainObject);
    } else {
      String key = (valueObject.getClass().getName() + "__" + valueObject.getID_Tracking());
      if (domMap.get(key) != null) {
        return (ims.emergency.domain.objects.Tracking) domMap.get(key);
      }
      domainObject =
          (ims.emergency.domain.objects.Tracking)
              domainFactory.getDomainObject(ims.emergency.domain.objects.Tracking.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_Tracking());

    domainObject.setBedAvailability(
        ims.emergency.vo.domain.BedAvailabilityForTrackVoAssembler.extractBedAvailability(
            domainFactory, valueObject.getBedAvailability(), domMap));
    domainObject.setAssociatedPendingEmergencyAdmission(
        ims.emergency.vo.domain.PendingEmergencyAdmissionShortVoAssembler
            .extractPendingEmergencyAdmission(
                domainFactory, valueObject.getAssociatedPendingEmergencyAdmission(), domMap));
    // SaveAsRefVO - treated as a refVo in extract methods
    ims.core.patient.domain.objects.Patient value3 = null;
    if (null != valueObject.getPatient()) {
      if (valueObject.getPatient().getBoId() == null) {
        if (domMap.get(valueObject.getPatient()) != null) {
          value3 = (ims.core.patient.domain.objects.Patient) domMap.get(valueObject.getPatient());
        }
      } else {
        value3 =
            (ims.core.patient.domain.objects.Patient)
                domainFactory.getDomainObject(
                    ims.core.patient.domain.objects.Patient.class,
                    valueObject.getPatient().getBoId());
      }
    }
    domainObject.setPatient(value3);
    domainObject.setAttendance(
        ims.emergency.vo.domain.EmergencyAttendanceForTriageLiteVoAssembler
            .extractEmergencyAttendance(domainFactory, valueObject.getAttendance(), domMap));
    // SaveAsRefVO - treated as a refVo in extract methods
    ims.core.admin.domain.objects.EmergencyEpisode value5 = null;
    if (null != valueObject.getEpisode()) {
      if (valueObject.getEpisode().getBoId() == null) {
        if (domMap.get(valueObject.getEpisode()) != null) {
          value5 =
              (ims.core.admin.domain.objects.EmergencyEpisode) domMap.get(valueObject.getEpisode());
        }
      } else {
        value5 =
            (ims.core.admin.domain.objects.EmergencyEpisode)
                domainFactory.getDomainObject(
                    ims.core.admin.domain.objects.EmergencyEpisode.class,
                    valueObject.getEpisode().getBoId());
      }
    }
    domainObject.setEpisode(value5);
    // SaveAsRefVO - treated as a refVo in extract methods
    ims.emergency.domain.objects.Triage value6 = null;
    if (null != valueObject.getTriageDetails()) {
      if (valueObject.getTriageDetails().getBoId() == null) {
        if (domMap.get(valueObject.getTriageDetails()) != null) {
          value6 = (ims.emergency.domain.objects.Triage) domMap.get(valueObject.getTriageDetails());
        }
      } else {
        value6 =
            (ims.emergency.domain.objects.Triage)
                domainFactory.getDomainObject(
                    ims.emergency.domain.objects.Triage.class,
                    valueObject.getTriageDetails().getBoId());
      }
    }
    domainObject.setTriageDetails(value6);
    domainObject.setCurrentArea(
        ims.emergency.vo.domain.TrackingAreaLiteVoAssembler.extractTrackingArea(
            domainFactory, valueObject.getCurrentArea(), domMap));
    domainObject.setIsDischarged(valueObject.getIsDischarged());
    domainObject.setCurrentStatus(
        ims.emergency.vo.domain.TrackingAttendanceStatusVoAssembler.extractTrackingAttendanceStatus(
            domainFactory, valueObject.getCurrentStatus(), domMap));
    // SaveAsRefVO - treated as a refVo in extract methods
    ims.emergency.domain.objects.SeenByHCP value10 = null;
    if (null != valueObject.getSeenBy()) {
      if (valueObject.getSeenBy().getBoId() == null) {
        if (domMap.get(valueObject.getSeenBy()) != null) {
          value10 = (ims.emergency.domain.objects.SeenByHCP) domMap.get(valueObject.getSeenBy());
        }
      } else {
        value10 =
            (ims.emergency.domain.objects.SeenByHCP)
                domainFactory.getDomainObject(
                    ims.emergency.domain.objects.SeenByHCP.class,
                    valueObject.getSeenBy().getBoId());
      }
    }
    domainObject.setSeenBy(value10);
    // SaveAsRefVO - treated as a refVo in extract methods
    ims.emergency.domain.objects.ReferralToSpecTeam value11 = null;
    if (null != valueObject.getCurrentReferral()) {
      if (valueObject.getCurrentReferral().getBoId() == null) {
        if (domMap.get(valueObject.getCurrentReferral()) != null) {
          value11 =
              (ims.emergency.domain.objects.ReferralToSpecTeam)
                  domMap.get(valueObject.getCurrentReferral());
        }
      } else {
        value11 =
            (ims.emergency.domain.objects.ReferralToSpecTeam)
                domainFactory.getDomainObject(
                    ims.emergency.domain.objects.ReferralToSpecTeam.class,
                    valueObject.getCurrentReferral().getBoId());
      }
    }
    domainObject.setCurrentReferral(value11);
    // SaveAsRefVO - treated as a refVo in extract methods
    ims.emergency.domain.objects.SeenByHCP value12 = null;
    if (null != valueObject.getSeenByNurse()) {
      if (valueObject.getSeenByNurse().getBoId() == null) {
        if (domMap.get(valueObject.getSeenByNurse()) != null) {
          value12 =
              (ims.emergency.domain.objects.SeenByHCP) domMap.get(valueObject.getSeenByNurse());
        }
      } else {
        value12 =
            (ims.emergency.domain.objects.SeenByHCP)
                domainFactory.getDomainObject(
                    ims.emergency.domain.objects.SeenByHCP.class,
                    valueObject.getSeenByNurse().getBoId());
      }
    }
    domainObject.setSeenByNurse(value12);

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

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

    // BedAvailability
    valueObject.setBedAvailability(
        ims.emergency.vo.domain.BedAvailabilityForTrackVoAssembler.create(
            map, domainObject.getBedAvailability()));
    // AssociatedPendingEmergencyAdmission
    valueObject.setAssociatedPendingEmergencyAdmission(
        ims.emergency.vo.domain.PendingEmergencyAdmissionShortVoAssembler.create(
            map, domainObject.getAssociatedPendingEmergencyAdmission()));
    // Patient
    valueObject.setPatient(
        ims.emergency.vo.domain.PatientForTriageVoAssembler.create(map, domainObject.getPatient()));
    // Attendance
    valueObject.setAttendance(
        ims.emergency.vo.domain.EmergencyAttendanceForTriageLiteVoAssembler.create(
            map, domainObject.getAttendance()));
    // Episode
    valueObject.setEpisode(
        ims.emergency.vo.domain.EmergencyEpisodeForTriageLiteVoAssembler.create(
            map, domainObject.getEpisode()));
    // TriageDetails
    valueObject.setTriageDetails(
        ims.emergency.vo.domain.TriageForClinicianWorklistVoAssembler.create(
            map, domainObject.getTriageDetails()));
    // CurrentArea
    valueObject.setCurrentArea(
        ims.emergency.vo.domain.TrackingAreaLiteVoAssembler.create(
            map, domainObject.getCurrentArea()));
    // isDischarged
    valueObject.setIsDischarged(domainObject.isIsDischarged());
    // CurrentStatus
    valueObject.setCurrentStatus(
        ims.emergency.vo.domain.TrackingAttendanceStatusVoAssembler.create(
            map, domainObject.getCurrentStatus()));
    // SeenBy
    valueObject.setSeenBy(
        ims.emergency.vo.domain.SeenByHCPForEDAssessmentComponentVoAssembler.create(
            map, domainObject.getSeenBy()));
    // CurrentReferral
    valueObject.setCurrentReferral(
        ims.emergency.vo.domain.ReferralToSpecialtyTeamForEDAssessmentComponentVoAssembler.create(
            map, domainObject.getCurrentReferral()));
    // SeenByNurse
    valueObject.setSeenByNurse(
        ims.emergency.vo.domain.SeenByHCPForEDAssessmentComponentVoAssembler.create(
            map, domainObject.getSeenByNurse()));
    return valueObject;
  }
  public static ims.emergency.domain.objects.Tracking extractTracking(
      ims.domain.ILightweightDomainFactory domainFactory,
      ims.emergency.vo.TrackingForSeenByHCPVo valueObject,
      HashMap domMap) {
    if (null == valueObject) {
      return null;
    }
    Integer id = valueObject.getID_Tracking();
    ims.emergency.domain.objects.Tracking domainObject = null;
    if (null == id) {
      if (domMap.get(valueObject) != null) {
        return (ims.emergency.domain.objects.Tracking) domMap.get(valueObject);
      }
      // ims.emergency.vo.TrackingForSeenByHCPVo ID_Tracking field is unknown
      domainObject = new ims.emergency.domain.objects.Tracking();
      domMap.put(valueObject, domainObject);
    } else {
      String key = (valueObject.getClass().getName() + "__" + valueObject.getID_Tracking());
      if (domMap.get(key) != null) {
        return (ims.emergency.domain.objects.Tracking) domMap.get(key);
      }
      domainObject =
          (ims.emergency.domain.objects.Tracking)
              domainFactory.getDomainObject(ims.emergency.domain.objects.Tracking.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_Tracking());

    ims.core.patient.domain.objects.Patient value1 = null;
    if (null != valueObject.getPatient()) {
      if (valueObject.getPatient().getBoId() == null) {
        if (domMap.get(valueObject.getPatient()) != null) {
          value1 = (ims.core.patient.domain.objects.Patient) domMap.get(valueObject.getPatient());
        }
      } else if (valueObject.getBoVersion()
          == -1) // RefVo was not modified since obtained from the Assembler, no need to update the
                 // BO field
      {
        value1 = domainObject.getPatient();
      } else {
        value1 =
            (ims.core.patient.domain.objects.Patient)
                domainFactory.getDomainObject(
                    ims.core.patient.domain.objects.Patient.class,
                    valueObject.getPatient().getBoId());
      }
    }
    domainObject.setPatient(value1);
    // SaveAsRefVO - treated as a refVo in extract methods
    ims.emergency.configuration.domain.objects.TrackingArea value2 = null;
    if (null != valueObject.getCurrentArea()) {
      if (valueObject.getCurrentArea().getBoId() == null) {
        if (domMap.get(valueObject.getCurrentArea()) != null) {
          value2 =
              (ims.emergency.configuration.domain.objects.TrackingArea)
                  domMap.get(valueObject.getCurrentArea());
        }
      } else {
        value2 =
            (ims.emergency.configuration.domain.objects.TrackingArea)
                domainFactory.getDomainObject(
                    ims.emergency.configuration.domain.objects.TrackingArea.class,
                    valueObject.getCurrentArea().getBoId());
      }
    }
    domainObject.setCurrentArea(value2);
    domainObject.setCurrentStatus(
        ims.emergency.vo.domain.TrackingAttendanceStatusVoAssembler.extractTrackingAttendanceStatus(
            domainFactory, valueObject.getCurrentStatus(), domMap));
    domainObject.setIsDischarged(valueObject.getIsDischarged());
    domainObject.setSeenBy(
        ims.emergency.vo.domain.SeenByHCPVoAssembler.extractSeenByHCP(
            domainFactory, valueObject.getSeenBy(), domMap));
    domainObject.setTriageDetails(
        ims.emergency.vo.domain.TriageForSeenByHcpVoAssembler.extractTriage(
            domainFactory, valueObject.getTriageDetails(), domMap));
    domainObject.setSeenByNurse(
        ims.emergency.vo.domain.SeenByHCPVoAssembler.extractSeenByHCP(
            domainFactory, valueObject.getSeenByNurse(), domMap));
    domainObject.setAttendance(
        ims.emergency.vo.domain.AttendanceForSeenByHCPVoAssembler.extractEmergencyAttendance(
            domainFactory, valueObject.getAttendance(), 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.emergency.domain.objects.Tracking
   */
  public static ims.emergency.vo.TrackingForSeenByHCPVo insert(
      DomainObjectMap map,
      ims.emergency.vo.TrackingForSeenByHCPVo valueObject,
      ims.emergency.domain.objects.Tracking domainObject) {
    if (null == domainObject) {
      return valueObject;
    }
    if (null == map) {
      map = new DomainObjectMap();
    }

    valueObject.setID_Tracking(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()));
      }
    }
    // CurrentArea
    valueObject.setCurrentArea(
        ims.emergency.vo.domain.TrackingAreaLiteVoAssembler.create(
            map, domainObject.getCurrentArea()));
    // CurrentStatus
    valueObject.setCurrentStatus(
        ims.emergency.vo.domain.TrackingAttendanceStatusVoAssembler.create(
            map, domainObject.getCurrentStatus()));
    // isDischarged
    valueObject.setIsDischarged(domainObject.isIsDischarged());
    // SeenBy
    valueObject.setSeenBy(
        ims.emergency.vo.domain.SeenByHCPVoAssembler.create(map, domainObject.getSeenBy()));
    // TriageDetails
    valueObject.setTriageDetails(
        ims.emergency.vo.domain.TriageForSeenByHcpVoAssembler.create(
            map, domainObject.getTriageDetails()));
    // SeenByNurse
    valueObject.setSeenByNurse(
        ims.emergency.vo.domain.SeenByHCPVoAssembler.create(map, domainObject.getSeenByNurse()));
    // Attendance
    valueObject.setAttendance(
        ims.emergency.vo.domain.AttendanceForSeenByHCPVoAssembler.create(
            map, domainObject.getAttendance()));
    return valueObject;
  }