/// <summary> /// Compare the two messages. /// </summary> /// <param name="resultsReporter">Results reporter.</param> /// <param name="thatBaseComparator">Reference comparator.</param> /// <returns>bool - true = messages compared, false messages not compared</returns> public override bool Compare(ResultsReporter resultsReporter, BaseComparator thatBaseComparator) { bool compared = false; if (thatBaseComparator is DicomComparator) { DicomComparator thatDicomComparator = (DicomComparator)thatBaseComparator; // Check if both templates have been initialized correctly if ((this._template == null) || (thatDicomComparator._template == null)) { return(false); } // Check for comparator equality if (this == thatDicomComparator) { return(true); } MessageComparisonResults messageComparisonResults = new MessageComparisonResults(this._name, thatDicomComparator._name, this._template.Command, thatDicomComparator._template.Command, this._template.SopClassUid, thatDicomComparator._template.SopClassUid); // Iterate over this comparator foreach (DicomComparisonTag thisComparisonTag in this._template.ComparisonTags) { // try to get the equivalent tag in thatDicomComparator DicomComparisonTag thatComparisonTag = thatDicomComparator._template.ComparisonTags.Find(thisComparisonTag.Tag); if (thatComparisonTag != null) { AttributeComparisonResults attributeComparisonResults = new AttributeComparisonResults(thisComparisonTag.Tag, thisComparisonTag.DataFormat.ToDicomFormat(), thatComparisonTag.DataFormat.ToDicomFormat()); if (thisComparisonTag.DataFormat.Equals(thatComparisonTag.DataFormat) == false) { DvtkData.Validation.ValidationMessage validationMessage = new DvtkData.Validation.ValidationMessage(); validationMessage.Type = DvtkData.Validation.MessageType.Error; validationMessage.Message = "Attribute values do not match."; attributeComparisonResults.Messages.Add(validationMessage); } messageComparisonResults.Add(attributeComparisonResults); } } resultsReporter.WriteMessageComparisonResults(messageComparisonResults); compared = true; } return(compared); }
public void SetComparators(Dvtk.Comparator.BaseComparatorCollection comparatorCollection) { if (_transaction is DicomTransaction) { System.String name = System.String.Empty; DicomTransaction dicomTransaction = (DicomTransaction)_transaction; switch (dicomTransaction.Direction) { case TransactionDirectionEnum.TransactionReceived: name = System.String.Format("Received by {0} from {1}", ActorNames.Name(_fromActorName), ActorNames.Name(_toActorName)); break; case TransactionDirectionEnum.TransactionSent: name = System.String.Format("Sent from {0} to {1}", ActorNames.Name(_fromActorName), ActorNames.Name(_toActorName)); break; default: break; } for (int i = 0; i < dicomTransaction.DicomMessages.Count; i++) { DicomMessage dicomMessage = (DicomMessage)dicomTransaction.DicomMessages[i]; DvtkHighLevelInterface.Comparator.Comparator comparator = new DvtkHighLevelInterface.Comparator.Comparator(name); Dvtk.Comparator.DicomComparator dicomComparator = comparator.InitializeDicomComparator(dicomMessage); if (dicomComparator != null) { comparatorCollection.Add(dicomComparator); } } } }
public DicomComparator InitializeDicomComparator(DicomMessage dicomMessage) { DicomComparator dicomComparator = new DicomComparator(_name); bool initialized = dicomComparator.Initialize(dicomMessage.DvtkDataDicomMessage); if (initialized == false) { dicomComparator = null; } return dicomComparator; }
/// <summary> /// Initializes the encapsulated Dvtk.Comparator.Hl7Comparator class with the supplied HL7 message. /// </summary> /// <param name="hl7Message">The HL7 message.</param> /// <returns>The encapsulated Dvtk.Comparator.Hl7Comparator instance.</returns> public Hl7Comparator InitializeHl7Comparator(Hl7Message hl7Message) { _dicomComparator = null; bool initialized = _hl7Comparator.Initialize(hl7Message); if (initialized == false) { _hl7Comparator = null; } return _hl7Comparator; }
/// <summary> /// Initializes the encapsulated Dvtk.Comparator.DicomComparator class with the supplied DICOM message. /// </summary> /// <param name="dicomMessage">The DICOM message.</param> /// <returns>The encapsulated Dvtk.Comparator.DicomComparator instance.</returns> public DicomComparator InitializeDicomComparator(DicomMessage dicomMessage) { _hl7Comparator = null; bool initialized = _dicomComparator.Initialize(dicomMessage.DvtkDataDicomMessage); if (initialized == false) { _dicomComparator = null; } return _dicomComparator; }
public bool PopulateMessage(DvtkData.Dimse.DicomMessage dicomMessage, DicomComparator sourceComparator) { // Check for comparator equality if (this == sourceComparator) { return(false); } // Set up the comparator using the templates bool setUpOk = SetUp(dicomMessage); if (setUpOk == true) { // Copy the source comparator values into the dicom message if the tags are in this comparator setUpOk = CopyToDicomMessage(dicomMessage, sourceComparator); } return(setUpOk); }
private bool CopyToDicomMessage(DvtkData.Dimse.DicomMessage dicomMessage, DicomComparator sourceComparator) { bool messagePopulated = true; // Check if both templates have been initialized correctly if ((this.Template == null) || (sourceComparator.Template == null)) { return false; } // Iterate over this comparator foreach (DicomComparisonTag thisComparisonTag in this.Template.ComparisonTags) { // try to get the equivalent tag in the sourceComparator DicomComparisonTag sourceComparisonTag = sourceComparator.Template.ComparisonTags.Find(thisComparisonTag.Tag); if (sourceComparisonTag != null) { System.String stringValue = sourceComparisonTag.DataFormat.ToDicomFormat(); DvtkData.Dimse.DataSet dataset = dicomMessage.DataSet; if (dataset != null) { // we need to see if the parent sequence has been set up in the dataset if (thisComparisonTag.ParentSequenceTag != Tag.UNDEFINED) { // set up the parent sequence and add it to the dataset SequenceOfItems sequenceOfItems = null; DvtkData.Dimse.Attribute sequenceAttribute = dataset.GetAttribute(thisComparisonTag.ParentSequenceTag); if (sequenceAttribute == null) { // add in an empty item DvtkData.Dimse.SequenceItem item = new SequenceItem(); dataset.AddAttribute(thisComparisonTag.ParentSequenceTag.GroupNumber, thisComparisonTag.ParentSequenceTag.ElementNumber, VR.SQ, item); sequenceAttribute = dataset.GetAttribute(thisComparisonTag.ParentSequenceTag); } // get the sequence item and add in the required attribute sequenceOfItems = (SequenceOfItems)sequenceAttribute.DicomValue; if (sequenceOfItems.Sequence.Count == 1) { DvtkData.Dimse.SequenceItem item = sequenceOfItems.Sequence[0]; if (item != null) { // add the attribute to the item if (sourceComparisonTag.Vr == VR.SQ) { // add in an empty item // TODO - fix this properly DvtkData.Dimse.SequenceItem item1 = new SequenceItem(); item.AddAttribute(sourceComparisonTag.Tag.GroupNumber, sourceComparisonTag.Tag.ElementNumber, VR.SQ, item1); } else { // if the attribute already exists - then we need to remove it // - it was probably set to the default value DvtkData.Dimse.Attribute attribute = item.GetAttribute(sourceComparisonTag.Tag); if (attribute != null) { item.Remove(attribute); } // add the attribute to the item item.AddAttribute(sourceComparisonTag.Tag.GroupNumber, sourceComparisonTag.Tag.ElementNumber, sourceComparisonTag.Vr, stringValue); } } } } else { // if the attribute already exists - then we need to remove it // - it was probably set to the default value DvtkData.Dimse.Attribute attribute = dataset.GetAttribute(sourceComparisonTag.Tag); if (attribute != null) { dataset.Remove(attribute); } // add the attribute at the top level dataset.AddAttribute(sourceComparisonTag.Tag.GroupNumber, sourceComparisonTag.Tag.ElementNumber, sourceComparisonTag.Vr, stringValue); } } } } return messagePopulated; }
public bool PopulateMessage(DvtkData.Dimse.DicomMessage dicomMessage, DicomComparator sourceComparator) { // Check for comparator equality if (this == sourceComparator) { return false; } // Set up the comparator using the templates bool setUpOk = SetUp(dicomMessage); if (setUpOk == true) { // Copy the source comparator values into the dicom message if the tags are in this comparator setUpOk = CopyToDicomMessage(dicomMessage, sourceComparator); } return setUpOk; }
/// <summary> /// Set the Comparators needed to handle each message in the Transaction. /// </summary> /// <param name="comparatorCollection">Comparator collection to fill.</param> public void SetComparators(Dvtk.Comparator.BaseComparatorCollection comparatorCollection) { if (_transaction is DicomTransaction) { System.String name = System.String.Empty; DicomTransaction dicomTransaction = (DicomTransaction)_transaction; switch (dicomTransaction.Direction) { case TransactionDirectionEnum.TransactionReceived: name = System.String.Format("Received by {0}:{1} from {2}:{3}", ActorTypes.Type(_toActorName.Type), _toActorName.Id, ActorTypes.Type(_fromActorName.Type), _fromActorName.Id); break; case TransactionDirectionEnum.TransactionSent: name = System.String.Format("Sent from {0}:{1} to {2}:{3}", ActorTypes.Type(_toActorName.Type), _toActorName.Id, ActorTypes.Type(_fromActorName.Type), _fromActorName.Id); break; default: break; } for (int i = 0; i < dicomTransaction.DicomMessages.Count; i++) { DicomMessage dicomMessage = (DicomMessage)dicomTransaction.DicomMessages[i]; DvtkHighLevelInterface.Comparator.Comparator comparator = new DvtkHighLevelInterface.Comparator.Comparator(name); Dvtk.Comparator.DicomComparator dicomComparator = comparator.InitializeDicomComparator(dicomMessage); if (dicomComparator != null) { comparatorCollection.Add(dicomComparator); } } } else if (_transaction is Hl7Transaction) { System.String name = System.String.Empty; Hl7Transaction hl7Transaction = (Hl7Transaction)_transaction; switch (hl7Transaction.Direction) { case TransactionDirectionEnum.TransactionReceived: name = System.String.Format("Received by {0}:{1} from {2}:{3}", ActorTypes.Type(_toActorName.Type), _toActorName.Id, ActorTypes.Type(_fromActorName.Type), _fromActorName.Id); break; case TransactionDirectionEnum.TransactionSent: name = System.String.Format("Sent from {0}:{1} to {2}:{3}", ActorTypes.Type(_toActorName.Type), _toActorName.Id, ActorTypes.Type(_fromActorName.Type), _fromActorName.Id); break; default: break; } Hl7Message hl7Message = hl7Transaction.Request; DvtkHighLevelInterface.Comparator.Comparator comparator = new DvtkHighLevelInterface.Comparator.Comparator(name); Dvtk.Comparator.Hl7Comparator hl7Comparator = comparator.InitializeHl7Comparator(hl7Message); if (hl7Comparator != null) { comparatorCollection.Add(hl7Comparator); } } }
/// <summary> /// Compare the two messages. /// </summary> /// <param name="tagValueFilterCollection">Tag Value Filter.</param> /// <param name="resultsReporter">Results reporter.</param> /// <param name="thatBaseComparator">Reference comparator.</param> /// <returns>bool - true = messages compared, false messages not compared</returns> public override bool Compare(TagValueCollection tagValueFilterCollection, ResultsReporter resultsReporter, BaseComparator thatBaseComparator) { bool compared = false; if (thatBaseComparator is Hl7Comparator) { Hl7Comparator thatHl7Comparator = (Hl7Comparator)thatBaseComparator; // Check if both templates have been initialized correctly if ((this.Template == null) || (thatHl7Comparator.Template == null)) { return(false); } // Check for comparator equality if (this == thatHl7Comparator) { return(true); } // filter out comparators for the same message types if ((this.Template.MessageType == thatHl7Comparator.Template.MessageType) && (this.Template.MessageSubType == thatHl7Comparator.Template.MessageSubType)) { return(false); } // generate a local Tag Value collection from this // - this collection will include any tag value pair from the original collection and // the tag value pairs of any tags only (in the original collection) that match from this // comparator - that is the values are taken from this comparator. TagValueCollection lTagValueFilterCollection = GenerateTagValueCollection(tagValueFilterCollection); // check to see if the comparision filters match - without Univeral Matching // - now try to match this local filter collection against thatDicomComparator // - comparators that match will have the same tag value pairs (including the value) as // each other. if ((tagValueFilterCollection.Count == lTagValueFilterCollection.Count) && (thatHl7Comparator.UseComparator(lTagValueFilterCollection, false) == true)) { MessageComparisonResults messageComparisonResults = new MessageComparisonResults(this.Name, thatHl7Comparator.Name, this.Template.MessageType, thatHl7Comparator.Template.MessageType, this.Template.MessageSubType, thatHl7Comparator.Template.MessageSubType); // Iterate over this comparator foreach (Hl7ComparisonTag thisComparisonTag in this.Template.ComparisonTags) { // try to get the equivalent tag in thatHl7Comparator Hl7ComparisonTag thatComparisonTag = thatHl7Comparator.Template.ComparisonTags.Find(thisComparisonTag.Tag); if (thatComparisonTag != null) { AttributeComparisonResults attributeComparisonResults = new AttributeComparisonResults(SegmentNames.Name(thisComparisonTag.Tag.Segment), thisComparisonTag.Tag.FieldIndex, thisComparisonTag.DataFormat.ToHl7Format(), thatComparisonTag.DataFormat.ToHl7Format()); attributeComparisonResults.Name = DicomHl7TagMapTemplate.Hl7NameFromHl7Tag(thisComparisonTag.Tag); if (thisComparisonTag.DataFormat.Equals(thatComparisonTag.DataFormat) == false) { DvtkData.Validation.ValidationMessage validationMessage = new DvtkData.Validation.ValidationMessage(); validationMessage.Type = DvtkData.Validation.MessageType.Error; validationMessage.Message = "Attribute values do not match."; attributeComparisonResults.Messages.Add(validationMessage); } messageComparisonResults.Add(attributeComparisonResults); } } resultsReporter.WriteMessageComparisonResults(messageComparisonResults); compared = true; } } else if (thatBaseComparator is DicomComparator) { DicomComparator thatDicomComparator = (DicomComparator)thatBaseComparator; // Check if both templates have been initialized correctly if ((this.Template == null) || (thatDicomComparator.Template == null)) { return(false); } // generate a local Tag Value collection from this // - this collection will include any tag value pair from the original collection and // the tag value pairs of any tags only (in the original collection) that match from this // comparator - that is the values are taken from this comparator. TagValueCollection lTagValueFilterCollection = GenerateTagValueCollection(tagValueFilterCollection); // check to see if the comparision filters match - without Univeral Matching // - now try to match this local filter collection against thatDicomComparator // - comparators that match will have the same tag value pairs (including the value) as // each other. if ((tagValueFilterCollection.Count == lTagValueFilterCollection.Count) && (thatDicomComparator.UseComparator(lTagValueFilterCollection, false) == true)) { MessageComparisonResults messageComparisonResults = new MessageComparisonResults(this.Name, thatDicomComparator.Name, this.Template.MessageType, thatDicomComparator.Template.Command, this.Template.MessageSubType, thatDicomComparator.Template.SopClassUid); // Iterate over this comparator foreach (Hl7ComparisonTag thisComparisonTag in this.Template.ComparisonTags) { // try to get the equivalent tag in thatDicomComparator DicomComparisonTag thatComparisonTag = thatDicomComparator.Template.ComparisonTags.Find(DicomHl7TagMapTemplate.Hl7ToDicomTag(thisComparisonTag.Tag)); if (thatComparisonTag != null) { AttributeComparisonResults attributeComparisonResults = new AttributeComparisonResults(thatComparisonTag.Tag, SegmentNames.Name(thisComparisonTag.Tag.Segment), thisComparisonTag.Tag.FieldIndex, thisComparisonTag.DataFormat.ToHl7Format(), thatComparisonTag.DataFormat.ToDicomFormat()); if (thisComparisonTag.DataFormat.Equals(thatComparisonTag.DataFormat) == false) { DvtkData.Validation.ValidationMessage validationMessage = new DvtkData.Validation.ValidationMessage(); validationMessage.Type = DvtkData.Validation.MessageType.Error; validationMessage.Message = "Attribute values do not match."; attributeComparisonResults.Messages.Add(validationMessage); } messageComparisonResults.Add(attributeComparisonResults); } } resultsReporter.WriteMessageComparisonResults(messageComparisonResults); compared = true; } } return(compared); }
private bool CopyToDicomMessage(DvtkData.Dimse.DicomMessage dicomMessage, DicomComparator sourceComparator) { bool messagePopulated = true; // Check if both templates have been initialized correctly if ((this.Template == null) || (sourceComparator.Template == null)) { return(false); } // Iterate over this comparator foreach (DicomComparisonTag thisComparisonTag in this.Template.ComparisonTags) { // try to get the equivalent tag in the sourceComparator DicomComparisonTag sourceComparisonTag = sourceComparator.Template.ComparisonTags.Find(thisComparisonTag.Tag); if (sourceComparisonTag != null) { System.String stringValue = sourceComparisonTag.DataFormat.ToDicomFormat(); DvtkData.Dimse.DataSet dataset = dicomMessage.DataSet; if (dataset != null) { // we need to see if the parent sequence has been set up in the dataset if (thisComparisonTag.ParentSequenceTag != Tag.UNDEFINED) { // set up the parent sequence and add it to the dataset SequenceOfItems sequenceOfItems = null; DvtkData.Dimse.Attribute sequenceAttribute = dataset.GetAttribute(thisComparisonTag.ParentSequenceTag); if (sequenceAttribute == null) { // add in an empty item DvtkData.Dimse.SequenceItem item = new SequenceItem(); dataset.AddAttribute(thisComparisonTag.ParentSequenceTag.GroupNumber, thisComparisonTag.ParentSequenceTag.ElementNumber, VR.SQ, item); sequenceAttribute = dataset.GetAttribute(thisComparisonTag.ParentSequenceTag); } // get the sequence item and add in the required attribute sequenceOfItems = (SequenceOfItems)sequenceAttribute.DicomValue; if (sequenceOfItems.Sequence.Count == 1) { DvtkData.Dimse.SequenceItem item = sequenceOfItems.Sequence[0]; if (item != null) { // add the attribute to the item if (sourceComparisonTag.Vr == VR.SQ) { // add in an empty item // TODO - fix this properly DvtkData.Dimse.SequenceItem item1 = new SequenceItem(); item.AddAttribute(sourceComparisonTag.Tag.GroupNumber, sourceComparisonTag.Tag.ElementNumber, VR.SQ, item1); } else { // if the attribute already exists - then we need to remove it // - it was probably set to the default value DvtkData.Dimse.Attribute attribute = item.GetAttribute(sourceComparisonTag.Tag); if (attribute != null) { item.Remove(attribute); } // add the attribute to the item item.AddAttribute(sourceComparisonTag.Tag.GroupNumber, sourceComparisonTag.Tag.ElementNumber, sourceComparisonTag.Vr, stringValue); } } } } else { // if the attribute already exists - then we need to remove it // - it was probably set to the default value DvtkData.Dimse.Attribute attribute = dataset.GetAttribute(sourceComparisonTag.Tag); if (attribute != null) { dataset.Remove(attribute); } // add the attribute at the top level dataset.AddAttribute(sourceComparisonTag.Tag.GroupNumber, sourceComparisonTag.Tag.ElementNumber, sourceComparisonTag.Vr, stringValue); } } } } return(messagePopulated); }
/// <summary> /// Constructor. /// </summary> /// <param name="name">Name to supply to the encapsulated Dvtk.Comparator.DicomComparator and Dvtk.Comparator.Hl7Comparator classes.</param> public Comparator(System.String name) { _dicomComparator = new DicomComparator(name); _hl7Comparator = new Hl7Comparator(name); }
/// <summary> /// See the Dvtk.Comparator.DicomComparator.PopulateMessage method. /// </summary> /// <param name="dicomMessage">See the Dvtk.Comparator.DicomComparator.PopulateMessage method.</param> /// <param name="dicomSourceComparator">See the Dvtk.Comparator.DicomComparator.PopulateMessage method.</param> /// <returns>See the Dvtk.Comparator.DicomComparator.PopulateMessage method.</returns> public bool PopulateDicomMessage(DicomMessage dicomMessage, DicomComparator dicomSourceComparator) { bool messagePopulated = false; if (_dicomComparator != null) { messagePopulated = _dicomComparator.PopulateMessage(dicomMessage.DvtkDataDicomMessage, dicomSourceComparator); } return messagePopulated; }