private void GetBookingInformation(int patientID)
        {
            int    practitionerId = Convert.ToInt32(dataGridViewPractitioners.SelectedRows[0].Cells[0].Value);
            string date           = monthCalendarBooking.SelectionRange.Start.ToShortDateString();
            string time           = listBoxTime.SelectedItem.ToString();


            using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
            {
                labelBookingSummary.Text = $"Booking Information \n\nPractitioner: {context.Practitioners.Find(practitionerId)}\nBooking Date: {date}\nBooking Time: {time} \nServices:";
                var     customer     = context.Customers.Find(patientID);
                decimal bookingPrice = 0;
                foreach (Service s in listBoxServices.SelectedItems)
                {
                    if (customer.MSP != null)
                    {
                        bookingPrice += (s.ServicePrice * (1 - s.MSPCoverage));
                    }
                    else
                    {
                        bookingPrice += s.ServicePrice;
                    }
                    labelBookingSummary.Text += $"\n{s} MSP Coverage:{s.MSPCoverage * 100}% ";
                }

                labelPriceAmount.Text = $"{bookingPrice:C2}";
            }
        }
 private static void InitializePatientsRecordsView(DataGridView datagridview)
 {
     datagridview.Rows.Clear();
     // set number of columns
     datagridview.ColumnCount = 8;
     // Set the column header names.
     datagridview.Columns[0].Name = "Customer ID";
     datagridview.Columns[1].Name = "First Name";
     datagridview.Columns[2].Name = "Last Name";
     datagridview.Columns[3].Name = "Address";
     datagridview.Columns[4].Name = "City";
     datagridview.Columns[5].Name = "Province";
     datagridview.Columns[6].Name = "Email";
     datagridview.Columns[7].Name = "Phone Number";
     // using unit-of-work context
     using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
     {
         // loop through all customers
         foreach (Customer customer in context.Customers)
         {
             // get the needed information
             string[] rowAdd = { customer.CustomerID.ToString(), customer.User.FirstName, customer.User.LastName, customer.User.Address, customer.User.City, customer.User.Province, customer.User.Email, customer.User.PhoneNumber };
             // add to display
             datagridview.Rows.Add(rowAdd);
         }
     }
     // set all properties
     datagridview.AllowUserToAddRows    = false;
     datagridview.AllowUserToDeleteRows = false;
     datagridview.ReadOnly            = true;
     datagridview.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
 }
        private void GetPractitionerAvailability()
        {
            if (dataGridViewPractitioners.SelectedRows.Count != 1)
            {
                MessageBox.Show("Please select one Practitioner from the DataGridView before choosing a Date!");
                return;
            }
            if (monthCalendarBooking.SelectionRange.Start < monthCalendarBooking.TodayDate)
            {
                MessageBox.Show("Cannot book appointments before today's date!");
                return;
            }
            ResetBookingInformation();
            string dateRequested = monthCalendarBooking.SelectionRange.Start.ToShortDateString();

            LoadAllPossibleTimes();
            int selectedPractitionerId = Convert.ToInt32(dataGridViewPractitioners.SelectedRows[0].Cells[0].Value);

            using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
            {
                var bookingsOnThatDate = context.Bookings.Where(b => b.PractitionerID == selectedPractitionerId && b.Date == dateRequested).ToList();

                foreach (Booking b in bookingsOnThatDate)
                {
                    listBoxTime.Items.Remove(b.Time);
                }
            }
        }
        /// <summary>
        /// Method to initialize and populate all of customer's payments
        /// </summary>
        /// <param name="datagridview"> datagridview to be populated </param>
        /// <param name="customerID"> id of the customer</param>
        private static void InitializePatientsPayments(DataGridView datagridview, int customerID)
        {
            datagridview.Rows.Clear();
            // set number of columns
            datagridview.ColumnCount = 5;
            // Set the column header names.

            datagridview.Columns[0].Name = "Payment Date";
            datagridview.Columns[1].Name = "Payment Time";
            datagridview.Columns[2].Name = "Payment Amount";
            datagridview.Columns[3].Name = "Payment Type";
            datagridview.Columns[4].Name = "Payment Status";

            // using unit-of-work context
            using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
            {
                Customer customer = context.Customers.Find(customerID);
                // loop through all bookings
                foreach (Payment payment in customer.Payments)
                {
                    // get the needed information
                    string[] rowAdd = { payment.Date?.ToString("yyyy-MM-dd"), payment.Time?.ToString("hh\\:mm"), payment.TotalAmountPaid?.ToString("C2"), payment.Payment_Types.ToString(), payment.PaymentStatus.ToString() };
                    // add to display
                    datagridview.Rows.Add(rowAdd);
                }
            }
            // set all properties
            datagridview.AllowUserToAddRows    = false;
            datagridview.AllowUserToDeleteRows = false;
            datagridview.ReadOnly            = true;
            datagridview.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
        }
 /// <summary>
 /// Set up the practitionersRecordsView columns and populate data into the view
 /// </summary>
 /// <param name="datagridview"></param>
 private void InitializePractitionersRecordsView(DataGridView datagridview)
 {
     datagridview.Rows.Clear();
     // set number of columns
     datagridview.ColumnCount = 7;
     // set the column header names
     datagridview.Columns[0].Name = "Practitioner ID";
     datagridview.Columns[1].Name = "Type";
     datagridview.Columns[2].Name = "First Name";
     datagridview.Columns[3].Name = "Last Name";
     datagridview.Columns[4].Name = "City";
     datagridview.Columns[5].Name = "Province";
     datagridview.Columns[6].Name = "Email";
     // using unit-of-work context
     using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
     {
         // loop through all practitioners
         foreach (Practitioner practitioner in context.Practitioners)
         {
             // get the needed information
             string[] rowAdd = { practitioner.PractitionerID.ToString(), practitioner.Practitioner_Types.Title, practitioner.User.FirstName, practitioner.User.LastName, practitioner.User.City, practitioner.User.Province, practitioner.User.Email };
             // add to display
             datagridview.Rows.Add(rowAdd);
         }
         // set all properties
         datagridview.AllowUserToAddRows    = false;
         datagridview.AllowUserToDeleteRows = false;
         datagridview.ReadOnly            = true;
         datagridview.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
     }
 }
Exemple #6
0
 /// <summary>
 /// On load event of seeding the database
 /// </summary>
 private void MedicalCentreMainForm_Load()
 {
     using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
     {
         context.SeedDatabase();
     }
 }
        /// <summary>
        /// Method to set up the Patients booking display
        /// </summary>
        /// <param name="datagridview"> datagridview to be populated </param>
        /// <param name="customerID"> id of the customer</param>
        private static void InitializePatientsBookings(DataGridView datagridview, int customerID)
        {
            datagridview.Rows.Clear();
            // set number of columns
            datagridview.ColumnCount = 7;
            // Set the column header names.
            datagridview.Columns[0].Name = "Booking ID";
            datagridview.Columns[1].Name = "Practitioner Last Name";
            datagridview.Columns[2].Name = "Booking Time";
            datagridview.Columns[3].Name = "Booking Date";
            datagridview.Columns[4].Name = "Practitioner Comment";
            datagridview.Columns[5].Name = "Booking Price";
            datagridview.Columns[6].Name = "Booking Status";

            // using unit-of-work context
            using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
            {
                Customer customer = context.Customers.Find(customerID);
                // loop through all bookings
                foreach (Booking booking in customer.Bookings)
                {
                    // get the needed information
                    string[] rowAdd = { booking.BookingID.ToString(), context.Users.Find(booking.Practitioner.UserID).LastName, booking.Time.ToString(), booking.Date?.ToString("yyyy-MM-dd"), booking.PractitionerComment, booking.BookingPrice.ToString("C2"), booking.BookingStatus.ToString() };
                    // add to display
                    datagridview.Rows.Add(rowAdd);
                }
            }
            // set all properties
            datagridview.AllowUserToAddRows    = false;
            datagridview.AllowUserToDeleteRows = false;
            datagridview.ReadOnly            = true;
            datagridview.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
        }
Exemple #8
0
        /// <summary>
        /// Get all available times for a doctor on a requested date
        /// </summary>
        /// <param name="dateRequested"> date requested </param>
        /// <param name="selectedPractitionerId"> id of the practitioner requested</param>
        private void LoadAllAvailableTimes(DateTime dateRequested, int selectedPractitionerId)
        {
            // create all times
            List <TimeSpan> times = new List <TimeSpan>();

            for (int hour = 9; hour <= 16; hour++)
            {
                TimeSpan appointmentTime = new TimeSpan(hour, 0, 0);
                // make sure that today's past time appointments are not shown!
                if (dateRequested != DateTime.Now.Date || appointmentTime > DateTime.Now.TimeOfDay)
                {
                    times.Add(appointmentTime);
                }
            }
            // using unit-of-work
            using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
            {
                // get all bookings for that doctor on that date
                var bookingsOnThatDate = context.Bookings.Where(b => b.PractitionerID == selectedPractitionerId && b.Date == dateRequested).ToList();

                // remove from the list all times that match
                foreach (Booking b in bookingsOnThatDate)
                {
                    times.Remove((TimeSpan)b.Time);
                }
            }

            // add new range
            listBoxTime.DataSource = times;
        }
Exemple #9
0
        /// <summary>
        /// Set up the datagridview with the unpaid bookings
        /// </summary>
        /// <param name="patientID"> id of the customer whose bookings are searched </param>
        private void GetUnpaidBookings(int patientID)
        {
            dataGridViewBookings.ColumnCount = 5;
            // Set the column header names.
            dataGridViewBookings.Columns[0].Name = "Booking ID";
            dataGridViewBookings.Columns[1].Name = "Practitioner Last Name";
            dataGridViewBookings.Columns[2].Name = "Booking Time";
            dataGridViewBookings.Columns[3].Name = "Booking Date";
            dataGridViewBookings.Columns[4].Name = "Booking Price";

            using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
            {
                Customer customer = context.Customers.Find(patientID);
                // loop through all bookings
                foreach (Booking booking in customer.Bookings)
                {
                    // if status is not paid - add
                    if (booking.BookingStatus == BookingStatus.NOT_PAID)
                    {
                        string[] rowAdd = { booking.BookingID.ToString(), context.Users.Find(booking.Practitioner.UserID).LastName, booking.Time.ToString(), booking.Date?.ToString("yy-MM-dd"), booking.BookingPrice.ToString("C2") };
                        // add to display
                        dataGridViewBookings.Rows.Add(rowAdd);
                    }
                }
            }
            // set all properties
            dataGridViewBookings.AllowUserToAddRows    = false;
            dataGridViewBookings.AllowUserToDeleteRows = false;
            dataGridViewBookings.ReadOnly            = true;
            dataGridViewBookings.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
        }
Exemple #10
0
        /// <summary>
        /// Method to cancel booking
        /// </summary>
        /// <param name="practitionerID"></param>
        private void CancelBooking(int practitionerID)
        {
            // make sure a booking is selected
            if (dataGridViewPractitionerBookings.SelectedRows.Count != 1)
            {
                MessageBox.Show("One Booking needs to be selected to perform cancellation");
                return;
            }

            // get booking date and time
            string date = (string)dataGridViewPractitionerBookings.SelectedRows[0].Cells[4].Value;
            string time = (string)dataGridViewPractitionerBookings.SelectedRows[0].Cells[3].Value;
            // create date object
            DateTime bookingDate = DateTime.ParseExact(date + " " + time, "yyyy-MM-dd HH:mm", null);

            // if the date is in the past date display error message
            if (DateTime.Now > bookingDate)
            {
                MessageBox.Show("Cannot cancel past bookings!");
                return;
            }

            // get the bookingID
            int bookingID = Convert.ToInt32(dataGridViewPractitionerBookings.SelectedRows[0].Cells[0].Value);

            // if a booking is paid
            if ((string)dataGridViewPractitionerBookings.SelectedRows[0].Cells[6].Value == BookingStatus.PAID.ToString())
            {
                // using unit of work
                using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
                {
                    // find the payment for this booking
                    List <Payment> paymentToRefund = context.Payments.Where(p => p.BookingID == bookingID).ToList();
                    // set payment's status to Refunded
                    foreach (Payment payment in paymentToRefund)
                    {
                        payment.PaymentStatus = PaymentStatus.REFUNDED;
                    }
                    // save changes
                    context.SaveChanges();
                }
            }

            // whether the booking is paid or not - change it to Cancelled
            using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
            {
                // find booking by PK
                Booking bookingToChange = context.Bookings.Find(bookingID);
                // set new values
                bookingToChange.BookingStatus = BookingStatus.CANCELLED;
                bookingToChange.BookingPrice  = 0.0m;
                bookingToChange.Date          = null;
                bookingToChange.Time          = null;
                // save changes
                context.SaveChanges();
            }
            // update booking view
            InitializePractitionersBookings(dataGridViewPractitionerBookings, practitionerID);
        }
Exemple #11
0
 /// <summary>
 /// Method to validate a practitioner object
 /// </summary>
 /// <param name="practitioner"> object to be validated</param>
 /// <returns> TRUE if VALID </returns>
 public static bool IsValidPractitioner(this Practitioner practitioner)
 {
     // make sure that userID and PractitionerTypeID exist
     using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
     {
         return(context.Users.Any(u => u.UserID == practitioner.UserID) && context.Practitioner_Types.Any(u => u.TypeID == practitioner.TypeID));
     };
 }
 /// <summary>
 /// Method to ensure customer is valid
 /// </summary>
 /// <param name="customer"></param>
 /// <returns> TRUE if VALID</returns>
 public static bool IsValidCustomer(this Customer customer)
 {
     // Make sure such User exists and MSP is valid
     using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
     {
         return(context.Users.Any(u => u.UserID == customer.UserID) && IsValidMSP(customer));
     };
 }
Exemple #13
0
 private void GetGreeting(int patientID)
 {
     using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
     {
         var customer = context.Customers.Find(patientID);
         var user     = context.Users.Find(customer.UserID);
         labelPatientName.Text = $"Patient Name: {user.LastName}, {user.FirstName}";
     }
 }
Exemple #14
0
 /// <summary>
 /// using passed practitionerID to get Practitioner's name for greeting
 /// </summary>
 /// <param name="practitionerID"></param>
 private void GetGreeting(int practitionerID)
 {
     using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
     {
         var practitioner = context.Practitioners.Find(practitionerID);
         var user         = context.Users.Find(practitioner.UserID);
         labelPractitionerName.Text = $"Practitioner Name: {user.LastName}, {user.FirstName}";
     }
 }
Exemple #15
0
        /// <summary>
        /// Method to create a booking for the customer
        /// </summary>
        /// <param name="customerID"> id of the customer creating a booking</param>
        private void CreateBooking(int customerID)
        {
            // if some controls were not selected- error
            if (dataGridViewPractitioners.SelectedRows.Count != 1 || listBoxServices.SelectedIndex == -1 || listBoxTime.SelectedIndex == -1)
            {
                MessageBox.Show("Booking information is missing or is invalid!");
                return;
            }
            // create new Booking object
            Booking newBooking = new Booking
            {
                CustomerID          = customerID,
                PractitionerID      = Convert.ToInt32(dataGridViewPractitioners.SelectedRows[0].Cells[0].Value),
                Date                = monthCalendarBooking.SelectionRange.Start,
                Time                = (TimeSpan?)listBoxTime.SelectedItem,
                BookingPrice        = decimal.Parse(Regex.Replace(labelPriceAmount.Text, @"[^\d.]", "")),
                BookingStatus       = BookingStatus.NOT_PAID,
                PractitionerComment = ""
            };

            // add all selected services to the booking
            foreach (Service s in listBoxServices.SelectedItems)
            {
                newBooking.Services.Add(s);
            }

            // validate the new booking - error if not valid
            if (newBooking.InfoIsInvalid())
            {
                MessageBox.Show("Booking information is invalid!");
                return;
            }

            // try to add Booking
            using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
            {
                // attach services to context to prevent creating new rows in the Services table!
                foreach (Service s in newBooking.Services)
                {
                    context.Services.Attach(s);
                }
                // try to add
                if (context.Bookings.Add(newBooking) == null)
                {
                    MessageBox.Show("Cannot add booking to database"); // error if didn't work
                    return;
                }
                context.SaveChanges(); // save changes
            }

            // clear calendar before quitting
            monthCalendarBooking.SelectionStart = DateTime.Now;

            // if add was successful- set result to OK and close form
            DialogResult = DialogResult.OK;
            Close();
        }
Exemple #16
0
 /// <summary>
 /// Gets practitioner type from context and populate the practitioner type combo box
 /// </summary>
 private void PopulatePractitionerTypeComboBox()
 {
     using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
     {
         ArrayList practitionerTitles = new ArrayList();
         foreach (Practitioner_Types practitionerType in context.Practitioner_Types)
         {
             practitionerTitles.Add(practitionerType.Title);
         }
         comboBoxPractitionerType.Items.AddRange(practitionerTitles.ToArray());
     }
 }
        private void MedicalCentreAllRecordsForm_Load()
        {
            using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
            {
                context.SeedDatabase();
            }
            // common setup for datagridview controls

            InitializePatientsRecordsView(dataGridViewPatients);
            //InitializeDataGridView<Customer>(dataGridViewPatients, "Bookings", "Payments", "User");
            InitializePractitionersRecordsView(dataGridViewPractitioners);
        }
Exemple #18
0
        /// <summary>
        /// Prepopulate comment section
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PrePopulateComment(object sender, EventArgs e)
        {
            if (dataGridViewPractitionerBookings.SelectedRows.Count <= 0)
            {
                return;
            }
            int bookingID       = Convert.ToInt32(dataGridViewPractitionerBookings.SelectedRows[0].Cells[0].Value);
            var bookingToUpdate = Controller <MedicalCentreManagementEntities, Booking> .FindEntity(bookingID);

            // prepopulate comment field
            using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
            {
                textBoxComment.Text = bookingToUpdate.PractitionerComment;
            }
        }
 /// <summary>
 /// Method to reload the data of the practitioners
 /// </summary>
 /// <param name="datagridview"> datagridview to be reloaded</param>
 private void ReloadPractitionersRecordsView(DataGridView datagridview)
 {
     // clear current data
     datagridview.Rows.Clear();
     using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
     {
         // loop through all practitioners
         foreach (Practitioner practitioner in context.Practitioners)
         {
             // get the needed information
             string[] rowAdd = { practitioner.PractitionerID.ToString(), practitioner.Practitioner_Types.Title, practitioner.User.FirstName, practitioner.User.LastName, practitioner.User.City, practitioner.User.Province, practitioner.User.Email };
             // add to display
             datagridview.Rows.Add(rowAdd);
         }
     }
 }
Exemple #20
0
        /// <summary>
        /// update practitioner information
        /// </summary>
        /// <param name="practitionerID"></param>
        private void UpdatePractitioner(int practitionerID)
        {
            string firstName        = textBoxFirstName.Text;
            string lastName         = textBoxLastName.Text;
            string birthdate        = dateTimePickerBirthDate.Value.ToShortDateString();
            string address          = textBoxStreetAddress.Text;
            string city             = textBoxCity.Text;
            string province         = comboBoxProvince.GetItemText(comboBoxProvince.SelectedItem);
            string phoneNumber      = textBoxPhoneNumber.Text;
            string email            = textBoxEmail.Text;
            string practitionalType = comboBoxPractitionerType.GetItemText(comboBoxPractitionerType.SelectedItem);

            int practitionerTypeID;

            using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
            {
                practitionerTypeID = context.Practitioner_Types.SingleOrDefault(x => x.Title == practitionalType).TypeID;
            }
            var practitionerToUpdate = Controller <MedicalCentreManagementEntities, Practitioner> .FindEntity(practitionerID);

            var userToUpdate = Controller <MedicalCentreManagementEntities, User> .FindEntity(practitionerToUpdate.UserID);

            userToUpdate.FirstName   = firstName;
            userToUpdate.LastName    = lastName;
            userToUpdate.Birthdate   = birthdate;
            userToUpdate.Address     = address;
            userToUpdate.City        = city;
            userToUpdate.Province    = province;
            userToUpdate.PhoneNumber = phoneNumber;
            userToUpdate.Email       = email;

            practitionerToUpdate.TypeID = practitionerTypeID;

            if (Controller <MedicalCentreManagementEntities, User> .UpdateEntity(userToUpdate) == false)
            {
                MessageBox.Show("Cannot update User to database");
                return;
            }
            if (Controller <MedicalCentreManagementEntities, Practitioner> .UpdateEntity(practitionerToUpdate) == false)
            {
                MessageBox.Show("Cannot update Practitioner to database");
                return;
            }

            this.DialogResult = DialogResult.OK;
            Close();
        }
 private void PrePopulateFields(int patientID)
 {
     PopulateProvinceComboBox();
     using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
     {
         var customer = context.Customers.Find(patientID);
         var user     = context.Users.Find(customer.UserID);
         textBoxFirstName.Text         = user.FirstName;
         textBoxLastName.Text          = user.LastName;
         dateTimePickerBirthDate.Value = DateTime.ParseExact(user.Birthdate, "yyyy-mm-dd", CultureInfo.InvariantCulture);
         textBoxAddress.Text           = user.Address;
         textBoxCity.Text = user.City;
         comboBoxProvince.SelectedIndex = comboBoxProvince.FindStringExact(user.Province);
         textBoxEmail.Text       = user.Email;
         textBoxPhoneNumber.Text = user.PhoneNumber;
         textBoxMSP.Text         = customer.MSP;
     }
 }
Exemple #22
0
        /// <summary>
        /// creates new user and practitioner
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddNewPractitioner(object sender, EventArgs e)
        {
            string firstName        = textBoxFirstName.Text;
            string lastName         = textBoxLastName.Text;
            string birthdate        = dateTimePickerBirthDate.Value.ToShortDateString();
            string address          = textBoxStreetAddress.Text;
            string city             = textBoxCity.Text;
            string province         = comboBoxProvince.GetItemText(comboBoxProvince.SelectedItem);
            string phoneNumber      = textBoxPhoneNumber.Text;
            string email            = textBoxEmail.Text;
            string practitionalType = comboBoxPractitionerType.GetItemText(comboBoxPractitionerType.SelectedItem);

            User newUser = new User
            {
                FirstName   = firstName,
                LastName    = lastName,
                Birthdate   = birthdate,
                Address     = address,
                City        = city,
                Province    = province,
                PhoneNumber = phoneNumber,
                Email       = email
            };

            using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
            {
                User addedUser = context.Users.Add(newUser);
                context.SaveChanges();
                // get selected practitioner type
                Practitioner_Types selectedPractitionalType = context.Practitioner_Types.SingleOrDefault(x => x.Title == practitionalType);
                Practitioner       newPractitioner          = new Practitioner
                {
                    User               = addedUser,
                    UserID             = addedUser.UserID,
                    PractitionerID     = selectedPractitionalType.TypeID,
                    Practitioner_Types = selectedPractitionalType
                };
                context.Practitioners.Add(newPractitioner);
                context.SaveChanges();
            }

            this.DialogResult = DialogResult.OK;
            Close();
        }
Exemple #23
0
        /// <summary>
        /// Method to complete payment for a particular patient on a selected booking
        /// </summary>
        /// <param name="patientID"> id of a customer that is paying</param>
        private void CompletePayment(int patientID)
        {
            // make sure 1 booking is selected
            if (dataGridViewBookings.SelectedRows.Count != 1)
            {
                MessageBox.Show("One Booking needs to be selected to complete payment");
                return;
            }

            // create new payment object
            Payment newPayment = new Payment
            {
                CustomerID      = patientID,
                TotalAmountPaid = decimal.Parse(Regex.Replace(labelTotalAmountNumber.Text, @"[^\d.]", "")),
                BookingID       = Convert.ToInt32(dataGridViewBookings.SelectedRows[0].Cells[0].Value),
                PaymentTypeID   = (comboBoxPaymentType.SelectedItem as Payment_Types).PaymentTypeID,
                PaymentStatus   = PaymentStatus.APPROVED,
                Date            = DateTime.Now.Date,
                Time            = DateTime.Now.TimeOfDay,
            };

            // validate payment
            if (newPayment.InfoIsInvalid())
            {
                MessageBox.Show("Payment information is not valid!");
                return;
            }

            // try to add payment to db
            if (Controller <MedicalCentreManagementEntities, Payment> .AddEntity(newPayment) == null)
            {
                MessageBox.Show("Payment was not added to the database!");
                return;
            }
            // update that booking's status to Paid
            using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
            {
                context.Bookings.Find(newPayment.BookingID).BookingStatus = BookingStatus.PAID;
                context.SaveChanges();
            }
            // if successful- set result to OK and close form
            DialogResult = DialogResult.OK;
            Close();
        }
Exemple #24
0
 /// <summary>
 /// pre-populating practioner's information
 /// </summary>
 /// <param name="practitionerID"></param>
 private void PrePopulateFields(int practitionerID)
 {
     BaseFormMethods.PopulateProvinceComboBox(comboBoxProvince);
     PopulatePractitionerTypeComboBox();
     using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
     {
         var practitioner = context.Practitioners.Find(practitionerID);
         var user         = context.Users.Find(practitioner.UserID);
         textBoxFirstName.Text         = user.FirstName;
         textBoxLastName.Text          = user.LastName;
         dateTimePickerBirthDate.Value = (DateTime)user.Birthdate;
         textBoxStreetAddress.Text     = user.Address;
         textBoxCity.Text = user.City;
         comboBoxProvince.SelectedIndex = comboBoxProvince.FindStringExact(user.Province);
         textBoxEmail.Text       = user.Email;
         textBoxPhoneNumber.Text = user.PhoneNumber;
         comboBoxPractitionerType.SelectedIndex = comboBoxPractitionerType.FindStringExact(practitioner.Practitioner_Types.Title);
     }
 }
 /// <summary>
 /// Method to reload customers data
 /// </summary>
 /// <param name="datagridview"> datagridview to be reloaded </param>
 private void ReloadPatientsRecordsView(DataGridView datagridview)
 {
     datagridview.Rows.Clear(); // clear current rows
     using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
     {
         // loop through all customers
         foreach (Customer customer in context.Customers)
         {
             // do not add customer with id=6 (reserved for timeoff feature)
             if (customer.CustomerID == 6)
             {
                 continue;
             }
             // get the needed information
             string[] rowAdd = { customer.CustomerID.ToString(), customer.User.FirstName, customer.User.LastName, customer.User.Address, customer.User.City, customer.User.Province, customer.User.Email, customer.User.PhoneNumber };
             // add to display
             datagridview.Rows.Add(rowAdd);
         }
     }
 }
        /// <summary>
        /// Get current practitioner's availability and remove not available time from the time listbox
        /// </summary>
        /// <param name="practitionerID"></param>
        private void GetPractitionerAvailability(int practitionerID)
        {
            LoadAllPossibleTimes();
            if (monthCalendarBookingDate.SelectionRange.Start < monthCalendarBookingDate.TodayDate)
            {
                MessageBox.Show("Cannot book appointments before today's date!");
                return;
            }
            string dateRequested = monthCalendarBookingDate.SelectionRange.Start.ToShortDateString();

            using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
            {
                var bookingOnThatDate = context.Bookings.Select(b => b).Where(b => b.PractitionerID == practitionerID && b.Date == dateRequested).ToList();

                foreach (Booking b in bookingOnThatDate)
                {
                    listBoxTime.Items.Remove(b.Time);
                }
            }
        }
        private void AddNewPatient(object sender, EventArgs e)
        {
            string firstName   = textBoxFirstName.Text;
            string lastName    = textBoxLastName.Text;
            string birthdate   = dateTimePickerBirthDate.Value.ToShortDateString();
            string address     = textBoxAddress.Text;
            string city        = textBoxCity.Text;
            string province    = comboBoxProvince.GetItemText(comboBoxProvince.SelectedItem);
            string phoneNumber = textBoxPhoneNumber.Text;
            string email       = textBoxEmail.Text;
            string msp         = textBoxMSP.Text;

            User newUser = new User
            {
                FirstName   = firstName,
                LastName    = lastName,
                Birthdate   = birthdate,
                Address     = address,
                City        = city,
                Province    = province,
                PhoneNumber = phoneNumber,
                Email       = email,
            };

            using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
            {
                User addedUser = context.Users.Add(newUser);
                context.SaveChanges();

                Customer newCustomer = new Customer
                {
                    User   = addedUser,
                    UserID = addedUser.UserID,
                };
                context.Customers.Add(newCustomer);
                context.SaveChanges();
            }

            this.DialogResult = DialogResult.OK;
            Close();
        }
 /// <summary>
 /// Method to check if a customer is able to make bookings or if their account was suspended
 /// Suspended if any outstanding bills for 7 days!
 /// </summary>
 /// <param name="customerID"> id of the customer </param>
 private void IsActiveCustomer(int customerID)
 {
     // using unit-of-work context
     using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
     {
         // find customer
         Customer customer = context.Customers.Find(customerID);
         // loop through all bookings
         foreach (Booking booking in customer.Bookings)
         {
             DateTime bookingDate = (DateTime)(booking.Date);
             if (bookingDate.AddDays(7) < DateTime.Today.Date && booking.BookingStatus == BookingStatus.NOT_PAID)
             {
                 MessageBox.Show("Your account is suspended due to outstanding balance! Please make a payment to be able to make appointments!");
                 buttonBookAppointment.Enabled = false;
                 return;
             }
         }
         buttonBookAppointment.Enabled = true;
     }
 }
 /// <summary>
 /// Method to figure out if customer has any outstanding payments and display form if needed
 /// </summary>
 /// <param name="customerID"></param>
 private void IsNeededPayment(int customerID)
 {
     // using unit-of-work context
     using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
     {
         // find customer
         Customer customer = context.Customers.Find(customerID);
         // loop through all bookings
         foreach (Booking booking in customer.Bookings)
         {
             // if not paid- load form
             if (booking.BookingStatus == BookingStatus.NOT_PAID)
             {
                 ChildPatientActionsForm(new MedicalCentreMakePaymentForm(customerID), customerID);
                 return;
             }
         }
         // if no not paid bookings- message
         MessageBox.Show("This Customer has no Unpaid Bookings!");
     }
 }
 private static void LoadPractitionersIntoDataGridView(DataGridView datagridview, int typeId)
 {
     datagridview.Rows.Clear();
     // using unit-of-work context
     using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
     {
         var practitioners = context.Practitioners.Where(pr => pr.PractitionerID == typeId);
         // loop through all customers
         foreach (Practitioner practitioner in practitioners)
         {
             // get the needed information
             string[] rowAdd = { practitioner.PractitionerID.ToString(), practitioner.User.FirstName, practitioner.User.LastName, practitioner.User.Address, practitioner.User.City, practitioner.User.Province, practitioner.User.PhoneNumber };
             // add to display
             datagridview.Rows.Add(rowAdd);
         }
     }
     // set all properties
     datagridview.AllowUserToAddRows    = false;
     datagridview.AllowUserToDeleteRows = false;
     datagridview.ReadOnly            = true;
     datagridview.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
 }