override protected void Page_Load(object sender, System.EventArgs e) { if (Request.QueryString["eformId"] != null) { int _eformId = int.Parse(Request.QueryString["eformId"].ToString()); EFormController ctr = new EFormController(); DataSet eds = ctr.GetRecord(_eformId); if (eds.Tables[0].Rows.Count > 0) { // display report html from database if (eds.Tables[0].Rows[0][Caisis.BOL.EForm.EFormReport].ToString().Length > 0) { theReport.InnerHtml = eds.Tables[0].Rows[0][Caisis.BOL.EForm.EFormReport].ToString(); } } } string pageTitle = ""; if (Session[SessionKey.PtFirstName] != null && Session[SessionKey.PtFirstName].ToString().Length > 0) { pageTitle += Session[SessionKey.PtFirstName].ToString(); } if (Session[SessionKey.PtLastName] != null && Session[SessionKey.PtLastName].ToString().Length > 0) { pageTitle += " " + Session[SessionKey.PtLastName].ToString(); } eformTitle.Text = pageTitle + "<br/><br/><br/><br/>"; }
/// <summary> /// Get xml string from database and populate parent control /// </summary> protected void PopulateEform() { EFormController ctr = new EFormController(); //DataSet ds = ctr.GetOpenRecordByName(_patientId, _eformName); DataSet ds = ctr.GetRecord(_eformId); // get xml string from db if (ds.Tables[0].Rows.Count != 0) { XmlDocument xmlDoc = new XmlDocument(); string s = ds.Tables[0].Rows[0][Caisis.BOL.EForm.EFormXML].ToString(); // should replace col name w/ reference to BizO // put string in xml doc xmlDoc.LoadXml(s); if (xmlDoc.InnerXml.Length > 0) { TraverseEformControls(this.Controls, xmlDoc); } } else if (disableEformHiddenControls) { DisableEformHiddenControls(this.Controls); } }
/// <summary> /// Sets status of eform on page load. Stores the step COMPLETED in the process. /// User is directed to the step AFTER one completed. /// </summary> protected virtual string SetEFormStatus() { EFormController ect = new EFormController(); string page = Request.Path; string status; try { status = ect.GetEFormStatus(this.EFormId); } catch { status = ""; } // get status from the db string nextstatus = EformStatusManager.GetNextStatus(status, Request.UrlReferrer.PathAndQuery, Request.Path); // only updates status when one of the above pages is loaded AND eform has not been already approved (concurrency) if (nextstatus != "" && !status.Equals(EformStatusManager.Status_Approved) && !status.Equals(EformStatusManager.Status_Deleted)) { ect.UpdateEFormStatus(this.EFormId, nextstatus, this.EFormUserName); status = nextstatus; } return(status); }
protected override void Page_Load(object sender, System.EventArgs e) { base.Page_Load(sender, e); // disables view state // existing eforms use eform id to load components if (Request.QueryString["eformId"] != null && !Request.QueryString["eformId"].Equals("") && !Request.QueryString["eformId"].Equals("0")) { this.EFormId = int.Parse(Request.QueryString["eformId"]); // TODO: this query may be redundant EFormController ctr = new EFormController(); DataSet ds = ctr.GetRecord(int.Parse(Request.QueryString["eformId"])); if (ds.Tables[0].Rows.Count == 1) { this.EFormName = ds.Tables[0].Rows[0][EForm.EFormName].ToString(); isNewEForm = false; } } // new eform passes eform name in on url string when coming from list page else if (Request.QueryString["eform"] != null && !Request.QueryString["eform"].Equals("")) { this.EFormName = Request.QueryString["eform"]; if (Request.QueryString["status"] != null && Request.QueryString["status"].Equals("new")) { // TODO: BEFORE SETTING true we should see if this SAME eform has already been created today by the SAME physician; appears users click refresh isNewEForm = true; // do not check if user is allowed to enter multiple if (!EFormController.CanAllowMultiple(this.EFormName)) { Caisis.DataAccess.EFormsDa da = new EFormsDa(); DataRowView rv = da.GetPatientRecentEForm(this.EFormPatientId, Request.QueryString["eform"]); if (rv != null) { isNewEForm = false; this.EFormId = (int)rv["EFormId"]; this.EFormName = rv["EFormName"].ToString(); } } } } try { _status = this.SetEFormStatus(); } catch (ClientException ex) { Response.Write(ex.Message); Response.End(); } }
/// <summary> /// Get eform status and fire client side script back to calling page /// </summary> private void GetEFormStatus() { EFormController ect = new EFormController(); string status = ect.GetEFormStatus(_eformId); string jsScript = "<script language=javascript>parent.setEFormStatus('" + status + "')</script>"; Response.Write(jsScript); }
/// <summary> /// Iterates over control collection and puts values in Xml. Inserts/Updates DB with Xml /// </summary> /// <returns>eform Id</returns> protected int WriteEform() { if (_status.Equals(EformStatusManager.Status_Approved)) { // get user outta here if this form was already approved by someone else! Response.Redirect("ApproveEFormContainer.aspx?eformId=" + this.EFormId, true); } else { // fill in the values to the eform template loaded above XmlDocument eformXml = this.LoadEformXml(); this.AddInputValue(this, eformXml); // Eform Default Values EFormController.TransformEformDefaultValues(eformXml); // put xml doc in the database //string s = eformXml.InnerXml; EFormController ctr = new EFormController(); // insert on first save of eform if (this.EFormId == 0) { DataTable table = ctr.ValidateSessionAppointmentData(Session[SessionKey.PtMRN], Session[SessionKey.CurrentListCrit], Session[SessionKey.CurrentClinicDate]); object apptDate = null; string apptPhysician = ""; if (table.Rows.Count > 0) { DataRow row = table.Rows[0]; apptPhysician = row["ApptPhysician"].ToString(); apptDate = row["ApptTime"]; } int userId = this.GetAccountableUserId(apptPhysician); // returns 0 if can not match apptPhysician with a username // insert this.EFormId = ctr.InsertRecord(userId, EFormPatientId, EFormName, eformXml, _status, apptDate, apptPhysician); } else // update { // sets narrative equal to empty string so xsl is reapplied ctr.UpdateEFormRecord(this.EFormId, eformXml, "", _status); } } return(this.EFormId); }
protected void DeleteOnBtnClick(object sender, CommandEventArgs e) { if (base.EFormId > 0) { EFormController ect = new EFormController(); ect.UpdateEFormStatus(base.EFormId, EformStatusManager.Status_Deleted, base.EFormUserName); CancelBtn.Visible = false; DeleteBtn.Visible = false; UserMsg.Text = "The EForm has been deleted.<br><br>Click <a href=\"EFormList.aspx\">here</a> to select or start another eform from the list of clinic patients."; } }
protected override void Page_Load(object sender, System.EventArgs e) { base.Page_Load(sender, e); EFormController ctr = new EFormController(); int eformId = Convert.ToInt32(Request.QueryString["eformId"]); // get record using eform id because both approved and reviewed eforms may be displayed DataSet eds = ctr.GetRecord(eformId); //DataSet eds = ctr.GetOpenRecordByName(base.EFormPatientId, base.EFormName); if (eds.Tables[0].Rows.Count > 0) { //int eformId = Convert.ToInt32(eds.Tables[0].Rows[0][Caisis.BOL.EForm.EFormId]); // display html from database,status must be "Previewed" if (eds.Tables[0].Rows[0][Caisis.BOL.EForm.EFormReport].ToString().Length > 0) { theNarrative.InnerHtml = eds.Tables[0].Rows[0][Caisis.BOL.EForm.EFormReport].ToString(); } else { Exception ex = new Exception("No narrative present when attempting to view an approved EForm."); ExceptionHandler.Publish(ex); // TODO: add our "You have not created a narrative, would you like to do so?" html string html = // enter free-from html below: @" <html> <body> <div style=""margin-top: 50px; padding-left: 20px;""> <span> You have not created a narrative. If you would like to do so, please click the Review Data button above. </span> </div> </body> </html> " ; theNarrative.InnerHtml = String.Format(html, this.EFormId); } } }
/// <summary> /// /// </summary> private void BuildRecentEforms() { string datasetSql = CacheManager.GetDatasetSQL(Session[SessionKey.DatasetId]); UserController uc = new UserController(); EFormController ec = new EFormController(); EFormsDa da = new EFormsDa(); int userId = uc.GetUserId(); System.Data.DataTable dt = da.GetUserRecentEforms(userId, datasetSql, null, null); if (dt.Rows.Count > 0) { UserEformsRpt.DataSource = dt; UserEformsRpt.DataBind(); NoEformsMessage.Visible = false; } }
/// <summary> /// Takes status of eform and returns appropriate aspx page /// </summary> /// <param name="currentEformStatus">eform status</param> /// <returns>aspx page</returns> private string GetNextPageBasedOnStatus(string currentEformStatus) { if (currentEformStatus == "new") { // check for current eform string eformName = Request.QueryString["eform"]; object o_patientId = Session[SessionKey.PatientId]; int patientId = 0; // if ptId in query string, use as patient in session if (Request.QueryString["ptId"] != null && !string.IsNullOrEmpty(Request.QueryString["ptId"].ToString())) { patientId = Int32.Parse(Request.QueryString["ptId"].ToString()); // put patient in session PatientController ptController = new PatientController(); ptController.PutPatientInSession(Page, patientId); } else if (o_patientId != null && !String.IsNullOrEmpty(o_patientId.ToString())) { patientId = (int)o_patientId; } if (patientId != 0) { //int patientId = (int) o_patientId; // do not check if user is allowed to enter multiple if (!EFormController.CanAllowMultiple(eformName)) { Caisis.DataAccess.EFormsDa da = new Caisis.DataAccess.EFormsDa(); DataRowView rv = da.GetPatientRecentEForm(patientId, eformName); if (rv != null) { string status = rv["CurrentStatus"].ToString(); string page = GetNextPageNameBasedOnStatus(status); return(GetNextPageQueryString(page, status, rv["EFormId"].ToString(), rv["EFormName"].ToString())); } } } } string pagename = GetNextPageNameBasedOnStatus(currentEformStatus); return(GetNextPageQueryString(pagename, currentEformStatus, Request.QueryString["eformId"], Request.QueryString["eform"])); }
/// <summary> /// when eform has already been approved redirects user to the clinic list /// </summary> private void CheckEFormApproval() { EFormController ect = new EFormController(); string status = ect.GetEFormStatus(_eformId); if (status.Equals(EformStatusManager.Status_Approved)) { string approvedBy = ""; string approvedTime = ""; string userRealName = ""; // get the user who approved form and date EFormsDa da = new EFormsDa(); DataSet ds = da.GetEformsRecord(_eformId); if (ds.Tables[0].Rows.Count == 1) { approvedBy = ds.Tables[0].Rows[0][EForm.UpdatedBy].ToString(); approvedTime = ds.Tables[0].Rows[0][EForm.UpdatedTime].ToString(); UserDa userda = new UserDa(); DataSet userds = userda.GetByUserName(approvedBy); userRealName = userds.Tables[0].Rows[0]["UserFirstName"].ToString() + " " + userds.Tables[0].Rows[0]["UserLastName"].ToString(); } string jsScript = "<script language=javascript>alert('This eform was approved by " + userRealName + " on " + approvedTime + " and can no longer be updated.\\n\\n You will now be redirected to the clinic list'); top.location.href = 'Index.aspx?status=home';</script>"; Response.Write(jsScript); } // submit parent frame with data else { // js script from parent page passes in url var when it should submit if (Request.QueryString["submitMe"] != null && Request.QueryString["submitMe"].ToString().ToLower().Equals("true")) { //submitMe() string jsScript = "<script language=javascript>parent.submitMe();</script>"; Response.Write(jsScript); } } }
// Should never be on this page unless the form is approved protected override void Page_Load(object sender, System.EventArgs e) { base.Page_Load(sender, e); //this.SetEFormNavigationSteps(); EFormTitle.Text = base.EFormTitle; // form should be approved when reaching this page EFormController ct = new EFormController(); string status = ct.GetEFormStatus(base.EFormId); if (status.Equals(EformStatusManager.Status_Approved)) { //this.DisablePreviousSteps(); this.LoadPrintPage(); SetPageTitles(true); if (this.PromptForPrint() && !(this.ViewFromReferral())) // Make page autoPrint if defined in EForm Registry { PrintPageOnLoadScript.Visible = true; } PrintBtn.Visible = true; DoubleSidedPrintEnabled = false; System.Xml.XmlDocument xDoc = XmlUtil.GetModulesConfigXml(); string DSPrintConfig = xDoc.SelectSingleNode("/modules//module[@name='EForms']/configuration/allowDoubleSided") != null?xDoc.SelectSingleNode("/modules//module[@name='EForms']/configuration/allowDoubleSided").InnerText : string.Empty; if (DSPrintConfig.Length > 0 && bool.TryParse(DSPrintConfig, out DoubleSidedPrintEnabled)) { if (DoubleSidedPrintEnabled) { DoubleSidedPrintPreference = UserPrefDoubleSided(); } else { DoubleSidedPrintPreference = false; } } } }
/// <summary> /// Determines if eform xml is valid based on Xml Required attributes and/or an .xsd document. /// Note .xsd logic is currently commented out. If range validation is needed use .xsd as well. /// </summary> /// <returns>Return true/false if xml is valid</returns> private bool ValidateXml() { isValidXml = true; // get xml from database EFormController ctr = new EFormController(); //DataSet ds = ctr.GetOpenRecordByName(_patientId, _eformName); DataSet ds = ctr.GetRecord(base.EFormId); if (ds.Tables[0].Rows.Count > 0) { string xmlString = ds.Tables[0].Rows[0]["EFormXml"].ToString(); // should replace col name w/ reference to BizO // first check Xml doc for required fields this.CheckRequiredElements(xmlString); return(isValidXml); } // no record in db yet, should display msg return(false); }
/// <summary> /// Sets the state of the default navigation (opened or collapsed) /// </summary> protected void SetEFormNavigationState() { // default: use configuration value bool setShown = EFormController.ShownNavigation(base.EFormName); // check POSTed value to persist in navigation string POSTshowEformNav = Request.Form["ShowEformNav"]; string QSshowEformNav = Request.QueryString["showNav"]; if (!string.IsNullOrEmpty(POSTshowEformNav)) { setShown = bool.Parse(POSTshowEformNav); } else if (!string.IsNullOrEmpty(QSshowEformNav)) { setShown = bool.Parse(QSshowEformNav); } // register script string setShownString = setShown.ToString().ToLower(); ShowEformNav.Value = setShownString; }
/// <summary> /// /// </summary> private void BuildRecentEforms() { // string datasetSql = CacheManager.GetDatasetSQL(Session[SessionKey.DatasetId]); UserController uc = new UserController(); EFormController ec = new EFormController(); EFormsDa da = new EFormsDa(); int userId = uc.GetUserId(); // System.Data.DataTable dt = da.GetUserRecentEforms(userId, datasetSql, null, null); string msgType = "'" + EformStatusManager.Status_DataEntryInProgress + "','" + EformStatusManager.Status_DataEntryComplete + "','" + EformStatusManager.Status_Narrated + "'"; System.Data.DataSet iDs = da.GetEformsInbox(userId, msgType); if (iDs != null && iDs.Tables.Count > 0 && iDs.Tables[0].Rows.Count > 0) { UserEformsRpt.DataSource = iDs.Tables[0].DefaultView; UserEformsRpt.DataBind(); NoEformsMessage.Visible = false; } }
/// <summary> /// Gets the xml document from the eformname.xml template when starting a new eform. /// Gets xml from the database when eform has already been initiated. /// </summary> /// <param name="patientId"></param> /// <param name="eformName"></param> /// <returns></returns> protected XmlDocument LoadEformXml() { XmlDocument xmlDoc = new XmlDocument(); EFormController ctr = new EFormController(); // DONT use this anymore //int returnVal = ctr.IsNewEForm(this.EFormPatientId, this.EFormName); //if first time loaded use eform xml template if (isNewEForm) { string disease = Caisis.UI.Core.Classes.XmlUtil.GetParentModuleDirectory(this.EFormFileName + ".xml", "EForms"); xmlDoc = XmlUtil.GetXmlDoc("~\\Modules\\" + disease + "\\Eforms\\" + this.EFormFileName + ".xml"); } else // get xml from database column { DataSet ds = ctr.GetRecord(this.EFormId); string s = ds.Tables[0].Rows[0][Caisis.BOL.EForm.EFormXML].ToString(); // should replace col name w/ reference to BizO xmlDoc.LoadXml(s); } return(xmlDoc); }
/// <summary> /// Displays navigation from xml. XML file MUST be the same name as EFORM without whitespaces; /// ie the Prostate New Patient EForm should have a corresponding Xml file ProstateNewPatientEForm.xml /// </summary> /// <param name="eformName"></param> private void LoadEFormNavigationFromXml() { if (base.EFormName != null && !base.EFormName.Equals("")) { string eformName = base.EFormName; string eformFileName = base.EFormFileName; // authorize user for edit bool canEdit = EFormController.CanEditEForm(); // gets the directory name where the file exists; removes dependency on the current view mode string disease = Caisis.UI.Core.Classes.XmlUtil.GetParentModuleDirectory(eformFileName + ".xml", "EForms"); // get Xml XmlDocument eformsXml = XmlUtil.GetXmlDoc("~\\Modules\\" + disease + "\\EForms\\" + eformFileName + ".xml"); EFormNavTitle.Text = "Enter Data "; if (Session[SessionKey.PtFirstName] != null && Session[SessionKey.PtFirstName].ToString().Length > 0) { EFormNavTitle.Text += " for " + Session[SessionKey.PtFirstName].ToString(); } if (Session[SessionKey.PtLastName] != null && Session[SessionKey.PtLastName].ToString().Length > 0) { EFormNavTitle.Text += " " + Session[SessionKey.PtLastName].ToString(); } // get list of sections XmlNodeList eformSectionNames = eformsXml.SelectNodes("/eform/eformSection"); navigation.Text = ""; bool isFirstSection = true; // if section name is not defined yet- show the first section of eform! if (_sectionName.Equals("")) { try { XmlNode firstSection = eformSectionNames[0]; _sectionName = firstSection.Attributes["name"].Value; } catch (NullReferenceException) { throw new ClientException("EForm with this name does not appear to exist. The eform name attribute must be exactly the name of the file WITH spaces. For example: <eform name=\"Uro Pros FU\" displayName=\"Urology Prostate Follow Up\"> when the file name is UroProsFU.xml."); } } // put together navigation string foreach (XmlNode node in eformSectionNames) { string sectionName = ""; if (node.Attributes["name"] != null) { sectionName = node.Attributes["name"].Value; //string filename = node.Attributes["fileName"].Value; string linkCssClass = "eformNavigationHeading"; if (_sectionName.Equals(sectionName)) { linkCssClass = "eformNavigationHeadingOn"; } if (!isFirstSection) { navigation.Text += "<tr><td height=\"20\"> </td></tr>"; } else { isFirstSection = false; } if (canEdit) { navigation.Text += "<tr><td id=\"" + sectionName + "\" onclick=\"saveAndLoad('" + base.EFormId.ToString() + "', '" + eformName + "', '" + sectionName + "');\" class=\"" + linkCssClass + "\">" + sectionName + "</td></tr>"; } else { navigation.Text += "<tr><td class=\"" + linkCssClass + "\">" + sectionName + "</td></tr>"; } } //foreach(XmlNode innerNode in node) //{ // // attribute [0] is display name, attribute [1] is file name // if(innerNode.Attributes["displayName"] != null) // { // if ( _sectionName.Equals(sectionName) ) // { // navigation.Text += "<tr><td class=\"eformNavigationLinkOn\" onclick=\"document.location='#" + innerNode.Attributes["controlName"].Value + "';\">" + innerNode.Attributes["displayName"].Value + "</td></tr>"; // } // } //} // v6 - select nodes by name and attributes (ac) XmlNodeList eformSectionItems = node.SelectNodes("eformItem[@displayName and @controlName]"); foreach (XmlNode sectionItem in eformSectionItems) { string displayName = sectionItem.Attributes["displayName"].Value; string controlName = sectionItem.Attributes["controlName"].Value; if (_sectionName.Equals(sectionName)) { navigation.Text += "<tr><td class=\"eformNavigationLinkOn\" onclick=\"document.location='#" + controlName + "';\">" + displayName + "</td></tr>"; } } } } }
/// <summary> /// For the given eform docuemnt, build client scripts for handling client sider EFromDefaultValue logic. /// </summary> /// <param name="eformsXml">The Eform document containing EFromDefaultValue mappings</param> protected void BuildDefaultValuesScript(XmlDocument eformsXml) { var eFields = EFormController.GetEformDefaultValues(eformsXml); if (eFields.Count() > 0) { // list of all eform inputs IEnumerable <IEformInputField> inputs = PageUtil.GetControls <IEformInputField>(Page); // list of eform labels IEnumerable <EformDefaultLabel> labels = PageUtil.GetControls <EformDefaultLabel>(Page); // create JSON Serialier and list of output objects System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); // list of client JSON objects List <string> _clientConfigs = new List <string>(); // temp: fix to empty RecordId's Func <string, string, bool> matchRecordIds = (r1, r2) => { return((!string.IsNullOrEmpty(r1) ? r1 : "1") == (!string.IsNullOrEmpty(r2) ? r2 : "1")); }; foreach (var eField in eFields) { // FIND INPUTS // i.e., Table=Encounters, RecordId=1 var inputsByTableRecordId = inputs.Where(input => input.Table == eField.TargetTable && matchRecordIds(input.RecordId, eField.TargetRecordId)); // i.e., Table=Encounters, Field=EncDate, RecordId=1 var targetInput = inputsByTableRecordId.Where(input => input.Field == eField.TargetField); // i.e., Table=Encounters, Field!=EncDate, RecordId=1 var targetInputSiblings = inputsByTableRecordId.Except(targetInput); // get type of default EFormController.EformDefaultType type = eField.GetDefaultType(); if (targetInput.Count() > 0) { // get eform input field IEformInputField targetInputField = targetInput.First(); // i.e., find sources by table and record (will be reduced by field, if needed) var sourceInputs = from input in inputs // validate table where !string.IsNullOrEmpty(eField.TargetTable) where input.Table == eField.SourceTable && matchRecordIds(input.RecordId, eField.SourceRecordId) select input; // get child input fields of target if (eField.TriggeredByChildren) { // i.e. target=Survey.SurveyType,1, children=SurveyItems where ParentRecordId = 1 var targetChildInputs = from childTable in BOL.BusinessObject.GetChildTableNames(eField.TargetTable) from input in inputs where input.Table == childTable && matchRecordIds(input.ParentRecordId, targetInputField.RecordId) select input; if (targetChildInputs.Count() > 0) { // TODO: do we just combine sibling and children and rely on side effect ??? targetInputSiblings = targetInputSiblings.Concat(targetChildInputs).Distinct(); } } // FILTER and VALIDATE bool hasClientFields = true; switch (type) { case EFormController.EformDefaultType.Default: // no source sourceInputs = sourceInputs.Take(0); break; case EFormController.EformDefaultType.SourceDefaultValue: // validate: 1+ source if (sourceInputs.Count() == 0) { hasClientFields = false; } break; case EFormController.EformDefaultType.SourceValue: // validate: only 1 source (match exact Field) sourceInputs = sourceInputs.Where(i => i.Field == eField.SourceField).Take(1); if (sourceInputs.Count() == 0) { hasClientFields = false; } break; // never gets called default: hasClientFields = false; break; } // BUILD: client scripts if (hasClientFields) { // get fields as Control to get client id Control targetInputControl = targetInputField as Control; IEnumerable <Control> targetInputSiblingControls = targetInputSiblings.OfType <Control>(); IEnumerable <Control> sourceInputControls = sourceInputs.OfType <Control>(); // BUILD: client JSON var JSONConfig = new { DefaultType = type.ToString(), DefaultValue = eField.DefaultValue, Target = new { Type = targetInputControl.GetType().Name, Id = targetInputControl.ClientID }, TargetSiblings = targetInputSiblingControls.Select(s => new { Type = s.GetType().Name, Id = s.ClientID }), Sources = sourceInputControls.Select(t => new { Type = t.GetType().Name, Id = t.ClientID }), RequireSiblings = eField.RequireSiblings, TriggerSiblings = eField.TriggeredBySiblings }; // serialize object string JSONConfigString = serializer.Serialize(JSONConfig); _clientConfigs.Add(JSONConfigString); } } // BUILD: default labels if (type == EFormController.EformDefaultType.Default) { foreach (var label in labels) { // parse via id if (!string.IsNullOrEmpty(label.DefaultField)) { string labelTable = ""; string labelField = ""; string labelRecordId = ""; EFormController.EformDefaultValueField.ParseDefaultField(label.DefaultField, ref labelTable, ref labelField, ref labelRecordId); if (eField.TargetTable == labelTable && eField.TargetField == labelField && eField.TargetRecordId == labelRecordId) { label.Text = eField.DefaultValue; } } } } } // CLIENT SCRIPT: build and register client script if (_clientConfigs.Count() > 0) { // serialize list of objects into JSON array for client scripts string configJSONArray = "[" + string.Join(",", _clientConfigs.ToArray()) + "]"; // register start up script: validate functions exists string _script = "if(window.initEformDefaultValues) { window.initEformDefaultValues(" + configJSONArray + "); }"; Page.ClientScript.RegisterStartupScript(this.GetType(), "initEformDefaultValues_" + this.ClientID, _script, true); } } }
private void BuildEformPreview(string eformName) { Caisis.Security.SecurityController sc = new Caisis.Security.SecurityController(); string disease = sc.GetViewMode(); EFormController ec = new EFormController(); var eFormComponents = GetEformComponents(Page, disease, eformName); // DEBUG INFO // get all input controls across eform var map = from entry in eFormComponents select new { SectionName = entry.Key, Components = from component in entry.Value let inputs = CICHelper.GetCaisisInputControls(component).OfType <IEformInputField>() let inputTypes = from i in inputs group i by i.GetType().Name into g select g.Key + ": " + g.Count() select new { Component = component, Title = component.Title, InputControls = inputs, InputControlsCount = inputs.Count(), InputControlsStats = string.Join(" | ", inputTypes.ToArray()) } }; var allEformInputControls = map.SelectMany(a => a.Components.SelectMany(b => b.InputControls)); foreach (var inputControl in allEformInputControls) { var debugInfo = new Dictionary <string, string>(); // add standard debug debugInfo.Add("Table", inputControl.Table); debugInfo.Add("Field", inputControl.Field); debugInfo.Add("Record Id", inputControl.RecordId); debugInfo.Add("Parent Record Id", inputControl.ParentRecordId); // only show required if field is actually required if (inputControl.Required) { debugInfo.Add("Required", inputControl.Required.ToString()); } // type info debugInfo.Add("Control Type", inputControl.GetType().Name); // lookup code fix if (inputControl is ICaisisLookupControl) { var lkpControl = inputControl as ICaisisLookupControl; string lkpCode = lkpControl.LookupCode; string lkpDistinct = lkpControl.LookupDistinct; debugInfo.Add("Lookup Code", lkpCode); debugInfo.Add("Lookup Distinct", lkpDistinct); // supress @PatientId lookup if ((!string.IsNullOrEmpty(lkpCode) && lkpCode.Contains("@PatientId")) || (!string.IsNullOrEmpty(lkpDistinct) && lkpDistinct.Contains("@PatientId"))) { lkpControl.LookupCode = string.Empty; lkpControl.LookupDistinct = string.Empty; } } // set debug info if (inputControl is WebControl) { WebControl iWebControl = inputControl as WebControl; // cleanup attributes ( no need to show empty attributes) var tooltipInfo = from info in debugInfo where !string.IsNullOrEmpty(info.Value) select string.Format("{0}: {1}", info.Key, info.Value); // set tooltip iWebControl.Attributes["title"] = string.Join(" | ", tooltipInfo.ToArray()); } } // build navigation EformSectionNaviation.DataSource = map; EformSectionNaviation.DataBind(); // build UI EformSectionRptr.DataSource = map; EformSectionRptr.DataBind(); // debug XML EformConfig config = EformConfig.GetByName(eformName); var elements = from eControl in allEformInputControls let table = eControl.Table + "" let recordId = eControl.RecordId + "" let parentRecordId = eControl.ParentRecordId + "" let depth = BOL.BusinessObjectFactory.CanBuildBusinessObject(table) ? BOL.BusinessObject.GetTableDepth(table) : int.MaxValue group eControl by new { Table = table, RecordId = recordId, ParentRecordId = parentRecordId, Depth = depth } into g let recordSort = !string.IsNullOrEmpty(g.Key.RecordId) ? int.Parse(g.Key.RecordId) : 0 orderby g.Key.Depth ascending, g.Key.Table ascending, recordSort ascending select new { Table = g.Key.Table, Depth = g.Key.Depth, RecordId = g.Key.RecordId, ParentRecordId = g.Key.ParentRecordId, Fields = (from e in g orderby e.Field ascending select new { Field = e.Field.Trim() }).Distinct() }; var nodesWithChildren = from child in elements let childTableName = child.Table where BusinessObjectFactory.CanBuildBusinessObject(childTableName) let childParentTableName = BusinessObject.GetParentTablename(childTableName) join parent in elements on new { table = childParentTableName, b = child.ParentRecordId } equals new { table = parent.Table, b = parent.RecordId } into results let p = results.FirstOrDefault() where p != null select new { Parent = p, Child = child }; var nodesWithoutChildren = elements.Except(nodesWithChildren.Select(a => a.Parent)); // init a list of top level nodes, with those w/o child records List <XElement> topLevelNodes = new List <XElement>(from element in nodesWithoutChildren select new XElement(element.Table, new XAttribute("Depth", element.Depth), new XAttribute("RecordId", element.RecordId), new XAttribute("ParentRecordId", element.ParentRecordId), from e in element.Fields orderby e.Field ascending select new XElement(e.Field.Trim()) )); // create a lookup for finding parent node var lookup = new Dictionary <KeyValuePair <string, string>, XElement>(); foreach (var a in nodesWithChildren) { var child = a.Child; var parent = a.Parent; var testKey = new KeyValuePair <string, string>(parent.Table, parent.RecordId); var testChildKey = new KeyValuePair <string, string>(child.Table, child.ParentRecordId + "_" + child.RecordId); XElement parentNode = null; XElement childNode = null; if (lookup.ContainsKey(testKey)) { parentNode = lookup[testKey]; } else { parentNode = new XElement(parent.Table, new XAttribute("Depth", parent.Depth), new XAttribute("RecordId", parent.RecordId), new XAttribute("ParentRecordId", parent.ParentRecordId), from e in parent.Fields orderby e.Field ascending select new XElement(e.Field.Trim()) ); // add lookup entry lookup.Add(testKey, parentNode); topLevelNodes.Add(parentNode); } // add child if (lookup.ContainsKey(testChildKey)) { childNode = lookup[testChildKey]; } else { childNode = new XElement(child.Table, new XAttribute("Depth", child.Depth), new XAttribute("RecordId", child.RecordId), new XAttribute("ParentRecordId", child.ParentRecordId), from e in child.Fields orderby e.Field ascending select new XElement(e.Field.Trim()) ); // add lookup entry lookup.Add(testChildKey, childNode); parentNode.Add(childNode); } } // order all top level nodes var orderedContent = from element in topLevelNodes let recordSort = !string.IsNullOrEmpty(element.Attribute("RecordId").Value) ? int.Parse(element.Attribute("RecordId").Value) : 0 orderby int.Parse(element.Attribute("Depth").Value) ascending, element.Name.LocalName ascending, recordSort ascending select new XElement(element.Name.LocalName, element.Attributes().Where(a => a.Name.LocalName != "Depth" && !string.IsNullOrEmpty(a.Value)), element.Descendants()); // finally build XML document var debugXML = new XDocument( // declaration new XDeclaration("1.0", "utf-8", "yes"), // root with attributes new XElement("eform", new XAttribute("name", eformName), new XAttribute("displayName", config.DisplayName), // eform content orderedContent) ); // write to text box (for some reason, no declaration outpout by default) var outputWriter = new System.IO.StringWriter(); debugXML.Save(outputWriter); EformDebug.Text = outputWriter.ToString(); // cleanup outputWriter.Flush(); outputWriter.Close(); }