コード例 #1
0
 private bool IsPhoneAlreadyExists(string phone)
 {
     using (MedicalClinicContext context = new MedicalClinicContext())
     {
         return(context.PersonalData.Any(user => user.PhoneNumber == phone));
     }
 }
コード例 #2
0
 private bool IsLoginAlreadyExists(string login)
 {
     using (MedicalClinicContext context = new MedicalClinicContext())
     {
         return(context.User.Any(user => user.Login == login));
     }
 }
コード例 #3
0
 private bool IsEmailAlreadyExists(string email)
 {
     using (MedicalClinicContext context = new MedicalClinicContext())
     {
         return(context.PersonalData.Any(user => user.Email == email));
     }
 }
コード例 #4
0
 private bool IsAnyDoctors()
 {
     using (var context = new MedicalClinicContext())
     {
         return(context.Doctor.Any());
     }
 }
コード例 #5
0
 private bool IsAnyConclusion()
 {
     using (var context = new MedicalClinicContext())
     {
         return(context.Conclusion.Any(conc => conc.MedcardId == patient.MedcardId));
     }
 }
コード例 #6
0
        private string CheckAppointmentPageValues(int patientId, DateTime dateOfMeeting, string timeOfMeeting)
        {
            string message = "";

            if (String.IsNullOrEmpty(timeOfMeeting))
            {
                message = "Оберіть час запису";
                return(message);
            }

            using (MedicalClinicContext context = new MedicalClinicContext())
            {
                DateTime checkDateTime = dateOfMeeting.AddHours(ParseTimeStringToInt(timeOfMeeting));
                if (context.Appointment
                    .FirstOrDefault(app => app.PatientId == patientId &&
                                    app.DateTimeOfMeeting == checkDateTime) != null)
                {
                    message = "У вас вже є запис на вказаний час";
                }

                int      doctorsPersonalDataId = (DoctorsField.SelectedItem as PersonalData).Id;
                DateTime?absentDate            = context.Doctor.FirstOrDefault(doc => doc.PersonalDataId == doctorsPersonalDataId).AbsentDate;
                if (absentDate != null)
                {
                    if (dateOfMeeting < absentDate)
                    {
                        message = "На жаль, доктор не приймає в цей день.\nВін буде доступний з " + ((DateTime)absentDate).ToShortDateString();
                    }
                }
            }

            return(message);
        }
コード例 #7
0
        private void SetDoctorsListItemSource()
        {
            Doctors.Items.Clear();

            using (var context = new MedicalClinicContext())
            {
                foreach (var doc in context.Doctor)
                {
                    string nameSurname = $"{doc.PersonalData.Surname} {doc.PersonalData.Name}";
                    string speciality  = doc.Speciality.Name;
                    string login       = doc.User.Login;
                    string absentDate;
                    if (doc.AbsentDate == null)
                    {
                        absentDate = "(немає)";
                    }
                    else
                    {
                        absentDate = ((DateTime)doc.AbsentDate).ToShortDateString();
                    }

                    Doctors.Items.Add(new ElemOfList(doc.Id, nameSurname, speciality, login, absentDate));
                }
            }
        }
コード例 #8
0
        private void ConfirmAppointmentButtonClick(object sender, RoutedEventArgs e)
        {
            int      doctorsId;
            int      patientId     = patient.Id;
            string   description   = DescriptionOfAppointment.Text;
            DateTime?dateOfMeeting = DateOfAppointment.SelectedDate;
            string   timeOfMeeting = TimeOfAppointment.SelectedItem == null ? "" : TimeOfAppointment.SelectedItem.ToString();

            using (MedicalClinicContext context = new MedicalClinicContext())
            {
                PersonalData doctorsPersData = (DoctorsField.SelectedItem as PersonalData);
                doctorsId = context.Doctor
                            .FirstOrDefault(doc => doc.PersonalDataId == doctorsPersData.Id).Id;
            }

            string errorMessage = CheckAppointmentPageValues(patientId, (DateTime)dateOfMeeting, timeOfMeeting);

            if (!String.IsNullOrEmpty(errorMessage))
            {
                MessageBox.Show(errorMessage);
            }
            else
            {
                AddAppointment(doctorsId, patientId, description, (DateTime)dateOfMeeting, timeOfMeeting);
                MessageBox.Show("Реєстрація на зустріч пройшла успішно");
                ClearAppointmentPage();
            }
        }
コード例 #9
0
        private List <string> ListOfTimeOfAppointment(int selectedDoctorId, DateTime selectedDate)
        {
            var timeOfAppointments = new List <string>();

            using (MedicalClinicContext context = new MedicalClinicContext())
            {
                List <Appointment> appointments = context.Appointment
                                                  .Where(app => app.DoctorsId == selectedDoctorId &&
                                                         app.DateTimeOfMeeting.Year == selectedDate.Year &&
                                                         app.DateTimeOfMeeting.Month == selectedDate.Month &&
                                                         app.DateTimeOfMeeting.Day == selectedDate.Day)
                                                  .OrderBy(app => app.DateTimeOfMeeting)
                                                  .ToList();

                DateTime time = new DateTime(1, 1, 1, 9, 0, 0);

                while (time.Hour <= 18)
                {
                    if (!appointments.Any(app => app.DateTimeOfMeeting.Hour == time.Hour))
                    {
                        timeOfAppointments.Add($"{time.Hour}:00");
                    }
                    time = time.AddHours(1);
                }
            }

            return(timeOfAppointments);
        }
コード例 #10
0
        private void AddPatient(string login, string pass, string name, string surname, int specialityId, string sex, DateTime?date, string email, string phone)
        {
            using (MedicalClinicContext context = new MedicalClinicContext())
            {
                Doctor doctor = new Doctor();
                doctor.SpecialityId = specialityId;

                PersonalData patientPersonalData = new PersonalData();
                patientPersonalData.Name        = name;
                patientPersonalData.Surname     = surname;
                patientPersonalData.Sex         = sex;
                patientPersonalData.DateOfBirth = (DateTime)date;
                patientPersonalData.Email       = email;
                patientPersonalData.PhoneNumber = phone;

                context.PersonalData.Add(patientPersonalData);
                context.SaveChanges();

                User patientUser = new User();
                patientUser.Login    = login;
                patientUser.Password = pass;

                context.User.Add(patientUser);
                context.SaveChanges();

                doctor.User         = patientUser;
                doctor.PersonalData = patientPersonalData;

                doctor.UserId          = patientUser.Id;
                doctor.PersonalData.Id = patientPersonalData.Id;

                context.Doctor.Add(doctor);
                context.SaveChanges();
            }
        }
コード例 #11
0
        private void DeleteButtonClick(object sender, RoutedEventArgs e)
        {
            List <int> idOfAppointments = (Appointments.ItemsSource as List <ElemOfGrid>).Where(app => app.IsSelected == true)
                                          .Select(app => app.IdOfAppointment)
                                          .ToList();

            if (idOfAppointments.Count != 0)
            {
                List <Appointment> rangeToRemove = new List <Appointment>();
                using (var context = new MedicalClinicContext())
                {
                    foreach (var id in idOfAppointments)
                    {
                        rangeToRemove.Add(context.Appointment.FirstOrDefault(app => app.Id == id));
                    }

                    context.Appointment.RemoveRange(rangeToRemove);
                    context.SaveChanges();
                }
                SetDataGridItemSource();

                MessageBox.Show("Зустріч(і) були іспішно відхилені");
            }
            else
            {
                MessageBox.Show("Ви не обрали записи, які треба відмінити");
            }
        }
コード例 #12
0
 private void SetDateOfAbsent(DateTime date)
 {
     using (var context = new MedicalClinicContext())
     {
         context.Doctor.FirstOrDefault(doc => doc.Id == DoctorsId).AbsentDate = date;
         context.SaveChanges();
     }
 }
コード例 #13
0
 private bool IsAnyAppointment()
 {
     using (var context = new MedicalClinicContext())
     {
         DateTime date = DateTime.Now.AddHours(-1);
         return(context.Appointment.Any(app => app.PatientId == patient.Id && app.DateTimeOfMeeting > date));
     }
 }
コード例 #14
0
 private bool IsAnyAppointmentsForToday()
 {
     using (var context = new MedicalClinicContext())
     {
         return(context.Appointment.Any(app => app.DateTimeOfMeeting.Year == DateTime.Now.Year &&
                                        app.DateTimeOfMeeting.Month == DateTime.Now.Month &&
                                        app.DateTimeOfMeeting.Day == DateTime.Now.Day));
     }
 }
コード例 #15
0
        public void DeleteDateClick(object sender, RoutedEventArgs e)
        {
            using (var context = new MedicalClinicContext())
            {
                context.Doctor.FirstOrDefault(doc => doc.Id == DoctorsId).AbsentDate = null;
                context.SaveChanges();
            }

            MessageBox.Show("Дата була успішно видалена");
        }
コード例 #16
0
        private void PageInitialState(int doctorsId)
        {
            using (var context = new MedicalClinicContext())
            {
                Doctor doctor = context.Doctor.FirstOrDefault(doc => doc.Id == doctorsId);

                NameOfDoctor.Text      = $"{doctor.PersonalData.Surname} {doctor.PersonalData.Name}";
                DoctorsSpeciality.Text = doctor.Speciality.Name;
            }
        }
コード例 #17
0
        private bool IsAnyAppointments(DateTime dateEnd)
        {
            using (var context = new MedicalClinicContext())
            {
                DateTime dateStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
                dateStart = dateStart.AddDays(1);

                return(context.Appointment.Any(app => app.DateTimeOfMeeting > dateStart &&
                                               app.DateTimeOfMeeting < dateEnd));
            }
        }
コード例 #18
0
        private void SignOutInitialState()
        {
            DateText.DisplayDateStart = DateTime.Now.AddYears(-100);
            DateText.DisplayDateEnd   = DateTime.Now;

            using (var context = new MedicalClinicContext())
            {
                foreach (var spec in context.Speciality.OrderBy(spec => spec.Name))
                {
                    Speciality.Items.Add(spec);
                }
            }
        }
コード例 #19
0
        private void ProcessingPage()
        {
            using (var context = new MedicalClinicContext()) {
                foreach (int id in AppointmentsId)
                {
                    Appointment appointment = context.Appointment.FirstOrDefault(app => app.Id == id);

                    string   nameSurname = $"{appointment.Patient.PersonalData.Surname} {appointment.Patient.PersonalData.Name}";
                    string   phone       = appointment.Patient.PersonalData.PhoneNumber;
                    DateTime date        = appointment.DateTimeOfMeeting;

                    Patients.Items.Add(new ElemOfList(nameSurname, phone, date));
                }
            }
        }
コード例 #20
0
        private void AddAppointment(int doctorsId, int patientId, string description, DateTime dateOfMeeting, string timeOfMeeting)
        {
            using (MedicalClinicContext context = new MedicalClinicContext())
            {
                Appointment appointment = new Appointment();

                appointment.DoctorsId          = doctorsId;
                appointment.PatientId          = patientId;
                appointment.Description        = description;
                appointment.DateOfRegistration = DateTime.Now;
                appointment.DateTimeOfMeeting  = dateOfMeeting.AddHours(ParseTimeStringToInt(timeOfMeeting));

                context.Appointment.Add(appointment);
                context.SaveChanges();
            }
        }
コード例 #21
0
        private void FillSpecialitiesField()
        {
            SpecialitiesField.Items.Clear();

            using (MedicalClinicContext context = new MedicalClinicContext())
            {
                List <int> specId = doctors.Select(elem => elem.SpecialityId).Distinct().ToList();

                foreach (var spec in context.Speciality.OrderBy(spec => spec.Name))
                {
                    if (specId.Any(elem => elem == spec.Id))
                    {
                        SpecialitiesField.Items.Add(spec.Name);
                    }
                }
            }
        }
コード例 #22
0
        private void SetAccountInfo()
        {
            using (MedicalClinicContext context = new MedicalClinicContext())
            {
                PersonalData data = context.PersonalData.FirstOrDefault(elem => elem.Id == patient.PersonalDataId);
                User         user = context.User.FirstOrDefault(elem => elem.Id == patient.UserId);

                LabelLogin.Content       = user.Login;
                LabelPassword.Content    = user.Password;
                LabelName.Content        = data.Name;
                LabelSurname.Content     = data.Surname;
                LabelSex.Content         = data.Sex;
                LabelDateOfBirth.Content = data.DateOfBirth.Date.ToShortDateString();
                LabelPhone.Content       = data.PhoneNumber;
                LabelEmail.Content       = data.Email;
            }
        }
コード例 #23
0
        private void FillDoctorsField(string selectedItem)
        {
            DoctorsField.Items.Clear();

            using (MedicalClinicContext context = new MedicalClinicContext())
            {
                int speciality = context.Speciality.ToList().Find(spec => spec.Name == selectedItem).Id;

                foreach (var doctor in doctors)
                {
                    if (speciality == doctor.SpecialityId)
                    {
                        DoctorsField.Items.Add(context.PersonalData.FirstOrDefault(data => data.Id == doctor.PersonalDataId));
                    }
                }
            }
        }
コード例 #24
0
        private void FillConclusionList()
        {
            using (var context = new MedicalClinicContext())
            {
                List <Conclusion> conclusions = context.Conclusion.Where(conc => conc.MedcardId == patient.MedcardId).ToList();

                foreach (var conclusion in conclusions)
                {
                    string   nameSurname = $"{conclusion.Appointment.Doctor.PersonalData.Surname} {conclusion.Appointment.Doctor.PersonalData.Name}";
                    string   speciality  = conclusion.Appointment.Doctor.Speciality.Name;
                    DateTime date        = conclusion.Appointment.DateTimeOfMeeting;

                    ElemOfList elem = new ElemOfList(conclusion.Id, nameSurname, speciality, date);

                    Conclusions.Items.Add(elem);
                }
            }
        }
コード例 #25
0
        private void DateOfAppointmentItemSelect(object sender, SelectionChangedEventArgs e)
        {
            var dp = sender as DatePicker;

            if (dp.SelectedDate == null)
            {
                return;
            }

            int selectedDoctorId;

            using (MedicalClinicContext context = new MedicalClinicContext())
            {
                PersonalData doctorsPersData = (DoctorsField.SelectedItem as PersonalData);
                selectedDoctorId = context.Doctor.FirstOrDefault(doc => doc.PersonalDataId == doctorsPersData.Id).Id;
            }

            FillTimePicker((DateTime)dp.SelectedDate, selectedDoctorId);
        }
コード例 #26
0
        private void ConclusionClick(object sender, SelectionChangedEventArgs e)
        {
            if (Conclusions.SelectedValue == null)
            {
                return;
            }

            var        lv   = sender as ListView;
            ElemOfList elem = lv.SelectedItem as ElemOfList;
            int        appointmentId;

            using (var context = new MedicalClinicContext())
            {
                appointmentId = context.Conclusion.FirstOrDefault(conc => conc.Id == elem.ConclusionId).AppointmentId;
            }

            new ConclusionResultWindow(appointmentId).ShowDialog();
            Conclusions.SelectedItem = null;
        }
コード例 #27
0
        private void DeleteAppointments(DateTime dateEnd)
        {
            using (var context = new MedicalClinicContext())
            {
                DateTime dateStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
                dateStart = dateStart.AddDays(1);

                List <Appointment> appointmnetsToDelete = context.Appointment
                                                          .Where(app => app.DateTimeOfMeeting > dateStart &&
                                                                 app.DateTimeOfMeeting < dateEnd).ToList();

                List <int> appointmentsId = appointmnetsToDelete.Select(app => app.Id).ToList();

                ShowPatients(appointmentsId);

                context.Appointment.RemoveRange(appointmnetsToDelete);
                context.SaveChanges();
            }
        }
コード例 #28
0
        private void SetAppointmentListItemSource()
        {
            using (var context = new MedicalClinicContext())
            {
                string date = DateTime.Now.ToShortDateString();

                List <Appointment> appointments = context.Appointment.Where(app => app.DateTimeOfMeeting.Year == DateTime.Now.Year &&
                                                                            app.DateTimeOfMeeting.Month == DateTime.Now.Month &&
                                                                            app.DateTimeOfMeeting.Day == DateTime.Now.Day)
                                                  .ToList();

                foreach (var app in appointments)
                {
                    Patient patient = context.Patient.FirstOrDefault(pat => pat.Id == app.PatientId);

                    string nameSurname = $"{patient.PersonalData.Surname} {patient.PersonalData.Name}";
                    Appointments.Items.Add(new ElemOfGrid(app.Id, nameSurname, app.Description, app.DateTimeOfMeeting.ToShortTimeString()));
                }
            }
        }
コード例 #29
0
        bool IsConclusionExists(int appointmentId, out int?conclusionId)
        {
            conclusionId = null;
            using (var context = new MedicalClinicContext())
            {
                var appointment = context.Appointment.FirstOrDefault(app => app.Id == appointmentId);

                var conclusion = context.Conclusion.FirstOrDefault(conc => conc.AppointmentId == appointmentId);

                if (conclusion != null)
                {
                    conclusionId = conclusion.Id;
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
コード例 #30
0
        private void AddPatient(string login, string pass, string name, string surname, string sex, DateTime?date, string email, string phone)
        {
            using (MedicalClinicContext context = new MedicalClinicContext())
            {
                Patient patient = new Patient();

                PersonalData patientPersonalData = new PersonalData();
                patientPersonalData.Name        = name;
                patientPersonalData.Surname     = surname;
                patientPersonalData.Sex         = sex;
                patientPersonalData.DateOfBirth = (DateTime)date;
                patientPersonalData.Email       = email;
                patientPersonalData.PhoneNumber = phone;

                context.PersonalData.Add(patientPersonalData);
                context.SaveChanges();

                User patientUser = new User();
                patientUser.Login    = login;
                patientUser.Password = pass;

                context.User.Add(patientUser);
                context.SaveChanges();

                Medcard patientMedcard = new Medcard();

                context.Medcard.Add(patientMedcard);
                context.SaveChanges();

                patient.Medcard      = patientMedcard;
                patient.User         = patientUser;
                patient.PersonalData = patientPersonalData;

                patient.MedcardId       = patientMedcard.Id;
                patient.UserId          = patientUser.Id;
                patient.PersonalData.Id = patientPersonalData.Id;

                context.Patient.Add(patient);
                context.SaveChanges();
            }
        }