} // end of HandleAvailabilitiesSpecialServiceRequest #endregion #region HandleRequireDocs /// <summary> /// Handles a request to send doctors for consultation or assisting between departments /// </summary> /// <param name="del">The original request for doctors to consult or assist</param> /// <param name="controlUnit">Control unit that filed request for assistance or consultation</param> /// <param name="time">Time request was filed</param> /// <param name="simEngine">SimEngine responsible for simulation execution</param> /// <returns>True if request has been handled</returns> static public bool HandleRequireDocs(IDelegate del, ControlUnit controlUnit, DateTime time, ISimulationEngine simEngine) { foreach (SkillSet reqSkill in ((DelegateRequestDocsForAssisting)del).RequiredSkillSets) { List <EntityDoctor> possibleDoc = ((ControlUnitHealthCare)controlUnit).FindDoctorWithSkillSet(reqSkill); if (possibleDoc.Count == 0) { break; } EntityDoctor chosenDoc = null; foreach (EntityDoctor doc in possibleDoc) { if (doc.ParentControlUnit == controlUnit) { ActivityMove possibleMove = doc.GetPossibleMovingActivity(); if (possibleMove != null && (possibleMove.Destination == del.OriginControlUnit || possibleMove.Destination == doc.BaseControlUnit)) { chosenDoc = doc; break; } // end if } // end if if (((ControlUnitHealthCare)doc.ParentControlUnit).ControlUnitType == Enums.ControlUnitType.Inpatient) { chosenDoc = doc; break; } // end if } // end foreach if (chosenDoc == null) { chosenDoc = possibleDoc.First(); } if (chosenDoc.ParentControlUnit == controlUnit) { ActivityMove possibleMove = chosenDoc.GetPossibleMovingActivity(); if (possibleMove != null && possibleMove.Destination == chosenDoc.BaseControlUnit) { simEngine.RemoveScheduledEvent(possibleMove.EndEvent); chosenDoc.StopCurrentActivities(time, simEngine); ActivityMove move = new ActivityMove(controlUnit, chosenDoc, controlUnit, del.OriginControlUnit, del, TimeSpan.FromMinutes(1)); move.StartEvent.Trigger(time, simEngine); } // end if } else { controlUnit.SendDelegateTo(chosenDoc.ParentControlUnit, new DelegateSentDocForAssistedTreatment((ControlUnitHealthCare)del.OriginControlUnit, reqSkill)); } // end if } // end foreach return(true); } // end of HandleRequireDocs
} // 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