/// <summary> /// Updates the table's metadata as well as field's metadata /// </summary> protected override void Update() { bool hasDirtyFields = dirtyTableAttributes.Count() > 0 || base.dirtyRows.Count() > 0; // create meta fields bool hasNewMetaFields = InsertMetadataFields(); // update: table metadata (!important, order matters) UpdateTableAttributes(); // update: field metadata base.Update(); // refresh metadata MetadataTable biz = new MetadataTable(); biz.Get(tableId.Value); string tableName = biz[MetadataTable.TableName_Field].ToString(); // when updating table attributes, refresh BO and cached items if (hasDirtyFields) { BOL.BusinessObject.RefreshMetadataFromDatabase(tableName); // updating table label causes PDE refresh ??? if (dirtyTableAttributes.Contains(TableLabel.Field, StringComparer.OrdinalIgnoreCase)) { // CacheManager.RefreshPatientDataCache(QueryDiseaseName); } } // close modal, unless new meta fields added if (!hasNewMetaFields) { string updateScript = "if(top.reloadDataEntryFrame) { top.reloadDataEntryFrame(); top.hideModal(); }"; Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OnUpdateScript", updateScript, true); } }
/// <summary> /// Sets the default disease and table via query string /// </summary> private void SetQueryDefaults() { if (!string.IsNullOrEmpty(QueryTableId)) { MetadataTable table = new MetadataTable(); int key = int.Parse(QueryTableId); table.Get(key); SetTable(table); } else if (!string.IsNullOrEmpty(QueryTableName)) { MetadataTable metaTable = BusinessObject.GetByFields <MetadataTable>(new Dictionary <string, object> { { MetadataTable.TableName_Field, QueryTableName } }).FirstOrDefault(); if (metaTable != null) { SetTable(metaTable); } } // sets current disease id field if (QueryDiseaseId.HasValue) { // set pri key CurrentDiseaseId.Value = QueryDiseaseId.Value.ToString(); // set display name Disease disease = new Disease(); disease.Get(QueryDiseaseId.Value); CurrentDiseaseName.Value = disease[Disease.DiseaseName].ToString(); // show tables edit ManageTablesBtn.Visible = true; // set title ManageTablesBtn.InnerText = "Add/Remove " + QueryDiseaseName + " Forms"; } else { // show tables edit //ManageTablesBtn.Visible = false; } }
/// <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; } }