/// <summary> /// Copy from the given source Dataset into the local Dataset as defined by the /// default Tag Type list. In addition to the base copy we need to copy attributes from the /// Request Attributes Sequence (if present) and the Scheduled Procedure Step (if present). /// </summary> /// <param name="sourceDataset">Source Dataset used to populate the local Dataset.</param> public override void CopyFrom(AttributeSet sourceDataset) { // perform base copy base.CopyFrom(sourceDataset); // check if the Request Attributes Sequence is available in the source dataset DvtkData.Dimse.Attribute requestAttributesSequence = sourceDataset.GetAttribute(Tag.REQUEST_ATTRIBUTES_SEQUENCE); if (requestAttributesSequence != null) { SequenceOfItems sequenceOfItems = (SequenceOfItems)requestAttributesSequence.DicomValue; if (sequenceOfItems.Sequence.Count == 1) { DvtkData.Dimse.SequenceItem item = sequenceOfItems.Sequence[0]; // copy item attributes too base.CopyFrom(item); } } // check if the Scheduled Procedure Step Sequence is available in the source dataset DvtkData.Dimse.Attribute scheduledProcedureStepSequence = sourceDataset.GetAttribute(Tag.SCHEDULED_PROCEDURE_STEP_SEQUENCE); if (scheduledProcedureStepSequence != null) { SequenceOfItems sequenceOfItems = (SequenceOfItems)scheduledProcedureStepSequence.DicomValue; if (sequenceOfItems.Sequence.Count == 1) { DvtkData.Dimse.SequenceItem item = sequenceOfItems.Sequence[0]; // copy item attributes too base.CopyFrom(item); } } }
/// <summary> /// Check if the given match dataset is found in the local dataset using the default Tag Type list. /// A check is made to see if all the attributes in the given match dataset are present in the local /// dataset. In addition to the base match we need to try to match attributes from the /// Request Attributes Sequence (if present). /// </summary> /// <param name="matchDataset">Match dataset to check.</param> /// <returns>Boolean indicating if the match attributes are present in the local dataset.</returns> public override bool IsFoundIn(AttributeSet matchDataset) { bool isFoundIn = base.IsFoundIn(matchDataset); if (isFoundIn == false) { // check if the Request Attributes Sequence is available in the match dataset DvtkData.Dimse.Attribute requestAttributesSequence = matchDataset.GetAttribute(Tag.REQUEST_ATTRIBUTES_SEQUENCE); if (requestAttributesSequence != null) { SequenceOfItems sequenceOfItems = (SequenceOfItems)requestAttributesSequence.DicomValue; if (sequenceOfItems.Sequence.Count == 1) { // set up a temporary tag list to check the relevant tags in the Request Attributes Sequence TagTypeList itemTagTypeList = new TagTypeList(); itemTagTypeList.Add(new TagType(Tag.REQUESTED_PROCEDURE_ID, TagTypeEnum.TagOptional)); DvtkData.Dimse.SequenceItem item = sequenceOfItems.Sequence[0]; // check if found in item isFoundIn = base.IsFoundIn(itemTagTypeList, item); } } } return isFoundIn; }
/// <summary> /// Check if the given match dataset is found in the local dataset using the default Tag Type list. /// A check is made to see if all the attributes in the given match dataset are present in the local /// dataset. /// </summary> /// <param name="matchDataset">Match dataset to check.</param> /// <returns>Boolean indicating if the match attributes are present in the local dataset.</returns> public virtual bool IsFoundIn(AttributeSet matchDataset) { return IsFoundIn(_tagTypeList, matchDataset, false); }
/// <summary> /// Copy the attribute with a Unique tag from the local Dataset into the given destination Dataset. /// </summary> /// <param name="destinationDataset">Dataset being populated with the Unique tag attribute.</param> public void CopyUniqueTagTo(AttributeSet destinationDataset) { CopyTo(_tagTypeList, destinationDataset, true); }
/// <summary> /// Copy from the local Dataset into the given destination Dataset as defined by the /// given Tag Type list. /// </summary> /// <param name="tagTypeList">Tag Type list used to define copy.</param> /// <param name="destinationDataset">Dataset being populated by the given Tag Type list.</param> public void CopyTo(TagTypeList tagTypeList, AttributeSet destinationDataset) { CopyTo(tagTypeList, destinationDataset, false); }
/// <summary> /// Copy from the given source Dataset into the local Dataset as defined by the /// given Tag Type list. /// </summary> /// <param name="tagTypeList">Tag Type list identifying attributes to copy.</param> /// <param name="sourceDataset">Source Dataset used to populate the local Dataset.</param> public void CopyFrom(TagTypeList tagTypeList, AttributeSet sourceDataset) { if (tagTypeList != null) { foreach (TagType tagType in tagTypeList) { DvtkData.Dimse.Attribute sourceAttribute = sourceDataset.GetAttribute(tagType.Tag); if (sourceAttribute != null) { _dataset.Add(sourceAttribute); } } } }
/// <summary> /// Copy from the given source Dataset into the local Dataset as defined by the /// default Tag Type list. /// </summary> /// <param name="sourceDataset">Source Dataset used to populate the local Dataset.</param> public virtual void CopyFrom(AttributeSet sourceDataset) { CopyFrom(_tagTypeList, sourceDataset); }
/// <summary> /// Copy from the local Dataset into the given destination Dataset as defined by the /// given Tag Type list. If the copyUniqueTagOnly parameter is true - only copy the Unique Tag attribute. /// </summary> /// <param name="tagTypeList">Tag Type list used to define copy.</param> /// <param name="destinationDataset">Dataset being populated by the given Tag Type list.</param> /// <param name="copyUniqueTagOnly">Boolean indicator to define use of Unique Tag.</param> private void CopyTo(TagTypeList tagTypeList, AttributeSet destinationDataset, bool copyUniqueTagOnly) { if (tagTypeList != null) { foreach (TagType tagType in tagTypeList) { // check if we should only copy the unique TagType if (copyUniqueTagOnly) { if (tagType.Type != TagTypeEnum.TagUnique) continue; } DvtkData.Dimse.Attribute destinationAttribute = _dataset.GetAttribute(tagType.Tag); if (destinationAttribute != null) { destinationDataset.Add(destinationAttribute); } } } }
/// <summary> /// Copy the defined Additional Attributes from the local additional attributes to the given /// dataset. /// </summary> /// <param name="destinationDataset">Destinaion dataset for loacl additional attributes.</param> public void CopyAdditionalAttributes(AttributeSet destinationDataset) { // try adding all additional attributes foreach (DvtkData.Dimse.Attribute additionalAttribute in _additionalDatasetOverWrite) { // check if the attribute should first be removed from the dataset DvtkData.Dimse.Attribute lAdditionalAttribute = destinationDataset.GetAttribute(additionalAttribute.Tag); if (lAdditionalAttribute != null) { destinationDataset.Remove(lAdditionalAttribute); } // add to the dataset destinationDataset.Add(additionalAttribute); } // try adding all additional attributes foreach (DvtkData.Dimse.Attribute additionalAttribute in _additionalDatasetNoOverWrite) { // only add if not already in the dataset if (destinationDataset.GetAttribute(additionalAttribute.Tag) == null) { destinationDataset.Add(additionalAttribute); } } }
public BaseInformationEntityList ChildrenWithUniqueTagFoundIn(AttributeSet matchDataset) { BaseInformationEntityList baseInformationEntityList = new BaseInformationEntityList(); foreach(BaseInformationEntity baseInformationEntity in Children) { if (baseInformationEntity.IsUniqueTagFoundIn(matchDataset)) { baseInformationEntityList.Add(baseInformationEntity); } } return(baseInformationEntityList); }
/// <summary> /// Includes the non-dataset attributes in the information model. /// Handled attributes are, /// MODALITIES_IN_STUDY /// NUMBER_OF_PATIENT_RELATED_STUDIES /// NUMBER_OF_PATIENT_RELATED_SERIES /// NUMBER_OF_PATIENT_RELATED_INSTANCES /// NUMBER_OF_STUDY_RELATED_SERIES /// NUMBER_OF_STUDY_RELATED_INSTANCES. /// NUMBER_OF_SERIES_RELATED_INSTANCES /// </summary> /// <param name="sourceDataset"></param> public void CheckForSpecialTags(AttributeSet sourceDataset) { if (_tagTypeList != null&&sourceDataset!=null) { foreach (TagType tagType in _tagTypeList) { if (tagType.Tag == Tag.MODALITIES_IN_STUDY) { DvtkData.Dimse.Attribute sourceAttribute = sourceDataset.GetAttribute(tagType.Tag); if (sourceAttribute != null) { // if an entry already exists - remove it DvtkData.Dimse.Attribute destinationAttribute = _dataset.GetAttribute(tagType.Tag); if (destinationAttribute != null) { _dataset.Remove(destinationAttribute); } if (destinationAttribute != null && destinationAttribute.Tag == Tag.MODALITIES_IN_STUDY && destinationAttribute.ValueRepresentation == VR.CS) { StringCollection values = ((CodeString)destinationAttribute.DicomValue).Values; string actualModality = ((CodeString)sourceDataset.GetAttribute(Tag.MODALITY).DicomValue).Values[0]; if (actualModality != null && !values.Contains(actualModality.Trim())) { values.Add(actualModality.Trim()); } CodeString cs = new CodeString(); cs.Values = values; sourceAttribute.DicomValue = cs; System.UInt32 length = 0; foreach (String data in cs.Values) { length += (System.UInt32)data.Length; } sourceAttribute.Length = length + (System.UInt32)cs.Values.Count - 1; } _dataset.Add(sourceAttribute); } else if (tagType.Tag == Tag.MODALITIES_IN_STUDY) { sourceAttribute = new DvtkData.Dimse.Attribute(); sourceAttribute.Tag = Tag.MODALITIES_IN_STUDY; sourceAttribute.Name = "Modalities in study"; DvtkData.Dimse.Attribute destinationAttribute = _dataset.GetAttribute(tagType.Tag); string actualModality = ((CodeString)sourceDataset.GetAttribute(Tag.MODALITY).DicomValue).Values[0]; StringCollection values = null; if (destinationAttribute != null && destinationAttribute.ValueRepresentation == VR.CS) { _dataset.Remove(destinationAttribute); values = ((CodeString)destinationAttribute.DicomValue).Values; } if (values == null) values = new StringCollection(); if (actualModality != null && !values.Contains(actualModality.Trim())) { values.Add(actualModality.Trim()); } CodeString cs = new CodeString(); cs.Values = values; sourceAttribute.DicomValue = cs; System.UInt32 length = 0; foreach (String data in cs.Values) { length += (System.UInt32)data.Length; } sourceAttribute.Length = length + (System.UInt32)cs.Values.Count - 1; _dataset.Add(sourceAttribute); } } else if (tagType.Tag == Tag.NUMBER_OF_PATIENT_RELATED_STUDIES&&_level=="PATIENT") { HandlePatientRelatedStudies(tagType, sourceDataset); } else if (tagType.Tag == Tag.NUMBER_OF_PATIENT_RELATED_SERIES&& _level=="PATIENT") { HandlePatientRelatedSeries(tagType, sourceDataset); } else if (tagType.Tag == Tag.NUMBER_OF_PATIENT_RELATED_INSTANCES&&_level=="PATIENT") { HandlePatientRelatedInstances(tagType, sourceDataset); } else if (tagType.Tag == Tag.NUMBER_OF_STUDY_RELATED_SERIES&&_level=="STUDY") { HandleStudyRelatedSeries(tagType, sourceDataset); } else if (tagType.Tag == Tag.NUMBER_OF_STUDY_RELATED_INSTANCES&&_level=="STUDY") { HandleStudyRelatedInstances(tagType, sourceDataset); } else if (tagType.Tag == Tag.NUMBER_OF_SERIES_RELATED_INSTANCES&&_level=="SERIES") { HandleSeriesRelatedInstances(tagType, sourceDataset); } } } }
void HandleStudyRelatedSeries(TagType tagType, AttributeSet sourceDataset) { DvtkData.Dimse.Attribute sourceAttribute = sourceDataset.GetAttribute(tagType.Tag); if (sourceAttribute == null) { sourceAttribute = new DvtkData.Dimse.Attribute(); sourceAttribute.Tag = Tag.NUMBER_OF_STUDY_RELATED_SERIES; sourceAttribute.Name = "Number of Study related Series"; } DvtkData.Dimse.Attribute destinationAttribute = _dataset.GetAttribute(tagType.Tag); if (destinationAttribute != null) { _dataset.Remove(destinationAttribute); } IntegerString str = new IntegerString(); StringCollection colle = new StringCollection(); colle.Add(Children.Count.ToString()); str.Values = colle; System.UInt32 length = 0; foreach (String data in str.Values) { length += (System.UInt32)data.Length; } sourceAttribute.DicomValue = str; sourceAttribute.Length = length + (System.UInt32)str.Values.Count - 1; _dataset.Add(sourceAttribute); }
void HandlePatientRelatedSeries(TagType tagType, AttributeSet sourceDataset) { DvtkData.Dimse.Attribute sourceAttribute = sourceDataset.GetAttribute(tagType.Tag); if (sourceAttribute == null) { sourceAttribute = new DvtkData.Dimse.Attribute(); sourceAttribute.Tag = Tag.NUMBER_OF_PATIENT_RELATED_SERIES; sourceAttribute.Name = "Number of Patient related series"; } DvtkData.Dimse.Attribute destinationAttribute = _dataset.GetAttribute(tagType.Tag); if (destinationAttribute != null) { _dataset.Remove(destinationAttribute); } IntegerString str = new IntegerString(); StringCollection colle = new StringCollection(); int noOfSeries = 0; for (int i = 0; i < Children.Count; i++) { noOfSeries = noOfSeries + Children[i].Children.Count; } colle.Add(noOfSeries.ToString()); str.Values = colle; System.UInt32 length = 0; foreach (String data in str.Values) { length += (System.UInt32)data.Length; } sourceAttribute.DicomValue = str; sourceAttribute.Length = length + (System.UInt32)str.Values.Count - 1; _dataset.Add(sourceAttribute); //DvtkData.Dimse.Attribute sourceAttribute = sourceDataset.GetAttribute(tagType.Tag); //if (sourceAttribute != null) //{ // // if an entry already exists - remove it // DvtkData.Dimse.Attribute destinationAttribute = _dataset.GetAttribute(tagType.Tag); // if (destinationAttribute != null) // { // _dataset.Remove(destinationAttribute); // } // if (destinationAttribute != null && destinationAttribute.Tag == Tag.NUMBER_OF_PATIENT_RELATED_STUDIES) // { // IntegerString str = new IntegerString(); // StringCollection colle = new StringCollection(); // int noOfSeries = 0; // for (int i = 0; i < Children.Count; i++) // { // noOfSeries = noOfSeries + Children[i].Children.Count; // } // colle.Add(noOfSeries.ToString()); // str.Values = colle; // System.UInt32 length = 0; // foreach (String data in str.Values) // { // length += (System.UInt32)data.Length; // } // sourceAttribute.Length = length + (System.UInt32)str.Values.Count - 1; // } // _dataset.Add(sourceAttribute); //} //else //{ // sourceAttribute = new DvtkData.Dimse.Attribute(); // sourceAttribute.Tag = Tag.NUMBER_OF_PATIENT_RELATED_STUDIES; // sourceAttribute.Name = "Number of Patient related series"; // DvtkData.Dimse.Attribute destinationAttribute = _dataset.GetAttribute(tagType.Tag); // StringCollection values = null; // if (destinationAttribute != null) // { // _dataset.Remove(destinationAttribute); // } // values = new StringCollection(); // int noOfSeries = 0; // for (int i = 0; i < Children.Count; i++) // { // noOfSeries = noOfSeries + Children[i].Children.Count; // } // values.Add(noOfSeries.ToString()); // IntegerString IS = new IntegerString(); // IS.Values = values; // sourceAttribute.DicomValue = IS; // System.UInt32 length = 0; // foreach (String data in IS.Values) // { // length += (System.UInt32)data.Length; // } // sourceAttribute.Length = length + (System.UInt32)IS.Values.Count - 1; // _dataset.Add(sourceAttribute); //} }
void HandlePatientRelatedInstances(TagType tagType, AttributeSet sourceDataset) { DvtkData.Dimse.Attribute sourceAttribute = sourceDataset.GetAttribute(tagType.Tag); if (sourceAttribute == null) { sourceAttribute = new DvtkData.Dimse.Attribute(); sourceAttribute.Tag = Tag.NUMBER_OF_PATIENT_RELATED_INSTANCES; sourceAttribute.Name = "Number of Patient related instances"; } DvtkData.Dimse.Attribute destinationAttribute = _dataset.GetAttribute(tagType.Tag); if (destinationAttribute != null) { _dataset.Remove(destinationAttribute); } IntegerString str = new IntegerString(); StringCollection colle = new StringCollection(); int noOfInstances = 0; for (int i = 0; i < Children.Count; i++) { for (int j = 0; j < Children[i].Children.Count; j++) { noOfInstances = noOfInstances + Children[i].Children[j].Children.Count; } } colle.Add(noOfInstances.ToString()); str.Values = colle; System.UInt32 length = 0; foreach (String data in str.Values) { length += (System.UInt32)data.Length; } sourceAttribute.DicomValue = str; sourceAttribute.Length = length + (System.UInt32)str.Values.Count - 1; _dataset.Add(sourceAttribute); }
/// <summary> /// Check if the given match dataset is found in the local dataset using the given Tag Type list. /// A check is made to see if all the attributes in the given match dataset are present in the local /// dataset. /// </summary> /// <param name="tagTypeList">Match Tag Type list.</param> /// <param name="matchDataset">Match dataset to check.</param> /// <returns>Boolean indicating if the match attributes are present in the local dataset.</returns> public bool IsFoundIn(TagTypeList tagTypeList, AttributeSet matchDataset) { return IsFoundIn(tagTypeList, matchDataset, false); }
/// <summary> /// Check if the Unique Tag as defined in the local Tag Type list is present in the given match dataset. /// </summary> /// <param name="matchDataset">Dataset to check for match.</param> /// <returns>Boolean indicating if the match dataset contains the default Unique Tag.</returns> public bool IsUniqueTagFoundIn(AttributeSet matchDataset) { return IsFoundIn(_tagTypeList, matchDataset, true); }
/// <summary> /// Copy from the given source Dataset into the local Dataset as defined by the /// given Tag Type list. /// </summary> /// <param name="tagTypeList">Tag Type list identifying attributes to copy.</param> /// <param name="sourceDataset">Source Dataset used to populate the local Dataset.</param> public void CopyFrom(TagTypeList tagTypeList, AttributeSet sourceDataset) { if (tagTypeList != null) { foreach (TagType tagType in tagTypeList) { DvtkData.Dimse.Attribute sourceAttribute = sourceDataset.GetAttribute(tagType.Tag); if (sourceAttribute != null) { // if an entry already exists - remove it DvtkData.Dimse.Attribute destinationAttribute = _dataset.GetAttribute(tagType.Tag); if (destinationAttribute != null) { _dataset.Remove(destinationAttribute); } //if (destinationAttribute != null && destinationAttribute.Tag == Tag.MODALITIES_IN_STUDY&&destinationAttribute.ValueRepresentation==VR.CS) //{ // StringCollection values = ((CodeString)destinationAttribute.DicomValue).Values; // string actualModality = ((CodeString)sourceDataset.GetAttribute(Tag.MODALITY).DicomValue).Values[0]; // if (actualModality!=null&& !values.Contains(actualModality.Trim())) // { // values.Add(actualModality.Trim()); // } // CodeString cs=new CodeString(); // cs.Values=values; // sourceAttribute.DicomValue = cs; // System.UInt32 length = 0; // foreach (String data in cs.Values) // { // length += (System.UInt32)data.Length; // } // sourceAttribute.Length = length + (System.UInt32)cs.Values.Count - 1; //} _dataset.Add(sourceAttribute); } //else if (tagType.Tag == Tag.MODALITIES_IN_STUDY) //{ // sourceAttribute = new DvtkData.Dimse.Attribute(); // sourceAttribute.Tag = Tag.MODALITIES_IN_STUDY; // sourceAttribute.Name = "Modalities in study"; // DvtkData.Dimse.Attribute destinationAttribute = _dataset.GetAttribute(tagType.Tag); // string actualModality = ((CodeString)sourceDataset.GetAttribute(Tag.MODALITY).DicomValue).Values[0]; // StringCollection values=null; // if (destinationAttribute != null&&destinationAttribute.ValueRepresentation==VR.CS) // { // _dataset.Remove(destinationAttribute); // values = ((CodeString)destinationAttribute.DicomValue).Values; // } // if (values == null) // values = new StringCollection(); // if (actualModality != null && !values.Contains(actualModality.Trim())) // { // values.Add(actualModality.Trim()); // } // CodeString cs = new CodeString(); // cs.Values = values; // sourceAttribute.DicomValue = cs; // System.UInt32 length = 0; // foreach (String data in cs.Values) // { // length += (System.UInt32)data.Length; // } // sourceAttribute.Length = length + (System.UInt32)cs.Values.Count - 1; // _dataset.Add(sourceAttribute); //} } } }
/// <summary> /// Check if the given match dataset is found in the local dataset using the given Tag Type list. /// A check is made to see if all the attributes in the given match dataset are present in the local /// dataset. if the given matchOnUniqueTagOnly parameter is true only the Unique Tags will be checked. /// </summary> /// <param name="tagTypeList">Match Tag Type list.</param> /// <param name="matchDataset">Match dataset to check.</param> /// <param name="matchOnUniqueTagOnly">Boolean indicating if only the Unique Tag should be checked.</param> /// <returns>Boolean indicating if the match attributes are present in the local dataset.</returns> private bool IsFoundIn(TagTypeList tagTypeList, AttributeSet matchDataset, bool matchOnUniqueTagOnly) { bool isFound = true; bool uniqueTagFound = false; if (tagTypeList != null) { foreach (TagType tagType in tagTypeList) { // check if we should try to match on the unique TagType only if (matchOnUniqueTagOnly) { if (tagType.Type != TagTypeEnum.TagUnique) continue; } DvtkData.Dimse.Attribute thisAttribute = _dataset.GetAttribute(tagType.Tag); DvtkData.Dimse.Attribute matchAttribute = matchDataset.GetAttribute(tagType.Tag); if ((thisAttribute != null) && (matchAttribute == null)) { isFound = false; } else if ((thisAttribute == null) && (matchAttribute != null)) { isFound = false; } else if ((thisAttribute != null) && (matchAttribute != null)) { // set the unique tag used flag - if we get this far in the code when matching the // unique tag only then we must have found it if (matchOnUniqueTagOnly) { uniqueTagFound = true; } if (thisAttribute.ValueRepresentation != matchAttribute.ValueRepresentation) { isFound = false; } else { if ((thisAttribute.Length == 0) && (matchAttribute.Length ==0)) { // found } else if (thisAttribute.Length == 0) { // not found isFound = false; } else if (matchAttribute.Length == 0) { // not found isFound = false; } else { switch(thisAttribute.ValueRepresentation) { case VR.AE: { ApplicationEntity thisApplicationEntity = (ApplicationEntity)thisAttribute.DicomValue; ApplicationEntity matchApplicationEntity = (ApplicationEntity)matchAttribute.DicomValue; if (thisApplicationEntity.Values.Count != matchApplicationEntity.Values.Count) { isFound = false; } else { for (int i = 0; i < thisApplicationEntity.Values.Count; i++) { if (!WildCardMatchString(matchApplicationEntity.Values[i], thisApplicationEntity.Values[i])) { isFound = false; break; } } } break; } case VR.AS: { AgeString thisAgeString = (AgeString)thisAttribute.DicomValue; AgeString matchAgeString = (AgeString)matchAttribute.DicomValue; if (thisAgeString.Values.Count != matchAgeString.Values.Count) { isFound = false; } else { for (int i = 0; i < thisAgeString.Values.Count; i++) { if (!MatchString(matchAgeString.Values[i], thisAgeString.Values[i])) { isFound = false; break; } } } break; } case VR.AT: { AttributeTag thisAttributeTag = (AttributeTag)thisAttribute.DicomValue; AttributeTag matchAttributeTag = (AttributeTag)matchAttribute.DicomValue; if (thisAttributeTag.Values.Count != matchAttributeTag.Values.Count) { isFound = false; } else { for (int i = 0; i < thisAttributeTag.Values.Count; i++) { if (matchAttributeTag.Values[i] != thisAttributeTag.Values[i]) { isFound = false; break; } } } break; } case VR.CS: { CodeString thisCodeString = (CodeString)thisAttribute.DicomValue; CodeString matchCodeString = (CodeString)matchAttribute.DicomValue; if (thisCodeString.Values.Count != matchCodeString.Values.Count) { isFound = false; } else { for (int i = 0; i < thisCodeString.Values.Count; i++) { if (!WildCardMatchString(matchCodeString.Values[i], thisCodeString.Values[i])) { isFound = false; break; } } } break; } case VR.DA: { Date thisDate = (Date)thisAttribute.DicomValue; Date matchDate = (Date)matchAttribute.DicomValue; if (thisDate.Values.Count != matchDate.Values.Count) { isFound = false; } else { for (int i = 0; i < thisDate.Values.Count; i++) { System.String thisDateString = thisDate.Values[i].Trim(); System.String matchDateString = matchDate.Values[i].Trim(); switch (matchDateString.Length) { case 9: // ToDate = -YYYYMMDD // FromDate = YYYYMMDD- if (matchDateString.StartsWith("-")) { System.String date = matchDateString.Substring(1,8); int comparison = thisDateString.CompareTo(date); if (comparison > 0) { isFound = false; } } else if (matchDateString.EndsWith("-")) { System.String date = matchDateString.Substring(0,8); int comparison = thisDateString.CompareTo(date); if (comparison < 0) { isFound = false; } } break; case 17: // DateRange = YYYYMMDD-YYYYMMDD System.String[] dates = matchDateString.Split('-'); int comparison1 = thisDateString.CompareTo(dates[0]); int comparison2 = thisDateString.CompareTo(dates[1]); if ((comparison1 < 0) || (comparison2 > 0)) { isFound = false; } break; case 8: // Date = YYYYMMDD default: if (!MatchString(matchDateString, thisDateString)) { isFound = false; } break; } if (isFound == false) break; } } break; } case VR.DS: { DecimalString thisDecimalString = (DecimalString)thisAttribute.DicomValue; DecimalString matchDecimalString = (DecimalString)matchAttribute.DicomValue; if (thisDecimalString.Values.Count != matchDecimalString.Values.Count) { isFound = false; } else { for (int i = 0; i < thisDecimalString.Values.Count; i++) { if (!MatchString(matchDecimalString.Values[i], thisDecimalString.Values[i])) { isFound = false; break; } } } break; } case VR.DT: { DvtkData.Dimse.DateTime thisDateTime = (DvtkData.Dimse.DateTime)thisAttribute.DicomValue; DvtkData.Dimse.DateTime matchDateTime = (DvtkData.Dimse.DateTime)matchAttribute.DicomValue; if (thisDateTime.Values.Count != matchDateTime.Values.Count) { isFound = false; } else { for (int i = 0; i < thisDateTime.Values.Count; i++) { if (!MatchString(matchDateTime.Values[i], thisDateTime.Values[i])) { isFound = false; break; } } } break; } case VR.FD: { FloatingPointDouble thisFloatingPointDouble = (FloatingPointDouble)thisAttribute.DicomValue; FloatingPointDouble matchFloatingPointDouble = (FloatingPointDouble)matchAttribute.DicomValue; if (thisFloatingPointDouble.Values.Count != matchFloatingPointDouble.Values.Count) { isFound = false; } else { for (int i = 0; i < thisFloatingPointDouble.Values.Count; i++) { if (matchFloatingPointDouble.Values[i] != thisFloatingPointDouble.Values[i]) { isFound = false; break; } } } break; } case VR.FL: { FloatingPointSingle thisFloatingPointSingle = (FloatingPointSingle)thisAttribute.DicomValue; FloatingPointSingle matchFloatingPointSingle = (FloatingPointSingle)matchAttribute.DicomValue; if (thisFloatingPointSingle.Values.Count != matchFloatingPointSingle.Values.Count) { isFound = false; } else { for (int i = 0; i < thisFloatingPointSingle.Values.Count; i++) { if (matchFloatingPointSingle.Values[i] != thisFloatingPointSingle.Values[i]) { isFound = false; break; } } } break; } case VR.IS: { IntegerString thisIntegerString = (IntegerString)thisAttribute.DicomValue; IntegerString matchIntegerString = (IntegerString)matchAttribute.DicomValue; if (thisIntegerString.Values.Count != matchIntegerString.Values.Count) { isFound = false; } else { for (int i = 0; i < thisIntegerString.Values.Count; i++) { if (!MatchString(matchIntegerString.Values[i], thisIntegerString.Values[i])) { isFound = false; break; } } } break; } case VR.LO: { LongString thisLongString = (LongString)thisAttribute.DicomValue; LongString matchLongString = (LongString)matchAttribute.DicomValue; if (thisLongString.Values.Count != matchLongString.Values.Count) { isFound = false; } else { for (int i = 0; i < thisLongString.Values.Count; i++) { if (!WildCardMatchString(matchLongString.Values[i], thisLongString.Values[i])) { isFound = false; break; } } } break; } case VR.LT: { break; } case VR.OB: { break; } case VR.OF: { break; } case VR.OW: { break; } case VR.PN: { PersonName thisPersonName = (PersonName)thisAttribute.DicomValue; PersonName matchPersonName = (PersonName)matchAttribute.DicomValue; if (thisPersonName.Values.Count != matchPersonName.Values.Count) { isFound = false; } else { for (int i = 0; i < thisPersonName.Values.Count; i++) { if (!WildCardMatchString(matchPersonName.Values[i], thisPersonName.Values[i])) { isFound = false; break; } } } break; } case VR.SH: { ShortString thisShortString = (ShortString)thisAttribute.DicomValue; ShortString matchShortString = (ShortString)matchAttribute.DicomValue; if (thisShortString.Values.Count != matchShortString.Values.Count) { isFound = false; } else { for (int i = 0; i < thisShortString.Values.Count; i++) { if (!WildCardMatchString(matchShortString.Values[i], thisShortString.Values[i])) { isFound = false; break; } } } break; } case VR.SL: { SignedLong thisSignedLong = (SignedLong)thisAttribute.DicomValue; SignedLong matchSignedLong = (SignedLong)matchAttribute.DicomValue; if (thisSignedLong.Values.Count != matchSignedLong.Values.Count) { isFound = false; } else { for (int i = 0; i < thisSignedLong.Values.Count; i++) { if (matchSignedLong.Values[i] != thisSignedLong.Values[i]) { isFound = false; break; } } } break; } case VR.SQ: { // SequenceOfItems sequenceOfItems = (SequenceOfItems)attribute.DicomValue; // foreach (SequenceItem item in sequenceOfItems.Sequence) // { // } break; } case VR.SS: { SignedShort thisSignedShort = (SignedShort)thisAttribute.DicomValue; SignedShort matchSignedShort = (SignedShort)matchAttribute.DicomValue; if (thisSignedShort.Values.Count != matchSignedShort.Values.Count) { isFound = false; } else { for (int i = 0; i < thisSignedShort.Values.Count; i++) { if (matchSignedShort.Values[i] != thisSignedShort.Values[i]) { isFound = false; break; } } } break; } case VR.ST: { break; } case VR.TM: { Time thisTime = (Time)thisAttribute.DicomValue; Time matchTime = (Time)matchAttribute.DicomValue; if (thisTime.Values.Count != matchTime.Values.Count) { isFound = false; } else { for (int i = 0; i < thisTime.Values.Count; i++) { System.String thisTimeString = thisTime.Values[i].Trim(); System.String matchTimeString = matchTime.Values[i].Trim(); switch (matchTimeString.Length) { case 7: // ToDate = -HHMMSS // FromDate = HHMMSS- if (matchTimeString.StartsWith("-")) { System.String time = matchTimeString.Substring(1,6); int comparison = thisTimeString.CompareTo(time); if (comparison > 0) { isFound = false; } } else if (matchTimeString.EndsWith("-")) { System.String time = matchTimeString.Substring(0,6); int comparison = thisTimeString.CompareTo(time); if (comparison < 0) { isFound = false; } } break; case 13: // DateRange = HHMMSS-HHMMSS System.String[] times = matchTimeString.Split('-'); int comparison1 = thisTimeString.CompareTo(times[0]); int comparison2 = thisTimeString.CompareTo(times[1]); if ((comparison1 < 0) || (comparison2 > 0)) { isFound = false; } break; case 6: // Date = HHMMSS default: if (!MatchString(matchTimeString, thisTimeString)) { isFound = false; } break; } if (isFound == false) break; } } break; } case VR.UI: { UniqueIdentifier thisUniqueIdentifier = (UniqueIdentifier)thisAttribute.DicomValue; UniqueIdentifier matchUniqueIdentifier = (UniqueIdentifier)matchAttribute.DicomValue; // check for list of UID matching if ((thisUniqueIdentifier.Values.Count == 1) && (matchUniqueIdentifier.Values.Count > 1)) { isFound = false; // iterate over all the possible matches for (int i = 0; i < matchUniqueIdentifier.Values.Count; i++) { if (MatchString(matchUniqueIdentifier.Values[i], thisUniqueIdentifier.Values[0])) { isFound = true; break; } } } else if (thisUniqueIdentifier.Values.Count == matchUniqueIdentifier.Values.Count) { for (int i = 0; i < thisUniqueIdentifier.Values.Count; i++) { if (!MatchString(matchUniqueIdentifier.Values[i], thisUniqueIdentifier.Values[i])) { isFound = false; break; } } } else { isFound = false; } break; } case VR.UL: { UnsignedLong thisUnsignedLong = (UnsignedLong)thisAttribute.DicomValue; UnsignedLong matchUnsignedLong = (UnsignedLong)matchAttribute.DicomValue; if (thisUnsignedLong.Values.Count != matchUnsignedLong.Values.Count) { isFound = false; } else { for (int i = 0; i < thisUnsignedLong.Values.Count; i++) { if (matchUnsignedLong.Values[i] != thisUnsignedLong.Values[i]) { isFound = false; break; } } } break; } case VR.UN: { break; } case VR.US: { UnsignedShort thisUnsignedShort = (UnsignedShort)thisAttribute.DicomValue; UnsignedShort matchUnsignedShort = (UnsignedShort)matchAttribute.DicomValue; if (thisUnsignedShort.Values.Count != matchUnsignedShort.Values.Count) { isFound = false; } else { for (int i = 0; i < thisUnsignedShort.Values.Count; i++) { if (matchUnsignedShort.Values[i] != thisUnsignedShort.Values[i]) { isFound = false; break; } } } break; } case VR.UT: { break; } default: isFound = false; break; } } } if (isFound == false) { break; } } } } // check for special case where we should match on the Unique Tag only - but it was not found if ((matchOnUniqueTagOnly == true) && (uniqueTagFound == false)) { // no match isFound = false; } return isFound; }
/// <summary> /// Copy the defined Additional Attributes from the local additional attributes to the given /// dataset. /// </summary> /// <param name="destinationDataset">Destinaion dataset for loacl additional attributes.</param> public void CopyAdditionalAttributes(AttributeSet destinationDataset) { // try adding all additional attributes foreach (DvtkData.Dimse.Attribute additionalAttribute in _additionalDataset) { // check that the attribute is not already in the destination dataset if (destinationDataset.GetAttribute(additionalAttribute.Tag) == null) { destinationDataset.Add(additionalAttribute); } } }