protected void Page_Load(object sender, EventArgs e) { // Hide database error on page load DataBaseError.Visible = false; // Hide gridview on page load DoctorGridView.Enabled = false; // Redirect to login page if not logged in if (Session[Global.user] == null) { Response.Redirect("Login.aspx"); } // If logged in attempt to pull data from database try { // Bind doctor data to gridview List <Doctor> doctors = DoctorUtility.GetDoctors(); DoctorGridView.DataSource = doctors; DoctorGridView.DataBind(); } // If exception caught show database error // and hide gridview catch (Exception) { DataBaseError.Visible = true; DoctorGridView.Enabled = false; } }
// Validate provided doctor ID exists in database protected void DoctorIdValidate(object sender, ServerValidateEventArgs e) { try { int id; // Try parse input to int if (int.TryParse(e.Value, out id)) { // Get doctor from database with provided id // using stored procedure Doctor doctor = DoctorUtility.GetDoctor(id); // Valid if found if (doctor != null) { e.IsValid = true; return; } } // Throw exception if no valid doctor found // or input not parsable to int throw new Exception(); } // Invalid if any exception caught catch (Exception) { // Hide GridView on invalid search // clears any previous completed // search results to avoid confusion DoctorPatientGridView.Visible = false; e.IsValid = false; } }
// Get doctor name for gridview protected string GetDoctorName(object doctorId) { return(DoctorUtility.GetDoctor( Convert.ToInt32(doctorId.ToString())).name); }
// Search doctor patient history submit protected void InfoClick(object sender, EventArgs e) { try { int id; // Hide grid and error messages each time submit is clicked InfoErrorMessage.Visible = false; DoctorPatientGridView.Visible = false; DatabaseError.Visible = false; // Try parse text field to int if (int.TryParse(DoctorId1.Text, out id)) { // Try get doctor from database with id from // text box Doctor doctor = DoctorUtility.GetDoctor(id); // If no doctor exists return control to // allow validators to produce error messages if (doctor == null) { return; } } // if not a valid int return control to allow // validators to produce error messages else { return; } // Get all visits and instantiate return list List <Visit> visits = VisitUtility.GetVisits(); List <Visit> searchReturn = new List <Visit>(); // Fill return list with visits provided doctor number // attended foreach (Visit visit in visits) { if (visit.doctor.ToString().Contains(DoctorId1.Text)) { searchReturn.Add(visit); } } // Bind and show grid view if results are found if (searchReturn.Any()) { DoctorPatientGridView.DataSource = searchReturn; DoctorPatientGridView.DataBind(); DoctorPatientGridView.Visible = true; } // Hide grid view and show error message if not else { DoctorPatientGridView.Visible = false; InfoErrorMessage.Visible = true; } } // If an exception is caught here there was an issue // with the database and database error is shown catch (Exception) { DatabaseError.Visible = true; } }
// Add new visit submit protected void AssignClick(object sender, EventArgs e) { try { // Hide error messages when assign button is clicked DatabaseError.Visible = false; AssignSuccess.Visible = false; AssignFail.Visible = false; // Get patient and doctor Patient patient = PatientUtility.GetPatient( int.Parse(PatientId.Text)); Doctor doctor = DoctorUtility.GetDoctor( int.Parse(DoctorId.Text)); // Break if either not found, error messages will // be given by validators if (patient == null || doctor == null) { return; } // Generate pseudo id for object creation // (real id assigned by database) int visitId = VisitUtility.GetNewId(); // Get system date string fullDate = DateTime.Now.ToString(); // Split date from time string[] fullDateSplit = fullDate.Split(' '); // Split date into 3 parts (D,M,Y) string[] dateArray = fullDateSplit[0].Split('/'); // Recreate date in MM/DD/YYYY format for storing string date = String.Format("{0}/{1}/{2} {3}", dateArray[1], dateArray[0], dateArray[2], fullDateSplit[1]); // Set type to outpatient int visitType = 1; // If inpatient if (PatientTypeRadioButtonList.SelectedItem.ToString() == "Inpatient") { // Change type visitType = 0; // Get Bed Bed bed = BedUtility.GetBed(int.Parse(Bed.Text)); // Create new invisit InVisit inVisit = new InVisit(visitId, patient.id, visitType, doctor.id, date, "", bed.id); // Attempt to add object to database throw exception // on failure if (!VisitUtility.AddVisit(inVisit)) { throw new Exception(); } } // If outpatient else { // Set discharge date to visit date string discharge = date; // Create new outvisit object OutVisit outVisit = new OutVisit(visitId, patient.id, visitType, doctor.id, date, discharge); // Attempt to add object to database throw exception // on failure if (!VisitUtility.AddVisit(outVisit)) { throw new Exception(); } } // If no exception thrown operation was a success, show // confirmation message and hide errors AssignFail.Visible = false; AssignSuccess.Visible = true; AssignSubmit.Enabled = false; } // If exception is caught there is an issue with database connection // show appropriate error messages catch (Exception) { AssignSuccess.Visible = false; AssignFail.Visible = true; DatabaseError.Visible = true; } }