Пример #1
0
        private void btTakeAppointment_Click(object sender, RoutedEventArgs e)
        {
            using (clinicEntities context = new clinicEntities())
            {
                // get the selected spot from grid
                display_available_slots slot = (display_available_slots)display_available_slotsDataGrid.SelectedItem;
                int slotId = slot.TimeSoltId;
                MessageBox.Show(string.Format("you have chosen slot: {0}", slotId.ToString()));

                //get the selected patient id from list
                patient p         = (patient)patientListView.SelectedItem;
                int     patientId = p.Id;
                MessageBox.Show(string.Format("you have chosen patient with Id: {0}", patientId.ToString()));
                appointment app = new appointment(slotId, patientId);
                MessageBox.Show(string.Format("this appointment will be made {0}", app.ToString()));
                context.appointments.Add(app);
                context.SaveChanges();

                //load the view, need to find out how to refresh the viw of display_available_slots??
                context.display_available_slots.Load();
                display_available_slotsViewSource.Source = context.display_available_slots.Local;
                MessageBoxResult messageBoxResult = MessageBox.Show("you have sucessfully made an appointment, do you need to make another appointment?", "Make more?", System.Windows.MessageBoxButton.YesNo);
                if (messageBoxResult == MessageBoxResult.Yes)
                {
                    tbPatientName.Text = "";
                    tbName.Text        = "";
                    dpFrom.Text        = "";
                    dpTo.Text          = "";
                }
                if (messageBoxResult == MessageBoxResult.No)
                {
                    Close();
                }
            }
        }
Пример #2
0
        private void btAdd_Click(object sender, RoutedEventArgs e)
        {
            DateTime?date      = null;
            TimeSpan?startTime = null;
            TimeSpan?endTime   = null;
            int      duration;

            if (!string.IsNullOrWhiteSpace(dpDateAddAv.Text))
            {
                date = Convert.ToDateTime(dpDateAddAv.Text);
            }
            if (!string.IsNullOrWhiteSpace(cmbStartTime.Text))
            {
                startTime = TimeSpan.Parse(cmbStartTime.Text);
            }
            if (!string.IsNullOrWhiteSpace(cmbEndTime.Text))
            {
                endTime = TimeSpan.Parse(cmbEndTime.Text);
            }

            if (rb30M.IsChecked == true)
            {
                duration = 30;
            }
            else
            {
                duration = 60;
            }

            //convert nullable DateTime to DateTime

            DateTime DateToPass = (DateTime)(date);
            DateTime sTime      = (DateTime)(date + startTime);
            DateTime eTime      = (DateTime)(date + endTime);
            //check the sTime if is overlapping with existing availabilities
            bool CanAddAvailability = true;
            var  list = context.availabilities.Where(a => a.DoctorId == Globals.SessionId);

            foreach (availability a in list)
            {
                if (sTime >= a.AvailableFrom && sTime <= a.AvailableTo)
                {
                    CanAddAvailability = false;
                }
            }
            if (CanAddAvailability)
            {
                availability av = new availability(Globals.SessionId, DateToPass, sTime, eTime, duration);
                context.availabilities.Add(av);
                context.SaveChanges();
                MessageBox.Show("Added ", av.ToString());
                dpDateAddAv.Text           = "";
                cmbStartTime.SelectedIndex = -1;
                cmbEndTime.SelectedIndex   = -1;
            }
            if (!CanAddAvailability)
            {
                MessageBox.Show("Please check the entry, it is overlapping with existing availability");
            }
        }
Пример #3
0
 private void btDelete_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         using (clinicEntities context = new clinicEntities())
         {
             doctor_schedule app           = (doctor_schedule)doctor_scheduleDataGrid.SelectedItem;
             int             timeslot      = app.slotId;
             int             appointmentId = app.appointmentId;
             var             app1          = context.appointments.Find(appointmentId);
             context.timeslots.Find(timeslot).IsAvailable = true;
             context.appointments.Remove(app1);
             MessageBoxResult messageBoxResult = MessageBox.Show("Are you sure to delete this appointment?", "Delete Confirmation", MessageBoxButton.YesNo);
             if (messageBoxResult == MessageBoxResult.Yes)
             {
                 context.SaveChanges();
                 MessageBox.Show("the appointment is deleted");
                 context.doctor_schedule.Load();
                 doctor_scheduleViewSource.Source = context.doctor_schedule.Local;
             }
         }
     }
     catch
     {
         MessageBox.Show("there is no appointment selected");
     }
 }
Пример #4
0
        private void Delete_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (clinicEntities context = new clinicEntities())
                {
                    display_available_slots s = (display_available_slots)display_available_slotsDataGrid.SelectedItem;
                    int slotId         = s.TimeSoltId;
                    int AvailabilityId = 0;

                    context.timeslots.Remove(context.timeslots.Find(slotId));


                    MessageBoxResult messageBoxResult = MessageBox.Show("Are you sure to delete this time slot?", "Delete Confirmation", MessageBoxButton.YesNo);
                    if (messageBoxResult == MessageBoxResult.Yes)
                    {
                        context.SaveChanges();
                        MessageBox.Show("the slot is deleted");
                        context.display_available_slots.Load();
                        display_available_slotsViewSource.Source = context.display_available_slots.Local;
                    }
                    // check in timeslots table, if no more availabilityId exists, meaning that availability can be deleted
                    var list = context.timeslots;
                    foreach (timeslot t in list)
                    {
                        if (t.Id == slotId)
                        {
                            AvailabilityId = t.AvailabilityId;
                        }
                    }
                    if (AvailabilityId == 0)
                    {
                        context.availabilities.Remove(context.availabilities.Find(AvailabilityId));
                        context.SaveChanges();
                    }
                }
            }
            catch (System.InvalidCastException ex) { MessageBox.Show("Exception caught: {0}", ex.ToString()); }
            finally{ MessageBox.Show("nothing is selected"); }
        }
Пример #5
0
        private void btAddDoctor_Click(object sender, RoutedEventArgs e)
        {
            var    d             = context.doctors;
            bool   CanAdd        = true;
            string firstName     = tbFirstName.Text.ToString();
            string lastName      = tbLastName.Text.ToString();
            string speciality    = tbSpeciality.Text.ToString();
            string phone         = tbPhone.Text.ToString();
            string email         = tbEmail.Text.ToString();
            string userName      = tbUserName.Text.ToString();
            string loginPassword = tbPassword.Text.ToString();

            // check if username is unique in with doctors table
            foreach (doctor doc in d)
            {
                if (doc.UserName == userName)
                {
                    CanAdd = false;
                    break;
                }
            }
            if (!CanAdd)
            {
                MessageBox.Show(string.Format("The UserName {0} exist already, please enter another userName", userName));
            }
            if (CanAdd)
            {
                doctor newDoctor = new doctor(firstName, lastName, speciality, phone, email, userName, loginPassword);
                context.doctors.Add(newDoctor);
                context.SaveChanges();
                MessageBox.Show("new doctor added");

                //after add, ask user if need to add more, if yes, set the ui field to empty if now close dialog window

                MessageBoxResult messageBoxResult = MessageBox.Show("Do you need to add another new doctor?", "Add more?", System.Windows.MessageBoxButton.YesNo);
                if (messageBoxResult == MessageBoxResult.Yes)
                {
                    tbFirstName.Text  = "";
                    tbLastName.Text   = "";
                    tbSpeciality.Text = "";
                    tbPhone.Text      = "";
                    tbEmail.Text      = "";
                    tbUserName.Text   = "";
                    tbPassword.Text   = "";
                }
                if (messageBoxResult == MessageBoxResult.No)
                {
                    Close();
                }
            }
        }
Пример #6
0
        private void btUpdate_Click(object sender, RoutedEventArgs e)
        {
            var d = context.doctors.Find(int.Parse(idLabel.Content.ToString()));

            d.FirstName     = firstNameTextBox.Text;
            d.LastName      = lastNameTextBox.Text;
            d.Speciality    = specialityTextBox.Text;
            d.Phone         = phoneTextBox.Text;
            d.Email         = emailTextBox.Text;
            d.UserName      = userNameTextBox.Text;
            d.LoginPassWord = loginPassWordTextBox.Text;
            context.SaveChanges();
            MessageBox.Show("update successful");
        }
        private void btCancelAppointment_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (clinicEntities context = new clinicEntities())
                {
                    display_appointements_for_Patient app = (display_appointements_for_Patient)display_appointements_for_PatientListView.SelectedItem;
                    int timeslot      = app.TimeSlotId;
                    int appointmentId = app.appointmentId;
                    var app1          = context.appointments.Find(appointmentId);
                    // check if the appointment to be cancelled is 48 hours away, if it is less then 48 hours away, it cannot be canncelled
                    int hoursAhead = (app.Start - DateTime.Now).Value.Hours;
                    if (hoursAhead < 48)
                    {
                        MessageBox.Show("you cannot cancel this appointment which is within 48 hours, please contact office");
                    }

                    else
                    {
                        context.timeslots.Find(timeslot).IsAvailable = true;
                        context.appointments.Remove(app1);
                        MessageBoxResult messageBoxResult = MessageBox.Show("Are you sure to delete this appointment?", "Delete Confirmation", MessageBoxButton.YesNo);
                        if (messageBoxResult == MessageBoxResult.Yes)
                        {
                            context.SaveChanges();
                            MessageBox.Show("the appointment cancelled");
                            context.display_appointements_for_Patient.Load();
                            display_appointements_for_PatientViewSource.Source      = context.display_appointements_for_Patient.Local;
                            display_appointements_for_PatientViewSource.View.Filter = item =>
                            {
                                display_appointements_for_Patient m = item as display_appointements_for_Patient;
                                if (m != null)
                                {
                                    if (m.PatientId.Equals(Globals.SessionId))
                                    {
                                        return(true);
                                    }
                                }
                                return(false);
                            };
                        }
                    }
                }
            }
            catch
            {
                MessageBox.Show("there is no appointment selected");
            }
        }
Пример #8
0
        private void btUPdate_Click(object sender, RoutedEventArgs e)
        {
            var p = context.patients.Find(int.Parse(idLabel.Content.ToString()));

            p.FirstName     = firstNameTextBox.Text;
            p.LastName      = lastNameTextBox.Text;
            p.DateOfBirth   = Convert.ToDateTime(dateOfBirthTextBox.Text);
            p.MedicalCardNo = medicalCardNoTextBox.Text;
            p.Phone         = phoneTextBox.Text;
            p.Email         = emailTextBox.Text;
            p.UserName      = userNameTextBox.Text;
            p.LoginPassWord = loginPassWordTextBox.Text;
            context.SaveChanges();
            MessageBox.Show("update successful");
        }
Пример #9
0
        public void InitializeNewRecord(int serviceId, int medicineId)
        {
            var oldRecord = _clinicEntities.ServiceStatistics.Where(s => s.IsActive == true && s.ServiceId == serviceId).FirstOrDefault();

            oldRecord.IsActive = false;
            oldRecord.EndDate  = DateTime.Now;

            _clinicEntities.ServiceStatistics.Add(new ServiceStatistic()
            {
                MedicineId = medicineId,
                ServiceId  = serviceId,
                IsActive   = true,
                StartDate  = DateTime.Now,
                Count      = 0,
            });

            _clinicEntities.SaveChanges();
        }
Пример #10
0
        //private void tbName_TextChanged(object sender, TextChangedEventArgs e)
        //{

        //    if (tbName == null || string.IsNullOrWhiteSpace(tbName.Text))
        //    {
        //        display_available_slotsViewSource.View.Filter = null;
        //        return;
        //    }
        //    else
        //    {
        //        string txt = tbName.Text.ToString().ToLower();
        //        display_available_slotsViewSource.View.Filter = item =>
        //        {

        //            display_available_slots m = item as display_available_slots;

        //            if (m != null)
        //            {
        //                if (!string.IsNullOrWhiteSpace(m.Doctor) && m.Doctor.ToLower().Contains(txt) && m.Start==null && m.End==null) { return true; } // only doctor box has input
        //                if(!string.IsNullOrWhiteSpace(m.Doctor) && m.Doctor.ToLower().Contains(txt) && m.End==null && m.Start > dpFrom.SelectedDate) { return true; } // doctor and dpFrom has input
        //                if(!string.IsNullOrWhiteSpace(m.Doctor) && m.Doctor.ToLower().Contains(txt) && m.Start==null && m.End <dpTo.SelectedDate && m.End >DateTime.Today) { return true; } // doctor and dpTo has input
        //                if (!string.IsNullOrWhiteSpace(m.Doctor) && m.Doctor.ToLower().Contains(txt) && m.Doctor.ToLower().Contains(txt) && m.Start > dpFrom.SelectedDate && m.End < dpTo.SelectedDate)   { return true; }// doctor and dpFrom and dpTo all has input

        //            }
        //            return false;
        //        };
        //    }
        //}
        //private void dpFrom_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
        //{
        //    if (dpFrom.SelectedDate == null)
        //    {
        //        display_available_slotsViewSource.View.Filter = null;
        //        return;
        //    }
        //    else
        //    {
        //        display_available_slotsViewSource.View.Filter = item =>
        //        {

        //            display_available_slots m = item as display_available_slots;

        //            if (m != null)
        //            {
        //                if (m.Start > dpFrom.SelectedDate)
        //                    return true;
        //            }
        //            return false;
        //        };
        //    }
        //}

        //private void dpTo_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
        //{
        //    if (dpTo.SelectedDate == null)
        //    {
        //        display_available_slotsViewSource.View.Filter = null;
        //        return;
        //    }
        //    else
        //    {
        //        display_available_slotsViewSource.View.Filter = item =>
        //        {

        //            display_available_slots m = item as display_available_slots;

        //            if (m != null)
        //            {
        //                if (m.End < dpTo.SelectedDate)
        //                    return true;
        //            }
        //            return false;
        //        };
        //    }
        //}

        private void btTakeAppointment_Click(object sender, RoutedEventArgs e)
        {
            using (clinicEntities context = new clinicEntities())
            {
                // get the selected item from grid
                display_available_slots slot = (display_available_slots)display_available_slotsDataGrid.SelectedItem;
                int slotId = slot.TimeSoltId;
                // MessageBox.Show(slotId.ToString());
                //MessageBox.Show(Globals.SessionId.ToString());


                appointment app = new appointment(slotId, Globals.SessionId);
                // MessageBox.Show(app.ToString());
                context.appointments.Add(app);
                context.SaveChanges();

                //load the view, need to find out how to refresh the viw of display_available_slots??
                context.display_available_slots.Load();
                display_available_slotsViewSource.Source = context.display_available_slots.Local;
                MessageBox.Show("you have succefully taken an appointment, go to view appointment to see");
            }
        }
Пример #11
0
        public static int DeleteLaboratorySupervisor(Employee user)
        {
            var res = (from klab in db.LaboratorySupervisor
                       where klab.EmployeeId == user.Id
                       select klab).FirstOrDefault();

            db.LaboratorySupervisor.Remove(res);

            return(db.SaveChanges());
        }
Пример #12
0
 private void Save()
 {
     _clinicEntities.SaveChanges();
 }
Пример #13
0
 private void btUpdate_Click(object sender, RoutedEventArgs e)
 {
     context.SaveChanges();
 }
Пример #14
0
        private void tbSavePatient_Click(object sender, RoutedEventArgs e)
        {
            var      p             = context.patients;
            bool     CanAdd        = true;
            string   firstName     = tbFirstName.Text.ToString();
            string   lastName      = tbLastName.Text.ToString();
            string   phone         = tbPhone.Text.ToString();
            string   email         = tbEmail.Text.ToString();
            DateTime?dob           = DateTime.Parse(dpDOB.Text);
            string   medicalCardNo = tbMedicalCardNo.Text.ToString();
            string   userName      = tbUserName.Text.ToString();
            string   loginPassword = tbLoginPassword.Text.ToString();

            // check if username is unique in with patients table
            foreach (patient pat in p)
            {
                if (pat.UserName == userName)
                {
                    CanAdd = false;
                    break;
                }
            }
            if (!CanAdd)
            {
                MessageBox.Show(string.Format("The UserName {0} exist already, please enter another userName", userName));
            }
            if (CanAdd)
            {
                patient newPatient = new patient(firstName, lastName, phone, email, dob, medicalCardNo, userName, loginPassword);
                context.patients.Add(newPatient);
                try
                {
                    context.SaveChanges();
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            Trace.TraceInformation("Property: {0} Error: {1}",
                                                   validationError.PropertyName,
                                                   validationError.ErrorMessage);
                            MessageBox.Show(validationError.ErrorMessage);
                        }
                    }
                }
                MessageBox.Show("new patient added");

                //after add, ask user if need to add more, if yes, set the ui field to empty if now close dialog window

                MessageBoxResult messageBoxResult = MessageBox.Show("Do you need to add another new patient?", "Add more?", System.Windows.MessageBoxButton.YesNo);
                if (messageBoxResult == MessageBoxResult.Yes)
                {
                    tbFirstName.Text     = "";
                    tbLastName.Text      = "";
                    tbPhone.Text         = "";
                    tbEmail.Text         = "";
                    dpDOB.Text           = "";
                    tbMedicalCardNo.Text = "";
                    tbUserName.Text      = "";
                    tbLoginPassword.Text = "";
                }
                if (messageBoxResult == MessageBoxResult.No)
                {
                    Close();
                }
            }
        }