/// <summary> /// Adds a single attribute with the tag, VR and values specified. /// </summary> /// <remarks> /// If an attribute already exists with this tag, it is removed first before it is again /// added. /// </remarks> /// <param name="dvtkDataTag">The tag of the attribute.</param> /// <param name="vR">The VR of the attribute.</param> /// <param name="values">The values, which will be copied from another attribute, for this attribute.</param> /// <exception cref="System.ArgumentException"> /// <paramref name="dvtkDataTag"/> is not valid for setting a FileMetaInformation attribute.<br></br> /// </exception> /// <exception cref="System.ArgumentNullException"> /// <paramref name="values"/> is a null reference. /// </exception> public override void Set(DvtkData.Dimse.Tag dvtkDataTag, VR vR, Values values) { TagSequence internalTagSequence = new TagSequence(); internalTagSequence.Add(new Tag(dvtkDataTag.GroupNumber, dvtkDataTag.ElementNumber)); // // Sanity checks. // // Check if the tag supplied is valid for a FileMetaInformation. if (!internalTagSequence.IsValidForFileMetaInformation) { throw new ArgumentException(internalTagSequence.ToString() + " is not valid for setting a FileMetaInformation attribute.", "dvtkDataTag"); } if (values == null) { throw new ArgumentNullException("values"); } // // Perform the actual operation. // Set(internalTagSequence, vR, values); if ((internalTagSequence.ToString() == "0x00020010") && (values.Count == 1)) { this.dvtkDataFileHead.TransferSyntax = new DvtkData.Dul.TransferSyntax(values[0]); } }
/// <summary> /// Adds a single attribute with the tag, VR and values specified. /// </summary> /// <remarks> /// If an attribute already exists with this tag, it is removed first before it is again /// added. /// </remarks> /// <param name="dvtkDataTag">The tag of the attribute.</param> /// <param name="vR">The VR of the attribute.</param> /// <param name="values">The values, which will be copied from another attribute, for this attribute.</param> /// <exception cref="System.ArgumentException"> /// <paramref name="dvtkDataTag"/> is not valid for setting a CommandSet attribute.<br></br> /// </exception> /// <exception cref="System.ArgumentNullException"> /// <paramref name="values"/> is a null reference. /// </exception> public override void Set(DvtkData.Dimse.Tag dvtkDataTag, VR vR, Values values) { TagSequence internalTagSequence = new TagSequence(); internalTagSequence.Add(new Tag(dvtkDataTag.GroupNumber, dvtkDataTag.ElementNumber)); // // Sanity checks. // // Check if the tag supplied is valid for a CommandSet. if (!internalTagSequence.IsValidForCommandSet) { throw new ArgumentException(internalTagSequence.ToString() + " is not valid for setting a CommandSet attribute.", "dvtkDataTag"); } if (values == null) { throw new ArgumentNullException("values"); } // // Perform the actual operation in the base class. // Set(internalTagSequence, vR, values); }
private String GetAttributeValueFromDataset(DataSet dataset, DvtkData.Dimse.Tag tag) { DicomMessage dicomMessage = new DicomMessage(DvtkData.Dimse.DimseCommand.CSTORERQ, dataset); String attributeValue = GenerateTriggers.GetValueFromMessageUsingTag(dicomMessage, tag); return(attributeValue); }
private DataSet GetMatchingDatasetFromStoreDataDirectory(String directory, DvtkData.Dimse.Tag matchingTag, String matchingTagValue, out String filename) { DataSet dataset = null; filename = String.Empty; try { DirectoryInfo directoryInfo = new DirectoryInfo(directory); FileInfo[] fileInfo = directoryInfo.GetFiles(); for (int i = 0; i < fileInfo.Length; i++) { DataSet lDataset = new DataSet(); lDataset.DvtkDataDataSet = Dvtk.DvtkDataHelper.ReadDataSetFromFile(fileInfo[i].FullName); // check if this dataset contains the required matching Tag if (DatasetContainsMatchingTag(lDataset, matchingTag, matchingTagValue) == true) { filename = fileInfo[i].FullName; dataset = lDataset; break; } } } catch (System.Exception) { } return(dataset); }
/// <summary> /// Adds a single attribute with the tag, VR and values specified. /// </summary> /// <remarks> /// Depending on the group number of the tag, the attribute /// is set in the CommandSet or DataSet of this instance. /// <br></br><br></br> /// If an attribute already exists with this tag, it is removed first before it is /// again set. /// </remarks> /// <param name="dvtkDataTag">The tag that uniquely identifies the attribute.</param> /// <param name="vR">The VR of the attribute.</param> /// <param name="parameters"> /// The values of the attribute. Do not use the DICOM delimeter '\' directly. Instead use /// multiple parameter arguments for this method when adding a single attribute with multiple values. /// </param> public void Set(DvtkData.Dimse.Tag dvtkDataTag, VR vR, params Object[] parameters) { TagSequence tagSequence = new TagSequence(); tagSequence.Add(new Tag(dvtkDataTag.GroupNumber, dvtkDataTag.ElementNumber)); Set(tagSequence, vR, parameters); }
/// <summary> /// /// </summary> /// <param name="affectedEntity"></param> /// <param name="tag"></param> /// <param name="prefix"></param> /// <param name="initialValue"></param> /// <param name="increment"></param> /// <param name="fieldSize"></param> public TagValueAutoIncrement(AffectedEntityEnum affectedEntity, DvtkData.Dimse.Tag tag, System.String prefix, int initialValue, int increment, int fieldSize) : base(affectedEntity, tag) { _prefix = prefix; _initialValue = initialValue; _increment = increment; _fieldSize = fieldSize; }
public System.String GetValue(DvtkData.Dimse.Tag sequenceTag, DvtkData.Dimse.Tag tag) { System.String lValue = System.String.Empty; if (_dicomMessage != null) { lValue = GenerateTriggers.GetValueFromMessageUsingTag(_dicomMessage, sequenceTag, tag); } return(lValue); }
private bool DatasetContainsMatchingTag(DataSet dataset, DvtkData.Dimse.Tag matchingTag, String matchingAttributeValue) { bool matchingTagFound = false; String fileAttributeValue = GetAttributeValueFromDataset(dataset, matchingTag); if ((fileAttributeValue != String.Empty) && (fileAttributeValue == matchingAttributeValue)) { matchingTagFound = true; } return(matchingTagFound); }
/// <summary> /// Try to find a comparison tag in the collection with the same tag as the given one. /// </summary> /// <param name="tag">Tag to try to find in the collection.</param> /// <returns>BaseTagValue - null if no match found</returns> public BaseTagValue Find(DvtkData.Dimse.Tag tag) { BaseTagValue baseTagValue = null; foreach (BaseTagValue lBaseTagValue in this) { if (lBaseTagValue.Tag == tag) { baseTagValue = lBaseTagValue; break; } } return(baseTagValue); }
/// <summary> /// Get the first value of the given attribute in the DICOM message with the given DICOM command name. /// First search the command set and then the dataset (if present). /// </summary> /// <param name="dimseCommandName">DICOM command name.</param> /// <param name="tag">Tag identifying attribute whose first value will be returned.</param> /// <param name="attributeValue">Out - returned attribute value.</param> /// <returns>bool - indicates whether the dimseCommandName was found in the transaction or not - true / false.</returns> public bool GetFirstDicomAttributeValue(String dimseCommandName, DvtkData.Dimse.Tag tag, out String attributeValue) { attributeValue = String.Empty; bool dimseCommandFound = false; if (_transaction is DicomTransaction) { String group = tag.GroupNumber.ToString("X").PadLeft(4, '0'); String element = tag.ElementNumber.ToString("X").PadLeft(4, '0'); String tagString = String.Format("0x{0}{1}", group, element); DicomTransaction dicomTransaction = (DicomTransaction)_transaction; for (int i = 0; i < dicomTransaction.DicomMessages.Count; i++) { DicomMessage dicomMessage = (DicomMessage)dicomTransaction.DicomMessages[i]; if (dicomMessage.CommandSet != null) { if (dicomMessage.CommandSet.DimseCommandName == dimseCommandName) { dimseCommandFound = true; // check the command set if (dicomMessage.CommandSet.Exists(tagString) == true) { attributeValue = dicomMessage.CommandSet.GetValues(tagString)[0]; } else if ((dicomMessage.DataSet != null) && (dicomMessage.DataSet.Exists(tagString) == true)) { // check the dataset attributeValue = dicomMessage.DataSet.GetValues(tagString)[0]; } break; } } } } return(dimseCommandFound); }
/// <summary> /// Adds a single attribute with the tag, VR and value specified. /// </summary> /// <remarks> /// Only use this method for setting an attribute with VR OB, OF or OW. /// <br></br><br></br> /// If an attribute already exists with this tag, it is removed first before it is again /// added. /// </remarks> /// <param name="dvtkDataTag">The tag of the attribute.</param> /// <param name="vR">The VR (may only be OB, OF or OW) of the attribute.</param> /// <param name="value">The value of the attribute.</param> /// <exception cref="System.ArgumentException"> /// <paramref name="dvtkDataTag"/> is not valid for setting a CommandSet attribute.<br></br> /// -or-<br></br> /// <paramref name="vR"/> is unequal to OB, OF or OW. /// </exception> /// <exception cref="System.ArgumentNullException"> /// <paramref name="value"/> is a null reference. /// </exception> public override void Set(DvtkData.Dimse.Tag dvtkDataTag, VR vR, Byte[] value) { TagSequence internalTagSequence = new TagSequence(); internalTagSequence.Add(new Tag(dvtkDataTag.GroupNumber, dvtkDataTag.ElementNumber)); // // Sanity checks. // // Check if the tag supplied is valid for a CommandSet. if (!internalTagSequence.IsValidForCommandSet) { throw new ArgumentException(internalTagSequence.ToString() + " is not valid for setting a CommandSet attribute.", "dvtkDataTag"); } // Check the supplied VR. if ((vR != VR.OB) && (vR != VR.OF) && (vR != VR.OW)) { throw new ArgumentException("Supplied VR is " + vR.ToString() + ". VR may only be OB, OF or OW.", "vR"); } if (value == null) { throw new ArgumentNullException("value"); } // // Perform the actual operation in the base class. // Set(internalTagSequence, vR, value); }
/// <summary> /// Adds an item to the <see cref="System.Collections.IList"/>. /// </summary> /// <param name="value">The item to add to the <see cref="System.Collections.IList"/>. </param> /// <returns>The position into which the new element was inserted.</returns> public int Add(DvtkData.Dimse.Tag value) { return(base.Add(value)); }
/// <summary> /// <see cref="IDefinitionManagement.GetAttributeNameFromDefinition"/> /// </summary> public System.String GetAttributeNameFromDefinition(DvtkData.Dimse.Tag tag) { System.String attributeName = this.m_adaptee.get_AttributeNameFromDefinition(tag); return(attributeName); }
/// <summary> /// Converts the supplied array to a DvtkData TagCollection. /// </summary> /// <remarks> /// When an array element is null, it will be skipped.<br></br><br></br> /// When an array element cannot be converted, it will be interpreted as a tag with value 0x00000000. /// </remarks> /// <param name="objects">The array to convert.</param> /// <returns>The returned DvtkData TagCollection.</returns> private DvtkData.Collections.TagCollection ConvertToTagCollection(object[] objects) { DvtkData.Collections.TagCollection tagCollection = new DvtkData.Collections.TagCollection(); foreach (object item in objects) { if (item != null) { DvtkData.Dimse.Tag dvtkDataTag = null; try { if (item is DvtkData.Dimse.Tag) { DvtkData.Dimse.Tag sourceDvtkDataTag = item as DvtkData.Dimse.Tag; dvtkDataTag = new DvtkData.Dimse.Tag(sourceDvtkDataTag.GroupNumber, sourceDvtkDataTag.ElementNumber); } else if (item is System.Int32) { dvtkDataTag = (System.Int32)item; } else if (item is System.UInt32) { dvtkDataTag = (System.UInt32)item; } else if (item is String) { TagSequence tagSequence = new TagSequence(item as String); if (tagSequence.IsSingleAttributeMatching) { if (tagSequence.Tags.Count == 1) { Tag tag = tagSequence.Tags[0] as Tag; dvtkDataTag = new DvtkData.Dimse.Tag(tag.GroupNumber, tag.ElementNumber); } else { throw new ArgumentException("One of the Array elements represents a nested tag."); } } else { throw new ArgumentException("One of the Array elements represents an indexed tag."); } } else { throw new ArgumentException("One of the Array elements is of an unexpected type."); } } catch { dvtkDataTag = new DvtkData.Dimse.Tag(0x0000, 0x0000); } tagCollection.Add(dvtkDataTag); } } return (tagCollection); }
private void AddReferencedSopSequence(ReferencedSopItemCollection storageCommitItems, uint tag, DvtkData.Dimse.AttributeSet attributeSet, InstanceStateEnum newInstanceState) { ushort group = (ushort)(tag >> 16); ushort element = (ushort)(tag & 0x0000FFFF); DvtkData.Dimse.Tag tagValue = new DvtkData.Dimse.Tag(group, element); DvtkData.Dimse.Attribute referencedSopSequence = attributeSet.GetAttribute(tagValue); if (referencedSopSequence != null) { attributeSet.Remove(referencedSopSequence); } referencedSopSequence = new DvtkData.Dimse.Attribute(tag, DvtkData.Dimse.VR.SQ); DvtkData.Dimse.SequenceOfItems referencedSopSequenceOfItems = new DvtkData.Dimse.SequenceOfItems(); referencedSopSequence.DicomValue = referencedSopSequenceOfItems; foreach (ReferencedSopItem referencedSopItem in storageCommitItems) { if ((referencedSopItem.InstanceState == InstanceStateEnum.InstanceStored) && (newInstanceState == InstanceStateEnum.InstanceStorageCommitRequested)) { DvtkData.Dimse.SequenceItem referencedSopSequenceItem = new DvtkData.Dimse.SequenceItem(); referencedSopSequenceItem.AddAttribute(DvtkData.Dimse.Tag.REFERENCED_SOP_CLASS_UID.GroupNumber, DvtkData.Dimse.Tag.REFERENCED_SOP_CLASS_UID.ElementNumber, DvtkData.Dimse.VR.UI, referencedSopItem.SopClassUid); referencedSopSequenceItem.AddAttribute(DvtkData.Dimse.Tag.REFERENCED_SOP_INSTANCE_UID.GroupNumber, DvtkData.Dimse.Tag.REFERENCED_SOP_INSTANCE_UID.ElementNumber, DvtkData.Dimse.VR.UI, referencedSopItem.SopInstanceUid); referencedSopItem.InstanceState = newInstanceState; referencedSopSequenceOfItems.Sequence.Add(referencedSopSequenceItem); } } attributeSet.Add(referencedSopSequence); }
/// <summary> /// Compare the DICOM files in the two directories based on there being corresponding /// files in each directory with the same attribute value for the matching Tag. /// </summary> /// <param name="directory1">Full directory name of first directory.</param> /// <param name="directory2">Full directory name of second directory.</param> /// <param name="matchingTag">DICOM Tag value to match in a file in each directory.</param> /// <returns>Total number of differences between compared files.</returns> public int Compare(String directory1, String directory2, DvtkData.Dimse.Tag matchingTag) { int totalDifferences = 0; StreamWriter htmlOutput = null; try { // create the output file writer if necessary if (_htmlOutputFilename != String.Empty) { htmlOutput = new StreamWriter(_htmlOutputFilename); } // compare all files in directory 1 with corresponding files in directory 2 // - the files compared is based on them having the same attribute value for the // Tag given. DirectoryInfo directoryInfo = new DirectoryInfo(directory1); FileInfo[] fileInfo = directoryInfo.GetFiles(); for (int i = 0; i < fileInfo.Length; i++) { DataSet dataset1 = new DataSet(); String filename1 = fileInfo[i].FullName; dataset1.DvtkDataDataSet = Dvtk.DvtkDataHelper.ReadDataSetFromFile(filename1); // get the attribute value for the matching tag from this dataset String valueToMatch = GetAttributeValueFromDataset(dataset1, matchingTag); if (valueToMatch != String.Empty) { // try to find a dataset (file) containing the same value in directory 2 String filename2 = String.Empty; DataSet dataset2 = GetMatchingDatasetFromStoreDataDirectory(directory2, matchingTag, valueToMatch, out filename2); // if a dataset is returned that contains the matching attribute value go on to compare all the attributes // in both datasets with eachother if (dataset2 != null) { // get a new compare instance and set the comparison flags StaticDicomCompare staticDicomCompare = new StaticDicomCompare(); FlagsDicomAttribute flags = FlagsDicomAttribute.Compare_values | FlagsDicomAttribute.Compare_present | FlagsDicomAttribute.Include_sequence_items; if (_compareVr == false) { staticDicomCompare.DisplayAttributeVR = false; } else { flags |= FlagsDicomAttribute.Compare_VR; } staticDicomCompare.DisplayGroupLength = _displayGroupLength; dataset1.UnVrDefinitionLookUpWhenReading = _unVrDefinitionLookUpWhenReading; dataset2.UnVrDefinitionLookUpWhenReading = _unVrDefinitionLookUpWhenReading; AttributeCollections datasets = new AttributeCollections(); datasets.Add(dataset1); datasets.Add(dataset2); StringCollection datasetDescriptions = new StringCollection(); datasetDescriptions.Add(filename1); datasetDescriptions.Add(filename2); String title = String.Format("Comparison Results with matching using Tag with {0}", matchingTag.ToString()); DvtkHighLevelInterface.Common.Compare.CompareResults datasetCompareResults = staticDicomCompare.CompareAttributeSets(title, datasets, datasetDescriptions, flags); if (htmlOutput != null) { if (_includeDetailedResults == true) { htmlOutput.WriteLine(datasetCompareResults.Table.ConvertToHtml()); } else { htmlOutput.WriteLine("<br />"); String message = String.Format("Compared {0} with {1} - number of differences: {2}", filename1, filename2, datasetCompareResults.DifferencesCount); htmlOutput.WriteLine(message); htmlOutput.WriteLine("<br />"); } } // update the total differences counter totalDifferences += datasetCompareResults.DifferencesCount; } } } } catch (System.Exception) { } if (htmlOutput != null) { htmlOutput.Flush(); htmlOutput.Close(); } return(totalDifferences); }
/// <summary> /// <see cref="IDefinitionManagement.GetAttributeVrFromDefinition"/> /// </summary> public DvtkData.Dimse.VR GetAttributeVrFromDefinition(DvtkData.Dimse.Tag tag) { DvtkData.Dimse.VR vr = this.m_adaptee.get_AttributeVrFromDefinition(tag); return(vr); }
/// <summary> /// Class constructor. /// </summary> /// <param name="affectedEntity">Affected Entity</param> /// <param name="tag">Tag</param> public BaseTagValue(AffectedEntityEnum affectedEntity, DvtkData.Dimse.Tag tag) { _affectedEntity = affectedEntity; _tag = tag; }
/// <summary> /// Class constructor. /// </summary> /// <param name="affectedEntity">Affected Entity</param> /// <param name="tag">Tag</param> public BaseDicomTagValue(AffectedEntityEnum affectedEntity, DvtkData.Dimse.Tag tag) { _affectedEntity = affectedEntity; _tag = tag; }
/// <summary> /// Determines the index of a specific item in the <see cref="System.Collections.IList"/>. /// </summary> /// <param name="value">The item to locate in the <see cref="System.Collections.IList"/>.</param> /// <returns>The index of <c>value</c> if found in the list; otherwise, -1.</returns> public int IndexOf(DvtkData.Dimse.Tag value) { return(base.IndexOf(value)); }
/// <summary> /// /// </summary> /// <param name="tag"></param> public TagValueDelete(DvtkData.Dimse.Tag tag) : base(AffectedEntityEnum.AnyEntity, tag) { }
/// <summary> /// See comments for this overridden method in the classes CommandSet, DataSet, SequenceItem and FileMetaInformation. /// </summary> /// <param name="dvtkDataTag">-</param> /// <param name="vR">-</param> /// <param name="values">-</param> public abstract void Set(DvtkData.Dimse.Tag dvtkDataTag, VR vR, Values values);
/// <summary> /// See comments for this overridden method in the classes CommandSet, DataSet, SequenceItem and FileMetaInformation. /// </summary> /// <param name="dvtkDataTag">-</param> /// <param name="vR">-</param> /// <param name="value">-</param> public abstract void Set(DvtkData.Dimse.Tag dvtkDataTag, VR vR, Byte[] value);
/// <summary> /// Class constructor. /// </summary> /// <param name="tag">Tag</param> /// <param name="lValue">Value</param> public TagValue(DvtkData.Dimse.Tag tag, System.String lValue) : base(AffectedEntityEnum.AnyEntity, tag) { _value = lValue; }
/// <summary> /// Class constructor. /// Value can be empty - universal match. /// </summary> /// <param name="tag">Tag</param> public TagValue(DvtkData.Dimse.Tag tag) : base(AffectedEntityEnum.AnyEntity, tag) { _value = System.String.Empty; }
// Zero based index. public UInt32 GetAttributeTagAsUInt32(int index) { DvtkData.Dimse.Tag dvtkDataTag = this.dvtkDataAttributeSet[index].Tag; return((UInt32)(dvtkDataTag.ElementNumber + (dvtkDataTag.GroupNumber * 65536))); }
/// <summary> /// See comments for this overridden method in the classes CommandSet, DataSet, SequenceItem and FileMetaInformation. /// </summary> /// <param name="dvtkDataTag">-</param> /// <param name="vR">-</param> /// <param name="values">-</param> public abstract void Set(DvtkData.Dimse.Tag dvtkDataTag, VR vR, params Object[] values);
/// <summary> /// Removes the first occurrence of a specific item from the IList. /// </summary> /// <param name="value">The item to remove from the <see cref="System.Collections.IList"/>.</param> public void Remove(DvtkData.Dimse.Tag value) { base.Remove(value); }
/// <summary> /// /// </summary> /// <param name="affectedEntity"></param> /// <param name="tag"></param> /// <param name="root"></param> /// <param name="format"></param> public TagValueAutoSetUid(AffectedEntityEnum affectedEntity, DvtkData.Dimse.Tag tag, System.String root, int format) : base(affectedEntity, tag) { _root = root.TrimEnd('.'); _format = format; }
/// <summary> /// Determines whether the <see cref="System.Collections.IList"/> contains a specific item. /// </summary> /// <param name="value">The item to locate in the <see cref="System.Collections.IList"/>.</param> /// <returns><see langword="true"/> if the item is found in the <see cref="System.Collections.IList"/>; otherwise, <see langword="false"/>.</returns> public bool Contains(DvtkData.Dimse.Tag value) { return(base.Contains(value)); }
/// <summary> /// /// </summary> /// <param name="affectedEntity"></param> /// <param name="tag"></param> public TagValueAutoSetTime(AffectedEntityEnum affectedEntity, DvtkData.Dimse.Tag tag) : base(affectedEntity, tag) { }
/// <summary> /// Inserts an item to the IList at the specified position. /// </summary> /// <param name="index">The zero-based index at which <c>value</c> should be inserted. </param> /// <param name="value">The item to insert into the <see cref="System.Collections.IList"/>.</param> public void Insert(int index, DvtkData.Dimse.Tag value) { base.Insert(index, value); }