Ejemplo n.º 1
0
 private void PopulateMetadataGrid()
 {
     if (TableList.SelectedIndex > 0)
     {
         MetadataGrid.DataSource = GetFieldNames(Int32.Parse(TableList.SelectedValue)).DefaultView;
         MetadataGrid.DataBind();
     }
 }
        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();
        }
Ejemplo n.º 3
0
        /// <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();
        }
Ejemplo n.º 4
0
        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();
        }
Ejemplo n.º 5
0
        /// <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();
            }
        }