Example #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // Hide database error on page load
            DataBaseError.Visible = false;

            // Enable submit button on page load
            SubmitButton.Enabled = true;

            // Redirect to login if not logged in
            if (Session[Global.user] == null)
            {
                Response.Redirect("Login.aspx");
            }

            // If logged in attempt to pull data from database
            try
            {
                List <Visit> visits = VisitUtility.GetVisits();
                VisitGridView.DataSource = visits;
                VisitGridView.DataBind();
            }
            // If exception caught show database error and
            // disable submit button
            catch (Exception)
            {
                DataBaseError.Visible = true;
                SubmitButton.Enabled  = false;
            }
        }
Example #2
0
        // Find and bind search results to grid view based
        // on radio button choice
        protected void SearchClick(object sender, EventArgs e)
        {
            List <Visit> visits       = VisitUtility.GetVisits();
            List <Visit> searchReturn = new List <Visit>();
            string       choice       = radiolist1.SelectedItem.Text;

            // Hide error message
            NotFoundError.Visible = false;

            // If name selected search for name
            if (choice == "Name")
            {
                foreach (Visit visit in visits)
                {
                    if (PatientUtility.GetPatient(visit.patientId).
                        name.ToString().Contains(Search.Text))
                    {
                        searchReturn.Add(visit);
                    }
                }
            }

            // If date of visit selected search for date
            if (choice == "Date of Visit")
            {
                foreach (Visit visit in visits)
                {
                    if (visit.date.ToString().Contains(Search.Text))
                    {
                        searchReturn.Add(visit);
                    }
                }
            }

            // If date of discharge selected search for date
            if (choice == "Date of Discharge")
            {
                foreach (Visit visit in visits)
                {
                    if (visit.discharge.ToString().Contains(Search.Text))
                    {
                        searchReturn.Add(visit);
                    }
                }
            }

            // If results found bind to grid view
            if (searchReturn.Any())
            {
                VisitGridView.DataSource = searchReturn;
                VisitGridView.DataBind();
            }
            // If no results found show error
            else
            {
                NotFoundError.Visible = true;
            }
        }
Example #3
0
        // Check if patient is a current inpatient
        protected void InpatientValidate(object sender,
                                         ServerValidateEventArgs e)
        {
            int id;

            try
            {
                // Try parse input to int
                if (int.TryParse(e.Value, out id))
                {
                    // Try to get patient from database
                    Patient patient = PatientUtility.GetPatient(id);

                    // If no patient found throw exception
                    if (patient == null)
                    {
                        throw new Exception();
                    }

                    // Try to get visits from database
                    List <Visit> visits = VisitUtility.GetVisits();

                    // Check eacb visit for patient
                    foreach (Visit visit in visits)
                    {
                        // If patient is found
                        if (visit.patientId == id)
                        {
                            // And visit type is invisit
                            if (visit.type == 0)
                            {
                                // without a discharge date
                                if (visit.discharge == null)
                                {
                                    // patient is busy and fails validation
                                    throw new Exception();
                                }
                            }
                        }
                    }

                    // If input located existing patient and patient
                    // is not current inpatient validation succeeds
                    e.IsValid = true;
                    return;
                }

                // Throw exception if unable to parse input to int
                throw new Exception();
            }
            // Invalid if any exception caught
            catch (Exception)
            {
                e.IsValid = false;
            }
        }
Example #4
0
        // Validate patient ID has current invisit
        protected void InpatientValidate(object sender,
                                         ServerValidateEventArgs e)
        {
            try
            {
                int id;

                // // If input is an int
                if (int.TryParse(e.Value, out id))
                {
                    // Create patient from id
                    Patient patient = PatientUtility.GetPatient(id);

                    // If not found fails PatientIdValidate
                    // and invisit validation can halt
                    if (patient == null)
                    {
                        return;
                    }

                    // Create list of all visits
                    List <Visit> visits = VisitUtility.GetVisits();
                    // For each visit in list
                    foreach (Visit visit in visits)
                    {
                        // If patient id matches and patient
                        // has current invisit
                        if (visit.patientId == patient.id &&
                            visit.type == 0 && visit.discharge == null)
                        {
                            // e is valid
                            e.IsValid = true;
                            return;
                        }
                    }
                }

                // If no valid visit is found throw exception
                throw new Exception();
            }
            // Any exceptions caught input is invalid
            catch (Exception)
            {
                e.IsValid = false;
                return;
            }
        }
Example #5
0
        // Discharge inpatient
        protected void PayClick(object sender, EventArgs e)
        {
            try
            {
                // Reset messages
                PayErrorMessage.Visible   = false;
                PaySuccessMessage.Visible = false;

                // Convert input to int
                int id = Convert.ToInt32(PatientId.Text);

                // Get list of visits
                List <Visit> visits  = VisitUtility.GetVisits();
                int          visitId = 0;

                // Get ID of valid visit
                foreach (Visit visit in visits)
                {
                    if (visit.patientId == id && visit.discharge == null)
                    {
                        visitId = visit.id;
                    }
                }

                // Get Visit from ID
                InVisit thisVisit = VisitUtility.GetInVisit(visitId);

                // Get time and split to Database datetime format
                string   dischargeTime = DateTime.Now.ToString();
                string[] timeSplit     = dischargeTime.Split(' ');
                string[] dateSplit     = timeSplit[0].Split('/');
                string   dischargeDate = String.Format("{0}/{1}/{2} {3}",
                                                       dateSplit[2], dateSplit[1], dateSplit[0], timeSplit[1]);

                // Create discharged patient to update database with
                InVisit update = new InVisit(thisVisit.id, thisVisit.patientId,
                                             thisVisit.type, thisVisit.doctor, thisVisit.date,
                                             dischargeDate, thisVisit.bed);

                // If database update successfull
                if (VisitUtility.UpdateVisit(update))
                {
                    // Show success message
                    PayErrorMessage.Visible   = false;
                    PaySuccessMessage.Visible = true;
                    // Disable paybutton
                    PayButton.Enabled = false;
                }
                else
                {
                    // Show error if not successful
                    PaySuccessMessage.Visible = false;
                    PayErrorMessage.Visible   = true;
                }
            }
            catch (Exception)
            {
                // Show error message if exception caught
                PaySuccessMessage.Visible = false;
                PayErrorMessage.Visible   = true;
            }
        }
Example #6
0
        // Return amount Patient owes for current visit if exists
        protected void InfoClick(object sender, EventArgs e)
        {
            // Reset panel
            InpatientGridView.Visible = false;
            DischargePanel.Visible    = false;
            AmountOwingLabel.Visible  = false;
            PayButton.Visible         = false;

            try
            {
                int id;

                // Parse input to int
                int.TryParse(PatientId.Text, out id);

                // Get patient with provided ID
                Patient patient = PatientUtility.GetPatient(id);

                // Get all visits
                List <Visit> visits = VisitUtility.GetVisits();

                // Id of valid visit
                int resultId = 0;

                // Get ID of valid visit
                foreach (Visit visit in visits)
                {
                    if (visit.type == 0 && visit.patientId == id &&
                        visit.discharge == null)
                    {
                        resultId = visit.id;
                    }
                }

                // If a valid visit is found
                if (resultId != 0)
                {
                    // Create new list to bind gridview to
                    List <InVisit> visit = new List <InVisit>();
                    // Add found visit to list from id
                    visit.Add(VisitUtility.GetInVisit(resultId));

                    // Grey out ID textbox
                    PatientId.Enabled = false;
                    // And info submit button
                    InfoSubmitButton.Enabled = false;

                    // Bind visit to gridview
                    InpatientGridView.DataSource = visit;
                    InpatientGridView.DataBind();
                    // Show gridview
                    InpatientGridView.Visible = true;

                    // Show discharge panel
                    DischargePanel.Visible = true;
                    AmountOwingLabel.Text  = String.Format(
                        "Total Price = ${0}", VisitUtility.GetPrice(visit[0]));
                    AmountOwingLabel.Visible = true;

                    // Enable pay button
                    PayButton.Visible = true;
                }
                // If not visit found throw exception
                else
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                // If anything went wrong
                // hide panels, error message
                // will be displayed by validators
                InpatientGridView.Visible = false;
                DischargePanel.Visible    = false;
                PayButton.Visible         = false;
            }
        }
Example #7
0
        // 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;
            }
        }
Example #8
0
        // 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;
            }
        }