} // 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
} // end of Event #endregion //-------------------------------------------------------------------------------------------------- // State Change //-------------------------------------------------------------------------------------------------- #region Trigger /// <summary> /// Overriden state change of the event. The patient path is set and the first 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) { Patient.SpecialFacilityPath = InputData.CreatePatientPath(OriginalRequest.SpecialFacilityAdmissionTypes, Patient, OriginalRequest); if (Patient.SpecialFacilityPath.TakeNextAction(simEngine, this, time, ParentControlUnit)) { ActivityWait waitPatient = new ActivityWait(ParentControlUnit, Patient, (((ControlUnitSpecialServiceModel)ParentControlUnit).WaitingAreaPatientForNextActionType(Patient.SpecialFacilityPath.GetCurrentActionType()))); SequentialEvents.Add(waitPatient.StartEvent); } // end if } // end of Trigger
} // end of EventInpatientStaffEnterLeave #endregion //-------------------------------------------------------------------------------------------------- // State Change //-------------------------------------------------------------------------------------------------- #region Trigger /// <summary> /// Overrides the state change method, incoming staff is blocked for dispatching if the origin delegate is DelegateSentDocForAssistedTreatment /// </summary> /// <param name="time">Time the staff member enters or leaves</param> /// <param name="simEngine">SimEngine responsible for simulation execution</param> protected override void StateChange(DateTime time, ISimulationEngine simEngine) { if (!IsEnter) { Staff.BlockedForDispatching = false; } // end if if (IsEnter) { SequentialEvents.Add(Staff.StartWaitingActivity(StaffWaitingArea)); if (IncomingDelegate != null && IncomingDelegate is DelegateSentDocForAssistedTreatment) { Staff.BlockedForDispatching = true; } } // end if } // end of StateChange
} // end of Event #endregion //-------------------------------------------------------------------------------------------------- // State Change //-------------------------------------------------------------------------------------------------- #region Trigger /// <summary> /// State change of event. Sends patient to the special service model /// </summary> /// <param name="time">Time event is triggered</param> /// <param name="simEngine">SimEngine responsible for simulation execution</param> protected override void StateChange(DateTime time, ISimulationEngine simEngine) { ControlUnitManagement jointControl = (ControlUnitManagement)ParentControlUnit.FindSmallestJointControl(Availability.ServiceControl); if (Patient != null) { ActivityMove movePatientToSpecialTreatment = new ActivityMove(jointControl, Patient, ParentControlUnit, Availability.ServiceControl, ReturnDelegate, jointControl.InputData.DurationMove(Patient, ParentControlUnit, Availability.ServiceControl)); SequentialEvents.Add(movePatientToSpecialTreatment.StartEvent); } // end if } // end of Trigger
} // end of Event #endregion //-------------------------------------------------------------------------------------------------- // State Change //-------------------------------------------------------------------------------------------------- #region Trigger /// <summary> /// State chage of event. Checks if patient comes from outside of the model. In that case /// a new event is triggered. Waiting for assign slot is started. /// </summary> /// <param name="time">Arriving time</param> /// <param name="simEngine">SimEngine responsible for simulation execution</param> protected override void StateChange(DateTime time, ISimulationEngine simEngine) { if (AdmissionType.IsExtern) { DateTime nextArrivalTime; Admission admission; EntityPatient newPatient = InputData.GetNextWaitingListPatient(out nextArrivalTime, out admission, ParentControlUnit, time); if (newPatient != null) { EventOutpatientWaitingListPatientArrival nextArrival = new EventOutpatientWaitingListPatientArrival(ParentControlUnit, OutpatientControlUnit, newPatient, admission, InputData); simEngine.AddScheduledEvent(nextArrival, nextArrivalTime); } // end if } // end if DateTime earliestTime = (time + TimeSpan.FromDays(AdmissionType.MinDaySpan)).Date; DateTime latestTime = DateTime.MaxValue; if (AdmissionType.MaxDaySpan < double.MaxValue) { latestTime = (time + TimeSpan.FromDays(AdmissionType.MaxDaySpan)).Date; } ActivityOutpatientWaitingListWaitToAssignSlot waitForAssignment = new ActivityOutpatientWaitingListWaitToAssignSlot(ParentControlUnit, Patient, AdmissionType, earliestTime, latestTime); SequentialEvents.Add(waitForAssignment.StartEvent); } // end of Trigger
} // end of Event #endregion //-------------------------------------------------------------------------------------------------- // State Change //-------------------------------------------------------------------------------------------------- #region StateChange /// <summary> /// Overriden state change of the event. If the patient is arrving externaly then the next arrival is /// scheduled. Else the path is updated and the next/first action is taken from the path. /// </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) { // if patient has a path it is updated if (Patient.EmergencyTreatmentPath != null) { Patient.EmergencyTreatmentPath.UpdateNextAction(); } else { // if patient has no path he is arriving externaly // path is created Patient.EmergencyTreatmentPath = ((ControlUnitEmergency)ParentControlUnit).InputData.CreateEmergencyPath(Patient); // patient is added to control unit ParentControlUnit.AddEntity(Patient); // arrival of next patient is created and scheduled EntityPatient nextPatient = ((ControlUnitEmergency)ParentControlUnit).InputData.GetNextPatient(); EventEmergencyPatientArrival nextPatientArrival = new EventEmergencyPatientArrival(ParentControlUnit, nextPatient, InputData); simEngine.AddScheduledEvent(nextPatientArrival, time + ((ControlUnitEmergency)ParentControlUnit).InputData.PatientArrivalTime(time)); } // end if // next action on path is taken if (Patient.EmergencyTreatmentPath.TakeNextAction(simEngine, this, time, ParentControlUnit)) { // possible waiting or waiting in facility is triggered if (Patient.OccupiedFacility == null || Patient.OccupiedFacility.ParentDepartmentControl != ParentControlUnit) { SequentialEvents.Add(Patient.StartWaitingActivity(((ControlUnitEmergency)ParentControlUnit).WaitingAreaPatientForNextActionType(Patient.EmergencyTreatmentPath.GetCurrentActionType()))); } else { ActivityWaitInFacility waitInFacility = new ActivityWaitInFacility(ParentControlUnit, Patient, Patient.OccupiedFacility); SequentialEvents.Add(waitInFacility.StartEvent); } // end if } // end if } // end of Trigger
} // end of InputData #endregion //-------------------------------------------------------------------------------------------------- // Methods //-------------------------------------------------------------------------------------------------- #region StateChange /// <summary> /// Overriden state change. Initializes a new arrival and patient paths and first action. /// </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) { Patient.OutpatientTreatmentPath = InputData.CreateOutpatientTreatmentPath(Patient, null, time, true); ParentControlUnit.AddEntity(Patient); DateTime nextTime;; EntityPatient nextPatient = InputData.GetNextWalkInPatient(out nextTime, ParentControlUnit, time); EventOutpatientWalkInPatientArrival nextPatientArrival = new EventOutpatientWalkInPatientArrival(ParentControlUnit, InputData, nextPatient); simEngine.AddScheduledEvent(nextPatientArrival, nextTime); if (Patient.EmergencyTreatmentPath.TakeNextAction(simEngine, this, time, ParentControlUnit)) { SequentialEvents.Add(Patient.StartWaitingActivity()); } // end if } // end of StateChange
} // end of EventStaffChange #endregion //-------------------------------------------------------------------------------------------------- // State Change //-------------------------------------------------------------------------------------------------- #region Trigger /// <summary> /// Overrides the state change method, staffing levels will change, for leaving /// staff requests for absence are filed, incoming staff is added to the /// parent control unit /// </summary> /// <param name="time">Time the staffing changes</param> /// <param name="simEngine">SimEngine responsible for simulation execution</param> protected override void StateChange(DateTime time, ISimulationEngine simEngine) { // foreach leaving staff a request to be absent is filed at their control unit // arriving staff is automatically added to the control by the triggering // of the event foreach (ResourceAssignmentStaff staffAssignment in StaffLeaving) { ParentDepartmentControl.AddRequest(new RequestBeAbsent(staffAssignment.Resource, time)); staffAssignment.Resource.StaffOutsideShift = true; } // end foreach foreach (ResourceAssignmentStaff staffAssignment in StaffAriving) { staffAssignment.Resource.StaffOutsideShift = false; staffAssignment.Resource.BlockedForDispatching = false; staffAssignment.Resource.BaseControlUnit = ParentDepartmentControl; staffAssignment.Resource.AssignmentType = staffAssignment.AssignmentType; if (staffAssignment.OrganizationalUnit == "RootDepartment") { ParentDepartmentControl.AddEntity(staffAssignment.Resource); } else { ParentDepartmentControl.OrganizationalUnitPerName[staffAssignment.OrganizationalUnit].AddEntity(staffAssignment.Resource); } SequentialEvents.Add(staffAssignment.Resource.StartWaitingActivity(ParentDepartmentControl.WaitingRoomForStaff(staffAssignment.Resource))); } // end foreach DateTime nextTime; // schedule the next staff change Event nextChange = StaffHandler.GetNextStaffChangingEvent(ParentDepartmentControl, time, out nextTime); simEngine.AddScheduledEvent(nextChange, nextTime); } // end of Trigger