Exemple #1
0
        /// <summary>
        /// Zwraca wartość określającą czy wskazany pracownik pracuje w danym dniu.
        /// </summary>
        /// <param name="workerId">ID pracownika, którego grafik ma zostać sprawdzony.</param>
        /// <param name="date">Dzień, pod kątem którego grafik ma zostać sprawdzony. Wartość null powoduje, że ta metoda zwraca false.</param>
        /// <returns>
        /// true jeśli pracownik pracuje w danym dniu,
        /// false jeśli nie pracuje, nie znaleziono pracownika o podanym ID lub jeśli drugi argument to null.
        /// </returns>
        public bool IsWorking(int workerId, DateTime date)
        {
            bool retval = false;

            if (date != null && workerId > 0)
            {
                // szukanie grafika danego pracownika, który obowiązuje w podanym dniu
                // (obowiązuje co najmniej od wskazanego dnia i nie ma daty utraty ważności lub data ta jest nie wcześniejsza niż data podana w argumencie)
                A_Schedule schedule = userService.SelectSchedule(x => x.WorkerId == workerId && x.ValidFrom <= date && (x.ValidTo == null || x.ValidTo >= date));

                // sprawdzanie, czy pracownik ma określone godziny pracy na wskazany dzień tygodnia
                switch (date.DayOfWeek)
                {
                case DayOfWeek.Monday:
                    if (schedule.D1From != null && schedule.D1To != null)
                    {
                        retval = true;
                    }
                    break;

                case DayOfWeek.Tuesday:
                    if (schedule.D2From != null && schedule.D2To != null)
                    {
                        retval = true;
                    }
                    break;

                case DayOfWeek.Wednesday:
                    if (schedule.D3From != null && schedule.D3To != null)
                    {
                        retval = true;
                    }
                    break;

                case DayOfWeek.Thursday:
                    if (schedule.D4From != null && schedule.D4To != null)
                    {
                        retval = true;
                    }
                    break;

                case DayOfWeek.Friday:
                    if (schedule.D5From != null && schedule.D5To != null)
                    {
                        retval = true;
                    }
                    break;

                case DayOfWeek.Saturday:
                    if (schedule.D6From != null && schedule.D6To != null)
                    {
                        retval = true;
                    }
                    break;
                }
            }

            return(retval);
        }
Exemple #2
0
        /// <summary>
        /// Pobiera z bazy danych grafik spełniający podane warunki.
        /// </summary>
        /// <param name="predicate">Funkcja (predykat) sprawdzająca warunek dla każdego elementu. Wartość null powoduje, że ta metoda również zwraca null.</param>
        /// <returns>
        /// Obiekt reprezentujący rekord z tabeli A_Schedules,
        /// null jeżeli nie znaleziono grafika odpowiadającego podanym warunkom lub podany argument to null.
        /// </returns>
        public A_Schedule SelectSchedule(System.Linq.Expressions.Expression <Func <A_Schedule, bool> > predicate)
        {
            A_Schedule entity = null;

            if (predicate != null)
            {
                db     = new MedicalCenterDBContainer();
                entity = db.A_Schedules.FirstOrDefault(predicate);
                db.Dispose();
            }

            return(entity);
        }
Exemple #3
0
        /// <summary>
        /// Pobiera z bazy danych godziny pracy wskazanego pracownika w danym dniu.
        /// </summary>
        /// <param name="workerId">ID pracownika, którego godziny pracy mają zostać pobrane.</param>
        /// <param name="date">Dzień, z którego godziny pracy pracownika mają zostać pobrane. Wartość null powoduje, że ta metoda również zwraca null.</param>
        /// <returns>
        /// Napis zawierający godziny pracy wybranego pracownika w danym dniu, w formacie {godzina od} - {godzina do},
        /// null jeśli nie znaleziono grafika dla wskazanego pracownika i/lub objemującego podaną datę, nie znaleziono pracownika o podanym ID, albo drugi argument to null.
        /// </returns>
        public string GetWorkingHours(int workerId, DateTime date)
        {
            string workingHours = null;

            if (date != null && workerId > 0)
            {
                // szukanie grafika danego pracownika, który obowiązuje w podanym dniu
                // (obowiązuje co najmniej od wskazanego dnia i nie ma daty utraty ważności lub data ta jest nie wcześniejsza niż data podana w argumencie)
                A_Schedule schedule = userService.SelectSchedule(x => x.WorkerId == workerId && x.ValidFrom <= date && (x.ValidTo == null || x.ValidTo >= date));

                if (schedule != null)
                {
                    switch (date.DayOfWeek)
                    {
                    case DayOfWeek.Monday:
                        if (schedule.D1From != null && schedule.D1To != null)
                        {
                            workingHours  = ((schedule.D1From.Value.Hour == 0) ? "00" : schedule.D1From.Value.Hour.ToString());
                            workingHours += ":" + ((schedule.D1From.Value.Minute == 0) ? "00" : schedule.D1From.Value.Minute.ToString());
                            workingHours += " - " + ((schedule.D1To.Value.Hour == 0) ? "00" : schedule.D1To.Value.Hour.ToString());
                            workingHours += ":" + ((schedule.D1To.Value.Minute == 0) ? "00" : schedule.D1To.Value.Minute.ToString());
                        }
                        break;

                    case DayOfWeek.Tuesday:
                        if (schedule.D2From != null && schedule.D2To != null)
                        {
                            workingHours  = ((schedule.D2From.Value.Hour == 0) ? "00" : schedule.D2From.Value.Hour.ToString());
                            workingHours += ":" + ((schedule.D2From.Value.Minute == 0) ? "00" : schedule.D2From.Value.Minute.ToString());
                            workingHours += " - " + ((schedule.D2To.Value.Hour == 0) ? "00" : schedule.D2To.Value.Hour.ToString());
                            workingHours += ":" + ((schedule.D2To.Value.Minute == 0) ? "00" : schedule.D2To.Value.Minute.ToString());
                        }
                        break;

                    case DayOfWeek.Wednesday:
                        if (schedule.D3From != null && schedule.D3To != null)
                        {
                            workingHours  = ((schedule.D3From.Value.Hour == 0) ? "00" : schedule.D3From.Value.Hour.ToString());
                            workingHours += ":" + ((schedule.D3From.Value.Minute == 0) ? "00" : schedule.D3From.Value.Minute.ToString());
                            workingHours += " - " + ((schedule.D3To.Value.Hour == 0) ? "00" : schedule.D3To.Value.Hour.ToString());
                            workingHours += ":" + ((schedule.D3To.Value.Minute == 0) ? "00" : schedule.D3To.Value.Minute.ToString());
                        }
                        break;

                    case DayOfWeek.Thursday:
                        if (schedule.D4From != null && schedule.D4To != null)
                        {
                            workingHours  = ((schedule.D4From.Value.Hour == 0) ? "00" : schedule.D4From.Value.Hour.ToString());
                            workingHours += ":" + ((schedule.D4From.Value.Minute == 0) ? "00" : schedule.D4From.Value.Minute.ToString());
                            workingHours += " - " + ((schedule.D4To.Value.Hour == 0) ? "00" : schedule.D4To.Value.Hour.ToString());
                            workingHours += ":" + ((schedule.D4To.Value.Minute == 0) ? "00" : schedule.D4To.Value.Minute.ToString());
                        }
                        break;

                    case DayOfWeek.Friday:
                        if (schedule.D5From != null && schedule.D5To != null)
                        {
                            workingHours  = ((schedule.D5From.Value.Hour == 0) ? "00" : schedule.D5From.Value.Hour.ToString());
                            workingHours += ":" + ((schedule.D5From.Value.Minute == 0) ? "00" : schedule.D5From.Value.Minute.ToString());
                            workingHours += " - " + ((schedule.D5To.Value.Hour == 0) ? "00" : schedule.D5To.Value.Hour.ToString());
                            workingHours += ":" + ((schedule.D5To.Value.Minute == 0) ? "00" : schedule.D5To.Value.Minute.ToString());
                        }
                        break;

                    case DayOfWeek.Saturday:
                        if (schedule.D6From != null && schedule.D6To != null)
                        {
                            workingHours  = ((schedule.D6From.Value.Hour == 0) ? "00" : schedule.D6From.Value.Hour.ToString());
                            workingHours += ":" + ((schedule.D6From.Value.Minute == 0) ? "00" : schedule.D6From.Value.Minute.ToString());
                            workingHours += " - " + ((schedule.D6To.Value.Hour == 0) ? "00" : schedule.D6To.Value.Hour.ToString());
                            workingHours += ":" + ((schedule.D6To.Value.Minute == 0) ? "00" : schedule.D6To.Value.Minute.ToString());
                        }
                        break;
                    }
                }
            }

            return(workingHours);
        }
Exemple #4
0
        /// <summary>
        /// Pobiera z bazy wybrany grafik wskazanego lekarza, a następnie oblicza ilu maksymalnie pacjentów może przyjąć w podanym dniu tygodnia ten lekarz.
        /// </summary>
        /// <param name="doctorId">ID lekarza, którego grafik ma zostać rozpatrzony.</param>
        /// <param name="date">Data, którą objemować ma grafik. Wartość null powoduje, że ta metoda zwraca wartość -1.</param>
        /// <returns>
        /// Maksymalną liczbę pacjentów, jaką lekarz może przyjąć w danym dniu tygodnia, wg. wybranego grafika,
        /// 0 jeśli nie znaleziono grafika dla wskazanego lekarza lub nie znaleziono lekarza o podanym ID,
        /// -1 jeśli nie znaleziono grafika objemującego podaną datę,
        /// -15 (-0xFF) jeśli drugi argument to null.
        /// </returns>
        public int GetVisitsPerDay(int doctorId, DateTime date)
        {
            int visitsPerDay = 0;

            if (date != null)
            {
                if (doctorId > 0)
                {
                    // szukanie grafika danego pracownika, który obowiązuje w podanym dniu
                    // (obowiązuje co najmniej od wskazanego dnia i nie ma daty utraty ważności lub data ta jest nie wcześniejsza niż data podana w argumencie)
                    A_Schedule schedule = userService.SelectSchedule(x => x.WorkerId == doctorId && x.ValidFrom <= date && (x.ValidTo == null || x.ValidTo >= date));

                    if (schedule != null)
                    {
                        switch (date.DayOfWeek)
                        {
                        case DayOfWeek.Monday:
                            if (schedule.D1From != null && schedule.D1To != null)
                            {
                                visitsPerDay = (int)(schedule.D1To.Value.Subtract(schedule.D1From.Value).TotalMinutes / 20.0);
                            }
                            break;

                        case DayOfWeek.Tuesday:
                            if (schedule.D2From != null && schedule.D2To != null)
                            {
                                visitsPerDay = (int)(schedule.D2To.Value.Subtract(schedule.D2From.Value).TotalMinutes / 20.0);
                            }
                            break;

                        case DayOfWeek.Wednesday:
                            if (schedule.D3From != null && schedule.D3To != null)
                            {
                                visitsPerDay = (int)(schedule.D3To.Value.Subtract(schedule.D3From.Value).TotalMinutes / 20.0);
                            }
                            break;

                        case DayOfWeek.Thursday:
                            if (schedule.D4From != null && schedule.D4To != null)
                            {
                                visitsPerDay = (int)(schedule.D4To.Value.Subtract(schedule.D4From.Value).TotalMinutes / 20.0);
                            }
                            break;

                        case DayOfWeek.Friday:
                            if (schedule.D5From != null && schedule.D5To != null)
                            {
                                visitsPerDay = (int)(schedule.D5To.Value.Subtract(schedule.D5From.Value).TotalMinutes / 20.0);
                            }
                            break;

                        case DayOfWeek.Saturday:
                            if (schedule.D6From != null && schedule.D6To != null)
                            {
                                visitsPerDay = (int)(schedule.D6To.Value.Subtract(schedule.D6From.Value).TotalMinutes / 20.0);
                            }
                            break;
                        }
                    }
                    else
                    {
                        visitsPerDay = -1;
                    }
                }
            }
            else
            {
                visitsPerDay = -0xFF;
            }

            return(visitsPerDay);
        }
        /// <summary>
        /// Tworzy listę planowych godzin rozpoczęcia wizyt, zawierającą także informacje o zarejestrowanych wizytach.
        /// </summary>
        /// <param name="doctorId">ID lekarza, którego tworzona lista dotyczy.</param>
        /// <param name="date">Dzień, z którego lista ma zostać utworzona. Wartość null powoduje, że ta metoda również zwraca null.</param>
        /// <returns>
        /// Lista obiektów z informacjami o wizytach (lub "pustych"),
        /// null jeśli lekarz nie przyjmuje we wskazanym dniu, nie znaleziono lekarza o podanym ID lub drugi argument to null.
        /// </returns>
        public List <DailyVisitsListItem> GetTodaysVisits(int doctorId, DateTime date)
        {
            List <DailyVisitsListItem> todaysVisits = null;

            if (date != null && doctorId > 0)
            {
                // jeśli wybrany dzień jest świętem lub pracownik jest nieobecny w tym dniu, to lista wizyt jest pusta
                if (!userBusinessService.IsHoliday(date) && !userBusinessService.IsWorkerAbsent(doctorId, date))
                {
                    // pobranie grafika wskazanego lekarza
                    A_Schedule schedule = userService.SelectSchedule(x => x.WorkerId == doctorId && x.ValidFrom <= date && (x.ValidTo == null || x.ValidTo >= date));

                    if (schedule != null)
                    {
                        DateTime dateOfVisit = date;
                        bool     hasSchedule = false;

                        // sprawdzenie czy w wybranym dniu tygodnia dany lekarz w ogóle pracuje
                        switch (date.DayOfWeek)
                        {
                        case DayOfWeek.Monday:
                            if (schedule.D1From != null && schedule.D1To != null)
                            {
                                hasSchedule = true;

                                //godzina startowa DXFrom
                                dateOfVisit = new DateTime(date.Year, date.Month, date.Day
                                                           , schedule.D1From.Value.Hour, schedule.D1From.Value.Minute, schedule.D1From.Value.Second);
                            }
                            break;

                        case DayOfWeek.Tuesday:
                            if (schedule.D2From != null && schedule.D2To != null)
                            {
                                hasSchedule = true;
                                dateOfVisit = new DateTime(date.Year, date.Month, date.Day
                                                           , schedule.D2From.Value.Hour, schedule.D2From.Value.Minute, schedule.D2From.Value.Second);
                            }
                            break;

                        case DayOfWeek.Wednesday:
                            if (schedule.D3From != null && schedule.D3To != null)
                            {
                                hasSchedule = true;
                                dateOfVisit = new DateTime(date.Year, date.Month, date.Day
                                                           , schedule.D3From.Value.Hour, schedule.D3From.Value.Minute, schedule.D3From.Value.Second);
                            }
                            break;

                        case DayOfWeek.Thursday:
                            if (schedule.D4From != null && schedule.D4To != null)
                            {
                                hasSchedule = true;
                                dateOfVisit = new DateTime(date.Year, date.Month, date.Day
                                                           , schedule.D4From.Value.Hour, schedule.D4From.Value.Minute, schedule.D4From.Value.Second);
                            }
                            break;

                        case DayOfWeek.Friday:
                            if (schedule.D5From != null && schedule.D5To != null)
                            {
                                hasSchedule = true;
                                dateOfVisit = new DateTime(date.Year, date.Month, date.Day
                                                           , schedule.D5From.Value.Hour, schedule.D5From.Value.Minute, schedule.D5From.Value.Second);
                            }
                            break;

                        case DayOfWeek.Saturday:
                            if (schedule.D6From != null && schedule.D6To != null)
                            {
                                hasSchedule = true;
                                dateOfVisit = new DateTime(date.Year, date.Month, date.Day
                                                           , schedule.D6From.Value.Hour, schedule.D6From.Value.Minute, schedule.D6From.Value.Second);
                            }
                            break;
                        }

                        // jeśli lekarz przyjmuje w danym dniu tygodnia
                        if (hasSchedule)
                        {
                            // pobranie listy wizyt zarejestrowanych do wybranego lekarza na wskazany dzień
                            List <M_Visit> temp = new List <M_Visit>(medicalService.SelectVisits(x => x.DoctorId == doctorId && x.DateOfVisit.Date == date.Date));

                            todaysVisits = new List <DailyVisitsListItem>();
                            M_Patient patient;

                            // podstawowym warunkiem stopu jest maksymalna liczba wizyt możliwych do zarejstrowania w dany dzień u danego lekarza
                            int stop = userBusinessService.GetVisitsPerDay(doctorId, date);

                            // jeśli rozważanym dniem jest dzień dzisiejszy, uwzględniane są także nagłe przypadki
                            if (date.Date == DateTime.Today)
                            {
                                stop += EmergencyCount(doctorId);
                            }

                            // stworzenie listy planowych godzin rozpoczęcia wizyt
                            for (int i = 0; i < stop; ++i)
                            {
                                // jeśli są jeszcze jakieś zarejestrowane wizyty
                                if (temp.Count > 0)
                                {
                                    // jeśli następna wizyta jest za więcej niż 20 minut lub została anulowana, wstawiamy do listy "puste miejsce"
                                    if (temp[0].DateOfVisit > dateOfVisit || temp[0].State > 2)
                                    {
                                        todaysVisits.Add(new DailyVisitsListItem(dateOfVisit));
                                    }
                                    else
                                    {
                                        // w przeciwnym razie wstawiamy do listy informacje o zarejestrowanej wizycie
                                        patient = patientService.SelectPatient(temp[0].PatientId);
                                        todaysVisits.Add(new DailyVisitsListItem(temp[0].DateOfVisit, patient.LastName, patient.FirstName, temp[0].State, temp[0].IsEmergency));
                                        temp.RemoveAt(0);
                                    }
                                }
                                // jeśli brak już zarejestrowanych wizyt, wstawiamy do listy "puste miejsce"
                                else
                                {
                                    todaysVisits.Add(new DailyVisitsListItem(dateOfVisit));
                                }

                                dateOfVisit = dateOfVisit.AddMinutes(20.0);
                            }

                            medicalService.Dispose();
                        }
                    }
                }
            }

            return(todaysVisits);
        }