/// <summary> /// ****** INTERNAL USE ONLY **** /// /// Returns a validator instance lookup key for a DicomAttribute attribute. /// /// </summary> /// <param name="attribute"></param> /// <returns></returns> static internal int GetKey(DicomAttribute attribute) { // use attribute parent collection hashcode as key // if the attribute doesn't have a parent collection, use its type instead int key; if (attribute.ParentCollection != null) key = attribute.ParentCollection.GetHashCode(); else key = attribute.GetType().GetHashCode(); return key; }
/// <summary> /// Sets the dicom attribute value from enum. Sets it to upper case as per dicom Standard. /// If <paramref name="formatFromPascal"/> is true, then it formats the <paramref name="value"/> from Pascal - ie, MammoClear would /// be set as MAMMO CLEAR . /// </summary> /// <param name="dicomAttribute">The dicom attribute.</param> /// <param name="value">The value.</param> /// <param name="formatFromPascal">if set to <c>true</c> [format from pascal].</param> public static void SetAttributeFromEnum(DicomAttribute dicomAttribute, object value, bool formatFromPascal) { if (value == null || String.IsNullOrEmpty(value.ToString()) || String.Compare(value.ToString(), "None", StringComparison.OrdinalIgnoreCase) == 0 || String.Compare(value.ToString(), "Unknown", StringComparison.OrdinalIgnoreCase) == 0) { dicomAttribute.SetNullValue(); } else { if (formatFromPascal) { value = FormatFromPascal(value.ToString()); } dicomAttribute.SetStringValue(value.ToString().ToUpperInvariant()); } }
public override string GetTypedValue(IStudyItem item) { DicomAttribute attribute = item[base.Tag]; if (attribute == null) { return(null); } if (attribute.IsNull) { return(string.Empty); } return(attribute.ToString()); }
private void InsertStringDicomElement(DicomAttributeCollection dataHeader, Tag stringTagName, string tagValue) { var element = DicomAttribute.CreateAttribute(stringTagName); if (tagValue == null) { return; } if (!element.SetString(0, tagValue)) { Logger.LogWarning("Failed to Insert NULL " + stringTagName.ToString() + " to Data header"); } dataHeader.AddDicomAttribute(element); }
/// <summary> /// Return an instance of the TMStringValidator object /// Note: the returned object may be shared among threads or objects. /// </summary> /// <param name="attribute"></param> /// <returns></returns> /// <remarks> /// ///</remarks> public static TMStringValidator GetInstance(DicomAttribute attribute) { lock (_mutex) { int key = GetKey(attribute); TMStringValidator validator = _map[key] as TMStringValidator; if (validator == null) { validator = new TMStringValidator(); _map[key] = validator; } return(validator); } }
protected void CacheArrayStatus(uint tagCode, string [] value) { if (_dataHead.Contains(tagCode)) { _dataHead.RemoveDicomAttribute(tagCode); } DicomTag tag = new DicomTag(tagCode, "", VR.CS, true, false); DicomAttribute dicomAttr = DicomAttribute.CreateAttribute(tag); for (int i = 0; i < value.Length; i++) { dicomAttr.SetString(i, value[i]); } _dataHead.AddDicomAttribute(dicomAttr); }
public override bool TryGetAttribute(uint tag, out DicomAttribute attribute) { lock (SyncLock) { if (_sop.IsStoredTag(tag)) { attribute = _sop[tag]; if (!attribute.IsEmpty) { return(true); } } return(base.TryGetAttribute(tag, out attribute)); } }
public bool SetFloat(uint tagCode, float value) { if (_dataHead.Contains(tagCode)) { _dataHead.RemoveDicomAttribute(tagCode); } DicomVR TagVR = new DicomVR(VR.FL); DicomTag tag = new DicomTag(tagCode); tag.TagVR = TagVR; DicomAttribute dicomAttr = DicomAttribute.CreateAttribute(tag); dicomAttr.SetFloat32(0, value); _dataHead.AddDicomAttribute(dicomAttr); return(true); }
private void GetTag <T>(uint tag, out T value, uint position, out bool tagExists, GetTagDelegate <T> getter) { value = default(T); tagExists = false; DicomAttribute dicomAttribute = this[tag]; if (dicomAttribute != null) { tagExists = !dicomAttribute.IsEmpty && dicomAttribute.Count > position; if (tagExists) { getter(dicomAttribute, position, out value); } } }
public bool SetString16Array(uint tagCode, string [] value) { if (_dataHead.Contains(tagCode)) { _dataHead.RemoveDicomAttribute(tagCode); } DicomTag tag = new DicomTag(tagCode, "", VR.CS, true, false); DicomAttribute dicomAttr = DicomAttribute.CreateAttribute(tag); for (int i = 0; i < value.Length; i++) { dicomAttr.SetString(i, value[i]); } _dataHead.AddDicomAttribute(dicomAttr); return(true); }
private bool MatchVr(DicomAttribute element) { DicomVr elementVr = element.Tag.VR; if (!elementVr.Equals(DicomVr.DAvr) && !elementVr.Equals(DicomVr.TMvr) && !elementVr.Equals(DicomVr.DTvr)) { return(false); } if (HasWildcardMatching(element.ToString( ))) { return(false); } return(true); }
public static void InsertBytesDicomElement(DicomAttributeCollection dataHeader, Tag stringTagName, byte[] tagValues) { var element = DicomAttribute.CreateAttribute(stringTagName); if (tagValues == null) { return; } if (!element.SetBytes(0, tagValues)) { Logger.LogWarning("Failed to Insert NULL " + stringTagName.ToString() + " to Data header"); } dataHeader.AddDicomAttribute(element); }
protected void CacheStatus(uint tagCode, string value) { if (_dataHead.Contains(tagCode)) { _dataHead.RemoveDicomAttribute(tagCode); } DicomVR TagVR = new DicomVR(VR.CS); DicomTag tag = new DicomTag(tagCode); tag.TagVR = TagVR; DicomAttribute dicomAttr = DicomAttribute.CreateAttribute(tag); dicomAttr.SetString(0, value); _dataHead.AddDicomAttribute(dicomAttr); }
public void PrivateAttributeTest() { DicomFile file = new DicomFile("LittleEndianPrivateReadFileTest.dcm"); DicomAttributeCollection dataSet = file.DataSet; SetupMR(dataSet); dataSet[DicomTags.StudyDescription].SetNullValue(); List <DicomTag> tagList = new List <DicomTag>(); SetupPrivateGroups(tagList, dataSet); SetupMetaInfo(file); // Little Endian Tests file.TransferSyntax = TransferSyntax.ImplicitVrLittleEndian; DicomReadOptions readOptions = DicomReadOptions.Default; // Use ExplicitLengthSequence to force SQ attributes to UN VR when they're read back in Assert.IsTrue(file.Save(DicomWriteOptions.ExplicitLengthSequence)); DicomFile newFile = new DicomFile(file.Filename); newFile.Load(readOptions); Assert.IsTrue(newFile.DataSet[DicomTags.StudyDescription].IsNull); Assert.AreNotEqual(file.DataSet.Equals(newFile.DataSet), true); foreach (DicomTag tag in tagList) { DicomAttributeUN unAttrib = newFile.DataSet[tag] as DicomAttributeUN; Assert.IsNotNull(unAttrib, String.Format("UN VR Attribute is not null for tag {0}", tag)); ByteBuffer bb = unAttrib.GetByteBuffer(TransferSyntax.ImplicitVrLittleEndian, newFile.DataSet[DicomTags.SpecificCharacterSet].ToString()); Assert.IsNotNull(bb, String.Format("ByteBuffer not null for tag: {0}", tag)); DicomAttribute validAttrib = tag.VR.CreateDicomAttribute(tag, bb); Assert.IsNotNull(validAttrib); Assert.IsTrue(validAttrib.Equals(file.DataSet[tag]), String.Format("Attributes equal for tag {0}", tag)); } }
/// <summary> /// ****** INTERNAL USE ONLY **** /// /// Returns a validator instance lookup key for a DicomAttribute attribute. /// /// </summary> /// <param name="attribute"></param> /// <returns></returns> static internal int GetKey(DicomAttribute attribute) { // use attribute parent collection hashcode as key // if the attribute doesn't have a parent collection, use its type instead int key; if (attribute.ParentCollection != null) { key = attribute.ParentCollection.GetHashCode(); } else { key = attribute.GetType().GetHashCode(); } return(key); }
public bool GetUInt16(DicomAttributeCollection headInfo, Tag tag, out ushort value) { if (!headInfo.Contains(tag)) { value = 0; return(false); } else { DicomAttribute element = headInfo[tag]; if (!element.GetUInt16(0, out value)) { return(false); } return(true); } }
internal static void AddCondition(ref string query, DicomAttribute condition, string dbname) { object[] values; if ((condition.Exists) && (condition.Value != null)) { if (condition.IsMultiple) { query = query + " AND ( 1=0 "; values = condition.Value as object[]; query = values.Aggregate(query, (current, value) => current + " OR " + dbname + " = '" + value.ToString() + "'"); query = query + " )"; } else { AddStringCondition(ref query, condition.Value.ToString(), dbname); } } }
/// <summary> /// Sends the move request (called after the association is accepted). /// </summary> /// <param name="client">The client.</param> /// <param name="association">The association.</param> private void SendMoveRequest(DicomClient client, ClientAssociationParameters association) { byte pcid = association.FindAbstractSyntaxOrThrowException(MoveSopClass); var dicomMessage = new DicomMessage(); foreach (DicomAttribute dicomAttribute in _dicomAttributeCollection) { // Need to do it this way in case the attribute is blank DicomAttribute dicomAttribute2 = dicomMessage.DataSet[dicomAttribute.Tag]; if (dicomAttribute.Values != null) { dicomAttribute2.Values = dicomAttribute.Values; } } _moveMessageId = client.NextMessageID(); client.SendCMoveRequest(pcid, _moveMessageId, _destinationAe, dicomMessage); }
/// <summary> /// Sets the date time attribute values for the specified dicom attributes. /// Will first attempt to write to the <paramref name="dateTimeAttribute"/> if it is not null, otherwise /// it will write the values to the separate date and time attributes. /// </summary> /// <param name="value">The value.</param> /// <param name="dateTimeAttribute">The date time attribute.</param> /// <param name="dateAttribute">The date attribute.</param> /// <param name="timeAttribute">The time attribute.</param> public static void SetDateTimeAttributeValues(DateTime?value, DicomAttribute dateTimeAttribute, DicomAttribute dateAttribute, DicomAttribute timeAttribute) { if (dateTimeAttribute != null) { if (value.HasValue) { dateTimeAttribute.SetDateTime(0, value.Value); } else { dateTimeAttribute.SetNullValue(); } } else { SetDateTimeAttributeValues(value, dateAttribute, timeAttribute); } }
public void ReadPixelDataReferencesTest() { DicomFile file = new DicomFile("LittleEndianReadFileTest2.dcm"); DicomAttributeCollection dataSet = file.DataSet; SetupMR(dataSet); SetupMetaInfo(file); // Little Endian Tests file.TransferSyntax = TransferSyntax.ExplicitVrLittleEndian; DicomReadOptions readOptions = DicomReadOptions.StorePixelDataReferences; bool result = file.Save(DicomWriteOptions.Default); Assert.AreEqual(result, true); DicomFile newFile = new DicomFile(file.Filename); newFile.Load(readOptions); DicomAttribute attrib = newFile.DataSet[DicomTags.PixelData]; Assert.IsFalse(attrib.IsEmpty); Assert.IsFalse(attrib.IsNull); Assert.AreEqual(attrib.StreamLength, dataSet[DicomTags.PixelData].StreamLength); // Set the pixel data to null and re-read dataSet[DicomTags.PixelData].SetNullValue(); result = file.Save(DicomWriteOptions.Default); Assert.AreEqual(result, true); newFile = new DicomFile(file.Filename); newFile.Load(readOptions); attrib = newFile.DataSet[DicomTags.PixelData]; Assert.IsFalse(attrib.IsEmpty); Assert.IsTrue(attrib.IsNull); Assert.AreEqual(attrib.StreamLength, dataSet[DicomTags.PixelData].StreamLength); }
public bool SetInt32(uint tagCode, int value) { if (_dataHead.Contains(tagCode)) { _dataHead.RemoveDicomAttribute(tagCode); } DicomVR TagVR = new DicomVR(VR.SL); DicomTag tag = new DicomTag(tagCode); tag.TagVR = TagVR; DicomAttribute dicomAttr = DicomAttribute.CreateAttribute(tag); if (!dicomAttr.SetInt32(0, value)) { return(false); } _dataHead.AddDicomAttribute(dicomAttr); return(true); }
private bool IsSequenceWithExcludedTags(DicomAttribute attribute) { if (!(attribute is DicomAttributeSQ)) { return(false); } var tag = attribute.Tag.TagValue; // cache the results for the recursive SQ item excluded tags check - it adds up if you've got a multiframe image and functional group sequences get accessed repeatedly bool sequenceHasExcludedTags; if (!_sequenceHasExcludedTags.TryGetValue(tag, out sequenceHasExcludedTags)) { var items = attribute.Values as DicomSequenceItem[]; _sequenceHasExcludedTags[tag] = sequenceHasExcludedTags = (items != null && items.OfType <InstanceXmlDicomSequenceItem>().Any(item => item.HasExcludedTags(true))); } return(sequenceHasExcludedTags); }
public bool SetFloat(uint tagCode, float [] value) { if (_dataHead.Contains(tagCode)) { _dataHead.RemoveDicomAttribute(tagCode); } DicomTag tag = new DicomTag(tagCode, "", VR.FL, true, false); DicomAttribute dicomAttr = DicomAttribute.CreateAttribute(tag); for (int i = 0; i < value.Length; i++) { if (!dicomAttr.SetFloat32(i, value[i])) { return(false); } } _dataHead.AddDicomAttribute(dicomAttr); return(true); }
internal static void AddDateTimeCondition(ref string query, DicomAttribute DateCondition, DicomAttribute TimeCondition, string dbname) { if (!string.IsNullOrEmpty(DateCondition.Value.ToString()) && DateCondition.Value.ToString() != "*" && !string.IsNullOrEmpty(TimeCondition.Value.ToString()) && TimeCondition.Value.ToString() != "*") { if (DateCondition.Value.ToString().IndexOf("-", StringComparison.Ordinal) == -1) // if Single Date { DateTime t = DateCondition.DateTimeTo; DateTime startTime = TimeCondition.DateTimeFrom; DateTime endTime = TimeCondition.DateTimeTo; DateTime startDateTime = t.Add(new TimeSpan(startTime.Hour, startTime.Minute, startTime.Second)); DateTime endDateTime = t.Add(new TimeSpan(endTime.Hour, endTime.Minute, endTime.Second)); AddSingleDateCondition(ref query, startDateTime, ">=", dbname); AddSingleDateCondition(ref query, endDateTime, "<=", dbname); } else if (DateCondition.Value.ToString().IndexOf("-", StringComparison.Ordinal) == 0) // -YYYYMMDD format { DateTime t = DateCondition.DateTimeTo; DateTime endTime = TimeCondition.DateTimeTo; DateTime endDateTime = t.Add(new TimeSpan(endTime.Hour, endTime.Minute, endTime.Second)); AddSingleDateCondition(ref query, endDateTime, "<=", dbname); } else if (DateCondition.Value.ToString().IndexOf("-", StringComparison.Ordinal) == DateCondition.Value.ToString().Length - 1) // YYYYMMDD- format { DateTime t = DateCondition.DateTimeFrom; DateTime startTime = TimeCondition.DateTimeFrom; DateTime startDateTime = t.Add(new TimeSpan(startTime.Hour, startTime.Minute, startTime.Second)); AddSingleDateCondition(ref query, startDateTime, ">=", dbname); } else // YYYYMMDD-YYYYMMDD format { DateTime startDate = DateCondition.DateTimeFrom; DateTime endDate = DateCondition.DateTimeTo; DateTime startTime = TimeCondition.DateTimeFrom; DateTime endTime = TimeCondition.DateTimeTo; DateTime startDateTime = startDate.Add(new TimeSpan(startTime.Hour, startTime.Minute, startTime.Second)); DateTime endDateTime = endDate.Add(new TimeSpan(endTime.Hour, endTime.Minute, endTime.Second)); AddSingleDateCondition(ref query, startDateTime, ">=", dbname); AddSingleDateCondition(ref query, endDateTime, "<=", dbname); } } }
public void TestIgnoreOutOfRangeTags() { DicomFile file = new DicomFile(); DicomAttributeCollection collection = file.DataSet; SetupMR(collection); collection.IgnoreOutOfRangeTags = true; DicomTag tag = new DicomTag(0x00030010, "Test", "TestBad", DicomVr.STvr, false, 1, 1, false); Assert.IsNotNull(collection.GetAttribute(tag)); Assert.IsNotNull(collection[tag]); Assert.IsNotNull(collection[tag.TagValue]); collection.IgnoreOutOfRangeTags = false; try { collection.GetAttribute(tag); Assert.Fail("DicomAttributeCollection.GetAttribute failed"); } catch (DicomException) { } try { DicomAttribute attrib = collection[tag]; Assert.Fail("DicomAttributeCollection.GetAttribute failed"); } catch (DicomException) { } try { DicomAttribute attrib = collection[tag.TagValue]; Assert.Fail("DicomAttributeCollection.GetAttribute failed"); } catch (DicomException) { } }
internal static void AddDateCondition(ref string query, DicomAttribute condition, string dbname) { if (condition.Exists && !string.IsNullOrEmpty(condition.Value.ToString()) && condition.Value.ToString() != "*") { if (condition.Value.ToString().IndexOf("-", StringComparison.Ordinal) == -1) // if Single Date { DateTime t = condition.DateTimeTo; //note: a single day span is less useful than the provided date to now for our specimen X_rays t = DateTime.Now; // t.Add(new TimeSpan(23, 59, 59)); AddSingleDateCondition(ref query, t, "<=", dbname); } else { AddSingleDateCondition(ref query, condition.DateTimeTo, "<=", dbname); } AddSingleDateCondition(ref query, condition.DateTimeFrom, ">=", dbname); } }
public override string[] GetValues() { if (Elements.Count == 0) { return(base.GetValues()); } if (Elements.Count > 1) { if (VR == DicomVr.TMvr || VR == DicomVr.DAvr) { List <string> values = new List <string> ( ); for (int index = 0; index < Elements.Count; index += 2) { DicomAttribute dateElement = null; DicomAttribute timeElement = null; string value = null; for (int localIndex = index; localIndex < index + 2 && localIndex < Elements.Count; localIndex++) { var element = Elements[localIndex]; if (element.Tag.VR == DicomVr.DAvr) { dateElement = element; } else if (element.Tag.VR == DicomVr.TMvr) { timeElement = element; } } if (null != dateElement) { } } } } return(base.GetValues( )); }
/// <summary> /// Recursively find UI attributes and try to map any known uids it finds (unknown uids are left alone) /// </summary> /// <param name="dataset"></param> /// <param name="uidMap"></param> private static void MapKnownUids(DicomAttributeCollection dataset, IDictionary <string, string> uidMap) { foreach (uint tag in GetTagsToRemap()) { DicomAttribute attribute = dataset[tag]; int count = (int)(0x7fffffff & attribute.Count); for (int n = 0; n < count; n++) { string originalUid = attribute.GetString(n, ""); if (uidMap.ContainsKey(originalUid)) { attribute.SetString(n, uidMap[originalUid]); } } } //foreach (DicomAttribute attribute in dataset) //{ // if (attribute is DicomAttributeUI) // { // int count = (int) (0x7fffffff & attribute.Count); // for (int n = 0; n < count; n++) // { // string originalUid = attribute.GetString(n, ""); // if (uidMap.ContainsKey(originalUid)) // { // attribute.SetString(n, uidMap[originalUid]); // } // } // } // else if (attribute is DicomAttributeSQ) // { // DicomAttributeSQ sq = (DicomAttributeSQ) attribute; // int count = (int) (0x7fffffff & attribute.Count); // for (int n = 0; n < count; n++) // { // MapKnownUids(sq[n], uidMap); // } // } //} }
/// <summary> /// Gets whether or not the full header is needed in order to retrieve the <see cref="DicomAttribute"/> for /// the given tag, as opposed to the <see cref="InstanceXml">xml</see>, which may be partial. /// </summary> /// <returns>Whether or not the full header should be loaded via <see cref="LoadFullHeader"/>.</returns> protected virtual bool NeedFullHeader(uint tag) { if (_fullHeaderLoaded) { return(false); } var xmlDataSet = (InstanceXmlDicomAttributeCollection)SourceMessage.DataSet; // if it's a private tag and not already in the collection, we MUST retrieve full header // early releases of the study XML functionality excluded private tags but also did not report their exclusion if (DicomTag.IsPrivateTag(tag) && !xmlDataSet.Contains(tag)) { return(true); } if (xmlDataSet.IsTagExcluded(tag)) { return(true); } DicomAttribute attribute = base[tag]; if (attribute is DicomAttributeSQ) { // cache the results for the recursive SQ item excluded tags check - it adds up if you've got a multiframe image and functional group sequences get accessed repeatedly bool sequenceHasExcludedTags; if (!_sequenceHasExcludedTags.TryGetValue(tag, out sequenceHasExcludedTags)) { var items = attribute.Values as DicomSequenceItem[]; _sequenceHasExcludedTags[tag] = sequenceHasExcludedTags = (items != null && items.OfType <InstanceXmlDicomSequenceItem>().Any(item => item.HasExcludedTags(true))); } if (sequenceHasExcludedTags) { return(true); } } return(false); }
private bool TryGetXmlAttribute(uint tag, out DicomAttribute attribute) { if (_fullHeaderLoaded) { attribute = null; return(false); } var needFullHeader = false; var dataset = SourceMessage.DataSet; if (dataset.TryGetAttribute(tag, out attribute)) { //If it's a sequence, it can have excluded tags in it. if (IsSequenceWithExcludedTags(attribute)) { needFullHeader = true; } else { return(true); //We have all we need. } } if (!needFullHeader) { // if it's a private tag and not already in the collection (which has been checked already), we MUST retrieve full header // early releases of the study XML functionality excluded private tags but also did not report their exclusion if (DicomTag.IsPrivateTag(tag) || ((InstanceXmlDicomAttributeCollection)dataset).IsTagExcluded(tag)) { needFullHeader = true; } } if (needFullHeader) { LoadFullHeader(); } return(false); }
public void OnStudyEditing(WebEditStudyContext context) { Platform.Log(LogLevel.Info, "Updating OriginalAttributesSequence..."); List <DicomAttribute> values = new List <DicomAttribute>(); foreach (BaseImageLevelUpdateCommand c in context.EditCommands) { if (!(c is SetTagCommand)) { continue; } DicomAttribute value = c.UpdateEntry.TagPath.Tag.CreateDicomAttribute(); value.SetStringValue(c.UpdateEntry.OriginalValue); values.Add(value); } int cut = context.Reason.IndexOf("::"); context.EditCommands.Insert(0, new AddOriginalAttributes(CreateOriginalAttributesSequence(values, null, null, context.Reason.Substring(0, cut > DicomVr.CSvr.MaximumLength || cut < 0 ? Math.Min((int)DicomVr.CSvr.MaximumLength, context.Reason.Length) : cut)))); }
private static bool IsDateTimeAttributeToAdjust(DicomAttribute attribute) { return DateTimeTagsToAdjust.Contains(attribute.Tag.TagValue); }
private static bool IsUidAttributeToRemap(DicomAttribute attribute) { return UidsToRemap.Contains(attribute.Tag.TagValue); }
private static bool IsAttributeToNull(DicomAttribute attribute) { return TagsToNull.Contains(attribute.Tag.TagValue); }
private static bool IsPrivateAttribute(DicomAttribute attribute) { return (attribute.Tag.IsPrivate || attribute.Tag.Name == "Private Tag"); }
private static bool IsAttributeToRemove(DicomAttribute attribute) { return IsPrivateAttribute(attribute) || TagsToRemove.Contains(attribute.Tag.TagValue); }
private static XmlElement CreateDicomAttributeElement(XmlDocument document, DicomAttribute attribute, string name) { return CreateDicomAttributeElement(document, attribute.Tag, name); }
/// <summary> /// Sets the date time attribute values for the specified dicom attributes. /// Will first attempt to write to the <paramref name="dateTimeAttribute"/> if it is not null, otherwise /// it will write the values to the separate date and time attributes. /// </summary> /// <param name="value">The value.</param> /// <param name="dateTimeAttribute">The date time attribute.</param> /// <param name="dateAttribute">The date attribute.</param> /// <param name="timeAttribute">The time attribute.</param> public static void SetDateTimeAttributeValues(DateTime? value, DicomAttribute dateTimeAttribute, DicomAttribute dateAttribute, DicomAttribute timeAttribute) { if (dateTimeAttribute != null) { if (value.HasValue) dateTimeAttribute.SetDateTime(0, value.Value); else dateTimeAttribute.SetNullValue(); } else { SetDateTimeAttributeValues(value, dateAttribute, timeAttribute); } }
/// <summary> /// Temporary workaround code in place of DicomAttribute.SetInt32(0, value) which can throw a IndexOutOfRangeException if attribute is null /// </summary> /// <param name="attrib"></param> /// <param name="value"></param> public static void SetInt32(DicomAttribute attrib, int value) { //TODO - replace this with DicomAttribute.SetInt32(0, value) when it is fixed (ticket #1411) attrib.SetString(0, value.ToString()); }
private static void TrySetValue(int index, DicomAttribute attrib) { // one of these statements should be able to put a non-null value on the attribute try { attrib.SetDateTime(index, DateTime.Now); } catch(DicomException) { try { attrib.SetFloat32(index, 0f); } catch (DicomException) { try { attrib.SetInt16(index, 0); } catch (DicomException) { try { attrib.SetUInt16(index, 0); } catch (DicomException) { try { attrib.SetUid(index, DicomUid.GenerateUid()); } catch (DicomException) { try { attrib.SetString(index, "fdsa"); } catch (DicomException) { try { attrib.SetString(index, "1"); } catch (DicomException) { try { attrib.SetString(index, "11"); } catch (DicomException) { try { attrib.SetString(index, "1111"); } catch (DicomException) { try { attrib.SetString(index, "111111"); } catch (DicomException) { try { attrib.SetString(index, "11111111"); } catch (DicomException) { try { attrib.SetStringValue("asdf"); } catch (DicomException) { try { DicomSequenceItem item = new DicomSequenceItem(); attrib.AddSequenceItem(item); item[DicomTags.InstanceNumber].SetString(index, "1"); } catch (DicomException) { Assert.Fail("Test case deficiency: doesn't know how to set an attribute of VR {0}", attrib.Tag.VR.Name); } } } } } } } } } } } } } }
private object CheckAttributeCollection(DicomAttribute attrib) { if (attrib.IsEmpty || attrib.IsNull) return null; if (attrib.Tag.VR.Equals(DicomVr.SLvr)) return attrib.GetInt32(0, 0); if (attrib.Tag.VR.Equals(DicomVr.SSvr)) return attrib.GetInt16(0, 0); if (attrib.Tag.VR.Equals(DicomVr.ATvr) || attrib.Tag.VR.Equals(DicomVr.ULvr)) return attrib.GetUInt32(0, 0); if (attrib.Tag.VR.Equals(DicomVr.DSvr) || attrib.Tag.VR.Equals(DicomVr.FDvr)) return attrib.GetFloat64(0, 0f); if (attrib.Tag.VR.Equals(DicomVr.FLvr)) return attrib.GetFloat32(0, 0f); if (attrib.Tag.VR.Equals(DicomVr.ISvr)) return attrib.GetInt64(0, 0); if (attrib.Tag.VR.Equals(DicomVr.USvr)) return attrib.GetUInt16(0, 0); if (attrib.Tag.VR.Equals(DicomVr.SLvr)) return attrib.GetInt32(0, 0); if (attrib.Tag.VR.Equals(DicomVr.OBvr) || attrib.Tag.VR.Equals(DicomVr.OWvr) || attrib.Tag.VR.Equals(DicomVr.OFvr) || attrib.Tag.VR.Equals(DicomVr.ODvr)) return attrib.StreamLength.ToString(CultureInfo.InvariantCulture); return attrib.ToString().Trim(); }
/// <summary> /// Temporary workaround code in place of DicomAttribute.SetDateTime(0, value) which can throw a IndexOutOfRangeException if attribute is null /// </summary> /// <param name="attrib"></param> /// <param name="value"></param> public static void SetTime(DicomAttribute attrib, DateTime? value) { //TODO - replace this with DicomAttribute.SetDateTime(0, value) when it is fixed (ticket #1411) if (value.HasValue) attrib.SetString(0, string.Format(TimeParser.DicomFullTimeFormat, value.Value)); else attrib.SetNullValue(); }
/// <summary> /// Return an instance of the TMStringValidator object /// Note: the returned object may be shared among threads or objects. /// </summary> /// <param name="attribute"></param> /// <returns></returns> /// <remarks> /// ///</remarks> public static TMStringValidator GetInstance(DicomAttribute attribute) { lock (_mutex) { int key = GetKey(attribute); TMStringValidator validator = _map[key] as TMStringValidator; if (validator == null) { validator = new TMStringValidator(); _map[key] = validator; } return validator; } }
private static IEnumerable<DicomAttributeCollection> GetSubCollections(DicomAttribute attribute) { if (attribute is DicomAttributeSQ && attribute.Values != null) { DicomSequenceItem[] sequenceItems = (DicomSequenceItem[]) attribute.Values; foreach (DicomSequenceItem sequenceItem in sequenceItems) yield return sequenceItem; } }
private void RemapUidAttribute(DicomAttribute attribute) { int i = 0; foreach (string oldUid in (string[]) attribute.Values) { if (!String.IsNullOrEmpty(oldUid)) { string newUid; if (_uidMap.ContainsKey(oldUid)) { newUid = _uidMap[oldUid]; } else { newUid = DicomUid.GenerateUid().UID; if (String.IsNullOrEmpty(newUid) || newUid == oldUid) throw new DicomAnonymizerException("An error occurred while generating a new Uid."); _uidMap[oldUid] = newUid; } attribute.SetString(i++, newUid); } } }
/// <summary> /// Sets the specified date attribute values based on the specified <paramref name="value">Date value</paramref>. /// </summary> /// <param name="value">The value.</param> /// <param name="dateAttribute">The date attribute.</param> public static void SetDateAttributeValues(DateTime? value, DicomAttribute dateAttribute) { if (value.HasValue) { dateAttribute.SetDateTime(0, value.Value); } else { dateAttribute.SetNullValue(); } }
private void AdjustDateTimeAttribute(DicomAttribute attribute) { if (_studyDateDifference != null) { int i = 0; if (attribute is DicomAttributeDA) { foreach (string date in (string[]) attribute.Values) attribute.SetString(i++, AdjustDate(date, _studyDateDifference.Value)); } else if (attribute is DicomAttributeDT) { foreach (string datetime in (string[]) attribute.Values) attribute.SetString(i++, AdjustDateTime(datetime, _studyDateDifference.Value)); } } else { //remove it altogether. attribute.SetNullValue(); } }
private static string ReadSequenceItem(DicomAttribute attribute, int index) { if (attribute is DicomAttributeSQ) return (((DicomAttributeSQ) attribute)[index])[DicomTags.TextValue].ToString(); return null; }
private static StudyXmlTagInclusion AttributeShouldBeIncluded(DicomAttribute attribute, StudyXmlOutputSettings settings) { if (settings == null) return StudyXmlTagInclusion.IncludeTagValue; if (attribute is DicomAttributeSQ) { if (attribute.Tag.IsPrivate) return settings.IncludePrivateValues; return StudyXmlTagInclusion.IncludeTagValue; } // private tag if (attribute.Tag.IsPrivate) { if (settings.IncludePrivateValues != StudyXmlTagInclusion.IncludeTagValue) return settings.IncludePrivateValues; } // check type if (attribute is DicomAttributeUN) { if (settings.IncludeUnknownTags != StudyXmlTagInclusion.IncludeTagValue) return settings.IncludeUnknownTags; } // This check isn't needed, but it bypasses the StreamLength calculation if its not needed if (settings.IncludeLargeTags == StudyXmlTagInclusion.IncludeTagValue) return settings.IncludeLargeTags; // check the size ulong length = attribute.StreamLength; if (length <= settings.MaxTagLength) return StudyXmlTagInclusion.IncludeTagValue; // Move here, such that we first check if the tag should be excluded if ((attribute is DicomAttributeOB) || (attribute is DicomAttributeOW) || (attribute is DicomAttributeOF) || (attribute is DicomFragmentSequence)) return StudyXmlTagInclusion.IncludeTagExclusion; return settings.IncludeLargeTags; }