Pega Foundation for Healthcare provides a pre-configured File Service rule instance called X12file.X12.X12Inbound that reads the X12 message input file and calls the activity X12ParseMessageStart to start the processing.
The X12ParseMessageStart activity includes Java that calls the X12ParseMessageType activity. This activity sets the type of transactions that are in each functional group. It then calls an activity that handles the given message type by calling the X12ParseMessage activity defined in the appropriate class (such as PegaX12-Data-N837).
The X12ParseMessage activity is composed of Java code that parses the message according to its message type (such as 837) to determine the segments and the context of where these segments lie within the message. With this information, the activity determines the classes that should be populated with the data and calls a Parse Delimited rule for each segment. The rule parses the data and puts the data onto the clipboard. After the entire functional group has been processed, an instance of the X12 data object is created.
The Java code in the activity uses the syntax of a given message type based on the segments used and the format of the transaction as defined in the associated EDI Implementation Guide. The code uses the following logic to parse the X12 message one segment at a time:
- Gather control information from the ISA, GS, and ST segments and determine the message type found in the GS functional group.
- Keep track of the current loop identifier and monitor when it changes. The loop
identifier is hard coded into the Java code based on the message type. With the
837 message type, the starting loop ID is HEADER, which switches to the second
loop 2000A. The loop ID can change when any of the following is found:
- HL segment identifying a new Hierarchical Level
- NM1 segment identifying a new sub-loop
- For each segment, identify the Parse Delimited rule name and the class that should be populated with this segments data. Invoke that Parse Delimited rule to populate the clipboard with the appropriate class and properties.