using framework_business; using framework_library; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Reflection; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Telerik.Web.UI; public partial class controls_module_medicalSymptoms : UserControl, ISurfaceControlBase { #region methods /// /// Reload Control /// /// public void ReloadControl(oSurfaceFieldData controlFieldData, bool alternateView = false, bool readOnly = false) { try { ViewState["patientType"] = null; oMedicalPatientSymptom medicalPatientSymptom = new oMedicalPatientSymptom(); medicalPatientSymptom.surfaceItemId = controlFieldData.surfaceItemId; foreach (oMedicalPatientSymptom currentMPS in xData.GetTypedByCriteriaSpecific("recId", typeof(oMedicalPatientSymptom), "surfaceItemId", controlFieldData.surfaceItemId.ToString())) { medicalPatientSymptom = currentMPS; } MedicalPatientSymptom = medicalPatientSymptom; SetupControl(MedicalPatientSymptom); } catch (Exception ex) { exception.HandleException("symptoms:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Save Control Data /// /// public void SaveControlData(ref oSurfaceFieldData _surfaceFieldData) { try { SetHfSymptoms(); SetHfTrauma(); MedicalPatientSymptom.symptoms = hfSymptoms.Text; MedicalPatientSymptom.drugsTaken = txtDrugsTaken.Value; MedicalPatientSymptom.traumaticEvents = hfTrauma.Text; MedicalPatientSymptom.surfaceItemId = _surfaceFieldData.surfaceItemId; if (MedicalPatientSymptom.recId > 0) xData.UpdateTyped("recId", MedicalPatientSymptom.recId.ToString(), typeof(oMedicalPatientSymptom), MedicalPatientSymptom); else MedicalPatientSymptom.recId = xData.SaveTyped("recId", typeof(oMedicalPatientSymptom), MedicalPatientSymptom); _surfaceFieldData.surfaceFieldLookupID = MedicalPatientSymptom.recId; } catch (Exception ex) { exception.HandleException("medicalSymptoms:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Set Symtoms Value /// private void SetHfSymptoms() { try { bool firstItem = true; foreach (GridViewRow row in grdSymptoms.Rows) { if (row.RowType == DataControlRowType.DataRow) { DataRowView rowView = (DataRowView)row.DataItem; Label lblId = (Label)row.FindControl("lblId"); RadioButton optPast = (RadioButton)row.FindControl("optPast"); RadioButton optCurrent = (RadioButton)row.FindControl("optCurrent"); RadioButton optNever = (RadioButton)row.FindControl("optNever"); string iValue = string.Empty; if (optPast.Checked) iValue = string.Format("P_{0}", lblId.Text); if (optCurrent.Checked) iValue = string.Format("C_{0}", lblId.Text); if (optNever.Checked) iValue = string.Format("N_{0}", lblId.Text); if (firstItem) { hfSymptoms.Text = iValue; firstItem = false; } else hfSymptoms.Text += ";" + iValue; } } } catch (Exception ex) { exception.HandleException("medicalSymptoms:", MethodBase.GetCurrentMethod().Name, ex, this.MedicalPatientSymptom); Response.Redirect("/error", false); } } /// /// Set Trauma Value /// private void SetHfTrauma() { try { bool firstItem = true; foreach (GridViewRow row in grdTrauma.Rows) { if (row.RowType == DataControlRowType.DataRow) { DataRowView rowView = (DataRowView)row.DataItem; Label lblId = (Label)row.FindControl("lblId"); RadioButton optYes = (RadioButton)row.FindControl("optYes"); RadioButton optNo = (RadioButton)row.FindControl("optNo"); string iValue = string.Empty; if (optYes.Checked) iValue = string.Format("Y_{0}", lblId.Text); if (optNo.Checked) iValue = string.Format("N_{0}", lblId.Text); if (firstItem) { hfSymptoms.Text = iValue; firstItem = false; } else hfSymptoms.Text += ";" + iValue; } } } catch (Exception ex) { exception.HandleException("medicalSymptoms:", MethodBase.GetCurrentMethod().Name, ex, this.MedicalPatientSymptom); Response.Redirect("/error", false); } } /// /// Setup Control /// /// private void SetupControl(oMedicalPatientSymptom MPS) { try { BindPatientSymptom(MPS); } catch (Exception ex) { exception.HandleException("medicalSymptoms:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Bind Patient History /// /// private void BindPatientSymptom(oMedicalPatientSymptom MPS) { //Todo: find way to identify patient type //if (ppc.PatientType == PatientPersonType.Adult) //{ // txtHistoryJobs.Text = phc.HealthJobs; // hfSocial.Text = phc.SocialPastCurrentActivities; //} try { hfSymptoms.Text = MPS.symptoms; hfTrauma.Text = MPS.traumaticEvents; txtDrugsTaken.Value = MPS.drugsTaken; BindDataGrids(); } catch (Exception ex) { exception.HandleException("medicalSymptoms:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Bind Data Grids /// private void BindDataGrids() { try { if (utils.verifySession("PatientType")) { PatientType = (pNums.PatientType)Convert.ToInt32(Session["PatientType"].ToString()); } DataTable dtGeneralSymptoms = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oMedicalSymptom), "isActive,patientType", "1," + PatientType.GetHashCode()); grdSymptoms.DataSource = dtGeneralSymptoms; grdSymptoms.DataBind(); if (PatientType == pNums.PatientType.Paediatric) { lblSymptomHeading.Text = "Has your child ever or does he/she suffer with any of the following symptoms below (click on the tick to select):"; lblDrugHeading.Text = "Please list Prescription & Non-Prescription drugs your child takes (if applicable):"; divTrauma.Visible = true; DataTable dtTrauma = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oMedicalTraumaticEvent), "isActive,patientType", "1," + PatientType.GetHashCode()); grdTrauma.DataSource = dtTrauma; grdTrauma.DataBind(); } else { lblSymptomHeading.Text = "Have you ever or do you suffer with any of the following symptoms below (click on the tick to select):"; lblDrugHeading.Text = "Please list Prescription & Non-Prescription drugs you take (if applicable):"; divTrauma.Visible = false; } } catch (Exception ex) { exception.HandleException("medicalSymptoms:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } #endregion #region events /// /// Page Load /// /// /// protected void Page_Load(object sender, EventArgs e) { try { if (!Page.IsPostBack) { } } catch (Exception ex) { exception.HandleException("symptoms:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// grdSymptoms RowDataBound /// /// /// protected void grdSymptoms_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { DataRowView rowView = (DataRowView)e.Row.DataItem; Label lblId = (Label)e.Row.FindControl("lblId"); lblId.Text = rowView["recId"].ToString(); string[] scArray = hfSymptoms.Text.Split(';'); string iValue = string.Format("N_{0}", lblId.Text); RadioButton optNever = (RadioButton)e.Row.FindControl("optNever"); optNever.Checked = (hfSymptoms.Text.Split(';').Contains(iValue)); optNever.GroupName = string.Format("Symptoms_{0}", lblId.Text); iValue = string.Format("P_{0}", lblId.Text); RadioButton optPast = (RadioButton)e.Row.FindControl("optPast"); optPast.Checked = (hfSymptoms.Text.Split(';').Contains(iValue)); optPast.GroupName = string.Format("Symptoms_{0}", lblId.Text); iValue = string.Format("C_{0}", lblId.Text); RadioButton optCurrent = (RadioButton)e.Row.FindControl("optCurrent"); optCurrent.Checked = (hfSymptoms.Text.Split(';').Contains(iValue)); optCurrent.GroupName = string.Format("Symptoms_{0}", lblId.Text); } } /// /// grdTrauma RowDataBound /// /// /// protected void grdTrauma_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { DataRowView rowView = (DataRowView)e.Row.DataItem; Label lblId = (Label)e.Row.FindControl("lblId"); lblId.Text = rowView["recId"].ToString(); string[] scArray = hfTrauma.Text.Split(';'); string iValue = string.Format("N_{0}", lblId.Text); RadioButton optNo = (RadioButton)e.Row.FindControl("optNo"); optNo.Checked = (hfTrauma.Text.Split(';').Contains(iValue)); optNo.GroupName = string.Format("Trauma_{0}", lblId.Text); iValue = string.Format("Y_{0}", lblId.Text); RadioButton optYes = (RadioButton)e.Row.FindControl("optYes"); optYes.Checked = (hfTrauma.Text.Split(';').Contains(iValue)); optYes.GroupName = string.Format("Trauma_{0}", lblId.Text); } } #endregion #region properties /// /// MPS getter and setter /// public oMedicalPatientSymptom MedicalPatientSymptom { get { if (ViewState["medicalPatientSymptom"] == null) return null; else return (oMedicalPatientSymptom)ViewState["medicalPatientSymptom"]; } set { ViewState["medicalPatientSymptom"] = value; } } public pNums.PatientType PatientType { get { pNums.PatientType patientType = pNums.PatientType.Adult; if (utils.verifySession("SurfaceAppItem")) { oSurfaceItem surfaceItem = (oSurfaceItem)Session["SurfaceAppItem"]; foreach (oSurfaceField field in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldName", surfaceItem.surfaceId.ToString() + ",PatientType_PatientType_PatientType")) { foreach (oSurfaceFieldData data in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceFieldId,surfaceItemId,surfaceId", field.recId.ToString() + "," + surfaceItem.recId.ToString() + "," + surfaceItem.surfaceId.ToString())) { foreach (oSurfaceLookup lookup in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "recId", data.surfaceFieldLookupID.ToString())) { patientType = (pNums.PatientType)Enum.Parse(typeof(pNums.PatientType), lookup.display.Substring(0, lookup.display.IndexOf(' '))); } } } } return patientType; } set { ViewState["patientType"] = value; } } #endregion }