} // end of Event #endregion //-------------------------------------------------------------------------------------------------- // State Change //-------------------------------------------------------------------------------------------------- #region Trigger /// <summary> /// Acutal state change of arrival. If patient arrives from waiting list path is set, otherwise /// next action is taken. /// </summary> /// <param name="time">Time the patient arrives</param> /// <param name="simEngine">SimEngine responsible for simulation execution</param> protected override void StateChange(DateTime time, ISimulationEngine simEngine) { //-------------------------------------------------------------------------------------------------- // In case Patient is returning from special service facility the path // has already been set and needs update to next action //-------------------------------------------------------------------------------------------------- if (Patient.OutpatientTreatmentPath != null) { Patient.OutpatientTreatmentPath.UpdateNextAction(); } else { Patient.OutpatientTreatmentPath = InputData.CreateOutpatientTreatmentPath(Patient, Admission, ScheduledTime, false); ParentControlUnit.AddEntity(Patient); } // end if if (Patient.OutpatientTreatmentPath.TakeNextAction(simEngine, this, time, ParentControlUnit)) { if (Patient.OccupiedFacility == null || Patient.OccupiedFacility.ParentDepartmentControl != ParentControlUnit) { SequentialEvents.Add(Patient.StartWaitingActivity(((ControlUnitOutpatient)ParentControlUnit).WaitingAreaPatientForNextActionType(Patient.OutpatientTreatmentPath.GetCurrentActionType()))); } else { ActivityWaitInFacility waitInFacility = new ActivityWaitInFacility(ParentControlUnit, Patient, Patient.OccupiedFacility); SequentialEvents.Add(waitInFacility.StartEvent); } // end if } // end if } // end of Trigger