/// <summary> /// Gets the current disease view /// </summary> /// <returns></returns> private string GetDiseaseView() { Caisis.Security.SecurityController sc = new Caisis.Security.SecurityController(); string viewMode = sc.GetViewMode(); return(viewMode); }
override protected void Page_Load(object sender, EventArgs e) { int _patientId = int.Parse(Session[SessionKey.PatientId].ToString()); if (PermissionManager.HasPermission(PermissionManager.EditNarrative) == false) { // always display other comments, but only allow users to add if their group permission submit.Enabled = false; NewComment.Attributes.Add("ReadOnly", "True"); NewComment.Attributes.Add("onClick", "alert('Sorry. Your user group has not been granted permission to add comments.')"); } if (Page.IsPostBack && NewComment.Value != "") { // TODO: Should we add the permission? Security.SecurityController sc = new Caisis.Security.SecurityController(); Narrative narrative = new Narrative(); //narrative.NewRow(); narrative[Narrative.PatientId] = _patientId; narrative[Narrative.Narrative_Field] = NewComment.Value.Trim(); narrative[Narrative.EnteredTime] = DateTime.Now.ToString(); narrative[Narrative.EnteredBy] = sc.GetUserName(); narrative[Narrative.NarratedBy] = sc.GetUserName(); narrative.Save(); NewComment.Value = ""; commentDiv.Visible = true; NarrativeTitle.Visible = true; NewComment.Style["height"] = "40px"; } //Narrative ptNarratives = new Narrative(); //ptNarratives.GetByParent(_patientId); //ptNarratives.DataSourceView.Sort = "EnteredTime DESC"; DataView narratives = BusinessObject.GetByParentAsDataView <Narrative>(_patientId); narratives.Sort = "EnteredTime DESC"; //if (ptNarratives.RecordCount > 0) if (narratives.Count > 0) { //RptComments.DataSource = ptNarratives.DataSourceView; RptComments.DataSource = narratives; RptComments.DataBind(); } else { commentDiv.Visible = false; NarrativeTitle.Visible = false; NewComment.Style["height"] = "100px"; } }
/// <summary> /// Insert an Uploaded File into DB /// </summary> /// <param name="theFile"></param> /// <returns></returns> private int InsertFileRecord(HttpPostedFile theFile) { int fileId = 0; // get lenths of file name (including extension) and label names int fileNameLength = System.IO.Path.GetFileName(theFile.FileName).Length; int labelLength = FileLabel.Text.Length; // get the max lenths of file name and label from database int?originalFileNameMaxLength = BOL.UploadedFile.GetFieldMaxLength("Files", BOL.UploadedFile.OriginalFileName); int?fileLabelMaxLength = BOL.UploadedFile.GetFieldMaxLength("Files", BOL.UploadedFile.FileLabel); bool insertFile = true; if (originalFileNameMaxLength != null && fileNameLength > originalFileNameMaxLength) { insertFile = false; UploadErrorMsg.Text = UploadErrorMsg.Text + "<br/>File name (including extension) must be " + originalFileNameMaxLength.ToString() + " characters or less."; } if (fileLabelMaxLength != null && labelLength > fileLabelMaxLength) { insertFile = false; UploadErrorMsg.Text = UploadErrorMsg.Text + "<br/>File label must be " + fileLabelMaxLength.ToString() + " characters or less. "; } if (insertFile) { UploadedFile file = LoadFileRecord(theFile); // add entered by on insert; no ability to lock records right now Caisis.Security.SecurityController sc = new Caisis.Security.SecurityController(); file[BusinessObject.EnteredBy] = sc.GetUserName(); //file[BusinessObject.EnteredTime] = DateTime.Now; file.Save(); fileId = (int)file[UploadedFile.FileId]; } return(fileId); }
/// <summary> /// Load BizObj for saving/updating /// </summary> /// <param name="theFile"></param> /// <returns></returns> private UploadedFile LoadFileRecord(HttpPostedFile theFile) { UploadedFile fileBO = new UploadedFile(); // Set BizObj Fields fileBO[UploadedFile.TableName] = _tableName; fileBO[UploadedFile.TablePrimaryKey] = _tablePrimaryKey.ToString(); fileBO[UploadedFile.OriginalFileName] = System.IO.Path.GetFileName(theFile.FileName); fileBO[UploadedFile.FileType] = theFile.ContentType; fileBO[UploadedFile.FileLabel] = FileLabel.Text; // only value submitted by user via interface fileBO[UploadedFile.OnFileServer] = "1"; fileBO[UploadedFile.FileExtension] = new FileInfo(theFile.FileName).Extension; // may NOT want to store file path for better portability fileBO[UploadedFile.FilePath] = _savePath; // add audit info for update and inserts Caisis.Security.SecurityController sc = new Caisis.Security.SecurityController(); fileBO[BusinessObject.EnteredBy] = sc.GetUserName(); fileBO[BusinessObject.EnteredTime] = DateTime.Now; return(fileBO); }
/// <summary> /// Returns a DataTable of lookupcodes /// </summary> /// <param name="lkpCode"></param> /// <param name="isDistinct"></param> /// <returns></returns> private DataTable GetLookupCodes(string lkpCode, bool isDistinct) { DataTable dataSourceTable = new DataTable(); string LookupColumn = LookupCode.LkpCode; string LookupDescriptionColumn = LookupCode.LkpDescription; if (isDistinct) { string[] lookupDistinctVals = lkpCode.Split(new char[] { ';' }); string tablename = lookupDistinctVals[0].Trim(); string valuefield = lookupDistinctVals[1].Trim(); string textfield = lookupDistinctVals[2].Trim(); string restriction = null; string order = null; if (lookupDistinctVals.Length >= 4) { restriction = lookupDistinctVals[3].Trim(); System.Web.SessionState.HttpSessionState tempSession = Page.Session; if (restriction.Contains("@PatientId") && tempSession != null && tempSession[SessionKey.PatientId] != null) { restriction = restriction.Replace("@PatientId", tempSession[SessionKey.PatientId].ToString()); } if (restriction.Contains("@UserName")) { Caisis.Security.SecurityController sc = new Caisis.Security.SecurityController(); restriction = restriction.Replace("@UserName", String.Format("'{0}'", sc.GetUserName())); } if (lookupDistinctVals.Length >= 5) { order = lookupDistinctVals[4].Trim(); } } dataSourceTable = LookupCodeDa.GetLookupData(tablename, valuefield, textfield, restriction, order).Table; LookupColumn = "DropDownText"; } else { string[] specialLkpCode = lkpCode.Split(';'); if (specialLkpCode.Length == 3) { LookupCodeDa da = new LookupCodeDa(); string childLkpCode = specialLkpCode[0]; string parentLkpCode = specialLkpCode[1]; string parentLkpCodeValue = specialLkpCode[2]; DataTable parentLkpCodes = da.GetLookupsByFieldName(parentLkpCode).Tables[0]; DataRow[] results = parentLkpCodes.Select("LkpCode = '" + parentLkpCodeValue + "'"); if (results.Length > 0) { int lkpCodeId = int.Parse(results[0][LookupCode.LookupCodeId].ToString()); dataSourceTable = da.GetChildCodesByLookupIdAndChildLookupName(lkpCodeId, childLkpCode); } } else { dataSourceTable = CacheManager.GetLookupCodeList(lkpCode); } } return(dataSourceTable); }
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(); }