using framework_business; using framework_library; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Linq; using System.Reflection; using System.Text; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using Telerik.Web.UI; public partial class controls_module_procedureBooking : System.Web.UI.UserControl, ISurfaceControlBase { #region override public void ReloadControl(oSurfaceFieldData controlFieldData, bool alternateView = false, bool readOnly = false) { try { BindPlaceOfService(); BindMacroProcedures(); ArrayList list = xData.GetTypedByCriteriaSpecific("recId", typeof(oMedicalPatientProcedureBooking), "surfaceItemId", controlFieldData.surfaceItemId.ToString()); PopulateForm(list); LoadProcedures(); } catch (Exception ex) { exception.HandleException("booking:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } public void SaveControlData(ref oSurfaceFieldData _surfaceFieldData) { try { SaveForm(_surfaceFieldData.surfaceItemId); } catch (Exception ex) { exception.HandleException("booking:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } #endregion #region methods private void BindPlaceOfService() { try { DataTable siteData = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oPlaceOfService), "isActive", "1", "display"); //Office/Consulting Room needs to be removed from options for (int i=siteData.Rows.Count-1; i>=0; i--) { if (siteData.Rows[i]["indicator"].ToString() == "11") { siteData.Rows.RemoveAt(i); break; } } ddPlaceOfservice.DataSource = siteData; ddPlaceOfservice.DataTextField = "display"; ddPlaceOfservice.DataValueField = "indicator"; ddPlaceOfservice.DataBind(); //default to Hospital(19) if (ddPlaceOfservice.Items.FindByValue("19") != null) ddPlaceOfservice.SelectedValue = "19"; } catch(Exception ex) { exception.HandleException("booking:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } private void BindMacroProcedures() { try { ddMacroProcedure.Items.Clear(); ddMacroProcedure.ClearSelection(); DataTable ProcedureList = xData.GetDynamicTable("recId", typeof(oMedicalProcedure), "code"); for (int i = ProcedureList.Rows.Count - 1; i >= 0; i--) { if (ProcedureList.Rows[i]["codeType"].ToString() == "3") ProcedureList.Rows.RemoveAt(i); } ProcedureList.Columns.Add(new DataColumn("TextField", System.Type.GetType("System.String"), "code + ' - ' + description")); ddMacroProcedure.DataSource = ProcedureList; ddMacroProcedure.DataTextField = "TextField"; ddMacroProcedure.DataValueField = "recId"; ddMacroProcedure.DataBind(); } catch (Exception ex) { exception.HandleException("booking:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } private HtmlGenericControl BuildProcedure(oMedicalProcedure procedure, bool selected) { HtmlGenericControl divProcedure = new HtmlGenericControl(); try { divProcedure.ID = "divProcedure" + procedure.recId; Button btnProcedure = new Button(); btnProcedure.ID = "btnProcedure" + procedure.recId; string text = procedure.description; if (procedure.procedureAbbreviation != String.Empty) text = procedure.procedureAbbreviation; btnProcedure.Text = text; btnProcedure.Click += new EventHandler(btnProcedure_Click); btnProcedure.CssClass = "btn btn-default col-md-3 diagnosiscatbtn " + (selected ? "selected" : ""); HtmlGenericControl divButton = new HtmlGenericControl(); divButton.ID = "divButton" + procedure.recId; divButton.Attributes.Add("class", "col-md-12"); divButton.Controls.Add(btnProcedure); divProcedure.Controls.Add(divButton); } catch (Exception ex) { exception.HandleException("booking:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } return divProcedure; } private void LoadProcedures() { try { divBooking.Controls.Clear(); DataTable dtBookings = new DataTable(); if (utils.verifySession("BookingProcedures")) dtBookings = (DataTable)Session["BookingProcedures"]; foreach (oMedicalProcedure procedure in xData.GetTypedByCriteriaSpecific("recId", typeof(oMedicalProcedure), "codeType", "3")) { if (procedure.nonSurgical == false) { //determine if macro has been selected, then enable bool selected = false; foreach (DataRow row in dtBookings.Rows) { if (row["macroProcedureId"].ToString() == procedure.recId.ToString()) { selected = true; break; } } divBooking.Controls.Add(BuildProcedure(procedure, selected)); } } } catch (Exception ex) { exception.HandleException("booking:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } private void PopulateForm(ArrayList bookingList) { try { //find the buttons and divs and set style & visibility ArrayList procList = xData.GetTypedByCriteriaSpecific("recId", typeof(oMedicalProcedure), "codeType", "3"); DataTable dt = new DataTable(); dt.Columns.Add("id"); dt.Columns.Add("macroProcedureId"); dt.Columns.Add("macroDescription"); dt.Columns.Add("procedureId"); dt.Columns.Add("description"); dt.Columns.Add("quantity"); foreach (oMedicalPatientProcedureBooking booking in bookingList) { if (booking.placeOfServiceIndicator > 0 && ddPlaceOfservice.Items.FindByValue(booking.placeOfServiceIndicator.ToString()) != null) ddPlaceOfservice.SelectedValue = booking.placeOfServiceIndicator.ToString(); oMedicalProcedure macroProc = new oMedicalProcedure(); foreach (oMedicalProcedure proc in procList) { if (proc.recId == booking.macroProcedureId) { macroProc = proc; break; } } string description = ""; if (ddMacroProcedure.Items.FindByValue(booking.procedureId.ToString()) != null) description = ddMacroProcedure.Items.FindByValue(booking.procedureId.ToString()).Text; DataRow newRow = dt.NewRow(); newRow["id"] = dt.Rows.Count; newRow["macroProcedureId"] = macroProc.recId; newRow["macroDescription"] = macroProc.procedureAbbreviation; newRow["procedureId"] = booking.procedureId; newRow["description"] = description; newRow["quantity"] = booking.procedureQty; dt.Rows.Add(newRow); } rptMacroProcedures.DataSource = dt; rptMacroProcedures.DataBind(); Session["BookingProcedures"] = dt; } catch (Exception ex) { exception.HandleException("diagnosis:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } private void SaveForm(int surfaceItemId) { try { //resave from scratch. delete all existing patient diagnosis for this surfaceItemId if (xData.DeleteTyped("surfaceItemId", surfaceItemId.ToString(), typeof(oMedicalPatientProcedureBooking))) { ArrayList itemsToUpdate = new ArrayList(); if (utils.verifySession("BookingProcedures")) { //default to Hospital(19) int placeOfServiceIndicator = 19; if (ddPlaceOfservice.SelectedItem != null) if (!int.TryParse(ddPlaceOfservice.SelectedItem.Value, out placeOfServiceIndicator)) placeOfServiceIndicator = 19; DataTable dt = (DataTable)Session["BookingProcedures"]; if (dt != null) { foreach (DataRow row in dt.Rows) { int macroProcId = 0; int.TryParse(row["macroProcedureId"].ToString(), out macroProcId); int procedureId = 0; int.TryParse(row["procedureId"].ToString(), out procedureId); int qty = 0; int.TryParse(row["quantity"].ToString(), out qty); if (procedureId > 0) { oMedicalPatientProcedureBooking booking = new oMedicalPatientProcedureBooking(); booking.dateSaved = System.DateTime.Now; booking.macroProcedureId = macroProcId; booking.procedureId = procedureId; booking.surfaceItemId = surfaceItemId; int userId = 0; if (utils.verifySession("user")) userId = ((oUser)Session["user"]).recId; booking.userIdSaved = userId; booking.procedureQty = qty < 1 ? 1 : qty; booking.placeOfServiceIndicator = placeOfServiceIndicator; booking.recId = xData.SaveTyped("recId", typeof(oMedicalPatientProcedureBooking), booking); if (surfaceItemId == 0) itemsToUpdate.Add(booking); } } } } if (itemsToUpdate.Count > 0) Session["PatientBookingItemsNotLinked"] = itemsToUpdate; } } catch (Exception ex) { exception.HandleException("booking:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } #endregion #region events protected void Page_Init(object sender, EventArgs e) { try { BindPlaceOfService(); BindMacroProcedures(); LoadProcedures(); } catch (Exception ex) { exception.HandleException("booking:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } protected void Page_Load(object sender, EventArgs e) { } protected void btnProcedure_Click(object sender, EventArgs e) { try { Button btn = (Button)sender; if (btn != null) { if (!btn.CssClass.Contains("selected")) { btn.AddCssClass("selected"); } //CVH 2016-11-12 Add macro procedures to table int macroProcedureId = 0; int.TryParse(btn.ID.Replace("btnProcedure", ""), out macroProcedureId); string macroProcedureDesc = btn.Text; if (macroProcedureId > 0) { DataTable dt = new DataTable(); if (utils.verifySession("BookingProcedures")) dt = (DataTable)Session["BookingProcedures"]; if (dt.Columns.Count <= 0) { dt.Columns.Add("id"); dt.Columns.Add("macroProcedureId"); dt.Columns.Add("macroDescription"); dt.Columns.Add("procedureId"); dt.Columns.Add("description"); dt.Columns.Add("quantity"); } foreach (oMedicalProcedure _Procedure in xData.GetTypedByCriteriaSpecific("recId", typeof(oMedicalProcedure), "recId", macroProcedureId.ToString())) { if (_Procedure.codeType == 3)//macro { foreach (string macro in _Procedure.macroProcedures.Split(',')) { int index = macro.IndexOf("|"); if (index > 0) { string procId = macro.Substring(0, index); string qty = macro.Substring(index + 1); if (qty.IndexOf("|") > 0) qty = qty.Substring(qty.IndexOf("|") + 1); string description = ""; if (ddMacroProcedure.Items.FindByValue(procId) != null) { description = ddMacroProcedure.Items.FindByValue(procId).Text; } //modifiers can be added to a macro only once 0005 0018 0011 0014 0009 0008 bool modifierExists = false; if (description.StartsWith("0005 -") || description.StartsWith("0018 -") || description.StartsWith("0011 -") || description.StartsWith("0014 -") || description.StartsWith("0009 -") || description.StartsWith("0008 -")) { foreach (DataRow chkExists in dt.Rows) { if (chkExists["procedureId"].ToString() == procId) { modifierExists = true; break; } } } if (!modifierExists) { DataRow row = dt.NewRow(); row["id"] = dt.Rows.Count; row["macroProcedureId"] = macroProcedureId; row["macroDescription"] = macroProcedureDesc; row["procedureId"] = procId; row["description"] = description; row["quantity"] = qty; dt.Rows.Add(row); } } } } break; } Session["BookingProcedures"] = dt; rptMacroProcedures.DataSource = dt; rptMacroProcedures.DataBind(); } } } catch (Exception ex) { exception.HandleException("booking:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } protected void btnAddMacroProcedure_Click(object sender, EventArgs e) { try { if (ddMacroProcedure.SelectedItem != null) { DataTable dt = new DataTable(); if (utils.verifySession("BookingProcedures")) dt = (DataTable)Session["BookingProcedures"]; if (dt.Columns.Count <= 0) { dt.Columns.Add("id"); dt.Columns.Add("procedureId"); dt.Columns.Add("description"); dt.Columns.Add("quantity"); } string procedureId = ddMacroProcedure.SelectedItem.Value; string description = ddMacroProcedure.SelectedItem.Text; int qty = 0; int.TryParse(txtMacroQty.Text, out qty); qty = (qty <= 0 ? 1 : qty); //modifiers can be added to a macro only once 0005 0018 0011 0014 0009 0008 bool modifierExists = false; if (description.StartsWith("0005 -") || description.StartsWith("0018 -") || description.StartsWith("0011 -") || description.StartsWith("0014 -") || description.StartsWith("0009 -") || description.StartsWith("0008 -")) { if (!description.StartsWith("0011 -")) qty = 1; foreach (DataRow chkExists in dt.Rows) { if (chkExists["procedureId"].ToString() == procedureId) { modifierExists = true; break; } } } if (!modifierExists) { DataRow newRow = dt.NewRow(); newRow["id"] = dt.Rows.Count; newRow["procedureId"] = procedureId; newRow["description"] = description; newRow["quantity"] = qty; dt.Rows.Add(newRow); } Session["BookingProcedures"] = dt; rptMacroProcedures.DataSource = dt; rptMacroProcedures.DataBind(); } } catch (Exception ex) { exception.HandleException("booking:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } protected void lnkRemoveMacro_Click(object sender, EventArgs e) { try { LinkButton btn = (LinkButton)sender; if (btn != null) { int id = int.Parse(btn.CommandArgument); if (utils.verifySession("BookingProcedures")) { DataTable dt = (DataTable)Session["BookingProcedures"]; if (dt != null) { for (int i = dt.Rows.Count - 1; i >= 0; i--) { if (dt.Rows[i]["id"].ToString() == id.ToString()) { dt.Rows.RemoveAt(i); break; } } } Session["BookingProcedures"] = dt; rptMacroProcedures.DataSource = dt; rptMacroProcedures.DataBind(); LoadProcedures(); } } } catch (Exception ex) { exception.HandleException("booking:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } protected void btnRemoveAll_Click(object sender, EventArgs e) { try { if (utils.verifySession("BookingProcedures")) { DataTable dt = (DataTable)Session["BookingProcedures"]; dt.Clear(); Session["BookingProcedures"] = dt; rptMacroProcedures.DataSource = dt; rptMacroProcedures.DataBind(); } PopulateForm(new ArrayList()); LoadProcedures(); } catch (Exception ex) { exception.HandleException("booking:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } #endregion }