/// <summary>
        /// Initialization: Patient arrival stream for waiting list patients is initialized.
        /// If dispatching is done at discrete events this stream is initialized as well.
        /// </summary>
        /// <param name="startTime">Time the simulation starts</param>
        /// <param name="simEngine">SimEngine that handles the simulation run</param>
        protected override void CustomInitialize(DateTime startTime, ISimulationEngine simEngine)
        {
            WaitingListSchedule.Initialize(startTime);

            AddEntity((EntityWaitingListSchedule)WaitingListSchedule);

            DateTime      nextArrivalTime;
            Admission     admission;
            EntityPatient newPatient = InputData.GetNextWaitingListPatient(out nextArrivalTime, out admission, this, startTime);

            if (newPatient != null)
            {
                EventOutpatientWaitingListPatientArrival nextArrival =
                    new EventOutpatientWaitingListPatientArrival(this,
                                                                 (ControlUnitOutpatient)ParentControlUnit,
                                                                 newPatient,
                                                                 admission,
                                                                 InputData);

                simEngine.AddScheduledEvent(nextArrival, nextArrivalTime);
            } // end if

            WaitingListSchedule.ReadyForDispatch = true;

            if (AssigningSlotsAtEvents)
            {
                EventOutpatientStartDispatching nextDispatch = new EventOutpatientStartDispatching(this, WaitingListSchedule, InputData);

                simEngine.AddScheduledEvent(nextDispatch, InputData.NextDispatching(startTime));

                WaitingListSchedule.ReadyForDispatch = false;
            }
        } // end of Initialize
        } // end of Initialize

        #endregion

        //--------------------------------------------------------------------------------------------------
        // Rule Handling
        //--------------------------------------------------------------------------------------------------

        #region PerformCustomRules

        /// <summary>
        /// Dispatches slot requests by booking in the booking model, further, now show probabilities
        /// and arrival deviations of patients are calculated. Corresponding events for arrival are scheduled.
        /// </summary>
        /// <param name="startTime">Time rules are executed</param>
        /// <param name="simEngine">SimEngine responsible for simulation execution</param>
        /// <returns>False</returns>
        protected override bool PerformCustomRules(DateTime time, ISimulationEngine simEngine)
        {
            if (RAEL.Count == 0)
            {
                return(false);
            }

            if (!WaitingListSchedule.ReadyForDispatch)
            {
                return(false);
            }

            while (RAEL.Count > 0)
            {
                RequestOutpatientWaitingListPatientToAssignSlot reqToDisptatch = (RequestOutpatientWaitingListPatientToAssignSlot)RAEL.First();

                DateTime earliestTime = time;

                earliestTime = reqToDisptatch.EarliestTime;

                Slot slot = WaitingListSchedule.GetEarliestSlotTime(time,
                                                                    earliestTime,
                                                                    reqToDisptatch.Patient,
                                                                    reqToDisptatch.AdmissionType);

                WaitingListSchedule.BookSlot(slot, reqToDisptatch.AdmissionType);

                reqToDisptatch.Patient.StopCurrentActivities(time, simEngine);
                ParentControlUnit.RemoveRequest(reqToDisptatch);
                RemoveRequest(reqToDisptatch);

                if (InputData.NoShowForAppointment(reqToDisptatch.Patient, reqToDisptatch.AdmissionType, slot, time))
                {
                    continue;
                }

                DateTime arrivalTime = slot.StartTime + InputData.PatientArrivalDeviationFromSlotTime(reqToDisptatch.Patient, reqToDisptatch.AdmissionType);

                arrivalTime = new DateTime(Math.Max(time.Ticks, arrivalTime.Ticks));

                EventOutpatientArrival arrival = new EventOutpatientArrival(ParentControlUnit,
                                                                            reqToDisptatch.Patient,
                                                                            slot.StartTime,
                                                                            InputData,
                                                                            reqToDisptatch.AdmissionType);

                simEngine.AddScheduledEvent(arrival, arrivalTime);

                Event patientWait = reqToDisptatch.Patient.StartWaitingActivity(null);

                patientWait.Trigger(time, simEngine);
            } // end while

            WaitingListSchedule.ReadyForDispatch = false;

            return(false);
        } // end of PerformCustomRules
Beispiel #3
0
        } // end of ControlUnit

        #endregion

        #region Initialize

        /// <summary>
        /// Just adds the waiting list schedule to the controlled entities and intializes it
        /// </summary>
        /// <param name="startTime">Start time of the simulation model</param>
        /// <param name="simEngine">SimEngine responsible for simulation execution</param>
        protected override void CustomInitialize(DateTime startTime, ISimulationEngine simEngine)
        {
            AddEntity(WaitingListSchedule);

            WaitingListSchedule.Initialize(startTime);
        } // end of Initialize
        } // end of ToString

        #endregion

        #region Clone

        override public Event Clone()
        {
            return(new EventOutpatientStartDispatching(ParentControlUnit, (EntityWaitingListSchedule)WaitingListSchedule.Clone(), InputData));
        } // end of Clone