Hi Derek,

I don't believe that EncodedMessageComparator does, but you could always
null it out in both the expected and actual message before you compare.

Alternately, Hl7V2MessageCompare has a method "setFieldsToIgnore()" which
lets you put in one or more terser paths to ignore. So you could do
something like:

Set<String> fieldsToIgnore = new HashSet<String>();
fieldsToIgnore("/MSH-10");
cmp.setFieldsToIgnore(fieldsToIgnore);

Cheers,
James

On Wed, Aug 8, 2012 at 3:45 PM, Derek Mahar <[email protected]>wrote:

> Does EncodedMessageComparator.equivalent() ignore the time stamp in the
> message header?
>
>
> http://hl7api.sourceforge.net/base/apidocs/ca/uhn/hl7v2/util/EncodedMessageComparator.html#equivalent(java.lang.String,
> java.lang.String)
>
> Derek
>
> On Wed, Aug 8, 2012 at 3:31 PM, christian ohr <[email protected]>wrote:
>
>>
>> ... or there's ca.uhn.hl7v2.util.EncodedMessageComparator, which provides
>> a
>> couple of methods that help standardizing and comparing messages.
>>
>> cheers
>> Christian
>>
>>
>>
>> rahul somasunderam-2 wrote:
>> >
>> > I wrote up a method using LightHL7Lib:
>> >
>> >   public void assertMessagesEqual(Hl7Record expected, Hl7Record actual)
>> {
>> >     List<String> headers = expected.listSegments();
>> >     headers.addAll(actual.listSegments());
>> >     assertEquals(expected.listSegments(), actual.listSegments());
>> >     Set<String> segments = new TreeSet<String>(headers);
>> >
>> >     for (String segmentName : segments) {
>> >       if (segmentName.contains("|")) {
>> >         break;
>> >       }
>> >       int i = 0;
>> >       while (true) {
>> >         i++;
>> >         Hl7Segment expectedSeg = expected.getSegment(segmentName, i);
>> >         Hl7Segment actualSeg = actual.getSegment(segmentName, i);
>> >
>> >         if (expectedSeg == null && actualSeg == null) {
>> >           break;
>> >         }
>> >         if (expectedSeg == null || actualSeg == null) {
>> >           assertEquals("Comparing " + segmentName + "[" + i +
>> > "].",expectedSeg, actualSeg);
>> >         }
>> >
>> >         assertNotNull("Comparing " + segmentName + "[" + i + "].",
>> > actualSeg);
>> >
>> >         int j  ;
>> >         if (segmentName.equals("MSH")) {
>> >           j = 2;
>> >         } else {
>> >           j = 1;
>> >         }
>> >
>> >         int maxFields = expectedSeg.fieldAll().length;
>> >         if (maxFields < actualSeg.fieldAll().length) {
>> >           maxFields = actualSeg.fieldAll().length;
>> >         }
>> >         for ( /*Use j as is*/; j <= maxFields ; j++) {
>> >           if (expectedSeg.field(j) == null /*||
>> > expectedSeg.field(j).toString().length() == 0*/) {
>> >             continue;
>> >           }
>> >
>> >           /* Check if field exists */
>> >           assertNotNull("Comparing " + segmentName + "[" + i + "]." + j,
>> > actualSeg.field(j));
>> >
>> >           if (expectedSeg.field(j).getCompCount() > 1) {
>> >             /* Check components */
>> >             for (int k = 0; k < expectedSeg.field(j).getCompCount();
>> k++)
>> > {
>> >               if (expectedSeg.field(j)
>> >                   .getComp(k + 1) == null /*||
>> > expectedSeg.field(j).getComp(k+1).toString().length() == 0*/) {
>> >                 continue;
>> >               }
>> >               assertNotNull("Comparing " + segmentName + "[" + i + "]."
>> +
>> > j + "." + k,
>> >                   actualSeg.field(j).getComp(k + 1));
>> >               if (expectedSeg.field(j).getComp(k + 1).getSubcompCount()
>> >
>> > 1) {
>> >                 /* Check subcomponents */
>> >                 for (int l = 0; l < expectedSeg.field(j).getComp(k +
>> > 1).getSubcompCount(); l++) {
>> >                   if (expectedSeg.field(j).getComp(k + 1).getSubcomp(l +
>> > 1) == null
>> >                     /*||
>> > expectedSeg.field(j).getComp(k+1).getSubcomp(l+1).toString().length() ==
>> > 0*/) {
>> >                     continue;
>> >                   }
>> >                   assertNotNull("Comparing " + segmentName + "[" + i +
>> > "]." + j + "." + k + "." + l,
>> >                       actualSeg.field(j).getComp(k + 1).getSubcomp(l +
>> > 1));
>> >                   assertEquals("Comparing " + segmentName + "[" + i +
>> "]."
>> > + j + "." + k + "." + l,
>> >                       expectedSeg.field(j).getComp(k + 1).getSubcomp(l +
>> > 1).toString(),
>> >                       actualSeg.field(j).getComp(k + 1).getSubcomp(l +
>> > 1).toString());
>> >
>> >                 }
>> >               } else {
>> >                 assertEquals("Comparing " + segmentName + "[" + i +
>> "]." +
>> > j + "." + (k + 1),
>> >                     expectedSeg.field(j).getComp(k +
>> 1).toString().trim(),
>> > actualSeg.field(j).getComp(k + 1).toString().trim());
>> >               }
>> >             }
>> >           } else {
>> >             assertEquals("Comparing " + segmentName + "[" + i + "]." +
>> j,
>> > expectedSeg.field(j).toString().trim(),
>> >                 actualSeg.field(j).toString().trim());
>> >           }
>> >         }
>> >       }
>> >     }
>> >   }
>> >
>> > It gives detailed information on which segment and which field are
>> > different. Better than plain diff, but not using HAPI.
>> >
>> > R,
>> > rahul
>> >
>> > On Aug 8, 2012, at 8:58 AM, Derek Mahar wrote:
>> >
>> >> Is comparing the string representation of a HAPI message the only way
>> to
>> >> compare messages?  We noticed that HAPI messages don't redefine method
>> >> equals(), so comparisons using JUnit assertions or Mockito verify()
>> calls
>> >> must use Object.equals() which compares object identity, not contents.
>> >> Are there any plans to implement methods equals() and hashCode() in
>> >> messages and segments?
>>
>
> --
> Derek Mahar
> Senior Software Developer
> Intelerad Medical Systems Incorporated
> 895 de la Gauchetiere W. Suite 400
> Montreal, QC, Canada, H3B 4G1
> Tel: 514.931.6222 x7754
> Fax: 514.931.4653
> [email protected]
> www.intelerad.com
>
>
>
> This email or any attachments may contain confidential or legally
> privileged information intended for the sole use of the addressees. Any
> use, redistribution, disclosure, or reproduction of this information,
> except as intended, is prohibited. If you received this email in error,
> please notify the sender and remove all copies of the message, including
> any attachments.
>
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Hl7api-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/hl7api-devel
>
>
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Hl7api-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/hl7api-devel

Reply via email to