} // end of PerformAssessment

        #endregion

        #region PerformAssessment

        protected bool PerformAssessment(DateTime time, ISimulationEngine simEngine)
        {
            PossibleRAEL.Clear();
            PossibleEmergencyStayInBed.Clear();
            PossibleScheduledStayInBed.Clear();
            PossibleChangeWard.Clear();

            bool bedsAvailable = AllAvailableBeds > 0;

            foreach (ActivityRequest request in RAEL)
            {
                if (request.Activity == "ActivityInpatientStayInBed" && bedsAvailable)
                {
                    if (((RequestInpatientStayInBed)request).InpatientOrigin == InpatientOrigin.Scheduled)
                    {
                        PossibleScheduledStayInBed.Add((RequestInpatientStayInBed)request);
                    }
                    else if (((RequestInpatientStayInBed)request).InpatientOrigin == InpatientOrigin.Emergency)
                    {
                        PossibleEmergencyStayInBed.Add((RequestInpatientStayInBed)request);
                    }
                }
                else if (request is RequestInpatientActivity && ((RequestInpatientActivity)request).InpatientTreatment.IsEmergencyTreatment)
                {
                    PossibleRAEL.Add(request);
                }
                else if (request is RequestInpatientActivity && ((RequestInpatientActivity)request).Patient.StaysInBed &&
                         !RoundsDue &&
                         DuringWeekday)
                {
                    PossibleRAEL.Add(request);
                }
                else if (request is RequestInpatientResumeActivity && ((RequestInpatientResumeActivity)request).Patient.StaysInBed &&
                         !RoundsDue &&
                         DuringWeekday)
                {
                    PossibleRAEL.Add(request);
                }
                else if (request is RequestInpatientDoctorOrganziationalWork &&
                         ((RequestInpatientDoctorOrganziationalWork)request).Doctor.IsWaiting() &&
                         !RoundsDue &&
                         (((RequestInpatientDoctorOrganziationalWork)request).Doctor).ParentControlUnit == this)
                {
                    PossibleRAEL.Add(request);
                }
                else if (bedsAvailable && request is RequestInpatientChangeWard && ((RequestInpatientChangeWard)request).Patient.StaysInBed)
                {
                    PossibleChangeWard.Add((RequestInpatientChangeWard)request);
                }
            } // end foreach

            return(false);
        } // end of PerformAssessment
        } // end of PerformAssessment

        #endregion

        #region PerformDisptatching

        protected bool PerformDisptatching(DateTime time, ISimulationEngine simEngine)
        {
            #region StayInBed

            bool triggeredStayInBed = false;


            foreach (RequestInpatientStayInBed request in PossibleEmergencyStayInBed)
            {
                EntityPatient     patient       = request.Patient;
                List <EntityWard> possibleWards = WardsPerType[patient.InpatientPath.CurrentTreatmentBlock.WardType];

                EntityBed bed = null;

                foreach (EntityWard ward in possibleWards)
                {
                    bed = ward.GetBed(patient.InpatientPath.CurrentTreatmentBlock.BedType);
                    if (bed != null)
                    {
                        break;
                    }
                } // end foreach

                if (bed != null)
                {
                    patient.InpatientPath.CurrentTreatmentBlock.InititateTreatmentBlock(bed.ParentWard, bed);
                    patient.StopCurrentActivities(time, simEngine);
                    ActivityInpatientStayInBed stayInBed = new ActivityInpatientStayInBed(this, patient, bed.ParentWard, bed, false);
                    stayInBed.StartEvent.Trigger(time, simEngine);
                    triggeredStayInBed = true;

                    RemoveRequest(request);
                } // end if
            }     // end foreach

            foreach (RequestInpatientChangeWard request in PossibleChangeWard)
            {
                EntityPatient     patient       = request.Patient;
                List <EntityWard> possibleWards = WardsPerType[patient.InpatientPath.CurrentTreatmentBlock.WardType];

                EntityBed bed = null;

                foreach (EntityWard ward in possibleWards)
                {
                    bed = ward.GetBed(patient.InpatientPath.CurrentTreatmentBlock.BedType);
                    if (bed != null)
                    {
                        break;
                    }
                } // end foreach

                if (bed != null)
                {
                    patient.InpatientPath.CurrentTreatmentBlock.InititateTreatmentBlock(bed.ParentWard, bed);
                    request.OldBed.RemovePatient();
                    patient.StopCurrentActivities(time, simEngine);
                    ActivityInpatientStayInBed stayInBed = new ActivityInpatientStayInBed(this, patient, bed.ParentWard, bed, false);
                    stayInBed.StartEvent.Trigger(time, simEngine);

                    RemoveRequest(request);
                } // end if
            }     // end foreach

            foreach (RequestInpatientStayInBed request in PossibleScheduledStayInBed)
            {
                EntityPatient     patient       = request.Patient;
                List <EntityWard> possibleWards = WardsPerType[patient.InpatientPath.CurrentTreatmentBlock.WardType];

                EntityBed bed = null;

                foreach (EntityWard ward in possibleWards)
                {
                    bed = ward.GetBed(patient.InpatientPath.CurrentTreatmentBlock.BedType);
                    if (bed != null)
                    {
                        break;
                    }
                } // end foreach

                if (bed != null)
                {
                    patient.InpatientPath.CurrentTreatmentBlock.InititateTreatmentBlock(bed.ParentWard, bed);
                    patient.StopCurrentActivities(time, simEngine);
                    ActivityInpatientStayInBed stayInBed = new ActivityInpatientStayInBed(this, patient, bed.ParentWard, bed, false);
                    stayInBed.StartEvent.Trigger(time, simEngine);

                    RemoveRequest(request);
                } // end if
            }     // end foreach

            #endregion

            #region InpatientActivities

            List <RequestInpatientActivity>       originalRequests = PossibleRAEL.Where(p => p is RequestInpatientActivity).Cast <RequestInpatientActivity>().ToList();
            List <RequestInpatientResumeActivity> resumeRequests   = PossibleRAEL.Where(p => p is RequestInpatientResumeActivity).Cast <RequestInpatientResumeActivity>().ToList();

            List <RequestInpatientActivity>       requestsEmergencyTreatment = originalRequests.Where(p => p.InpatientTreatment.IsEmergencyTreatment && ((RequestInpatientActivity)p).EarliestTime <= time).Cast <RequestInpatientActivity>().ToList();
            List <RequestInpatientActivity>       requestsTreatment          = originalRequests.Where(p => !p.InpatientTreatment.IsEmergencyTreatment && ((RequestInpatientActivity)p).EarliestTime <= time).Cast <RequestInpatientActivity>().ToList();
            List <RequestInpatientResumeActivity> requestsResumeTreatment    = resumeRequests.Where(p => !p.InpatientTreatment.IsEmergencyTreatment && ((RequestInpatientResumeActivity)p).EarliestTime <= time).Cast <RequestInpatientResumeActivity>().ToList();


            #region EmergencyTreatments

            if (requestsEmergencyTreatment.Count > 0)
            {
                EntityPatient patient = requestsEmergencyTreatment.First().Patient;

                EntityDoctor doctor = ChooseDoctor(requestsEmergencyTreatment.First().Patient, requestsEmergencyTreatment.First());

                if (doctor != null)
                {
                    ActivityInpatientEmergencyTreatment newInpatientEmergencyTreatment = new ActivityInpatientEmergencyTreatment(this,
                                                                                                                                 patient,
                                                                                                                                 doctor,
                                                                                                                                 patient.Ward,
                                                                                                                                 patient.Bed);
                    patient.StopCurrentActivities(time, simEngine);
                    doctor.StopCurrentActivities(time, simEngine);

                    newInpatientEmergencyTreatment.StartEvent.Trigger(time, simEngine);

                    PossibleRAEL.Remove(requestsEmergencyTreatment[0]);
                    RemoveRequest(requestsEmergencyTreatment[0]);
                    requestsEmergencyTreatment.RemoveAt(0);

                    return(true);
                } // end if
            }     // end if

            #endregion

            #region Treatments

            if (requestsTreatment.Count > 0)
            {
                EntityPatient patient = requestsTreatment.First().Patient;

                EntityDoctor doctor = ChooseDoctor(requestsTreatment.First().Patient, requestsTreatment.First());

                if (doctor != null)
                {
                    ActivityInpatientTreatment newInpatientTreatment = new ActivityInpatientTreatment(
                        this,
                        patient,
                        doctor,
                        patient.Ward,
                        patient.Bed,
                        requestsTreatment.First().InpatientTreatment);
                    patient.StopCurrentActivities(time, simEngine);
                    doctor.StopCurrentActivities(time, simEngine);

                    newInpatientTreatment.StartEvent.Trigger(time, simEngine);

                    PossibleRAEL.Remove(requestsTreatment[0]);
                    RemoveRequest(requestsTreatment[0]);
                    requestsTreatment.RemoveAt(0);

                    return(true);
                } // end if
            }     // end if

            #endregion

            #region ResumeTreatments

            if (requestsResumeTreatment.Count > 0)
            {
                EntityPatient patient = requestsResumeTreatment.First().Patient;

                EntityDoctor doctor = ChooseDoctor(requestsResumeTreatment.First().Patient, requestsResumeTreatment.First());

                if (doctor != null)
                {
                    ActivityInpatientTreatment newInpatientTreatment = new ActivityInpatientTreatment(this,
                                                                                                      patient,
                                                                                                      doctor,
                                                                                                      patient.Ward,
                                                                                                      patient.Bed,
                                                                                                      requestsResumeTreatment.First().DegreeOfCompletion,
                                                                                                      requestsResumeTreatment.First().Duration,
                                                                                                      requestsResumeTreatment.First().InpatientTreatment);
                    patient.StopCurrentActivities(time, simEngine);
                    doctor.StopCurrentActivities(time, simEngine);

                    newInpatientTreatment.StartEvent.Trigger(time, simEngine);

                    PossibleRAEL.Remove(requestsResumeTreatment[0]);
                    RemoveRequest(requestsResumeTreatment[0]);
                    requestsResumeTreatment.RemoveAt(0);

                    return(true);
                } // end if
            }     // end if

            #endregion

            #endregion

            #region OrganizationalWork

            bool triggeredOrganizationalWork = false;

            List <RequestInpatientDoctorOrganziationalWork> allOrgReqs = PossibleRAEL.Where(p => p is RequestInpatientDoctorOrganziationalWork).Cast <RequestInpatientDoctorOrganziationalWork>().ToList();

            foreach (RequestInpatientDoctorOrganziationalWork reqOrg in allOrgReqs)
            {
                if (reqOrg.Doctor.IsWaiting())
                {
                    reqOrg.Doctor.StopCurrentActivities(time, simEngine);

                    ActivityInpatientDoctorOrganizationalWork orgWork = new ActivityInpatientDoctorOrganizationalWork(this, reqOrg.Doctor, WaitingRoomStaff, reqOrg.DegreeOfCompletion, reqOrg.Duration);

                    orgWork.StartEvent.Trigger(time, simEngine);

                    triggeredOrganizationalWork = true;

                    PossibleRAEL.Remove(reqOrg);
                    RemoveRequest(reqOrg);
                } // end if
            }     // end foreach

            #endregion

            return(triggeredStayInBed || triggeredOrganizationalWork);
        } // end of PerformDisptatching