Managing Transmission Responses
Some EDI specifications define the interchanges and messages to be used to notify the EDI sender about transmission status, from initial receipt of the transmission to the errors, if any, encountered in the EDI data stream received from the EDI sender. For example:
- HIPAA and X12 use the TA1 interchange to indicate whether a transmission was accepted, accepted with errors, or rejected. The 997 transaction set is used to report errors encountered during EDI processing.
- EDIFACT uses the CONTRL message to indicate acceptance or rejection of a transmission, and also to report errors encountered during EDI processing.
As described in Response Element, the Analyze method generates dialect-specific transmission responses as Receipt and Acknowledgement elements in the EDI analysis report.
This section covers the following topics:
Receipt Element Example
Here is an example of the Receipt element from the analysis report created using the Analyze method to convert the sample file threemsgs.x12 to XML:
<Receipt> <X12> <ISA> <ISA01>00</ISA01> <ISA03>00</ISA03> <ISA05>01</ISA05> <ISA06>5151515151</ISA06> <ISA07>01</ISA07> <ISA08>1515151515</ISA08> <ISA11>^</ISA11> <ISA12>00403</ISA12> <ISA13>0</ISA13> <ISA14>0</ISA14> <ISA15>P</ISA15> <ISA16>*</ISA16> </ISA> <TA1> <TA101>32123</TA101> <TA102>041201</TA102> <TA103>1217</TA103> <TA104>A</TA104> <TA105>000</TA105> </TA1> <IEA/> </X12> </Receipt>The specific structure of the Receipt element varies based on the dialect, and contents, of the EDI stream being converted. In this example:
- The X12 element specifies the EDI dialect of the EDI data stream that was converted to XML.
- The ISA element represents the Interchange Control Header segment; its subelements (ISA01, ISA02, and so on) show the values for the corresponding segment fields (Authorization Information Qualifier, Authorization Information, and so on).
- The TA1 element represents the Transaction Acknowledgement segment; its subelements (TA101, TA102, and so on) show the values for the corresponding segment fields (Interchange Control Number, Interchange Date, and so on).
- The IEA element represents the Interchange Control Trailer segment; it is empty because the values for this segment are computed automatically by DataDirect XML Converters when the Receipt element is converted to EDI for transmission back to the EDI sender.
Other EDI segments that are computed when the XML is converted to EDI include the Transaction Set Trailer (SE) and Function Group Trailer (GE).
Acknowledgement Element Example
Following is an example of the Acknowledgement element from the same analysis report created using the Analyze method to convert the sample file threemsgs.x12 to XML. Note that is has been abbreviated for formatting considerations.
<Acknowledgement> <X12> <ISA> … </ISA> <GS> … </GS> <TS_997> <ST> <ST01>997</ST01> <ST02>0</ST02> </ST> <AK1> <AK101>CT</AK101> <AK102>128</AK102> </AK1> <AK2> <AK201>831</AK201> <AK202>00128001</AK202> </AK2> <AK5> … </AK5> <AK2> <AK201>831</AK201> <AK202>00128002</AK202> </AK2> <AK3> … </AK3> <AK4> <AK401> … </AK401> <AK402>782</AK402> <AK403>6</AK403> <AK404>ZZZZ</AK404> </AK4> <AK5> … </AK5> <AK2> … </AK2> <AK201>831</AK201> <AK202>00128003</AK202> <AK5> … </AK5> <AK9> <AK901>P</AK901> <AK902>3</AK902> <AK903>3</AK903> <AK904>2</AK904> </AK9> <SE/> </TS_997> <GE/> <IEA/> </X12> </Acknowledgement>
- The X12 and ISA elements serve the same function as those in the Receipt element.
- The GS element represents the Functional Group Header segment; its subelements (GS01, GS02, and so on) show the values for the corresponding segment fields (Functional Identifier Code, Application Sender’s Code, and so on).
- The TS_997 element serves as a message wrapper for all functional acknowledgement transaction messages. The TS stands for transaction set, and 997 indicates the type of message. In this case, 997 represents the X12 997 functional acknowledgement. Functional acknowledgement transaction message wrapper elements have different names in different EDI dialects.
- The ST element represents the Transaction Set Header.
- The AK elements represent the
- Functional Group Response Header (AK1) and Functional Group Response Trailer (AK9) segments. There is one pair of AK1/AK9 segments for every group of transactions.
- Transaction Set Response Header (AK2) and Transaction Set Response Trailer (AK5). These pairs of segments can repeat, once for each transaction in the transaction set. In this example, there are three AK2 segments because there are three messages in the threemsgs.x12 EDI source document.
If a message contains an error, the analysis report will also contain elements representing these segments:
- AK3 (Data Segment Note). This segment identifies the invalid segment’s position within the transaction, as well as an error code that specifies the type of error.
- AK4 (Data Element Note). If the segment is determined to be invalid because of bad data (a value with an improper data type, for example), the AK4 subelements specify the Data Element Syntax Error Code (AK403) and Copy of Bad Data Element (AK404).
- The SE, GE, and IEA segments are the same as those described in Receipt Element Example.
Converting Response Messages to EDI
Since transmission responses are structured as XML, they need to be converted to EDI before they can be returned to the EDI sender. This example shows how to
To see a complete example application that converts both Receipt and Acknowledgement responses to EDI, see Example 14.
Invoking the Analyze Method
To get started, the EDI XML Converter is used to initiate the conversion of the source EDI document, threemsgs.x12 to EDI:
try { Source ediSource = new UriSource(uriString + "threemsgs.x12"); ConvertToXml toXml = factory.CreateConvertToXml("converter:EDI");Next the Analyze method is used to generate the analysis report and saves the output to report.xml:
See Receipt Element Example for a sample of the analysis report, report.xml.
Converting the Source EDI
In this section of code, the analysis report is used as input to convert the EDI stream to XML. Any errors in the EDI stream are recorded in the analysis report, which is used by ConvertToXml as a filter so that only valid EDI messages are converted to XML. Here, the valid EDI is written to an XML document, twomsgs.xml.
Source reportSource = new UriSource(new FileInfo("report.xml").FullName); Result xmlResult = new UriResult("twomsgs.xml"); toXml.Convert(ediSource, xmlResult, reportSource);Locating Response Messages
The EDI analysis report is used again, this time as the source for the EDI transmission response messages that have been generated in the Receipt and Acknowledgement elements in the XML report. It is these elements whose contents will be converted to EDI for transmission back to the EDI sender. Here the report is opened with an instance of XmlReader.
Once the XmlReader object is created, we can read through the analysis report, skipping first to the Receipt element, then to the X12 element:
while(rdr.Read()) { if ( rdr.NodeType == XmlNodeType.Element && rdr.LocalName == "Receipt") break; } while(rdr.Read()) { if ( rdr.NodeType == XmlNodeType.Element && rdr.LocalName == "X12") break; }(For a refresher of the Receipt element structure, see Receipt Element Example.)
Converting the Receipt Element to EDI
Once the Receipt element is located in the analysis report, it can be converted to EDI for transmission back to the EDI sender. Note that the converter: property is specified as ED.
ConvertFromXml converter = factory.CreateConvertFromXml("converter:EDI"); Source responseSource = new XmlReaderSource(rdr); Result receiptResult = new UriResult("receipt.x12"); converter.Convert(responseSource, receiptResult);The resulting EDI is written to the file, receipt.x12, which contains the following:
ISA+00+ +00+ +01+5151515151 +01+1515151515 +090818+1110+^+00403+000000000+0+P+*' TA1+000032123+041201+1217+A+000' IEA+0+000000000'Notice that the IEA segment (Interchange Control Trailer), which was represented in the original XML conversion of the source EDI document as an empty element (<IEA/) has been automatically computed by the EDI XML Converter and now includes values for the Number of Included Functional Groups (IEA01) and Interchange Control Number (IEA02) segments.
Sending Responses to the EDI Sender
When you send a response to an EDI sender, you typically must provide each interchange with a unique identifier – for X12, for example, this is the Interchange Control Number (ISA12 ) segment; for EDIFACT, this is the Interchange Control Reference (UNB05) segment.
You can perform this task as part of the application code that extracts the Receipt or Acknowledgement element from the analysis report; it is expected that the generation of a unique identifier is handled elsewhere.
Example
This simple XSLT locates the Interchange Control Header (ISA) segment, replaces the value of the Interchange Control Number (ISA12) segment with 1000, and converts the node to EDI for transmission to the EDI sender.
<?xml version='1.0'?> <xsl:stylesheet version="1.0" xmlns:xsl= "http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes"/> <xsl:param name="InterchangeControlID"/> <xsl:template match="/"> <xsl:apply-templates select="/AnalyzeReport/Response/Receipt/X12"/> </xsl:template> <xsl:template match="*"> <xsl:copy> <xsl:apply-templates/> </xsl:copy> </xsl:template> <xsl:template match="ISA12"> <ISA12><xsl:value-of select="$InterchangeControlID"/></ISA12> </xsl:template> </xsl:stylesheet>