
@MessageHeader.source.name = “PAT_IDENTIFY_X_REF_MGR_MISYS_TLS”
@MessageHeader.source.endpoint = “ALLSCRIPTS”
@MessageHeader.destination.name = “OTHER_IBM_BRIDGE_TLS“
@MessageHeader.destination.endpoint = “IBM”
I’m actually checking a bundle but use a little string substitution hackery to replace MessageHeader with %context.entry.resource.ofType(MessageHeader) at the head of the expression to save me about 31 characters of typing each time.
The next bit of fun is enabling the assertions to come close to where they are useful in the message. It should be obvious that each test case has two streams of data, the message, and the assertions. They can easily be interwoven. So, assertions can easily follow the segment, but I also wanted more, because some segments can be very long. Borrowing from other scripting languages (e.g., bash), I allow the introduction of the \ character at the end of the line to allow lines to be continued. I realized that it would be important to visually see the start an end of a segment in the file, so I ignore leading whitespace at the beginning of continuation lines. So now I can write:
# Outbound ack:
MSH|^~\&|\
PAT_IDENTITY_X_REF_MGR_MISYS_TLS|\
@MessageHeader.source.name = “PAT_IDENTIFY_X_REF_MGR_MISYS_TLS”
ALLSCRIPTS|\
@MessageHeader.source.endpoint = “ALLSCRIPTS”
OTHER_IBM_BRIDGE_TLS|\
@MessageHeader.destination.name = “OTHER_IBM_BRIDGE_TLS“
IBM|20090224114149-0500|\
@MessageHeader.destination.endpoint = “IBM”
|ACK^A04|OpenPIXPDQ10.243.0.65.19767899354465|P|2.3.1
MSA|AA|0851077658473390286
And so forth. In this way, I now have a test case where I can start with the message in my usual form (simple text with a blank line between cases). From there I can augment the test case with assertions that I feel are important. Following that, I can also break things up, even just long lines of V2 messages to make the test files more readable.
The final piece of this was to allow long assertions to be broken up the same way messages are, and to steal the final comment in the assertion expression (comments are part of FHIRPath syntax) to use for my assertion message in my testing framework. That’s also just simple string substitution as well.
You can find all of the code for this in V2toFHIR, the open-source converter my team and I created for some of our ongoing work. The two key files of interest are MessageParserTests.java and TestData.java. The method TestData.load() is where all the test input parsing magic happens. It’s not really that complicated.