コード例 #1
0
 /// <summary>
 /// Creates 10 doctors and adds them to the Doctors table
 /// </summary>
 public void ThreadFive()
 {
     //Skapar doctors och lägger till dem i doctorstabellen
     using (var db = new KrankenhausContext())
     {
         for (int i = 0; i < 10; i++)
         {
             var doctor = KrankenhausHelpMethods.GetANewRandomDoctor(rnd);
             db.Doctors.Add(doctor);
             db.SaveChanges();
         }
     }
 }
コード例 #2
0
        /// <summary>
        /// Updates the conditionLevel of the patients and adds a rotation point to the doctor assigned to the ICU and Sanatorium
        /// </summary>
        public void ThreadThree()
        {
            lock (krankenhausLock)
            {
                using (var db = new KrankenhausContext())
                {
                    var patientsToUpdate   = db.Patients.Where(P => P.SignedOut == null && P.ConditionLevel > 0 && P.ConditionLevel < 10).ToList();
                    var doctorInICU        = db.Doctors.Where(D => D.assignedToICU == true).FirstOrDefault();
                    var doctorInSanatorium = db.Doctors.Where(D => D.assignedToSantorium == true).FirstOrDefault();

                    int doctorInICUSkill        = 0;
                    int doctorInSanatoriumSkill = 0;

                    if (doctorInICU != null)
                    {
                        doctorInICUSkill = doctorInICU.SkillLevel;
                        doctorInICUSkill = doctorInICU.NumberOfRotationsLeft > 0 ? doctorInICU.SkillLevel : 0;
                        doctorInICU.NumberOfRotationsLeft += -1;
                        db.SaveChanges();
                    }
                    if (doctorInSanatorium != null)
                    {
                        doctorInSanatoriumSkill = doctorInSanatorium.SkillLevel;
                        doctorInSanatoriumSkill = doctorInSanatorium.NumberOfRotationsLeft > 0 ? doctorInSanatorium.SkillLevel : 0;
                        doctorInSanatorium.NumberOfRotationsLeft += -1;
                        db.SaveChanges();
                    }


                    for (int i = 0; i < patientsToUpdate.Count; i++)
                    {
                        if (patientsToUpdate[i].PatientQueueID != null)
                        {
                            patientsToUpdate[i].ConditionLevel = KrankenhausHelpMethods.ModifyCoditionLevelQueue(rnd, patientsToUpdate[i].ConditionLevel);
                        }
                        else if (patientsToUpdate[i].SanatoriumID != null)
                        {
                            patientsToUpdate[i].ConditionLevel = KrankenhausHelpMethods.ModifyCoditionLevelSanatorium(rnd, patientsToUpdate[i].ConditionLevel, doctorInSanatoriumSkill);
                        }
                        else if (patientsToUpdate[i].IntensiveCareUnitID != null)
                        {
                            patientsToUpdate[i].ConditionLevel = KrankenhausHelpMethods.ModifyCoditionLevelICU(rnd, patientsToUpdate[i].ConditionLevel, doctorInICUSkill);
                        }

                        db.SaveChanges();
                    }
                }
            }
        }
        /// <summary>
        /// Moves all records in the patient table to a patientHistory table
        /// </summary>
        /// <param name="simulationNumber"></param>
        internal void MovePatientInfoToHistory(int simulationNumber)
        {
            using (var db = new KrankenhausContext())
            {
                var patients = db.Patients.ToList();

                for (int i = 0; i < patients.Count; i++)
                {
                    var patientsHistory = KrankenhausHelpMethods.GetAPatientHistory(patients[i], simulationNumber);
                    db.Patients.Remove(patients[i]);
                    db.PatientHistories.Add(patientsHistory);
                    db.SaveChanges();
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Creates 30 patients and adds them to the PatienQueue
        /// </summary>
        public void ThreadOne()
        {
            lock (krankenhausLock)
            {
                using (var db = new KrankenhausContext())
                {
                    for (int i = 0; i < 30; i++)
                    {
                        var newQueueSlip = new PatientQueue();
                        db.PatientQueue.Add(newQueueSlip);
                        db.SaveChanges();

                        var newPatient = KrankenhausHelpMethods.GetANewRandomPatient(rnd);
                        newPatient.PatientQueue = newQueueSlip;
                        db.Patients.Add(newPatient);
                        db.SaveChanges();
                    }

                    db.SaveChanges();
                }
            }
        }