コード例 #1
0
        } // end of EntityLeaveControlUnit

        #endregion

        //--------------------------------------------------------------------------------------------------
        // Custom Methods
        //--------------------------------------------------------------------------------------------------

        #region ChooseResourcesForAction

        /// <summary>
        /// Helping method to choose resource for action requests, first available resources
        /// that satisfy requirements are chosen
        /// </summary>
        /// <param name="actionRequest">Request for that resources are looked for</param>
        /// <param name="resources">Out parameter that represent the assigned resources</param>
        /// <returns>True if all resources have been assigned, false else</returns>
        public bool ChooseResourcesForAction(
            RequestSpecialFacilityAction actionRequest,
            out ResourceSet resources)
        {
            resources = new ResourceSet();

            #region Doctors

            List <EntityDoctor> chosenDoctors = new List <EntityDoctor>();

            #region MainDoc

            if (actionRequest.ActionType.MainDoctorRequirements != null)
            {
                if (actionRequest.ResourceSet.MainDoctor != null)
                {
                    if (actionRequest.ResourceSet.MainDoctor.IsWaiting())
                    {
                        chosenDoctors.Add(resources.MainDoctor);
                        resources.MainDoctor = actionRequest.ResourceSet.MainDoctor;
                    }
                    else
                    {
                        return(false);
                    } // end if
                }
                else
                {
                } // end if
            }     // end if

            #endregion

            #region AssistingDoctors

            if (actionRequest.ActionType.AssistingDoctorRequirements != null)
            {
                if (actionRequest.ResourceSet.AssistingDoctors != null)
                {
                    foreach (EntityDoctor doctor in actionRequest.ResourceSet.AssistingDoctors)
                    {
                        if (!doctor.IsWaiting())
                        {
                            return(false);
                        }
                    } // end foreach
                }
                else
                {
                    List <EntityDoctor> foundDoctors = new List <EntityDoctor>();

                    List <EntityDoctor> allDoctors = new List <EntityDoctor>(ControlledDoctors);

                    foreach (SkillSet skillSet in actionRequest.ActionType.AssistingDoctorRequirements)
                    {
                        EntityDoctor foundDoc = null;

                        foreach (EntityDoctor doc in allDoctors)
                        {
                            if (doc.IsWaiting() &&
                                doc.SatisfiesSkillSet(skillSet) &&
                                !chosenDoctors.Contains(doc) &&
                                !doc.StaffOutsideShift)
                            {
                                foundDoc = doc;
                                break;
                            } // end if
                        }     // end foreach

                        if (foundDoc == null)
                        {
                            return(false);
                        }
                        else
                        {
                            allDoctors.Remove(foundDoc);
                            foundDoctors.Add(foundDoc);
                            chosenDoctors.Add(foundDoc);
                        } // end if
                    }     // end foreach

                    resources.AssistingDoctors = foundDoctors.ToArray();
                } // end if
            }     // end if

            #endregion

            #endregion

            #region Nurses

            List <EntityNurse> chosenNurses = new List <EntityNurse>();

            #region MainNurse

            if (actionRequest.ActionType.MainNurseRequirements != null)
            {
                if (actionRequest.ResourceSet.MainNurse != null)
                {
                    if (actionRequest.ResourceSet.MainNurse.IsWaiting())
                    {
                        chosenNurses.Add(resources.MainNurse);
                        resources.MainNurse = actionRequest.ResourceSet.MainNurse;
                    }
                    else
                    {
                        return(false);
                    } // end if
                }
                else
                {
                    List <EntityNurse> possibleDocs = ControlledNurses.Where(p => p.IsWaiting() &&
                                                                             p.SatisfiesSkillSet(actionRequest.ActionType.MainNurseRequirements) &&
                                                                             !p.StaffOutsideShift).ToList();

                    if (possibleDocs.Count == 0)
                    {
                        return(false);
                    }

                    resources.MainNurse = possibleDocs.First();
                    chosenNurses.Add(resources.MainNurse);
                } // end if
            }     // end if

            #endregion

            #region AssistingNurses

            if (actionRequest.ActionType.AssistingNurseRequirements != null)
            {
                if (actionRequest.ResourceSet.AssistingNurses != null)
                {
                    foreach (EntityNurse nurse in actionRequest.ResourceSet.AssistingNurses)
                    {
                        if (!nurse.IsWaiting())
                        {
                            return(false);
                        }
                    } // end foreach
                }
                else
                {
                    List <EntityNurse> foundNurses = new List <EntityNurse>();

                    List <EntityNurse> allNurses = new List <EntityNurse>(ControlledNurses);

                    foreach (SkillSet skillSet in actionRequest.ActionType.AssistingNurseRequirements)
                    {
                        EntityNurse foundDoc = null;

                        foreach (EntityNurse nurse in allNurses)
                        {
                            if (nurse.IsWaiting() &&
                                nurse.SatisfiesSkillSet(skillSet) &&
                                !chosenNurses.Contains(nurse) &&
                                !nurse.StaffOutsideShift)
                            {
                                foundDoc = nurse;
                                break;
                            } // end if
                        }     // end foreach

                        if (foundDoc == null)
                        {
                            return(false);
                        }
                        else
                        {
                            allNurses.Remove(foundDoc);
                            foundNurses.Add(foundDoc);
                            chosenNurses.Add(foundDoc);
                        } // end if
                    }     // end foreach

                    resources.AssistingNurses = foundNurses.ToArray();
                } // end if
            }     // end if

            #endregion

            #endregion

            #region TreatmentFacilities

            bool foundFacility = false;

            foreach (EntityTreatmentFacility fac in AssignedTreatmentFacilities.Where(p => !p.BlockedForPatient))
            {
                if (!fac.Occupied && fac.SatisfiesSkillSet(actionRequest.ActionType.FacilityRequirements))
                {
                    resources.TreatmentFacility = fac;
                    foundFacility = true;
                    break;
                } // end if
            }     // end foreach

            if (!foundFacility)
            {
                return(false);
            }

            #endregion

            return(true);
        } // end of ChooseResourcesForAction
コード例 #2
0
        } // end of PerformAssessment

        #endregion

        #region PerformDisptatching

        /// <summary>
        /// Handles requests of staff members to leave that are out of shift, routes action requests
        /// to corresponding organizational control units and handles a shared treatment facility by
        /// assigning it to the busier organizational unit
        /// </summary>
        /// <param name="startTime">Time rules are executed</param>
        /// <param name="simEngine">SimEngine responsible for simulation execution</param>
        /// <returns>False</returns>
        protected bool PerformDisptatching(DateTime time, ISimulationEngine simEngine)
        {
            #region StaffOutsideShift

            List <RequestBeAbsent> staffEndRequests = RAEL.Where(p => p is RequestBeAbsent).Cast <RequestBeAbsent>().ToList();

            foreach (RequestBeAbsent req in staffEndRequests)
            {
                if (req.StaffMember.IsWaiting() && req.StaffMember.CurrentPatients.Count == 0)
                {
                    req.StaffMember.StopCurrentActivities(time, simEngine);
                    EventStaffLeave staffLeave = new EventStaffLeave(req.StaffMember.ParentControlUnit, req.StaffMember);

                    staffLeave.Trigger(time, simEngine);

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

            #endregion

            #region RequestRouting

            List <RequestEmergencyAction> actionRequests = new List <RequestEmergencyAction>(RAEL.Where(p => p.Activity == "ActivityHealthCareAction").Cast <RequestEmergencyAction>());

            foreach (RequestEmergencyAction request in actionRequests)
            {
                if (request.ActionType.Type == "Triage" || request.ActionType.Type == "Register")
                {
                    OrganizationalUnitPerName["OrgUnitTriageRegister"].AssignRequest(request);
                }
                else
                {
                    if (request.Patient.PatientClass.Category == "Surgical")
                    {
                        OrganizationalUnitPerName["OrgUnitSurgical"].AssignRequest(request);
                    }
                    else
                    {
                        OrganizationalUnitPerName["OrgUnitInternal"].AssignRequest(request);
                    }
                } // end if

                RemoveRequest(request);
            } // end foreach

            #endregion

            #region ResourceSharing

            foreach (EntityTreatmentFacility sharedTreatFac in AssignedTreatmentFacilities.Where(p => p.AssignmentType == AssignmentType.Shared))
            {
                if (sharedTreatFac.PatientBlocking != null)
                {
                    continue;
                }

                if (sharedTreatFac.CurrentlyAssignedOrganizationalUnit != null)
                {
                    sharedTreatFac.CurrentlyAssignedOrganizationalUnit.RemoveAssignedTreatmentFacility(sharedTreatFac);
                }

                if (OrganizationalUnitPerName["OrgUnitInternal"].RAEL.Count > OrganizationalUnitPerName["OrgUnitSurgical"].RAEL.Count)
                {
                    OrganizationalUnitPerName["OrgUnitSurgical"].AddAssignedTreatmentFacility(sharedTreatFac);
                }
                else
                {
                    OrganizationalUnitPerName["OrgUnitInternal"].AddAssignedTreatmentFacility(sharedTreatFac);
                } // end if
            }     // end foreach

            #endregion

            return(false);
        } // end of PerformDisptatching