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_medicalHistory : UserControl, ISurfaceControlBase { #region methods /// /// Reload Control /// /// public void ReloadControl(oSurfaceFieldData controlFieldData, bool alternateView = false, bool readOnly = false) { try { oMedicalPatientHistory medicalPatientHistory = new oMedicalPatientHistory(); medicalPatientHistory.surfaceItemId = controlFieldData.surfaceItemId; foreach (oMedicalPatientHistory currentMPH in xData.GetTypedByCriteriaSpecific("recId", typeof(oMedicalPatientHistory), "surfaceItemId", controlFieldData.surfaceItemId.ToString())) { medicalPatientHistory = currentMPH; } this.MedicalPatientHistory = medicalPatientHistory; SetupControl(MedicalPatientHistory); } catch (Exception ex) { exception.HandleException("medicalHistory:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Save Control Data /// /// public void SaveControlData(ref oSurfaceFieldData _surfaceFieldData) { try { SetHfSpefiedConditions(); SetHfFamily(); SetHfTreated(); SetHfPastCurrentData(); SetHfSocial(); MedicalPatientHistory.specifiedConditions = hfSpecifiedConditions.Text; MedicalPatientHistory.seriousConditions = txtHistorySeriousConditions.Value; MedicalPatientHistory.familyConditions = hfFamily.Text; MedicalPatientHistory.familyTreated = hfTreated.Text; MedicalPatientHistory.hereditaryConditions = txtHistoryHereditaryConditions.Value; MedicalPatientHistory.pastCurrentConditions = hfPastCurrentData.Text; MedicalPatientHistory.socialConditions = hfSocial.Text; MedicalPatientHistory.surfaceItemId = _surfaceFieldData.surfaceItemId; if (MedicalPatientHistory.recId > 0) xData.UpdateTyped("recId", MedicalPatientHistory.recId.ToString(), typeof(oMedicalPatientHistory), MedicalPatientHistory); else MedicalPatientHistory.recId = xData.SaveTyped("recId", typeof(oMedicalPatientHistory), MedicalPatientHistory); _surfaceFieldData.surfaceFieldLookupID = MedicalPatientHistory.recId; } catch (Exception ex) { exception.HandleException("medicalHistory:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Set Control /// /// private void SetupControl(oMedicalPatientHistory mph) { try { if (utils.verifySession("PatientType")) { PatientType = (pNums.PatientType)Convert.ToInt32(Session["PatientType"].ToString()); } BindPatientHistory(mph); if (PatientType == pNums.PatientType.Paediatric) { lblConditions.Text = "Has your child ever been diagnosed with any of the following conditions below (click on the tick to select):"; lblCurrent.Text = "Indicate ALL PAST and CURRENT conditions you feel may be contributing to your child's present problem:"; divSocialHistory.Visible = false; } else { lblConditions.Text = "Have you ever been diagnosed with any of the following conditions below (click on the tick to select):"; lblCurrent.Text = "Indicate ALL PAST and CURRENT conditions you feel may be contributing to your present problem:"; divSocialHistory.Visible = true; } upMedicalHistory.Update(); } catch (Exception ex) { exception.HandleException("medicalHistory:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Bind Patient History /// /// private void BindPatientHistory(oMedicalPatientHistory mph) { //Todo: find way to identify patient type //if (ppc.PatientType == PatientPersonType.Adult) //{ // txtHistoryJobs.Text = phc.HealthJobs; // hfSocial.Text = phc.SocialPastCurrentActivities; //} try { hfSpecifiedConditions.Text = mph.specifiedConditions; txtHistorySeriousConditions.Value = mph.seriousConditions; hfFamily.Text = mph.familyConditions; hfTreated.Text = mph.familyTreated; txtHistoryHereditaryConditions.Value = mph.hereditaryConditions; hfPastCurrentData.Text = mph.pastCurrentConditions; hfSocial.Text = mph.socialConditions; BindStaticControls(); ClearGrids(); BindDataGrids(); } catch (Exception ex) { exception.HandleException("medicalHistory:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Clear Grids /// private void ClearGrids() { grdPastCurrentConditions.DataSource = null; grdSocialHistory.DataSource = null; grdSpecifiedConditions.DataSource = null; } /// /// Bind Controls /// private void BindStaticControls() { try { foreach (ListItem item in familyConditions.Items) { item.Selected = false; } foreach (ListItem item in familyTreated.Items) { item.Selected = false; } foreach (string familyMember in hfFamily.Text.Split(';')) { if (familyConditions.Items.FindByValue(familyMember) != null) familyConditions.Items.FindByValue(familyMember).Selected = true; } if (familyTreated.Items.FindByValue(hfTreated.Text) != null) familyTreated.Items.FindByValue(hfTreated.Text).Selected = true; } catch (Exception ex) { exception.HandleException("medicalHistory:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Bind Data Grids /// private void BindDataGrids() { try { DataTable dtSpecifiedConditions = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oMedicalCondition), "isActive,conditionType,patientType", "1," + pNums.ConditionType.HealthSpecifiedConditions.GetHashCode()+","+ PatientType.GetHashCode(), "sequence"); grdSpecifiedConditions.DataSource = dtSpecifiedConditions; grdSpecifiedConditions.DataBind(); DataTable dtPastCurrentConditions = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oMedicalCondition), "isActive,conditionType,patientType", "1," + pNums.ConditionType.PastCurrentConditions.GetHashCode() + "," + PatientType.GetHashCode(), "sequence"); grdPastCurrentConditions.DataSource = dtPastCurrentConditions; grdPastCurrentConditions.DataBind(); DataTable dtSocialActivities = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oMedicalCondition), "isActive,conditionType,patientType", "1," + pNums.ConditionType.SocialActivities.GetHashCode() + "," + PatientType.GetHashCode(), "sequence"); grdSocialHistory.DataSource = dtSocialActivities; grdSocialHistory.DataBind(); } catch (Exception ex) { exception.HandleException("medicalHistory:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Set Social value /// private void SetHfSocial() { try { bool firstItem = true; foreach (GridViewRow row in grdSocialHistory.Rows) { if (row.RowType == DataControlRowType.DataRow) { Label lblId = (Label)row.FindControl("lblId"); RadioButton optDaily = (RadioButton)row.FindControl("optDaily"); RadioButton optWeekends = (RadioButton)row.FindControl("optWeekends"); RadioButton optOccassionally = (RadioButton)row.FindControl("optOccassionally"); RadioButton optNever = (RadioButton)row.FindControl("optNever"); CheckBox chkCigarettes = (CheckBox)row.FindControl("chkCigarettes"); CheckBox chkCigars = (CheckBox)row.FindControl("chkCigars"); CheckBox chkPipe = (CheckBox)row.FindControl("chkPipe"); string iValue = string.Empty; if (chkCigarettes.Checked) iValue += string.Format("SCT_{0};", lblId.Text); if (chkCigars.Checked) iValue += string.Format("SCG_{0};", lblId.Text); if (chkPipe.Checked) iValue += string.Format("SP_{0};", lblId.Text); if (optDaily.Checked) iValue += string.Format("D_{0}", lblId.Text); if (optWeekends.Checked) iValue += string.Format("W_{0}", lblId.Text); if (optOccassionally.Checked) iValue += string.Format("O_{0}", lblId.Text); if (optNever.Checked) iValue += string.Format("N_{0}", lblId.Text); if (firstItem) { hfSocial.Text = iValue; firstItem = false; } else hfSocial.Text += ";" + iValue; } } } catch (Exception ex) { exception.HandleException("medicalHistory:", MethodBase.GetCurrentMethod().Name, ex, this.MedicalPatientHistory); Response.Redirect("/error", false); } } /// /// Set Specified Conditions value /// private void SetHfSpefiedConditions() { try { bool firstItem = true; foreach (GridViewRow row in grdSpecifiedConditions.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) { hfSpecifiedConditions.Text = iValue; firstItem = false; } else hfSpecifiedConditions.Text += ";" + iValue; } } } catch (Exception ex) { exception.HandleException("medicalHistory:", MethodBase.GetCurrentMethod().Name, ex, this.MedicalPatientHistory); Response.Redirect("/error", false); } } /// /// Set Family Values /// private void SetHfFamily() { try { hfFamily.Text = ""; bool firstItem = true; foreach (ListItem item in familyConditions.Items) { if (item.Selected) { if (firstItem) { hfFamily.Text += item.Value; firstItem = false; } else hfFamily.Text += ";" + item.Value; } } } catch (Exception ex) { exception.HandleException("medicalHistory:", MethodBase.GetCurrentMethod().Name, ex, this.MedicalPatientHistory); Response.Redirect("/error", false); } } /// /// Set Treated Values /// public void SetHfTreated() { try { hfTreated.Text = ""; bool firstItem = true; foreach (ListItem item in familyTreated.Items) { if (item.Selected) { if (firstItem) { hfTreated.Text += item.Value; firstItem = false; } else hfTreated.Text += ";" + item.Value; } } } catch (Exception ex) { exception.HandleException("medicalHistory:", MethodBase.GetCurrentMethod().Name, ex, this.MedicalPatientHistory); Response.Redirect("/error", false); } } /// /// Set Past/Current Values /// private void SetHfPastCurrentData() { try { bool firstItem = true; foreach (GridViewRow row in grdPastCurrentConditions.Rows) { if (row.RowType == DataControlRowType.DataRow) { DataRowView rowView = (DataRowView)row.DataItem; Label lblId = (Label)row.FindControl("lblId"); TextBox txtTreatmentAge = (TextBox)row.FindControl("txtTreatmentAge"); TextBox txtCareType = (TextBox)row.FindControl("txtCareType"); TextBox txtCareGiver = (TextBox)row.FindControl("txtCareGiver"); string TA = string.Format("TA_{0}${1}", lblId.Text, txtTreatmentAge.Text); string CT = string.Format("CT_{0}${1}", lblId.Text, txtCareType.Text); string CG = string.Format("CG_{0}${1}", lblId.Text, txtCareGiver.Text); if (firstItem) { hfPastCurrentData.Text = TA + "|" + CT + "|" + CG; firstItem = false; } else hfPastCurrentData.Text += "|" + TA + "|" + CT + "|" + CG; } } } catch (Exception ex) { exception.HandleException("medicalHistory:", MethodBase.GetCurrentMethod().Name, ex, this.MedicalPatientHistory); Response.Redirect("/error", false); } } /// /// Get Past/Current item Value /// /// /// private string GetPCItemValue(string iInputID) { string[] tVals = hfPastCurrentData.Text.Split('|'); foreach (string innerValue in tVals) { string[] pVals = innerValue.Split('$'); if (iInputID == pVals[0]) return pVals[1]; } return ""; } #endregion #region events /// /// Page Init /// /// /// protected void Page_Init(object sender, EventArgs e) { } /// /// Page Load /// /// /// protected void Page_Load(object sender, EventArgs e) { try { if (!Page.IsPostBack) { } } catch (Exception ex) { exception.HandleException("medicalHistory:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// grdPastCurrentConditions RowDataBound /// /// /// protected void grdPastCurrentConditions_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(); TextBox txtTreatmentAge = (TextBox)e.Row.FindControl("txtTreatmentAge"); txtTreatmentAge.Text = GetPCItemValue(string.Format("TA_{0}", rowView["recId"])); TextBox txtCareType = (TextBox)e.Row.FindControl("txtCareType"); txtCareType.Text = GetPCItemValue(string.Format("CT_{0}", rowView["recId"])); TextBox txtCareGiver = (TextBox)e.Row.FindControl("txtCareGiver"); txtCareGiver.Text = GetPCItemValue(string.Format("CG_{0}", rowView["recId"])); } } /// /// grdSpecifiedConditions RowDataBound /// /// /// protected void grdSpecifiedConditions_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 = hfSpecifiedConditions.Text.Split(';'); string iValue = string.Format("N_{0}", lblId.Text); RadioButton optNever = (RadioButton)e.Row.FindControl("optNever"); optNever.Checked = (hfSpecifiedConditions.Text.Split(';').Contains(iValue)); optNever.GroupName = string.Format("SpecifiedConditions_{0}", lblId.Text); iValue = string.Format("P_{0}", lblId.Text); RadioButton optPast = (RadioButton)e.Row.FindControl("optPast"); optPast.Checked = (hfSpecifiedConditions.Text.Split(';').Contains(iValue)); optPast.GroupName = string.Format("SpecifiedConditions_{0}", lblId.Text); iValue = string.Format("C_{0}", lblId.Text); RadioButton optCurrent = (RadioButton)e.Row.FindControl("optCurrent"); optCurrent.Checked = (hfSpecifiedConditions.Text.Split(';').Contains(iValue)); optCurrent.GroupName = string.Format("SpecifiedConditions_{0}", lblId.Text); } } /// /// grdSocialHistory RowDataBound /// /// /// protected void grdSocialHistory_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 iValue = string.Format("D_{0}", lblId.Text); RadioButton optDaily = (RadioButton)e.Row.FindControl("optDaily"); optDaily.GroupName = string.Format("SocialHistory_{0}", lblId.Text); optDaily.Checked = (hfSocial.Text.Contains(iValue)); iValue = string.Format("W_{0}", lblId.Text); RadioButton optWeekends = (RadioButton)e.Row.FindControl("optWeekends"); optWeekends.GroupName = string.Format("SocialHistory_{0}", lblId.Text); optWeekends.Checked = (hfSocial.Text.Contains(iValue)); iValue = string.Format("O_{0}", lblId.Text); RadioButton optOccassionally = (RadioButton)e.Row.FindControl("optOccassionally"); optOccassionally.GroupName = string.Format("SocialHistory_{0}", lblId.Text); optOccassionally.Checked = (hfSocial.Text.Contains(iValue)); iValue = string.Format("N_{0}", lblId.Text); RadioButton optNever = (RadioButton)e.Row.FindControl("optNever"); optNever.GroupName = string.Format("SocialHistory_{0}", lblId.Text); optNever.Checked = (hfSocial.Text.Contains(iValue)); //Do the conditional items. CheckBox chkCigarettes = (CheckBox)e.Row.FindControl("chkCigarettes"); CheckBox chkCigars = (CheckBox)e.Row.FindControl("chkCigars"); CheckBox chkPipe = (CheckBox)e.Row.FindControl("chkPipe"); if (rowView["condition"].ToString().ToLower() == "smoking") { //Cigarettes iValue = string.Format("SCT_{0}", lblId.Text); chkCigarettes.Checked = hfSocial.Text.Contains(iValue); //Cigars iValue = string.Format("SCG_{0}", lblId.Text); chkCigars.Checked = hfSocial.Text.Contains(iValue); //Pipe iValue = string.Format("SP_{0}", lblId.Text); chkPipe.Checked = hfSocial.Text.Contains(iValue); } else { Control divCigarettes = e.Row.FindControl("divCigarettes"); if (divCigarettes != null) divCigarettes.Visible = false; Control divCigars = e.Row.FindControl("divCigars"); if (divCigars != null) divCigars.Visible = false; Control divPipe = e.Row.FindControl("divPipe"); if (divPipe != null) divPipe.Visible = false; } } } #endregion #region properties /// /// MPH getter and setter /// public oMedicalPatientHistory MedicalPatientHistory { get { if (ViewState["medicalPatientHistory"] == null) return null; else return (oMedicalPatientHistory)ViewState["medicalPatientHistory"]; } set { ViewState["medicalPatientHistory"] = 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 }