//Displays details of the select refill request and the patient who requested it
        private void viewRefillRequestsButton_Click(object sender, EventArgs e)
        {
            if (!(newRefillRequestsListView.SelectedIndices.Count == 0))
            {
                selectedRefillRequest = (RefillRequest)RefillRequest.displayRefillRequests()[newRefillRequestsListView.SelectedIndices[0]];
                listView1.Items.Clear();
                listView2.Items.Clear();

                selectedRefillRequest.Prescription.retrieveMedicines();
                Patient patient = selectedRefillRequest.Prescription.retrievePatientDetails();

                int i = 0;
                foreach (Medicine medicine in patient.MedicineHistory)
                {
                    listView1.Items.Add(medicine.Date);
                    listView1.Items[i].SubItems.Add(medicine.Name);
                    listView1.Items[i].SubItems.Add("" + medicine.Quantity);
                    listView1.Items[i].SubItems.Add(medicine.Dosage);
                    i++;
                }
                i = 0;
                foreach (Medicine medicine in selectedRefillRequest.Prescription.Medicines)
                {
                    listView2.Items.Add(medicine.Name);
                    listView2.Items[i].SubItems.Add("" + medicine.Quantity);
                    listView2.Items[i].SubItems.Add(medicine.Dosage);
                    listView2.Items[i].SubItems.Add(medicine.Route);
                    listView2.Items[i].SubItems.Add(medicine.Instructions);
                    i++;
                }

                //Display patient information
                generalListView.Items.Clear();
                generalListView.Items.Add("Name: " + patient.Name);
                generalListView.Items.Add("Date of Birth: " + patient.BirthDate);
                generalListView.Items.Add("Height: " + patient.Height);
                generalListView.Items.Add("Weight: " + patient.Weight);
                generalListView.Items.Add("Body Mass Index: " + patient.BodyMassIndex);
                dateLabel.Text      = selectedRefillRequest.Date;
                statusLabel.Text    = selectedRefillRequest.Status;
                refillsLabel.Text   = "" + selectedRefillRequest.Prescription.Refills;
                remainingLabel.Text = "" + selectedRefillRequest.Prescription.RemainingRefills;
                allergyTextBox.Text = patient.Allergies;

                //Disable or enable Accept and Deny buttons depending on RefillRequest status
                if (selectedRefillRequest.Status.ToLower().Equals("unapproved"))
                {
                    acceptButton.Enabled = true;
                    rejectButton.Enabled = true;
                }
                else
                {
                    acceptButton.Enabled = false;
                    rejectButton.Enabled = false;
                }

                newRefillRequestsPanel.Hide();
                prescriptionDetailPanel.Show();
            }
        }
 //return to the new refill requests panel and refresh the listview
 private void backButton_Click(object sender, EventArgs e)
 {
     RefillRequest.retrieveRefillRequests();
     populateList();
     prescriptionDetailPanel.Hide();
     newRefillRequestsPanel.Show();
 }
 //displays how many unread notifications there are
 private void showUnread()
 {
     Notice.retrieveNotices();
     RefillRequest.retrieveRefillRequests();
     Appointment.retrieveAppointments(User.Id);
     notificationButton.Text     = "Notices  (" + Notice.Unread + ")";
     refillRequestButton.Text    = "Refill Requests  (" + RefillRequest.NewRefillRequestCount + ")";
     viewAppointmentsButton.Text = "Appointments  (" + Appointment.NewAppointmentCount + ")";
 }
        //Retrieves the user's refill requests from the database and saves them in the refillReqeusts arraylist
        public static void retrieveRefillRequests()
        {
            refillRequests.Clear();
            DataTable       table   = new DataTable();
            string          connStr = "server=csdatabase.eku.edu;user=stu_csc340;database=csc340_db;port=3306;password=Colonels18;SSLMode=None";
            MySqlConnection conn    = new MySqlConnection(connStr);

            try
            {
                Console.WriteLine("Connecting to MySQL...");
                conn.Open();
                string sql = @"SELECT DATE_FORMAT(re.dateRequested, ""%m-%d-%Y"") AS dateRequested, re.refillRequestStatus, 
                        re.id, pa.name AS patientName, pa.patientID, doc.name, pr.refills, pr.remainingRefills, pr.id AS 'pid', pr.pharmacyID
                        FROM DixonRefillRequest re JOIN DixonPrescription pr ON re.prescriptionID = pr.id
                        JOIN DixonPatient pa ON re.patientID = pa.patientID JOIN DixonDoctor doc ON pr.doctorID = doc.id 
                        WHERE pr.doctorID = @id AND re.refillRequestStatus = 'Unapproved';";

                MySqlCommand cmd = new MySqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@id", User.Id);
                MySqlDataAdapter myAdapter = new MySqlDataAdapter(cmd);
                myAdapter.Fill(table);
                Console.WriteLine("Table is ready.");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            conn.Close();

            int newCount = 0;

            foreach (DataRow row in table.Rows)
            {
                RefillRequest request = new RefillRequest();
                request.Prescription                  = new Prescription();
                request.Date                          = row["dateRequested"].ToString();
                request.Status                        = row["refillRequestStatus"].ToString();
                request.Id                            = row["id"].ToString();
                request.PharmacyID                    = row["pharmacyID"].ToString();
                request.Prescription.PatientName      = row["patientName"].ToString();
                request.Prescription.PrescriberName   = row["name"].ToString();
                request.Prescription.Refills          = (int)row["refills"];
                request.Prescription.RemainingRefills = (int)row["remainingRefills"];
                request.Prescription.Id               = (int)row["pid"];
                request.Prescription.PatientId        = (int)row["patientID"];
                newCount++;
                refillRequests.Add(request);
            }
            newRefillRequestCount = newCount;
        }
        //displays refill requests for the doctor in the listview
        public void populateList()
        {
            newRefillRequestsListView.Items.Clear();
            int i = 0;

            foreach (RefillRequest request in RefillRequest.displayRefillRequests())
            {
                newRefillRequestsListView.Items.Add(request.Status);
                newRefillRequestsListView.Items[i].SubItems.Add(request.Date);
                newRefillRequestsListView.Items[i].SubItems.Add(request.Prescription.PatientName);
                newRefillRequestsListView.Items[i].SubItems.Add(request.Prescription.PrescriberName);
                newRefillRequestsListView.Items[i].SubItems.Add(request.Prescription.Refills.ToString());
                newRefillRequestsListView.Items[i].SubItems.Add(request.Prescription.RemainingRefills.ToString());
                i++;
            }
        }