Custom Code - Getting Started
Getting Started — Hello World
The traditional way to introduce any programming tool is with a “Hello World” example. In HL7Spy, we will set MSH-3 (Sending Application) to “Hello World!” for every message in the active tab.
Open the Custom Code tool.
Click the + button in the Plugin List to add a new function. Give it a name, for example “Hello World”.
Replace the body of the
Run()method with the following code:
csharpHello World
Load some HL7 messages into a tab in HL7Spy.
Press F5 (Run).
A new tab named “Hello World Tab” appears with every message having
MSH-3set to “Hello World!”.
You can also access fields using the strongly-typed model: message.MSH.SendingApplication_03.NamespaceID_01.Value = "Hello World!";
Sample Source Code
public override void Run()
{
// Get an HL7 Message in parsed format
HL7Message message = GetParsedMessage();
// Set MSH-3 to "Hello World!"
message["MSH-3"] = "Hello World";
// Same thing, but using a different syntax
message.MSH.SendingApplication_03.NamespaceID_01.Value = "Hello World!";
// Save the altered message into a new tab
SaveMessage(message,"Hello World Tab");
}
Sample Output