Exemple #1
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;
            }
        }
Exemple #2
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;
            }
        }