// get meta data for the node name private DataTable GetMetaDataForTable(string tableName) { MetadataDa mda = new MetadataDa(); DataTable dt = mda.GetFieldMetadataByTableName(tableName); return(dt); }
protected override void PopulateAttributeValues() { int?_tableId = null; int?_fieldId = null; string qTableId = Request.QueryString["tableId"]; string qFieldId = Request.QueryString["fieldId"]; if (!string.IsNullOrEmpty(qTableId)) { _tableId = int.Parse(qTableId); if (!string.IsNullOrEmpty(qFieldId)) { _fieldId = int.Parse(qFieldId); } } if (!_tableId.HasValue) { return; } // populate table field attributes MetadataDa da = new MetadataDa(); DataTable dt = da.GetFieldMetadata(_tableId.Value, QueryDiseaseId); // build a list of unique metadata tables with there associated metadata var tableToAttributes = from row in dt.AsEnumerable() let fieldId = (int)row[MetadataField.FieldId] // restrict to single field (if applicable) where !_fieldId.HasValue || fieldId == _fieldId group row by fieldId into groupByField let filedName = groupByField.First()[MetadataField.FieldName].ToString() let fieldSort = groupByField.First()[MetadataField.FieldOrder].ToString() // sort by field sort order, with null to bottom let sort = !string.IsNullOrEmpty(fieldSort) ? int.Parse(fieldSort) : int.MaxValue orderby sort ascending, filedName ascending select new { TableId = _tableId, FieldId = groupByField.Key, FieldName = filedName, //FieldSuppress = groupByField.First()[MetadataField.FieldSuppress], //FieldOrder = groupByField.First()[MetadataField.FieldOrder], Data = groupByField, DiseaseAttributes = from record in groupByField where !record.IsNull(DiseaseAttributeValue.DiseaseAttributeValueId) select record }; MetadataGrid.DataSource = tableToAttributes; MetadataGrid.DataBind(); }
// get label for table name private string GetTableLabelByTableName(string tableName) { MetadataDa mda = new MetadataDa(); DataTable dt = mda.GetFieldsByTableName(tableName); if (dt.Rows.Count > 0 && dt.Rows[0][MetadataTable.TableLabel_Field].ToString() != "") { return(dt.Rows[0][MetadataTable.TableLabel_Field].ToString()); } else { return(tableName); } }
// set literal that displays the record note is associated with private void SetReferencedRecord(string tableName, int tableRecordId, bool showReferencesCheckbox) { // display information about the reference record if exists if (tableRecordId != null && tableRecordId > 0) { string recordInfo = ""; string date = ""; // get Table Label from Meta Data // TODO: THIS LOGIC SHOULD BE BUILT INTO THE MIDDLE TIER, i.e. BusinessObject.GetTableMetaLabel() MetadataDa da = new MetadataDa(); DataTable dt = new DataTable(); dt = da.GetTableMetaDataByTableName(tableName); if (dt.Rows.Count == 1) { recordInfo = "This note references " + dt.Rows[0][MetadataTable.TableLabel_Field].ToString(); } // instiantiate an biz object by table name and if there is a date text value, show it BusinessObject bo = BusinessObjectFactory.BuildBusinessObject(tableName); bo.Get(tableRecordId); IEnumerable <string> columnNames = bo.FieldNames; foreach (string column in columnNames) { if (column.ToLower().Contains("datetext") && !column.ToLower().Contains("stop")) { date = bo[column].ToString(); // check for date length and make sure "stop" is not part of column name if (date.Length > 0) { recordInfo += " dated " + date + "."; } } } RecordReferencedTitle.Text = recordInfo; if (showReferencesCheckbox) { RecordReferenced.Visible = true; RecordReferenced.Checked = true; // RecordReferencedRow.Visible = true; } } }
/// <summary> /// Binds the helper layer to a section 'secName' with title 'secTitle' /// </summary> /// <param name="secName"></param> /// <param name="secTitle"></param> protected void BindSection(string secName, string secTitle) { // Verify section name is given if (!string.IsNullOrEmpty(secName)) { MetadataDa mdDa = new MetadataDa(); // Set global meta field attribute values for use in binding repeater values metaTable = mdDa.GetFieldMetadataByTableName("Project"); // Bind to meta field list DataTable metaFieldList = mdDa.GetFieldsByTableName("Project"); HelpDescriptionRptr.DataSource = metaFieldList; HelpDescriptionRptr.DataBind(); LayerSectionTitle.InnerText = secTitle; LayerSectionTitle.Attributes["title"] = secTitle; } }
/// <summary> /// Bind the datagrid to a datasource, and set titles via metadata /// </summary> /// <param name="grid"></param> /// <param name="dt"></param> /// <param name="biz"></param> protected void BindGridViaMetaData(GridView grid, DataTable dt, string tablename) { MetadataDa mdDa = new MetadataDa(); DataTable fieldsDt = mdDa.GetFieldsByTableName(tablename); DataTable attributesDt = mdDa.GetFieldMetadataByTableName(tablename); foreach (DataColumn col in dt.Columns) { if (col.ColumnName != "LoggedBy") { string s = CICHelper.GetFieldAttributeValue(attributesDt, col.ColumnName, "FieldLabel"); BoundField newGridCol = new BoundField(); newGridCol.DataField = col.ColumnName; newGridCol.HeaderText = !string.IsNullOrEmpty(s) ? s : col.ColumnName; grid.Columns.Add(newGridCol); } } grid.DataSource = dt; grid.DataBind(); }
/// <summary> /// Builds a list of available MetadataTables /// </summary> protected override void PopulateAttributeValues() { MetadataDa da = new MetadataDa(); var allTables = da.GetAllTableMetadata(null, QueryDiseaseId).AsEnumerable(); // restrict to disease specific tables if (QueryDiseaseId.HasValue) { allTables = allTables.Where(r => !r.IsNull(Disease.DiseaseId)); } // build a list of unique metadata tables with there associated metadata var tableToAttributes = from row in allTables let tableId = (int)row[MetadataTable.TableId] group row by tableId into groupByTable let tableName = groupByTable.First()[MetadataTable.TableName_Field].ToString() orderby tableName ascending select new { TableId = groupByTable.Key, TableName = tableName, Data = groupByTable, DiseaseAttributes = from record in groupByTable where !record.IsNull(DiseaseAttributeValue.DiseaseAttributeValueId) select record }; MetadataGrid.DataSource = tableToAttributes; MetadataGrid.DataBind(); // build missing metadata tables MetadataNewDa MNDa = new MetadataNewDa(); DataTable tablesDt = MNDa.GetAllTablesInDB(); // create display column for formatting DataView view = tablesDt.DefaultView; view.RowFilter = "TABLE_TYPE = 'BASE TABLE'"; view.Sort = "TABLE_NAME ASC"; NewMetadataTablesGrid.DataSource = view; NewMetadataTablesGrid.DataBind(); }
// append the labels of the child nodes and their values private void AppendChildNodesOfParent(XmlNode parentNode) { MetadataDa mda = new MetadataDa(); DataTable dt = mda.GetFieldMetadataByTableName(parentNode.Name); bool isEvenChildRow = false; // using this to simulate style options available in a repeater - jf foreach (XmlNode childNode in parentNode) { // we want to display ONLY child nodes where at least one node within the record has a value ( xml considers a value within an element a child node) if (childNode.HasChildNodes.Equals(false) || (childNode.Value != "" && !childNode.FirstChild.NodeType.Equals(XmlNodeType.Element)))// && childNode.ChildNodes.Count > 0 && childNode.FirstChild.NodeType.Equals(XmlNodeType.Element) ) //ChildNodes.Count > 1) // NEED TO ADD CLAUSE HERE TO FIND OUT IF CHILD NODE IS A VALUE { string s = GetFieldLabel(dt, childNode.Name); string[] labelAndDescription = s.Split(new Char[] { '|' }); string label = labelAndDescription[0]; string description = ""; if (labelAndDescription.Length == 2) { description = labelAndDescription[1]; } string recordId = ""; if (childNode.ParentNode.Attributes["RecordId"] != null) { recordId = parentNode.Attributes["RecordId"].Value; } // write string this.BuildChildOutputString(label, description, childNode.Name, childNode.InnerText, recordId, isEvenChildRow); isEvenChildRow = !isEvenChildRow; } } }
protected override void PopulateAttributeValues() { dirtyRows.Clear(); Caisis.Controller.PatientDataEntryController pdec = new Caisis.Controller.PatientDataEntryController(QueryDiseaseName); MetadataDa da = new MetadataDa(); // step 1: get all tables (optionally filtered attributes by disease) var allTables = da.GetAllTableMetadata(null, QueryDiseaseId).AsEnumerable(); // step 2: get all metadata tables var tableLookup = (from table in BOL.BusinessObject.GetAll <MetadataTable>() select new { TableId = (int)table[MetadataTable.TableId], TableName = table[MetadataTable.TableName_Field].ToString() }).ToDictionary(a => a.TableName, a => a.TableId); // step 3: build lookup of metadata and disease specific mappings var metadataLookup = (from row in allTables let tableId = (int)row[MetadataTable.TableId] group row by tableId into tableMetadata let source = tableMetadata.First() select new { TableName = source[MetadataTable.TableName_Field].ToString(), TableMetadata = tableMetadata, DiseaseAttributes = from record in tableMetadata where !record.IsNull(DiseaseAttributeValue.DiseaseAttributeValueId) select record }).ToDictionary( a => a.TableName, a => new KeyValuePair <IEnumerable <DataRow>, IEnumerable <DataRow> > (a.TableMetadata, a.DiseaseAttributes) ); // step 4: get tree structure of tables var depthMap = Caisis.Controller.PatientDataEntryController.GetPatientDataEntryMapLookup(tableLookup.Keys); // step 5: build data grid data source var dataSource = from entry in depthMap let table = entry.Key let tableId = tableLookup[table] let tableMetadata = metadataLookup.ContainsKey(table) ? metadataLookup[table].Key : new DataRow[0] let diseaseAttributes = metadataLookup.ContainsKey(table) ? metadataLookup[table].Value : new DataRow[0] select new { TableId = tableId, TableName = table, TableLabel = pdec.GetTableLabel(table), TableIcon = pdec.GetTableIcon(table, true), TableDepth = depthMap[table], Data = tableMetadata, DiseaseAttributes = diseaseAttributes }; //var tablesNames = allTables.Select(r => r[MetadataTable.TableName_Field].ToString()).Distinct(); //var depthMap = Caisis.Controller.PatientDataEntryController.GetTableDepthMapLookup(tablesNames, true); //// build a list of unique metadata tables with there associated metadata //var tableToAttributes = from row in allTables // let tableId = (int)row[MetadataTable.TableId] // group row by tableId into groupByTable // let tableName = groupByTable.First()[MetadataTable.TableName_Field].ToString() // orderby tableName ascending // select new // { // TableId = groupByTable.Key, // TableName = tableName, // TableLabel = pdec.GetTableLabel(tableName), // TableIcon = pdec.GetTableIcon(tableName, true), // TableDepth = depthMap.ContainsKey(tableName) ? depthMap[tableName] : 0, // Data = groupByTable, // DiseaseAttributes = from record in groupByTable // where !record.IsNull(DiseaseAttributeValue.DiseaseAttributeValueId) // select record // }; //var dbTables = BOL.BusinessObject.GetAllTableNames(); //tableToAttributes = from table in dbTables // join meta in tableToAttributes on table equals meta.TableName // select meta; //// get tables in depth map //var hasDepthEntry = from d in depthMap // join t in tableToAttributes on d.Key equals t.TableName // select t; //// append tables not in depth map //var dataSource = hasDepthEntry.Concat(tableToAttributes.Except(hasDepthEntry)); // bind table attributes data source MetadataGrid.DataSource = dataSource; MetadataGrid.DataBind(); }
/// <summary> /// Builds a list of available MetadataTables /// </summary> protected override void PopulateAttributeValues() { if (tableId.HasValue) { // populate main table attributes PopulateTableAttributes(); // populate table field attributes MetadataDa da = new MetadataDa(); DataTable dt = da.GetFieldMetadata(tableId.Value, QueryDiseaseId); // build a list of unique metadata tables with there associated metadata var tableToAttributes = from row in dt.AsEnumerable() let fieldId = (int)row[MetadataField.FieldId] group row by fieldId into groupByField let filedName = groupByField.First()[MetadataField.FieldName].ToString() let fieldOrderMetadata = from record in groupByField let attributeName = record[MetadataFieldAttribute.AttributeName].ToString() let attributeValue = record[MetadataFieldAttributeValue.AttributeValue].ToString() // filter by FieldOrder attribute where attributeName.Equals(MetadataField.FieldOrder, StringComparison.OrdinalIgnoreCase) && PageUtil.IsInteger(attributeValue) // filter by disease (or defaul=NULL) where (!QueryDiseaseId.HasValue && record.IsNull(Disease.DiseaseId)) || (QueryDiseaseId.HasValue && !record.IsNull(Disease.DiseaseId)) let fieldOrder = int.Parse(attributeValue) select fieldOrder // sort by field sort order, with null to bottom let fieldOrder = fieldOrderMetadata.Count() > 0 ? fieldOrderMetadata.First() : int.MaxValue //let sort = !string.IsNullOrEmpty(fieldSort) ? int.Parse(fieldSort) : int.MaxValue orderby fieldOrder ascending, filedName ascending select new { TableId = tableId, FieldId = groupByField.Key, FieldName = filedName, FieldOrder = fieldOrder, //FieldSuppress = false, Data = groupByField, DiseaseAttributes = from record in groupByField where !record.IsNull(DiseaseAttributeValue.DiseaseAttributeValueId) select record }; MetadataGrid.DataSource = tableToAttributes; MetadataGrid.DataBind(); // build fields without metadata MetadataTable biz = new MetadataTable(); biz.Get(tableId.Value); MetadataNewDa MNDa = new MetadataNewDa(); DataTable cols = MNDa.GetTableColumns(tableId.Value, biz[MetadataTable.TableName_Field].ToString()); // build a list of actual fields not yet assigned metadata var nonMetadataFields = from row in cols.AsEnumerable() select new { COLUMN_NAME = row["COLUMN_NAME"].ToString(), DATA_TYPE = row["DATA_TYPE"].ToString(), CHAR_MAX_LEN = row["CHAR_MAX_LEN"].ToString(), IS_VIRTUAL = false }; // build blank rows for new virtual fields var blankVirtualFields = from i in Enumerable.Range(0, 1) select new { COLUMN_NAME = string.Empty, DATA_TYPE = string.Empty, CHAR_MAX_LEN = string.Empty, IS_VIRTUAL = true }; var dataSource = nonMetadataFields.Concat(blankVirtualFields); NonMetadataFields.DataSource = dataSource; NonMetadataFields.DataBind(); } }
protected void PopulateTableAttributes() { dirtyTableAttributes.Clear(); // special cases if (tableId.HasValue && !Page.IsPostBack) { MetadataTable biz = new MetadataTable(); biz.Get(tableId.Value); string tableName = biz[MetadataTable.TableName_Field].ToString(); // display with children //var childTableNames = BOL.BusinessObject.GetChildTableNames(tableName); var childTableNames = _dataEntryController.GetDataEntryForms(); // only show picker if there are child tables if (childTableNames.Count() > 0) { DisplayWithChild.DataSource = childTableNames; DisplayWithChild.DataBind(); } else { DisplayWithChild.Visible = false; DisplayWithChild_Label.Visible = false; } // plugins Caisis.Controller.PluginsController pc = new Caisis.Controller.PluginsController(); var pluginNames = pc.GetPluginNames(); Plugins.DataSource = pluginNames; Plugins.DataBind(); } // special case: relevant tables if (tableId.HasValue && !Page.IsPostBack) { var allTableNames = _dataEntryController.GetDataEntryForms();// BOL.BusinessObject.GetAllTableNames(); MostRelevantTables.DataSource = allTableNames; MostRelevantTables.DataBind(); } // get list of table attribute names/description var namesAndDescriptions = BOL.BusinessObject.GetAll <MetadataTableAttribute>().ToDictionary(a => a[MetadataTableAttribute.TableAttributeName].ToString(), a => a[MetadataTableAttribute.TableAttributeDescription].ToString(), StringComparer.OrdinalIgnoreCase); // get all table metadata MetadataDa da = new MetadataDa(); var tableSpecificMetadata = da.GetAllTableMetadata(tableId, QueryDiseaseId).AsEnumerable(); var tableDataSource = from record in tableSpecificMetadata let dAttributeName = record[MetadataTableAttribute.TableAttributeName].ToString() let dAttributeValue = record[MetadataTableAttributeValue.TableAttributeValue].ToString() let dTableAttributeValueId = record[MetadataTableAttributeValue.TableAttributeValueId].ToString() let dAttributeValueId = record[DiseaseAttributeValue.DiseaseAttributeValueId].ToString() orderby(!record.IsNull(DiseaseAttributeValue.DiseaseAttributeValueId) ? 0 : 1) ascending let a = new { TableAttributeName = dAttributeName, TableAttributeValue = dAttributeValue, TableAttributeValueId = dTableAttributeValueId, DiseaseAttributeValueId = dAttributeValueId } group a by a.TableAttributeName into g select g.First(); var inputs = CICHelper.GetCaisisInputControls(TablePanel); // get a list of attributes var attributeFields = GetAttributeToHiddenFields(TableAttributesPanel); // populate attributes (i.e., "PageTitle", "MenuTile",...) PopulateAttributes(new MetadataTableAttribute().TableName, MetadataTableAttribute.TableAttributeName, attributeFields); // populate table attribute values foreach (var entry in attributeFields) { string attributeName = entry.Key; // i.e., "PageTitle" var attributeIdField = entry.Value; // i.e., "Encounter" > "PageTitle" var tableAttributeValueId = GetTableAttributeValueIdControl(TablePanel, attributeName); // i.e. "Prostate Encounter Form" var attributeValue = GetTableAttributeValueControl(TablePanel, attributeName); // i.e., "Prostate" > "Encounter" > "PageTitle" = "Prostate Encounter Form" var diseaseAttributeValueId = GetDiseaseAttributeValueId(TablePanel, attributeName); // locate table attribute values var found = tableDataSource.Where(a => a.TableAttributeName.Equals(attributeName, StringComparison.CurrentCultureIgnoreCase)); if (found.Count() > 0) { var dataSource = found.First(); // set field value SetInputControlValue(tableAttributeValueId, dataSource.TableAttributeValueId.ToString(), null); SetInputControlValue(attributeValue, dataSource.TableAttributeValue, null); SetInputControlValue(diseaseAttributeValueId, dataSource.DiseaseAttributeValueId.ToString(), null); } // set friendly tooltip for attribute if (namesAndDescriptions.ContainsKey(attributeName)) { string attributeDescription = namesAndDescriptions[attributeName]; var attributeLabel = TablePanel.FindControl(attributeName + "_Label") as Label; if (attributeLabel != null) { // set friendly tooltip attributeLabel.Attributes["onmouseover"] = "showToolTipMessage('" + PageUtil.EscapeSingleQuotes(attributeDescription) + "');"; attributeLabel.Attributes["onmouseout"] = "hideToolTip();"; attributeLabel.ToolTip = attributeDescription; } } } // SPECIAL CASE: handle columns and grid if (GridView.Checked) { NumDisplayColumns.SelectedIndex = 2; } }