/// <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(); }
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(); }
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; } }