private void SetAppointmentFields()
        {
            oldApp = AppointmentController.GetAppointmentInfo(appointmentList[cbAppointments.SelectedIndex].AppointmentId);

            tbNurse.Text = NurseController.GetNurseByID(oldApp.NurseId).UserName;
            tbPatient.Text = PatientController.GetPatientByID(oldApp.PersonId).FullName;
            tbSymptoms.Text = oldApp.Symptom;
            tbDate.Value = oldApp.AppointmentDate;
        }
        public static Appointment GetAppointmentInfo(int appointmentID)
        {
            Appointment returnAppt = new Appointment();

            try
            {
                returnAppt = AppointmentDB.GetAppointmentInfo(appointmentID);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString(), MessageBoxButtons.OK);
            }
            return returnAppt;
        }
        public static bool UpdateAppointmentDiagnosis(Appointment oldAppointment, Appointment newAppointment)
        {
            Boolean success = false;

            try
            {
                success = AppointmentDB.UpdateAppointmentDiagnosis(oldAppointment, newAppointment);

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString(), MessageBoxButtons.OK);

            }
            return success;
        }
        /// <summary>
        /// Adds an appointment to the db.
        /// </summary>
        /// <param name="newAppointment">The appointment to add</param>
        /// <returns>The id of the new appointment</returns>
        public static int AddAppointment(Appointment newAppointment)
        {
            int appointmentID = -1;

            try
            {
                appointmentID = AppointmentDB.AddAppointment(newAppointment);
                if (appointmentID == -1)
                {
                    throw new Exception("Error adding the appointment to the Database");
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString(), MessageBoxButtons.OK);
            }

            return appointmentID;
        }
        public static List<Appointment> GetAppointmentsWithoutDiagnosis()
        {
            List<Appointment> undiagnosedAppointmentList = new List<Appointment>();

            string selectStatement = "SELECT * FROM Appointment WHERE diagnosis IS NULL";
            
            try
            {
                using (SqlConnection connection = HealthCareDBConnection.GetConnection())
                {
                    connection.Open();
                    using (SqlCommand selectCommand = new SqlCommand(selectStatement, connection))
                    {
                        using (SqlDataReader reader = selectCommand.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                Appointment undiagnosedAppointment = new Appointment();
                                
                                undiagnosedAppointment.AppointmentId = (int)reader["appointmentID"];
                                
                                undiagnosedAppointmentList.Add(undiagnosedAppointment);
                            }
                            connection.Close();
                        }
                    }                       
                }
            }
            catch (SqlException ex)
            {
                throw ex;
            }

            catch (Exception ex)
            {
                throw ex;
            }

            return undiagnosedAppointmentList;

        }
        /// <summary>
        /// Adds a appointment record to the db.
        /// </summary>
        /// <param name="appointment">The appointment record to add</param>
        /// <returns>The appointment ID</returns>
        public static int AddAppointment(Appointment appointment)
        {
            int appointmentID = -1;
            try
            {
                using (SqlConnection connection = HealthCareDBConnection.GetConnection())
                {
                    string insertStatement =
                        "INSERT Appointment " +
                        "(PersonId, NurseId, DoctorId, AppointmentDate, Symptom) " +
                        "VALUES (@PersonID, @NurseID, @DoctorId, @AppointmentDate, @Symptom)";
                    using (SqlCommand insertCommand = new SqlCommand(insertStatement, connection))
                    {
                        insertCommand.Parameters.AddWithValue("@PersonID", appointment.PersonId);
                        insertCommand.Parameters.AddWithValue("@NurseID", appointment.NurseId);
                        insertCommand.Parameters.AddWithValue("@DoctorID", appointment.DoctorId);
                        insertCommand.Parameters.AddWithValue("@AppointmentDate", appointment.AppointmentDate);
                        insertCommand.Parameters.AddWithValue("@Symptom", appointment.Symptom);

                        connection.Open();
                        insertCommand.ExecuteNonQuery();
                        string selectStatement =
                            "SELECT IDENT_CURRENT('Appointment') FROM Appointment";

                        using (SqlCommand selectCommand = new SqlCommand(selectStatement, connection))
                        {
                            appointmentID = Convert.ToInt32(selectCommand.ExecuteScalar());
                        }
                    }
                }
            }
            catch (SqlException ex)
            {
                throw ex;
            }

            return appointmentID;
        }
        private void addButton_Click(object sender, EventArgs e)
        {
            //Validates required fields.
            if (Validator.AreAllPresent(controls))
            {
                newAppointment = new Appointment();
                newAppointment.PersonId = Convert.ToInt32(comboBoxPatient.SelectedValue);
                newAppointment.NurseId = GlobalVars.Instance.CurrentUser.UserID;
                newAppointment.DoctorId = Convert.ToInt32(cbDoctor.SelectedValue);
                newAppointment.AppointmentDate = dateTextBox.Value;
                newAppointment.Symptom = symptomsTextBox.Text;

                int appID = AppointmentController.AddAppointment(newAppointment);
                if (appID > -1)
                    MessageBox.Show("Appointment scheduled.", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                else
                    MessageBox.Show("Appointment not scheduled.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);

                ClearAllControls();


            }
        }
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            bool success = false;

            try
            {
                newApp = oldApp;
                if (Validator.IsPresent(tbDiagnosis))
                {
                    newApp.Diagnosis = tbDiagnosis.Text;
                    success = AppointmentController.UpdateAppointmentDiagnosis(oldApp, newApp);
                    GetUndiagnosedAppointments();
                }
                if (success)
                {
                    MessageBox.Show("Diagnosis has been successfully updated!", "Appointment Updated!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    
                }
                else
                    MessageBox.Show("The appointment has not been updated.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public static List<Appointment> GetAllAppointments()
        {
            List<Appointment> apptList = new List<Appointment>();

            string selectStatement = "SELECT appointmentID " +
                "FROM Appointment GROUP BY appointmentID";

            try
            {
                using (SqlConnection connection = HealthCareDBConnection.GetConnection())
                {
                    try
                    {
                        connection.Open();
                    }
                    catch (SqlException ex)
                    {
                        throw ex;
                    }
                    using (SqlCommand selectCommand = new SqlCommand(selectStatement, connection))

                    using (SqlDataReader reader = selectCommand.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Appointment aResult = new Appointment();

                            aResult.AppointmentId = (int)reader["AppointmentID"];


                            apptList.Add(aResult);
                        }
                        connection.Close();
                    }
                }
            }
            catch (SqlException ex)
            {
                throw ex;
            }

            catch (Exception ex)
            {
                throw ex;
            }

            return apptList;

        }
Example #10
0
        public static bool UpdateAppointmentDiagnosis(Appointment oldAppointment, Appointment newAppointment)
        {
            bool success = false;

            try
            {
                using (SqlConnection connection = HealthCareDBConnection.GetConnection())
                {
                    string updateStatement =
                          "UPDATE Appointment SET " +
                            "diagnosis = @NewDiagnosis " +
                          "WHERE appointmentID = @OldAppointmentID " +
                            "AND personID = @OldPersonID " +
                            "AND nurseID = @OldNurseID " +
                            "AND doctorID = @OldDoctorID " +
                            "AND symptom = @OldSymptom";

                    connection.Open();

                    using (SqlCommand updateCommand = new SqlCommand(updateStatement, connection))
                    {

                        //updateCommand.Parameters.AddWithValue("@NewAppointmentID", newAppointment.AppointmentId);
                        //updateCommand.Parameters.AddWithValue("@NewPersonID", newAppointment.PersonId);
                        //updateCommand.Parameters.AddWithValue("@NewNurseID", newAppointment.NurseId);
                        updateCommand.Parameters.AddWithValue("@NewDiagnosis", newAppointment.Diagnosis);
                        //updateCommand.Parameters.AddWithValue("@NewSymptom", newAppointment.Symptom);


                        updateCommand.Parameters.AddWithValue("@OldAppointmentID", oldAppointment.AppointmentId);
                        updateCommand.Parameters.AddWithValue("@OldPersonID", oldAppointment.PersonId);
                        updateCommand.Parameters.AddWithValue("@OldNurseID", oldAppointment.NurseId);
                        updateCommand.Parameters.AddWithValue("@OldDoctorID", oldAppointment.DoctorId);
                        updateCommand.Parameters.AddWithValue("@OldSymptom", oldAppointment.Symptom);

                        int count = updateCommand.ExecuteNonQuery();
                        if (count > 0)
                        {
                            success = true;
                        }
                        else
                        {
                            success = false;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return success;
        }
Example #11
0
        public static List<Appointment> GetAppointmentsWithoutVitals()
        {
            List<Appointment> appointmentsWithoutVitals = new List<Appointment>();

            string selectStatement = "SELECT * FROM Appointment WHERE Appointment.AppointmentId NOT IN (SELECT appointmentID FROM Vitals)";

            try
            {
                using (SqlConnection connection = HealthCareDBConnection.GetConnection())
                {
                    connection.Open();
                    using (SqlCommand selectCommand = new SqlCommand(selectStatement, connection))
                    {
                        using (SqlDataReader reader = selectCommand.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                Appointment appt = new Appointment();
                                appt.AppointmentId = (int)reader["AppointmentID"];
                                appointmentsWithoutVitals.Add(appt);
                            }
                            connection.Close();
                        }
                    }
                }
            }
            catch (SqlException ex)
            {
                throw ex;
            }

            catch (Exception ex)
            {
                throw ex;
            }

            return appointmentsWithoutVitals;

        }
Example #12
0
        public static List<Appointment> GetUndiagnosedAppointmentListByAppointmentID(int appointmentID)
        {
            List<Appointment> openApptList = new List<Appointment>();

            string selectStatement = "SELECT * " +
                "FROM Appointment WHERE Appointment.Diagnosis IS NULL AND Appointment.AppointmentID = " + appointmentID;

            try
            {
                using (SqlConnection connection = HealthCareDBConnection.GetConnection())
                {
                    try
                    {
                        connection.Open();
                    }
                    catch (SqlException ex)
                    {
                        throw ex;
                    }
                    using (SqlCommand selectCommand = new SqlCommand(selectStatement, connection))

                    using (SqlDataReader reader = selectCommand.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Appointment aResult = new Appointment();

                            aResult.AppointmentId = (int)reader["AppointmentID"];

                            aResult.AppointmentDate = (DateTime)reader["AppointmentDate"];


                            openApptList.Add(aResult);
                        }
                        connection.Close();
                    }
                }
            }
            catch (SqlException ex)
            {
                throw ex;
            }

            catch (Exception ex)
            {
                throw ex;
            }

            return openApptList;

        }
Example #13
0
        public static Appointment GetAppointmentInfo(int appointmentID)
        {
            Appointment appointment = new Appointment();

            try
            {
                using (SqlConnection connection = HealthCareDBConnection.GetConnection())
                {
                    string selectStatement = "SELECT * FROM Appointment WHERE appointmentID = @appointmentID";

                    using (SqlCommand selectCommand = new SqlCommand(selectStatement, connection))
                    {
                        selectCommand.Parameters.AddWithValue("@appointmentID", appointmentID);

                        connection.Open();
                        using (SqlDataReader reader = selectCommand.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                Appointment anAppointment = new Appointment();

                                anAppointment.AppointmentId = (int)reader["appointmentID"];
                                anAppointment.PersonId = (int)reader["personID"];
                                anAppointment.NurseId = (int)reader["nurseID"];
                                anAppointment.DoctorId = (int)reader["doctorID"];
                                anAppointment.AppointmentDate = (DateTime)reader["appointmentDate"];
                                anAppointment.Symptom = (String)reader["symptom"];
                                anAppointment.Diagnosis = !DBNull.Value.Equals(reader["diagnosis"]) ? (String)reader["diagnosis"] : null;

                                appointment = anAppointment;
                            }

                            return appointment;
                        }
                       
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void SetAppointmentFields()
        {
            oldApp = AppointmentController.GetAppointmentInfo(allAppointments[cbAppId.SelectedIndex].AppointmentId);

            tbNurse.Text = NurseController.GetNurseByID(oldApp.NurseId).UserName;
            tbPatient.Text = PatientController.GetPatientByID(oldApp.PersonId).FullName;
            tbSymptoms.Text = oldApp.Symptom;
            tbDate.Value = oldApp.AppointmentDate;
            tbDiagnosis.Text = oldApp.Diagnosis;
            tbDoctor.Text = DoctorController.GetDoctorByID(oldApp.DoctorId).FullName;
        }