Esempio n. 1
0
        protected void btnNext_Click(object sender, EventArgs e)
        {
            TheCancerProject.Core.Patient thePatient          = SessionObjects.ThePatient;
            TheCancerProject.Core.Patient thePatientToVerify  = SessionObjects.ThePatient;
            TheCancerProject.Core.Biodata theBiodataToReplace = new Core.Biodata();
            string uniqueID = string.Empty;

            if (thePatient == null || string.IsNullOrWhiteSpace(thePatient.UniqueID))
            {
                uniqueID = new PatientDAO().CreateUniqueID();
            }
            else if (thePatient != null && !string.IsNullOrWhiteSpace(thePatient.UniqueID))
            {
                uniqueID = thePatient.UniqueID;
            }
            try
            {
                bool doNotSaveInDB = false;
                if (System.Configuration.ConfigurationManager.AppSettings["DoNotSaveInDB"] != null && Boolean.TryParse(System.Configuration.ConfigurationManager.AppSettings["DoNotSaveInDB"], out doNotSaveInDB))
                {
                    if (doNotSaveInDB)
                    {
                        Response.Redirect("~/ThePages/Create/PresentingComplaints.aspx", false);
                    }
                }
                if (string.IsNullOrWhiteSpace(dateDateofBirth.Value))
                {
                    if (!Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), "message"))
                    {
                        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "<script type='text/javascript'>alertify.alert('Message', '" + "Please Enter a valid Date Of Birth" + "', function(){location = '/ThePages/Create/Biodata.aspx';});</script>", false);
                    }
                }
                //List<TheCancerProject.Core.Biodata> theBiodataList = new BiodataDAO().RetrieveByHospitalAndHospitalNumber(SessionObjects.TheHospital, SessionObjects.HospitalNumber);
                TheCancerProject.Core.Biodata theBiodata = new Core.Biodata();
                //theBiodata = theBiodataList.First();
                theBiodata.DateOfBirth           = Convert.ToDateTime(dateDateofBirth.Value);
                theBiodata.Age                   = Convert.ToString((DateTime.Now.Year - theBiodata.DateOfBirth.Year));
                theBiodata.TheHospital           = (SessionObjects.TheHospital != null) ? SessionObjects.TheHospital : null;
                theBiodata.Address               = txtAddress.Value;
                theBiodata.FirstName             = txtFirstName.Value;
                theBiodata.HospitalNumber        = txtHospitalNumber.Value;
                theBiodata.LastName              = txtLastName.Value;
                theBiodata.NextOfKinName         = txtNextOfKinName.Value;
                theBiodata.NextOfKinPhone        = txtNextofKinPhone.Value;
                theBiodata.Occupation            = txtOccupation.Value;
                theBiodata.PhoneNumber           = txtPhone.Value;
                theBiodata.OtherNames            = txtOtherNames.Value;
                theBiodata.Religion              = (Religion)Enum.Parse(typeof(Religion), ddlReligion.SelectedValue, true);
                theBiodata.Sex                   = (Sex)Enum.Parse(typeof(Sex), ddlSex.SelectedValue);
                theBiodata.Title                 = (Title)Enum.Parse(typeof(Title), ddlTitle.SelectedValue);
                theBiodata.StateOfResidence      = (State)Enum.Parse(typeof(State), ddlStates.SelectedValue);
                theBiodata.MaritalStatus         = (MaritalStatus)Enum.Parse(typeof(MaritalStatus), ddlMaritalStatus.SelectedValue);
                theBiodata.NextOfKinRelationship = (Relationship)Enum.Parse(typeof(Relationship), ddlRelationship.SelectedValue);
                theBiodata.DateCreated           = DateTime.Now;
                theBiodata.DateUpdated           = DateTime.Now;
                theBiodata.UniqueID              = uniqueID;

                Patient thePatientToSave = new Patient {
                    TheBiodata = theBiodata, TheHospital = (thePatient != null) ? thePatient.TheHospital : null, TheBreastAndAxillaryExamination = (thePatient != null) ? thePatient.TheBreastAndAxillaryExamination : null, TheComplaints = (thePatient != null) ? thePatient.TheComplaints : null, TheEventsOnAdmission = (thePatient != null) ? thePatient.TheEventsOnAdmission : null, TheGeneralExamination = (thePatient != null) ? thePatient.TheGeneralExamination : null, ThePreliminaryExamination = (thePatient != null) ? thePatient.ThePreliminaryExamination : null, LastUserAdministeringTreatment = (thePatient != null) ? thePatient.LastUserAdministeringTreatment : null, TheClinicVisits = (thePatient != null) ? thePatient.TheClinicVisits : null, TheInvestigation = (thePatient != null) ? thePatient.TheInvestigation : null, TheProcedures = (thePatient != null) ? thePatient.TheProcedures : null, TheDiagnoses = (thePatient != null) ? thePatient.TheDiagnoses : null, UniqueID = uniqueID, DateCreated = DateTime.Now, DateUpdated = DateTime.Now
                };
                //thePatient.TheBiodata = theBiodata;
                SessionObjects.TheBiodata      = theBiodata;
                SessionObjects.PatientUniqueID = uniqueID;
                //thePatient = thePatientToSave;
                //SessionObjects.ThePatient = thePatient;
                if (thePatient != null)
                {
                    thePatient.TheBiodata = theBiodata;
                }
                else
                {
                    thePatient = thePatientToSave;
                }

                if (thePatientToVerify == null) //nothing in session
                {
                    BiodataDAO.Save(theBiodata);
                    PatientDAO.Save(thePatient);
                    thePatient = new PatientDAO().RetrieveByUniqueID(SessionObjects.PatientUniqueID);
                    SessionObjects.ThePatient = thePatient;
                    Response.Redirect("~/ThePages/Create/PresentingComplaints.aspx", false);
                }
                else if (thePatientToVerify != null && thePatientToVerify.Id > 0 && thePatientToVerify.TheBiodata != null && thePatientToVerify.TheBiodata.Id <= 0)
                {
                    BiodataDAO.Save(theBiodata);
                    theBiodataToReplace   = new BiodataDAO().RetrieveByUniqueID(uniqueID); // Take newly saved biodata, so that the ID can be available during update query below
                    thePatient.TheBiodata = theBiodataToReplace;
                    PatientDAO.Update(thePatient);
                    thePatient = new PatientDAO().RetrieveByUniqueID(SessionObjects.PatientUniqueID);
                    SessionObjects.ThePatient = thePatient;
                    Response.Redirect("~/ThePages/Create/PresentingComplaints.aspx", false);
                }
                else if (thePatientToVerify != null && thePatientToVerify.Id > 0 && thePatientToVerify.TheBiodata != null && thePatientToVerify.TheBiodata.Id > 0 && thePatientToVerify.TheBiodata != theBiodata)
                {
                    theBiodata.Id = thePatient.TheBiodata.Id;
                    BiodataDAO.Update(theBiodata);
                    theBiodataToReplace   = new BiodataDAO().RetrieveByUniqueID(uniqueID); // Take newly saved biodata, so that the ID can be available during update query below
                    thePatient.TheBiodata = theBiodataToReplace;
                    PatientDAO.Update(thePatient);
                    thePatient = new PatientDAO().RetrieveByUniqueID(SessionObjects.PatientUniqueID);
                    SessionObjects.ThePatient = thePatient;
                    Response.Redirect("~/ThePages/Create/PresentingComplaints.aspx", false);
                }
                else if (thePatientToVerify.TheBiodata != null && thePatientToVerify.TheBiodata == theBiodata)
                {
                    //If it's the same data, don't save or update, just redirect
                    Response.Redirect("~/ThePages/Create/PresentingComplaints.aspx", false);
                }
                else
                {
                    if (!Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), "message"))
                    {
                        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "<script type='text/javascript'>alertify.alert('Message', '" + "Unknown error encountered. Kindly contact admin!!!" + "', function(){location = '/ThePages/Create/Biodata.aspx';});</script>", false);
                    }
                }
            }
            catch (Exception ex)
            {
                string errorMessage = ex.InnerException == null ? ex.Message : ex.InnerException.Message;
                if (!Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), "message"))
                {
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", @"<script type='text/javascript'>alertify.alert('Message', """ + errorMessage.Replace("\n", "").Replace("\r", "") + @""", function(){});</script>", false);
                }
            }
        }
        protected void btnNext_Click(object sender, EventArgs e)
        {
            try
            {
                bool doNotSaveInDB = false;
                if (System.Configuration.ConfigurationManager.AppSettings["DoNotSaveInDB"] != null && Boolean.TryParse(System.Configuration.ConfigurationManager.AppSettings["DoNotSaveInDB"], out doNotSaveInDB))
                {
                    if (doNotSaveInDB)
                    {
                        Response.Redirect("~/ThePages/Create/PresentingComplaints.aspx", false);
                    }
                }

                List <TheCancerProject.Core.Biodata> theBiodataList = new BiodataDAO().RetrieveByHospitalAndHospitalNumber(SessionObjects.TheHospital, SessionObjects.HospitalNumber);
                TheCancerProject.Core.Biodata        theBiodata     = new Core.Biodata();
                //theBiodata = theBiodataList.First();
                theBiodata.TheHospital           = (SessionObjects.TheHospital != null) ? SessionObjects.TheHospital : null;
                theBiodata.Address               = txtAddress.Value;
                theBiodata.FirstName             = txtFirstName.Value;
                theBiodata.HospitalNumber        = txtHospitalNumber.Value;
                theBiodata.LastName              = txtLastName.Value;
                theBiodata.NextOfKinName         = txtNextOfKinName.Value;
                theBiodata.NextOfKinPhone        = txtNextofKinPhone.Value;
                theBiodata.Occupation            = txtOccupation.Value;
                theBiodata.PhoneNumber           = txtPhone.Value;
                theBiodata.OtherNames            = txtOtherNames.Value;
                theBiodata.Religion              = (Religion)Enum.Parse(typeof(Religion), ddlReligion.SelectedValue, true);
                theBiodata.Sex                   = (Sex)Enum.Parse(typeof(Sex), ddlSex.SelectedValue);
                theBiodata.Title                 = (Title)Enum.Parse(typeof(Title), ddlTitle.SelectedValue);
                theBiodata.StateOfResidence      = (State)Enum.Parse(typeof(State), ddlStates.SelectedValue);
                theBiodata.MaritalStatus         = (MaritalStatus)Enum.Parse(typeof(MaritalStatus), ddlMaritalStatus.SelectedValue);
                theBiodata.NextOfKinRelationship = (Relationship)Enum.Parse(typeof(Relationship), ddlRelationship.SelectedValue);
                theBiodata.DateCreated           = DateTime.Now;
                theBiodata.DateUpdated           = DateTime.Now;
                Patient thePatient = new Patient {
                    TheBiodata = theBiodata, TheHospital = null, TheBreastAndAxillaryExamination = null, TheComplaints = null, TheEventsOnAdmission = null, TheGeneralExamination = null, ThePreliminaryExamination = null, LastUserAdministeringTreatment = null, DateCreated = DateTime.Now, DateUpdated = DateTime.Now
                };
                //thePatient.TheBiodata = theBiodata;
                SessionObjects.TheBiodata = theBiodata;
                if (theBiodataList == null || theBiodataList.Count <= 0)
                {
                    BiodataDAO.Save(theBiodata);
                    PatientDAO.Save(thePatient);
                    Response.Redirect("~/ThePages/Create/PresentingComplaints.aspx", false);
                }
                else if (theBiodataList != null && theBiodataList.FirstOrDefault() != theBiodata)
                {
                    BiodataDAO.Update(theBiodata);
                    PatientDAO.Update(thePatient);
                    Response.Redirect("~/ThePages/Create/PresentingComplaints.aspx", false);
                }
                else if (theBiodataList != null && theBiodataList.FirstOrDefault() == theBiodata)
                {
                    //If it's the same data, don't save or update, just redirect
                    Response.Redirect("~/ThePages/Create/PresentingComplaints.aspx", false);
                }
                else if (theBiodataList != null && theBiodataList.Count > 1)
                {
                    if (!Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), "message"))
                    {
                        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "<script type='text/javascript'>alertify.alert('Message', '" + "Multiple Biodata Exists for this patient. Kindly contact admin!!!" + "', function(){location = '/Start/Login.aspx';});</script>", false);
                    }
                }
                else
                {
                    if (!Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), "message"))
                    {
                        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "<script type='text/javascript'>alertify.alert('Message', '" + "Unknown error encountered. Kindly contact admin!!!" + "', function(){location = '/Start/Login.aspx';});</script>", false);
                    }
                }
                //if (!Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), "message"))
                //{
                //    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "<script type='text/javascript'>alertify.alert('Message', '" + "Admin Saved Successfully" + "', function(){location = '/Start/Login.aspx';});</script>", false);
                //}
            }
            catch (Exception ex)
            {
                string errorMessage = ex.InnerException == null ? ex.Message : ex.InnerException.Message;
                if (!Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), "message"))
                {
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", @"<script type='text/javascript'>alertify.alert('Message', """ + errorMessage.Replace("\n", "").Replace("\r", "") + @""", function(){});</script>", false);
                }
            }
        }