/// <summary> /// Builds a list of available datasets /// </summary> private void EditDataset(int?datasetId) { // set visibility DatasetEditPanel.Visible = true; DeleteBtn.Visible = datasetId.HasValue; // set hidden field DatasetIdField.Value = datasetId.ToString(); // populate dataset fields if (datasetId.HasValue) { Dataset biz = new Dataset(); biz.Get(datasetId.Value); CICHelper.SetFieldValues(DatasetEditPanel.Controls, biz); // manually set dataset id DatasetId.Text = biz[Dataset.DatasetId].ToString(); // set dimensions var datasetNode = GetDataSetXmlNode(datasetId.Value.ToString()); if (datasetNode != null) { var lookup = GetDimensionsDropDown(); var dimensions = datasetNode.SelectNodes("dimension"); foreach (XmlElement dNode in dimensions) { string dimType = dNode.Attributes["type"].Value; string dimValue = dNode.Attributes["value"].Value; string searchType = dimType == "Category" ? "Categories" : dimType + "s"; if (lookup.ContainsKey(searchType)) { var dropDown = lookup[searchType]; dropDown.Value = dimValue; } } } } // poulate dataset diseas attributes DiseaseController ct = new DiseaseController(); DiseaseAttributeValue diseaseAttributeValue = ct.GetDiseaseAttributeValue(Dataset.DatasetId, datasetId.ToString()); if (diseaseAttributeValue != null) { CICHelper.SetFieldValues(DatasetEditPanel.Controls, diseaseAttributeValue); } if (datasetId.HasValue) { DatasetTitle.Text = DatasetName.Text; } else { DatasetTitle.Text = "New Dataset"; } }
protected void UpdateClick(object sender, EventArgs e) { foreach (GridViewRow row in DiseasesGrid.DirtyGridRows) { var lookup = CICHelper.GetCaisisInputControlDictionary(row); int?diseaseId = null; if (!string.IsNullOrEmpty(lookup[Disease.DiseaseId].Value)) { diseaseId = int.Parse(lookup[Disease.DiseaseId].Value); } string diseaseName = lookup[Disease.DiseaseName].Value; string diseaseAttributeValueId = lookup[DiseaseAttributeValue.DiseaseAttributeValueId].Value; string diseaseAttributeValue = (lookup[DiseaseAttributeValue.DiseaseAttributeValue_Field] as CheckBox).Checked.ToString(); ICaisisInputControl isViewAttributeId = lookup[DiseaseAttributeValue.DiseaseAttributeValueId]; CaisisCheckBox isViewAttribute = lookup[DiseaseAttributeValue.DiseaseAttributeValue_Field] as CaisisCheckBox; // insert/update disease Disease dBiz = new Disease(); if (diseaseId.HasValue) { dBiz.Get(diseaseId.Value); } dBiz[Disease.DiseaseName] = diseaseName; dBiz.Save(); diseaseId = (int)dBiz[Disease.DiseaseId]; // check if disease attribute exists, update if (isViewAttribute.Checked) { if (string.IsNullOrEmpty(isViewAttributeId.Value)) { DiseaseAttributeValue dav = new DiseaseAttributeValue(); dav[DiseaseAttributeValue.DiseaseId] = diseaseId; dav[DiseaseAttributeValue.DiseaseAttributeId] = GetDiseaseIsViewAttribute(); dav[DiseaseAttributeValue.DiseaseAttributeValue_Field] = true.ToString().ToLower(); dav.Save(); isViewAttributeId.Value = dav[dav.PrimaryKeyName].ToString(); } } else { // only delete if key exists if (!string.IsNullOrEmpty(isViewAttributeId.Value)) { DiseaseAttributeValue dav = new DiseaseAttributeValue(); dav.Delete(int.Parse(isViewAttributeId.Value)); isViewAttributeId.Value = string.Empty; } } } Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "reloadMainAdmin", "reloadMainAdmin();", true); }
/// <summary> /// /// </summary> /// <param name="diseaseId"></param> /// <param name="diseaseAttributeId"></param> /// <param name="diseaseAttributeValue"></param> /// <returns></returns> public DiseaseAttributeValue CreateDiseaseAttributeValue(int diseaseId, int diseaseAttributeId, string diseaseAttributeValue) { DiseaseAttributeValue biz = new DiseaseAttributeValue(); biz[DiseaseAttributeValue.DiseaseId] = diseaseId; biz[DiseaseAttributeValue.DiseaseAttributeId] = diseaseAttributeId; biz[DiseaseAttributeValue.DiseaseAttributeValue_Field] = diseaseAttributeValue; biz.Save(); return(biz); }
/// <summary> /// /// </summary> private void Save() { // get the name of the pri key, i.e., "TableId" string priKeyName = BOL.BusinessObject.GetPrimaryKeyName(QueryTable); // get disease attribute, i.e., "TableId" DiseaseAttribute_Table attributeBiz = dc.GetDiseaseAttribute(priKeyName); // if none exists, create if (attributeBiz == null) { attributeBiz = dc.CreateDiseaseAttribute(priKeyName); } // get required foreign keys int diseaseId = QueryDiseaseId.Value; int diseaseAttributeId = (int)attributeBiz[DiseaseAttribute_Table.DiseaseAttributeId]; foreach (GridViewRow row in DiseaseTableGrid.DirtyGridRows) { CaisisCheckBox cb = row.FindControl("DiseaseCheckBox") as CaisisCheckBox; int tablePriKey = (int)DiseaseTableGrid.DataKeys[row.RowIndex][priKeyName]; object diseaseValuePriKey = DiseaseTableGrid.DataKeys[row.RowIndex][DiseaseAttributeValue.DiseaseAttributeValueId]; // insert if no value exists if (cb.Checked && string.IsNullOrEmpty(diseaseValuePriKey.ToString())) { dc.CreateDiseaseAttributeValue(diseaseId, diseaseAttributeId, tablePriKey.ToString()); } // delete if there is a pri key else if (!cb.Checked && !string.IsNullOrEmpty(diseaseValuePriKey.ToString())) { int priKey = int.Parse(diseaseValuePriKey.ToString()); DiseaseAttributeValue biz = new DiseaseAttributeValue(); biz.Delete(priKey); } } }
protected void UpdateTableAttributes() { //bool isDiseaseSpecific = QueryDiseaseId.HasValue; // create table disease attribute var diseaseAttributeId = _diseaseController.GetDiseaseAttribute(MetadataTableAttributeValue.TableAttributeValueId); if (diseaseAttributeId == null) { diseaseAttributeId = _diseaseController.CreateDiseaseAttribute(MetadataTableAttributeValue.TableAttributeValueId); } int _diseaseAttributeId = (int)diseaseAttributeId[diseaseAttributeId.PrimaryKeyName]; // get a list of attributes var tableAttributeFields = GetAttributeToHiddenFields(TableAttributesPanel); // update each attribute //foreach (var entry in tableAttributeFields) //{ // string attributeName = entry.Key; // // only update "dirty" table attributes // if (dirtyTableAttributes.Contains(attributeName)) // { // // i.e., "PageTitle" // var attributeIdField = entry.Value; // // i.e., "Encounter" > "PageTitle" // var tableAttributeValueId = GetTableAttributeValueIdControl(TablePanel, attributeName); // // i.e. "Prostate Encounter Form" // var attributeValue = GetInputControlValue(GetTableAttributeValueControl(TablePanel, attributeName)); // // i.e., "Prostate" > "Encounter" > "PageTitle" = "Prostate Encounter Form" // var diseaseAttributeValueId = GetDiseaseAttributeValueId(TablePanel, attributeName); // // update/insert table attribute value // int? tavid = null; // MetadataTableAttributeValue biz = new MetadataTableAttributeValue(); // // load existing // if (!string.IsNullOrEmpty(tableAttributeValueId.Value)) // { // tavid = int.Parse(tableAttributeValueId.Value); // biz.Get(tavid.Value); // } // // else insert // else // { // biz[MetadataTableAttributeValue.TableAttributeId] = attributeIdField.Value; // biz[MetadataTableAttributeValue.TableId] = tableId.Value; // } // // validate attribute value (no empty values should be saved) // // TODO: move logic to base page // if (string.IsNullOrEmpty(attributeValue)) // { // // delete on empty values // if (tavid.HasValue) // { // // delete attribute value // biz.Delete(tavid.Value); // tavid = null; // tableAttributeValueId.Value = string.Empty; // // delete disease specific mapping // if (isDiseaseSpecific && !string.IsNullOrEmpty(diseaseAttributeValueId.Value)) // { // DiseaseAttributeValue dav = new DiseaseAttributeValue(); // dav.Delete(int.Parse(diseaseAttributeValueId.Value)); // diseaseAttributeValueId.Value = string.Empty; // } // continue; // } // } // else // { // biz[MetadataTableAttributeValue.TableAttributeValue] = attributeValue; // biz.Save(); // // update key // tavid = (int)biz[biz.PrimaryKeyName]; // tableAttributeValueId.Value = tavid.Value.ToString(); // // determine if disease mapping needed (and one doesn't exist) // if (isDiseaseSpecific && string.IsNullOrEmpty(diseaseAttributeValueId.Value)) // { // // create mapping of table attirbute value to disease // var diseaseMapping = _diseaseController.CreateDiseaseAttributeValue(QueryDiseaseId.Value, tableAttributeValueIdAttribute, tableAttributeValueId.Value); // diseaseAttributeValueId.Value = diseaseMapping[diseaseMapping.PrimaryKeyName].ToString(); // } // } // } //} // TODO // SPECIAL CASE: handle columns and grid if (NumDisplayColumns.SelectedIndex == 2) { GridView.Checked = true; } int metadataItemKey = tableId.Value; foreach (var dirtyAttributeValue in tableAttributeFields) { string attributeName = dirtyAttributeValue.Key; // only update if there is an attribute by this name if (tableAttributeFields.ContainsKey(attributeName)) { IBusinessObject attributeBiz = new MetadataTableAttribute();// BusinessObjectFactory.BuildBusinessObject(BIZ_ATTRIBUTE_TABLE.TableName); int? attributeId = null; int? attributeValueId = null; // get the table attribute id ICaisisInputControl attributeIdField = tableAttributeFields[attributeName]; // CREATE/LOAD: Attribute (i.e., "FieldLabel" -> MetadataFieldAttribute) // if attribute exists, set value if (!string.IsNullOrEmpty(attributeIdField.Value)) { attributeId = int.Parse(attributeIdField.Value); } // otherwise insert attribute else { // set required attribute name attributeBiz[MetadataTableAttribute.TableAttributeName] = attributeName; attributeBiz.Save(); // update hidden attribute id field attributeId = (int)attributeBiz[attributeBiz.PrimaryKeyName]; attributeIdField.Value = attributeId.Value.ToString(); } // INSERT/UPDATE: Attribute Value (i.e., "FieldLabel" + "My Field" -> MetadataFieldAttributeValue) // the field representing the AttributeValueId ICaisisInputControl attributeValueIdField = GetTableAttributeValueIdControl(TablePanel, attributeName); // the field representing the input control containing the AttributeValue ICaisisInputControl attributeValueControl = GetTableAttributeValueControl(TablePanel, attributeName); // the disease mapping to the attribute value ICaisisInputControl diseaseAttributeValueId = GetDiseaseAttributeValueId(TablePanel, attributeName); // validate fields exists if (attributeValueIdField != null && attributeValueControl != null) { IBusinessObject attributeValueBiz = new MetadataTableAttributeValue();// BusinessObjectFactory.BuildBusinessObject(attributeValueTableName); bool isDiseaseSpecific = QueryDiseaseId.HasValue && diseaseAttributeValueId != null; // load attribute value, if isn't disease specific or disease specific has a value if (!string.IsNullOrEmpty(attributeValueIdField.Value) && (!isDiseaseSpecific || !string.IsNullOrEmpty(diseaseAttributeValueId.Value))) { attributeValueId = int.Parse(attributeValueIdField.Value); attributeValueBiz.Get(attributeValueId.Value); } // set required foreign keys for insert else { // set required attribute id key (i.e., AttributeId) attributeValueBiz[MetadataTableAttribute.TableAttributeId] = attributeId; // set required metadata id (i.e., FieldId) attributeValueBiz[MetadataTable.TableId] = metadataItemKey; } // get attribute value (i.e., "ControlType" = "CaisisTextBox") string attributeValue = GetInputControlValue(attributeValueControl); // update table attribute value // validate (no empty values allowed) if (string.IsNullOrEmpty(attributeValue)) { // delete empty values if (attributeValueId.HasValue) { // delete atttibute value attributeValueBiz.Delete(attributeValueId.Value); attributeValueId = null; attributeValueIdField.Value = string.Empty; // delete disease specific mapping if (isDiseaseSpecific && !string.IsNullOrEmpty(diseaseAttributeValueId.Value)) { DiseaseAttributeValue dav = new DiseaseAttributeValue(); dav.Delete(int.Parse(diseaseAttributeValueId.Value)); diseaseAttributeValueId.Value = string.Empty; } } continue; } else { attributeValueBiz[MetadataTableAttributeValue.TableAttributeValue] = attributeValue; attributeValueBiz.Save(); // update hidden field attributeValueId = (int)attributeValueBiz[attributeValueBiz.PrimaryKeyName]; attributeValueIdField.Value = attributeValueId.ToString(); // handle disease specific mapping if (isDiseaseSpecific) { var diseaseAttributeValue = new DiseaseAttributeValue(); if (!string.IsNullOrEmpty(diseaseAttributeValueId.Value)) { diseaseAttributeValue.Get(int.Parse(diseaseAttributeValueId.Value)); } else { diseaseAttributeValue[DiseaseAttributeValue.DiseaseId] = QueryDiseaseId; diseaseAttributeValue[DiseaseAttributeValue.DiseaseAttributeId] = _diseaseAttributeId; } diseaseAttributeValue[DiseaseAttributeValue.DiseaseAttributeValue_Field] = attributeValueIdField.Value; diseaseAttributeValue.Save(); diseaseAttributeValueId.Value = diseaseAttributeValue[diseaseAttributeValue.PrimaryKeyName].ToString(); } } } } } // TODO // re-init dirty attributes dirtyTableAttributes.Clear(); }
/// <summary> /// Updates the metadta attibutes and attribute values /// </summary> protected virtual void Update() { GridView grid = GetMetadataGrid(); if (grid == null) { return; } foreach (var dirtyRow in dirtyRows) { // the "dirty" grid row GridViewRow row = dirtyRow.Key; int rowIndex = row.RowIndex; // lookup of key fields in row var rowDataKeys = grid.DataKeys[rowIndex].Values; // a list of controls which are "dirty" in row var dirtyControls = dirtyRow.Value; // a list of "dirty" controls which represent an attribute value var dirtyAttributes = dirtyControls.Where(c => c.Table == attributeValueTableName); // a list of "dirty" contorls which represents a dirty metdata item var dirtyMetadataItemFields = dirtyControls.Where(c => c.Table == metadataItemTableName); IBusinessObject metadataItemBiz = BusinessObjectFactory.BuildBusinessObject(metadataItemTableName); int metadataItemKey = (int)rowDataKeys[metadataItemBiz.PrimaryKeyName]; // for each row, only updates values(attribuet values) which have changed, not all attribute values foreach (ICaisisInputControl dirtyAttributeValue in dirtyAttributes) { string attributeName = dirtyAttributeValue.Field; // only update if there is an attribute by this name if (AttributeToHiddenField.ContainsKey(attributeName)) { IBusinessObject attributeBiz = BusinessObjectFactory.BuildBusinessObject(BIZ_ATTRIBUTE_TABLE.TableName); int? attributeId = null; int? attributeValueId = null; // get the table attribute id ICaisisInputControl attributeIdField = AttributeToHiddenField[attributeName]; // CREATE/LOAD: Attribute (i.e., "FieldLabel" -> MetadataFieldAttribute) // if attribute exists, set value if (!string.IsNullOrEmpty(attributeIdField.Value)) { attributeId = int.Parse(attributeIdField.Value); } // otherwise insert attribute else { // set required attribute name attributeBiz[attributeFieldName] = attributeName; attributeBiz.Save(); // update hidden attribute id field attributeId = (int)attributeBiz[attributeBiz.PrimaryKeyName]; attributeIdField.Value = attributeId.Value.ToString(); } // INSERT/UPDATE: Attribute Value (i.e., "FieldLabel" + "My Field" -> MetadataFieldAttributeValue) // the field representing the AttributeValueId ICaisisInputControl attributeValueIdField = GetTableAttributeValueIdControl(row, attributeName); // the field representing the input control containing the AttributeValue ICaisisInputControl attributeValueControl = GetTableAttributeValueControl(row, attributeName); // the disease mapping to the attribute value ICaisisInputControl diseaseAttributeValueId = GetDiseaseAttributeValueId(row, attributeName); // validate fields exists if (attributeValueIdField != null && attributeValueControl != null) { IBusinessObject attributeValueBiz = BusinessObjectFactory.BuildBusinessObject(attributeValueTableName); bool isDiseaseSpecific = QueryDiseaseId.HasValue && diseaseAttributeValueId != null; // load attribute value, if isn't disease specific or disease specific has a value if (!string.IsNullOrEmpty(attributeValueIdField.Value) && (!isDiseaseSpecific || !string.IsNullOrEmpty(diseaseAttributeValueId.Value))) { attributeValueId = int.Parse(attributeValueIdField.Value); attributeValueBiz.Get(attributeValueId.Value); } // set required foreign keys for insert else { // set required attribute id key (i.e., AttributeId) attributeValueBiz[attributeBiz.PrimaryKeyName] = attributeId; // set required metadata id (i.e., FieldId) attributeValueBiz[metadataItemBiz.PrimaryKeyName] = metadataItemKey; } // get attribute value (i.e., "ControlType" = "CaisisTextBox") string attributeValue = GetInputControlValue(attributeValueControl); // update table attribute value // validate (no empty values allowed) if (string.IsNullOrEmpty(attributeValue)) { // delete empty values if (attributeValueId.HasValue) { // delete atttibute value attributeValueBiz.Delete(attributeValueId.Value); attributeValueId = null; attributeValueIdField.Value = string.Empty; // delete disease specific mapping if (isDiseaseSpecific && !string.IsNullOrEmpty(diseaseAttributeValueId.Value)) { DiseaseAttributeValue dav = new DiseaseAttributeValue(); dav.Delete(int.Parse(diseaseAttributeValueId.Value)); diseaseAttributeValueId.Value = string.Empty; } } continue; } else { attributeValueBiz[attributeValueFieldName] = attributeValue; attributeValueBiz.Save(); // update hidden field attributeValueId = (int)attributeValueBiz[attributeValueBiz.PrimaryKeyName]; attributeValueIdField.Value = attributeValueId.ToString(); // handle disease specific mapping if (isDiseaseSpecific) { var diseaseAttributeValue = new DiseaseAttributeValue(); var diseaseAttributeId = GetMetadataDiseaseAttributeId(); // load existing mapping if (!string.IsNullOrEmpty(diseaseAttributeValueId.Value)) { diseaseAttributeValue.Get(int.Parse(diseaseAttributeValueId.Value)); } // new else { diseaseAttributeValue[DiseaseAttributeValue.DiseaseId] = QueryDiseaseId.Value; diseaseAttributeValue[DiseaseAttributeValue.DiseaseAttributeId] = diseaseAttributeId.Value; } diseaseAttributeValue[DiseaseAttributeValue.DiseaseAttributeValue_Field] = attributeValueIdField.Value; diseaseAttributeValue.Save(); diseaseAttributeValueId.Value = diseaseAttributeValue[diseaseAttributeValue.PrimaryKeyName].ToString(); } } } } } // update metadata item (i.e., MetadataField) if (dirtyMetadataItemFields.Count() > 0) { // load by pri key (i.e., FieldId) metadataItemBiz.Get(metadataItemKey); // update fields which have changed (i.e., FieldOrder, FieldSupress) foreach (ICaisisInputControl input in dirtyMetadataItemFields) { metadataItemBiz[input.Field] = GetInputControlValue(input); } // save record metadataItemBiz.Save(); } } // after update rebuilds lists PopulateAttributeValues(); }
private void Save(int?datasetId) { Dataset biz = new Dataset(); // update, else insert if (datasetId.HasValue) { biz.Get(datasetId.Value); } // fill with dataset values CICHelper.SetBOValues(DatasetEditPanel.Controls, biz, -1); // udpate biz.Save(); datasetId = (int)biz[biz.PrimaryKeyName]; DatasetIdField.Value = datasetId.ToString(); // update disease mapping DiseaseController ct = new DiseaseController(); if (!string.IsNullOrEmpty(DatasetDiseaseAttributeValueId.Value)) { DiseaseAttributeValue diseaseAttributeValue = new DiseaseAttributeValue(); diseaseAttributeValue.Get(int.Parse(DatasetDiseaseAttributeValueId.Value)); // if value empty, delete existing if (string.IsNullOrEmpty(Diseases_DropDown.Value)) { diseaseAttributeValue.Delete(int.Parse(DatasetDiseaseAttributeValueId.Value)); // reset key DatasetDiseaseAttributeValueId.Value = string.Empty; } // other updateing else { diseaseAttributeValue[DiseaseAttributeValue.DiseaseAttributeValue_Field] = datasetId; diseaseAttributeValue.Save(); } } else { // insert only if disease is selected if (!string.IsNullOrEmpty(Diseases_DropDown.Value)) { int diseaseId = int.Parse(Diseases_DropDown.Value); int?diseaseAttributeId = null; var diseaseAttribute = ct.GetDiseaseAttribute(Dataset.DatasetId); if (diseaseAttribute != null) { diseaseAttributeId = (int)diseaseAttribute[diseaseAttribute.PrimaryKeyName]; } else { diseaseAttribute = ct.CreateDiseaseAttribute(Dataset.DatasetId); diseaseAttributeId = (int)diseaseAttribute[diseaseAttribute.PrimaryKeyName]; } // insert DiseaseAttributeValue datasetAttributeValue = ct.CreateDiseaseAttributeValue(diseaseId, diseaseAttributeId.Value, datasetId.ToString()); // update pri key DatasetDiseaseAttributeValueId.Value = datasetAttributeValue[DiseaseAttributeValue.DiseaseAttributeValueId].ToString(); } } // repopulate fields EditDataset(datasetId.Value); }