Example #1
0
        /// <summary>
        /// שליפת העונות המכילות את התאריך הלועזי בתאריך שנשלח
        /// </summary>
        /// <param name="isDefined"></param>
        /// <param name="tempDate"></param>
        /// <returns> null מחזיר את הרשימה שנשלפה. אם לא קיים מחזיר   </returns>
        public static List <Seasons> GetCurrentDate(bool isDefined, DateTime?tempDate = null)
        {
            if (tempDate == null)
            {
                tempDate = DateTime.Today;
            }
            DateTime             date          = (DateTime)tempDate;
            Hospital_DBEntities2 db            = new Hospital_DBEntities2();
            List <Seasons>       seasonList    = db.Seasons.Where(s => s.Date != null && s.IsDefined == isDefined).ToList();
            List <Seasons>       seasonNewList = new List <Seasons>();

            for (int i = 0; i < db.Seasons.Count(); i++)
            {
                try
                {
                    if ((seasonList[i].Date.Value <= new DateTime(seasonList[i].Date.Value.Year, date.Month, date.Day)) && (
                            seasonList[i].Date.Value.AddDays(seasonList[i].NumOfDays) >= new DateTime(seasonList[i].Date.Value.Year, date.Month, date.Day)))
                    {
                        seasonNewList.Add(seasonList[i]);
                    }
                }
                catch (ArgumentOutOfRangeException)
                {
                    continue;
                }
            }

            return(seasonList.Where(s =>
                                    (s.Date.Value <= new DateTime(s.Date.Value.Year, date.Month, date.Day) &&
                                     s.Date.Value.AddDays(s.NumOfDays) >= new DateTime(s.Date.Value.Year, date.Month, date.Day))).ToList());
        }
Example #2
0
        /// <returns>של המחלקות ובתי החולים Jason  מחזיר תבנית</returns>
        public static string GetDepartmentList()
        {
            Hospital_DBEntities2 DB = new Hospital_DBEntities2();
            string departments      = JsonConvert.SerializeObject(new Hospital_DBEntities2().Departments.ToList()
                                                                  .Select(i => new { i.HospitalCode, i.Hospitals.HospitalName
                                                                                     , i.DepartmentCode, i.BaseDepartmentCode, i.DepartmentTypes.DepartmentTypeName }));;

            return(departments);
        }
        /// <summary>
        /// משנה עונה לעונה מוגדרת כאשר יש מספיק מידע המוכיח את השוני המשמעותי בעונה
        /// </summary>
        /// <param name="seasonType"></param>
        /// <param name="num"></param>
        public static void DefineSeasonInfo(int seasonType, int num)
        {
            Hospital_DBEntities2 db          = new Hospital_DBEntities2();
            List <Seasons>       tempSeasons = new List <Seasons>();
            Seasons tempLongSeasons          = new Seasons();

            switch (seasonType)
            {
            case 1: { db.Seasons.Add(new Seasons {
                        Date = DateTime.Today.Date, IsDefined = true, NumOfDays = 1
                    }); db.SaveChanges(); tempSeasons = BLManager.GetCurrentDate(false); tempLongSeasons = BLManager.GetLongDateSeason(); BLManager.CurrentDate = db.Seasons.Last(); } break;

            case 2: { db.Seasons.Add(new Seasons {
                        HebrewDate = DateTime.Today.Date, IsDefined = true, NumOfDays = 1
                    }); db.SaveChanges(); tempSeasons = BLManager.GetCurrentHeberewDate(false); tempLongSeasons = BLManager.GetLongHeberewDateSeason(); BLManager.CurrentHeberewDate = db.Seasons.Last(); } break;

            case 3: { db.Seasons.Add(new Seasons {
                        DayOfWeek = (int)DateTime.Today.DayOfWeek, IsDefined = true, NumOfDays = 1
                    }); tempSeasons = BLManager.GetCurrentDayOfWeek(false); BLManager.CurrentDayOfWeek = db.Seasons.Last(); } break;
            }

            db.SaveChanges();
            List <SeasonInformation> seasonTempInfo = new List <SeasonInformation>();

            if (tempLongSeasons == null)
            {
                //מקבץ את כל המידע לתקופה של תקופת יום בשבוע מסויימת לא מוגדרות
                CombineSeasons(GetInfoForSeasonList(tempSeasons), num, db.Seasons.ToList().Last().SeasonCode);
            }
            else
            {
                if (seasonType == 1)
                {
                    BLManager.CurrentDate = tempLongSeasons;
                }
                else
                {
                    BLManager.CurrentHeberewDate = tempLongSeasons;
                }
                CombineSeasons(GetInfoForSeasonList(tempSeasons), 5, tempLongSeasons.SeasonCode);
                db.Seasons.Remove(db.Seasons.Last());
            }

            db.SeasonInformation.ToList().ForEach(se => tempSeasons.ForEach(s => { if (se.SeasonCode == s.SeasonCode)
                                                                                   {
                                                                                       seasonTempInfo.Add(se);
                                                                                   }
                                                                            }));
            db.SeasonInformation.RemoveRange(seasonTempInfo);
            db.SaveChanges();
            List <int> listCode = tempSeasons.Select(i => i.SeasonCode).ToList();

            db.Seasons.RemoveRange(db.Seasons.Where(item => listCode.Any(item2 => item2 == item.SeasonCode)));
        }
Example #4
0
        DailyTrigger trigger; // every day at 00:00

        public BLManager()
        {
            Hospital_DBEntities2 DB = new Hospital_DBEntities2();

            CurrentStatusDepartmentList = new List <CurrentStatusDepartment>();
            isFirstRun = true;
            DB.Departments.ToList().ForEach(i => CurrentStatusDepartmentList.Add(new CurrentStatusDepartment {
                DepartmentCode = i.DepartmentCode
            }));
            trigger = new DailyTrigger(11, 58);
            trigger.OnTimeTriggered += saveDataByTrigger;
        }
Example #5
0
        /// <summary>
        /// שליפת העונות המכילות את התאריך העברי בתאריך שנשלח
        /// </summary>
        /// <param name="isDefined"></param>
        /// <param name="tempDate"></param>
        /// <returns> null מחזיר את הרשימה שנשלפה. אם לא קיים מחזיר   </returns>
        public static List <Seasons> GetCurrentHeberewDate(bool isDefined, DateTime?tempDate = null)
        {
            if (tempDate == null)
            {
                tempDate = DateTime.Today;
            }
            DateTime             date       = (DateTime)tempDate;
            Hospital_DBEntities2 db         = new Hospital_DBEntities2();
            List <Seasons>       seasonList = db.Seasons.Where(s => s.HebrewDate != null && s.IsDefined == isDefined).ToList();

            return(seasonList.Where(s => date.IsInRange(s.HebrewDate.Value, s.NumOfDays) == true).ToList());
        }
        /// <summary>
        /// אם הממוצע היומי שונה משמעותית מהמידע הכללי ולא מופיע לתאריך זה מידע שהוגדר
        /// נוצר מופע חדש של עונה לא מוגדרת המכילה את כל הנתונים- תאריך עברי לועזי ויום בשבוע לצורך בדיקה
        /// </summary>
        public void AddSeason()
        {
            List <Seasons>       seasonToCheck = new List <Seasons>();
            Hospital_DBEntities2 db            = new Hospital_DBEntities2();

            if (BLManager.CurrentDate != null)
            {
                seasonToCheck.Add(BLManager.CurrentDate);
            }
            if (BLManager.CurrentHeberewDate != null)
            {
                seasonToCheck.Add(BLManager.CurrentHeberewDate);
            }
            else if (BLManager.CurrentDate == null)
            {
                seasonToCheck.Add(new Seasons {
                    Date = DateTime.Today, DayOfWeek = ((int)DateTime.Today.DayOfWeek) + 1, HebrewDate = DateTime.Today, IsDefined = false, NumOfDays = 1
                });
                db.Seasons.Add(seasonToCheck[0]);
                db.SaveChanges();
            }
            seasonToCheck.ForEach(s =>
            {
                db.SeasonInformation.Add(new SeasonInformation
                {
                    AddingDate       = DateTime.Today,
                    DepartmentCode   = DepartmentCode,
                    Ishistory        = false,
                    StaffAvg         = StaffAvg,
                    WaitersAvg       = WaitersAvg,
                    WaitingTimeAvg   = DayWaitingAvg,
                    Whidnesstochange = 1,
                    SeasonCode       = s.SeasonCode
                });
            });
            db.SaveChanges();
            if (BLManager.GetCurrentDate(false).Count() == 10)
            {
                DefineSeasonInfo(1, 5);
            }

            if (BLManager.GetCurrentHeberewDate(false).Count() == 10)
            {
                DefineSeasonInfo(2, 5);
            }

            if (BLManager.GetCurrentDayOfWeek(false).Count() == 100)
            {
                DefineSeasonInfo(3, 52);
            }
        }
Example #7
0
        /// <summary>
        /// מחשבת את זמן ההמתנה המשוער במחלקה ובאגף המיון יחד
        /// עפ"י התאריך-העברי הלועזי והיום בשבוע והמצב הנוכחי במחלקה
        /// </summary>
        /// <param name="departmentCode"></param>
        public void CalcWaitingTime(int departmentCode)
        {
            Hospital_DBEntities2 db             = new Hospital_DBEntities2();
            SeasonInformation    dayOfWeekAvg   = null;
            SeasonInformation    dateAvg        = null;
            SeasonInformation    heberewDateAvg = null;

            if (BLManager.CurrentDayOfWeek != null)
            {
                dayOfWeekAvg = BLManager.GetSeasonInformation(BLManager.CurrentDayOfWeek.SeasonCode, departmentCode, true);
            }
            //בגלל שיש שוני בין השנים והמועדים הלועזיים תלויים ביום בחודש ובחודש לכן היחס ליום הינו אילו היה חל בשנה בו נשמר המידע
            if (BLManager.CurrentDate != null)
            {
                dateAvg = BLManager.GetSeasonInformation(BLManager.CurrentDate.SeasonCode, departmentCode, true);
            }
            if (BLManager.CurrentHeberewDate != null)
            {
                heberewDateAvg = BLManager.GetSeasonInformation(BLManager.CurrentHeberewDate.SeasonCode, departmentCode, true);
            }
            if (dayOfWeekAvg == null && heberewDateAvg == null && dateAvg == null)
            {
                WaitingTime += StatisticsCalculations.CalcEstimatedWaitingTime(db.Departments.FirstOrDefault(d => d.DepartmentCode == departmentCode).SeasonInformation.FirstOrDefault(si => si.SeasonCode == db.Seasons.FirstOrDefault(s => s.HebrewDate == null && s.Date.Value == null && s.DayOfWeek == null).SeasonCode));
            }
            else if (dayOfWeekAvg != null && heberewDateAvg == null && dateAvg == null)
            {
                WaitingTime += StatisticsCalculations.CalcEstimatedWaitingTime(dayOfWeekAvg);
            }
            else if (heberewDateAvg != null && dateAvg == null)
            {
                WaitingTime += StatisticsCalculations.CalcEstimatedWaitingTime(heberewDateAvg);
            }
            else if (heberewDateAvg == null && dateAvg != null)
            {
                WaitingTime += StatisticsCalculations.CalcEstimatedWaitingTime(dateAvg);
            }
            else if (heberewDateAvg != null && dateAvg != null)//אם יום מסויים הינו גם תאריך עברי מיוחד וגם תאריך לועזי מיוחד משוקלל הממוצע של שניהם
            {
                WaitingTime += StatisticsCalculations.CalcEstimatedWaitingTime(heberewDateAvg);
                WaitingTime += StatisticsCalculations.CalcEstimatedWaitingTime(dateAvg);
                WaitingTime -= StatisticsCalculations.CalcEstimatedWaitingTime(BLManager.GetSeasonInformation(db.Seasons.FirstOrDefault(s => s.NumOfDays == 365).SeasonCode, departmentCode, true));
            }
            else //אין אף תאריך מיוחד סימן הזיהוי של המידע הכללי הינו אורך של 365 ימים
            {
                WaitingTime += StatisticsCalculations.CalcEstimatedWaitingTime(BLManager.GetSeasonInformation(db.Seasons.FirstOrDefault(s => s.NumOfDays == 365).SeasonCode, departmentCode, true));
            }
        }
Example #8
0
        /// <summary>
        /// ממלא רשימה של בתי החולים ונתוניהם החישוביים
        /// </summary>
        /// <param name="startPoint"></param>
        /// <param name="preferredhospitalCode"></param>
        /// <returns> מחזיר את הרשימה ממוינת מהמהיר לפחות</returns>
        public List <CalculateHospital> CalcDifference(string startPoint, int preferredhospitalCode,
                                                       int preferredDepartmentCode, int preferredWingCode)
        {
            int departmentType = 1, wingType = 7;
            Hospital_DBEntities2 db = new Hospital_DBEntities2();

            if (preferredDepartmentCode != -1)
            {
                departmentType = db.Departments.Where(d => d.DepartmentCode == preferredDepartmentCode).FirstOrDefault().DepartmentTypeCode;
            }
            if (preferredWingCode != -1)
            {
                wingType = db.Departments.Where(d => d.DepartmentCode == preferredWingCode).FirstOrDefault().DepartmentTypeCode;
            }
            db.Hospitals.ToList()
            .ForEach(i => CalculateHospitalList
                     .Add(new CalculateHospital {
                HospitalCode    = i.HospitalCode,
                HospitalName    = i.HospitalName,
                HospitalAdrress = i.Street + " " + i.HouseNum + " " + i.City + " " + i.Country,
                IsPreferred     = (i.HospitalCode == preferredhospitalCode)
            }));
            CalculateHospitalList.ForEach(i => {
                Departments dtc = db.Departments.FirstOrDefault(d => d.HospitalCode == i.HospitalCode && d.DepartmentTypeCode == departmentType);
                if (dtc == null)
                {
                    dtc = db.Departments.FirstOrDefault(d => d.HospitalCode == i.HospitalCode && d.DepartmentTypeCode == 1);
                }
                i.CalcWaitingTime(dtc.DepartmentCode);
                dtc = db.Departments.FirstOrDefault(d => d.HospitalCode == i.HospitalCode && d.DepartmentTypeCode == wingType);
                if (dtc == null)
                {
                    dtc = db.Departments.FirstOrDefault(d => d.HospitalCode == i.HospitalCode && d.DepartmentTypeCode == 7);
                }
                i.CalcWaitingTime(dtc.DepartmentCode);
                i.GooglePlaces(startPoint);
            });
            CalculateHospitalList = CalculateHospitalList.Where(h => h.WaitingTime > 0 && h.TravelingTime > 0).ToList();
            CalculateHospitalList = CalculateHospitalList.OrderBy(i => i.TravelingTime + i.WaitingTime).ToList();//מיון על פי חישוב משך הזמן הכולל
            return(CalculateHospitalList);
        }
        /// <summary>
        ///צירוף מס' עונות לעונה אחת וקישור כל יחידות המידע של העונות לעונה החדשה שהוגדרה
        ///או כאשר רוצים ליצור עונה מוגדרת ארוכה מ-2 עונות מוגדרות רצופות)
        ///(או ליצור ממס' עונות לא מוגדרות של אותו תאריך עונה מוגדרת אחת
        /// </summary>
        /// <param name="seasonInfo">רשימת העונות שרוצים לצרף</param>
        /// <param name="num">המס' לפיו יוחלט האם המידע לעונה הוא היסטורי</param>
        public static void CombineSeasons(List <SeasonInformation> seasonInfo, int num, int seasonCode)
        {
            Hospital_DBEntities2 db = new Hospital_DBEntities2();

            seasonInfo
            .GroupBy(p => p.DepartmentCode)
            .Select(g => g.ToList())
            .ToList()
            .ForEach(i =>
            {
                db.SeasonInformation.Add(new SeasonInformation
                {
                    SeasonCode       = seasonCode,
                    StaffAvg         = (int)i.Average(s => s.StaffAvg),
                    WaitersAvg       = (int)i.Average(s => s.WaitersAvg),
                    WaitingTimeAvg   = (int)i.Average(s => s.WaitingTimeAvg),
                    Whidnesstochange = i.Count(),
                    DepartmentCode   = i.First().DepartmentCode,
                    Ishistory        = (i.Count >= num)
                });
                db.SaveChanges();
            });
        }
Example #10
0
        /// <summary>
        /// שומר/משכלל את הממוצעים היומיים במסד הנתונים
        /// </summary>
        /// <param name="information"></param>
        public void SetSeasonInfoInDB(SeasonInformation information)
        {
            Hospital_DBEntities2 db = new Hospital_DBEntities2();

            information                = db.SeasonInformation.Where(i => i.InfoCode == information.InfoCode).First();
            information.WaitersAvg     = (information.WaitersAvg * information.Whidnesstochange + WaitersAvg) / ++information.Whidnesstochange;
            information.StaffAvg       = (information.StaffAvg * (information.Whidnesstochange - 1) + StaffAvg) / information.Whidnesstochange;
            information.WaitingTimeAvg = (int)(information.WaitingTimeAvg * (information.Whidnesstochange - 1) + DayWaitingAvg) / information.Whidnesstochange;
            db.SaveChanges();
            //האם להעביר מידע לתקופה להיסטורי לפי מרחב המדגם
            if ((information.Seasons.DayOfWeek != null && information.Whidnesstochange == 52 /*(one year)*/) || (information.Seasons.DayOfWeek == null && information.Whidnesstochange == 5 /*(5 years)*/))
            {
                information.Ishistory = true;
                db.SaveChanges();
                db.SeasonInformation.Add(new SeasonInformation {
                    Ishistory      = false,
                    DepartmentCode = information.DepartmentCode,
                    SeasonCode     = information.SeasonCode,
                    AddingDate     = DateTime.Today
                });
                db.SaveChanges();
            }
        }
Example #11
0
        /// <summary>
        /// שליפת העונות המכילות את היום בשבוע בתאריך שנשלח
        /// </summary>
        /// <param name="isDefined"></param>
        /// <param name="tempDate"></param>
        /// <returns> null מחזיר את הרשימה שנשלפה. אם לא קיים מחזיר   </returns>
        public static List <Seasons> GetCurrentDayOfWeek(bool isDefined)
        {
            Hospital_DBEntities2 db = new Hospital_DBEntities2();

            return(db.Seasons.Where(i => i.DayOfWeek.Value == (int)DateTime.Today.DayOfWeek && i.IsDefined == isDefined).ToList());
        }