// UNCHECKBOXIZE -- item-name private void ProcessUncheckboxize(string[] commands) { const string UncheckboxizeNameFormat = "{0}_{1}"; const string UncheckboxizeValueSetSuffix = "_VS1"; Item item = (Item)GetSymbolFromName(commands[1],SymbolTypes.Item); if( !item.Alpha ) throw new Exception(String.Format(Messages.UncheckboxizeNotAlpha,item.Name)); if( item.ValueSets.Count == 0 ) throw new Exception(String.Format(Messages.UncheckboxizedNoValueSet,item.Name)); List<Value> checkboxValues = item.ValueSets[0].Values; int maxValueWidth = 0; foreach( Value value in checkboxValues ) maxValueWidth = Math.Max(maxValueWidth,value.Pairs[0].From.Trim().Length); if( maxValueWidth == 0 || item.Length % maxValueWidth != 0 ) throw new Exception(String.Format(Messages.UncheckboxizedNotValidCheckbox,item.Name,item.ValueSets[0].Name,maxValueWidth,item.Length)); int numCheckboxes = item.Length / maxValueWidth; // make sure that all of the names (to be created) are valid and available for( int occ = 0; occ < numCheckboxes; occ++ ) { string newName = null; try { newName = String.Format(UncheckboxizeNameFormat,item.Name,occ + 1); CheckIfValidNewName(item.ParentDictionary,newName); newName = newName + UncheckboxizeValueSetSuffix; CheckIfValidNewName(item.ParentDictionary,newName); } catch( Exception ) { throw new Exception(String.Format(Messages.UnsubitemizeNameInvalid,item.Name,newName)); } } // remove the old item int itemIndex = item.ParentRecord.Items.IndexOf(item); item.ParentRecord.Items.RemoveAt(itemIndex); // create the new items ValueSet baseVS = null; for( int occ = 0; occ < numCheckboxes; occ++ ) { Item newItem = new Item(item.ParentRecord); newItem.ParentRecord.Items.Insert(itemIndex + occ,newItem); newItem.Name = String.Format(UncheckboxizeNameFormat,item.Name,occ + 1); newItem.Label = occ < checkboxValues.Count ? String.Format("{0} ({1})",item.Label,checkboxValues[occ].Label) : item.Label; newItem.Start = item.Start + maxValueWidth * occ; newItem.Occurrences = 1; newItem.Note = item.Note; newItem.Length = maxValueWidth; newItem.Numeric = true; newItem.Subitem = item.Subitem; newItem.ZeroFill = item.ParentDictionary.ZeroFillDefault; ValueSet vs = null; // add the value set if( baseVS == null ) { Value uncheckedValue = new Value(); uncheckedValue.Label = "Unchecked"; uncheckedValue.Pairs.Add(new ValuePair("0")); Value checkedValue = new Value(); checkedValue.Label = "Checked"; checkedValue.Pairs.Add(new ValuePair("1")); baseVS = new ValueSet(newItem); baseVS.AddValue(uncheckedValue); baseVS.AddValue(checkedValue); vs = baseVS; } else { if( baseVS.LinkID == Int32.MinValue ) baseVS.LinkID = DataDictionaryWorker.GetNewValueSetLinkID(item.ParentDictionary); vs = new ValueSet(newItem); vs.EstablishValueSetLink(baseVS); } vs.Name = String.Format(UncheckboxizeNameFormat,item.Name,occ + 1) + UncheckboxizeValueSetSuffix; vs.Label = newItem.Label; newItem.AddValueSet(vs); } SetOutputSuccess(String.Format(Messages.UncheckboxizedSuccess,item.Name,numCheckboxes)); }
// FLATTEN -- [UNSUBITEMIZE] item-name public void ProcessFlatten(string[] commands) { const string FlattenNameFormat = "{0}_{1}"; const string FlattenLabelFormat = "{0} ({1})"; bool createItem = true; if( commands.Length == 3 ) { if( !commands[1].Equals("UNSUBITEMIZE",StringComparison.InvariantCultureIgnoreCase) ) throw new Exception(String.Format(Messages.ProcessorUnrecognizedCommandSpecify,commands[1])); createItem = false; } Item item = (Item)GetSymbolFromName(commands[createItem ? 1: 2],SymbolTypes.Item); if( !createItem ) CheckCanUnsubitemize(item); if( item.Occurrences == 1 ) throw new Exception(String.Format(Messages.FlattenMustHaveOccurrences,item.Name)); // make sure that all of the names (to be created) are valid and available for( int i = createItem ? - 1 : 0; i < item.Subitems.Count; i++ ) { Item thisItem = ( i == -1 ) ? item : item.Subitems[i]; for( int occ = 0; occ < item.Occurrences; occ++ ) { string newName = null; try { newName = String.Format(FlattenNameFormat,thisItem.Name,occ + 1); CheckIfValidNewName(item.ParentDictionary,newName); foreach( ValueSet vs in thisItem.ValueSets ) { newName = String.Format(FlattenNameFormat,vs.Name,occ + 1); CheckIfValidNewName(item.ParentDictionary,newName); } } catch( Exception ) { throw new Exception(String.Format(Messages.FlattenNameInvalid,item.Name,newName)); } } } List<Item> recordItems = item.ParentRecord.Items; int itemInsertionIndex = recordItems.IndexOf(item); recordItems.RemoveAt(itemInsertionIndex); // remove any subitems associated with the just removed item for( int i = 0; i < item.Subitems.Count; i++ ) recordItems.RemoveAt(itemInsertionIndex); int itemsAdded = 0; for( int occ = 0; occ < item.Occurrences; occ++ ) { Item firstItem = null; for( int i = createItem ? -1 : 0; i < item.Subitems.Count; i++ ) { Item thisItem = ( i == -1 ) ? item : item.Subitems[i]; Item newItem = new Item(thisItem.ParentRecord); if( createItem ) { if( firstItem == null ) firstItem = newItem; else firstItem.Subitems.Add(newItem); } newItem.Name = String.Format(FlattenNameFormat,thisItem.Name,occ + 1); // add an occurrence number (or label if it exists) newItem.Label = String.Format(FlattenLabelFormat,thisItem.Label, ( occ < item.OccurrenceLabels.Count ) ? item.OccurrenceLabels[occ] : ( occ + 1 ).ToString()); newItem.Start = thisItem.Start + item.Length * occ; newItem.Occurrences = 1; // most of the item is a direct copy newItem.Note = thisItem.Note; newItem.Length = thisItem.Length; newItem.Numeric = thisItem.Numeric; newItem.Subitem = createItem ? thisItem.Subitem : false; newItem.Decimal = thisItem.Decimal; newItem.DecChar = thisItem.DecChar; newItem.ZeroFill = thisItem.ZeroFill; // create linked value sets for each of the value sets foreach( ValueSet vs in thisItem.ValueSets ) { ValueSet newValueSet = new ValueSet(newItem); newValueSet.Name = String.Format(FlattenNameFormat,vs.Name,occ + 1); newValueSet.Label = String.Format(FlattenLabelFormat,vs.Label, ( occ < item.OccurrenceLabels.Count ) ? item.OccurrenceLabels[occ] : ( occ + 1 ).ToString()); // create a new linked value set if it is not already linked if( vs.LinkID == Int32.MinValue ) vs.LinkID = DataDictionaryWorker.GetNewValueSetLinkID(item.ParentDictionary); newValueSet.EstablishValueSetLink(vs); newItem.ValueSets.Add(newValueSet); } recordItems.Insert(itemInsertionIndex++,newItem); itemsAdded++; } } LoadDictionarySymbols(item.ParentDictionary); RefreshSymbolParents(); SetOutputSuccess(String.Format(Messages.FlattenSuccess,item.Name,item.Occurrences,itemsAdded)); }
public void EstablishValueSetLink(ValueSet vs) { _values = vs._values; LinkID = vs.LinkID; }
private string LoadValueSet() { _valueset = new ValueSet(_item); _vsValue = null; string line; bool firstName = true; while( ( line = ReadTrimmedLine() ) != null && !IsHeader(line) ) { string argument,value; ParseLine(line,out argument,out value); // special parsing for the name if( argument.Equals(DataDictionaryElements.DICT_NAME,StringComparison.InvariantCultureIgnoreCase) ) { if( firstName ) { _valueset.Name = value.ToUpper(); firstName = false; } else { int commaPos = value.IndexOf(','); if( commaPos < 0 ) throw new DataDictionaryReaderException(line); string specialVal,description; specialVal = value.Substring(0,commaPos); description = value.Substring(commaPos + 1); if( !description.Equals(DataDictionaryElements.VALUE_SPECIAL,StringComparison.InvariantCultureIgnoreCase) ) throw new DataDictionaryReaderException(line); else if( specialVal.Equals(DataDictionaryElements.VALUE_MISSING,StringComparison.InvariantCultureIgnoreCase) ) _vsValue.SpecialValue = Value.Special.Missing; else if( specialVal.Equals(DataDictionaryElements.VALUE_NOTAPPL,StringComparison.InvariantCultureIgnoreCase) ) _vsValue.SpecialValue = Value.Special.NotApplicable; else if( specialVal.Equals(DataDictionaryElements.VALUE_DEFAULT,StringComparison.InvariantCultureIgnoreCase) ) _vsValue.SpecialValue = Value.Special.Default; else throw new DataDictionaryReaderException(line); } } // a value (not value set) note else if( _vsValue != null && argument.Equals(DataDictionaryElements.DICT_NOTE,StringComparison.InvariantCultureIgnoreCase) ) _vsValue.Note = AppendNote(_vsValue.Note,value); else if( AssignSharedComponents(_valueset,argument,value) ) // the value set label and note will be handled here { } else if( argument.Equals(DataDictionaryElements.VALUE_LINK,StringComparison.InvariantCultureIgnoreCase) ) { int linkID = Int32.Parse(value,CultureInfo.InvariantCulture); if( _vsLinks.ContainsKey(linkID) ) _valueset.EstablishValueSetLink(_vsLinks[linkID]); else { _valueset.LinkID = linkID; _vsLinks.Add(linkID,_valueset); } } else if( argument.Equals(DataDictionaryElements.VALUE_VALUE,StringComparison.InvariantCultureIgnoreCase) ) { _vsValue = new Value(); AddValues(value); _valueset.AddValue(_vsValue); } else if( argument.Equals(DataDictionaryElements.VALUE_IMAGE,StringComparison.InvariantCultureIgnoreCase) ) _vsValue.ImageFilename = Paths.MakeAbsolutePath(Path.GetDirectoryName(_filename),value); else throw new DataDictionaryReaderException(line); } _item.AddValueSet(_valueset); return line; }
public void AddValueSet(ValueSet vs) { _valuesets.Add(vs); }
private void SaveValueSet(ValueSet vs) { _tw.WriteLine(); _tw.WriteLine(DataDictionaryElements.DICT_VALUESET); SaveSharedComponents(vs); if( vs.LinkID != Int32.MinValue ) { SaveOption(DataDictionaryElements.VALUE_LINK,vs.LinkID); if( _vsLinks.Contains(vs.LinkID) ) // the values have already been written return; _vsLinks.Add(vs.LinkID); } foreach( Value value in vs.Values ) SaveValue(value,vs.Parent); }
private string LoadValueSet() { _valueset = new ValueSet(_item); _vsValue = null; string line; bool firstName = true; while ((line = ReadTrimmedLine()) != null && !IsHeader(line)) { string argument, value; ParseLine(line, out argument, out value); // special parsing for the name if (argument.Equals(DataDictionaryElements.DICT_NAME, StringComparison.InvariantCultureIgnoreCase)) { if (firstName) { _valueset.Name = value.ToUpper(); firstName = false; } else { int commaPos = value.IndexOf(','); if (commaPos < 0) { throw new DataDictionaryReaderException(line); } string specialVal, description; specialVal = value.Substring(0, commaPos); description = value.Substring(commaPos + 1); if (!description.Equals(DataDictionaryElements.VALUE_SPECIAL, StringComparison.InvariantCultureIgnoreCase)) { throw new DataDictionaryReaderException(line); } else if (specialVal.Equals(DataDictionaryElements.VALUE_MISSING, StringComparison.InvariantCultureIgnoreCase)) { _vsValue.SpecialValue = Value.Special.Missing; } else if (specialVal.Equals(DataDictionaryElements.VALUE_NOTAPPL, StringComparison.InvariantCultureIgnoreCase)) { _vsValue.SpecialValue = Value.Special.NotApplicable; } else if (specialVal.Equals(DataDictionaryElements.VALUE_DEFAULT, StringComparison.InvariantCultureIgnoreCase)) { _vsValue.SpecialValue = Value.Special.Default; } else { throw new DataDictionaryReaderException(line); } } } // a value (not value set) note else if (_vsValue != null && argument.Equals(DataDictionaryElements.DICT_NOTE, StringComparison.InvariantCultureIgnoreCase)) { _vsValue.Note = AppendNote(_vsValue.Note, value); } else if (AssignSharedComponents(_valueset, argument, value)) // the value set label and note will be handled here { } else if (argument.Equals(DataDictionaryElements.VALUE_LINK, StringComparison.InvariantCultureIgnoreCase)) { int linkID = Int32.Parse(value, CultureInfo.InvariantCulture); if (_vsLinks.ContainsKey(linkID)) { _valueset.EstablishValueSetLink(_vsLinks[linkID]); } else { _valueset.LinkID = linkID; _vsLinks.Add(linkID, _valueset); } } else if (argument.Equals(DataDictionaryElements.VALUE_VALUE, StringComparison.InvariantCultureIgnoreCase)) { _vsValue = new Value(); AddValues(value); _valueset.AddValue(_vsValue); } else if (argument.Equals(DataDictionaryElements.VALUE_IMAGE, StringComparison.InvariantCultureIgnoreCase)) { _vsValue.ImageFilename = Paths.MakeAbsolutePath(Path.GetDirectoryName(_filename), value); } else { throw new DataDictionaryReaderException(line); } } _item.AddValueSet(_valueset); return(line); }