public bool UseComparator(TagValueCollection tagValueFilterCollection, bool universalMatchAllowed) { int filterCounter = 0; // Check if the filter values match those in the template foreach (BaseTagValue baseTagValue in tagValueFilterCollection) { Hl7TagValue hl7TagValue = null; if (baseTagValue is Hl7TagValue) { hl7TagValue = (Hl7TagValue)baseTagValue; } else if (baseTagValue is DicomTagValue) { DicomTagValue dicomTagValue = (DicomTagValue)baseTagValue; hl7TagValue = new Hl7TagValue(DicomHl7TagMapTemplate.DicomToHl7Tag(dicomTagValue.Tag), dicomTagValue.Value); } if (hl7TagValue.Tag != null) { foreach (Hl7ComparisonTag thisComparisonTag in this.Template.ComparisonTags) { // Tags are the same if (thisComparisonTag.Tag == hl7TagValue.Tag) { if (universalMatchAllowed == true) { // When universal matching either a zero-length or exact match are OK if ((hl7TagValue.Value == System.String.Empty) || (thisComparisonTag.DataFormat.ToHl7Format() == hl7TagValue.Value)) { filterCounter++; } } else if ((universalMatchAllowed == false) && (thisComparisonTag.DataFormat.ToHl7Format() == hl7TagValue.Value)) { // Not universal matching so only an exact match is OK filterCounter++; } break; } } } } bool useThisComparator = (tagValueFilterCollection.Count == filterCounter) ? true : false; return(useThisComparator); }
private TagValueCollection GenerateTagValueCollection(TagValueCollection tagValueFilterCollection) { TagValueCollection localTagValueCollection = new TagValueCollection(); // Check if the comparator can be used with a Universal Match on the Value of the Tag // - that is zero-length Value. if (this.UseComparator(tagValueFilterCollection, true) == true) { foreach (BaseTagValue baseTagValue in tagValueFilterCollection) { Hl7TagValue hl7TagValue = null; if (baseTagValue is Hl7TagValue) { hl7TagValue = (Hl7TagValue)baseTagValue; } else if (baseTagValue is DicomTagValue) { DicomTagValue dicomTagValue = (DicomTagValue)baseTagValue; hl7TagValue = new Hl7TagValue(DicomHl7TagMapTemplate.DicomToHl7Tag(dicomTagValue.Tag), dicomTagValue.Value); } // If the Value is empty (Universal Match) then try to get the actual // value from the comparator so that is actual value will be used against // other comparators. if (hl7TagValue.Tag != null) { if (hl7TagValue.Value == System.String.Empty) { // try to get a value for this Tag from this comparator System.String lValue = getValue(hl7TagValue.Tag); // Add a new Tag Value - with Value coming from this comparator // to the local filter. Hl7TagValue lHl7TagValue = new Hl7TagValue(hl7TagValue.Tag, lValue); localTagValueCollection.Add(lHl7TagValue); } else { // Just add the given Tag Value pair to the local filter localTagValueCollection.Add(hl7TagValue); } } } } // Return the local filter return(localTagValueCollection); }
/// <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 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); } // filter out comparators for the same message types if ((this.Template.Command == thatDicomComparator.Template.Command) && (this.Template.SopClassUid == thatDicomComparator.Template.SopClassUid)) { 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.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; } } else 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); } // 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.Command, thatHl7Comparator.Template.MessageType, this.Template.SopClassUid, thatHl7Comparator.Template.MessageSubType); // Iterate over this comparator foreach (DicomComparisonTag thisComparisonTag in this.Template.ComparisonTags) { // try to get the equivalent tag in thatHl7Comparator Hl7ComparisonTag thatComparisonTag = thatHl7Comparator.Template.ComparisonTags.Find(DicomHl7TagMapTemplate.DicomToHl7Tag(thisComparisonTag.Tag)); if (thatComparisonTag != null) { AttributeComparisonResults attributeComparisonResults = new AttributeComparisonResults(thisComparisonTag.Tag, SegmentNames.Name(thatComparisonTag.Tag.Segment), thatComparisonTag.Tag.FieldIndex, thisComparisonTag.DataFormat.ToDicomFormat(), thatComparisonTag.DataFormat.ToHl7Format()); 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); }