What is an EDI template?
EDI Tools for .NET defines an EDI template as:
- A regular C# .NET class that represents the shape of an EDI transaction.
- Is annotated with our EDI Template Format attributes.
So an EDI Template is a normal C# class with some extra markup. EDI transactions are usually accompanied by their implementation guides, either the official ones (from UN/EDIFACT or ASC X12) or the respective trading partners' specific ones. The guides are meant for humans and are in text or PDF formats and can't be transferred automatically from machine to machine.
This article explains the layout of EDI Template Format, used to exchange EDI implementation guidelines in a machine-readable form. EDI translators, such as EDI Tools for .NET, which can directly import EDI templates can save users considerable time in developing new translations or maps.
EDI Template Example
- An excerpt from EDI Transaction Guide for X12 270 looks like this:
- The corresponding EDI Template for X12 270, would like like this:
EDI Tools for .NET and EDI Templates
The purpose of an EDI Template is to represent the implementation guide of an EDI transaction in such a way that:
- Is machine-friendly
- Is .NET developer-friendly
- It can easily be created or modified
- It can easily be transferred, shared, and documented
- Is completely free
- It does not require extra learning or tooling
When EDI Tools for .NET parses an EDI file, it produces .NET objects which are instances of the corresponding EDI templates (.NET classes). Similarly, when EDI Tools for .NET creates EDI files, it writes the data from .NET objects which are instances of EDI templates (.NET classes). We can safely say that all available operations in EDI Tools for .NET work on either EDI files or .NET objects.
EDI and .NET equivalent terms
.NET | EDI Tools for .NET | EDI |
---|---|---|
C# Class | EDI Template | EDI Guideline |
Class instance (POCO) | .NET object | EDI transaction (EDI document) |
EDI Template Format Specification
The EDI templates define a standard way for accessing and manipulating EDI transactions. All that is required to turn an EDI guide to an EDI template is the .NET Framework (or .NET Core) and the EdiFabric NuGet package.
EDI Transactions
[Message("X12", "002040", "810")]
public class TS810 : EdiMessage
EDI transaction sets are represented as regular C# classes, annotated with the MessageAttribute and inheriting from EdiMessage. The first parameter in the MessageAttribute is the EDI standard (X12, EDIFACT, HL7, etc.). The second parameter is the EDI version (edition + release). The last parameter is the EDI transaction set identifier.
EDI Tools for .NET uses internally these attribute values to locate and load the correct transaction set class whilst parsing an EDI file. All EDI transactions in the file will be matched to a template by the three values - EDI standard, EDI version, and EDI transaction set. Classes with the same values for all three attributes are not allowed in the same assembly and are regarded as duplicates.
Position Numbers
[Pos(1)]
public ST ST { get; set; }
[Pos(2)]
public BIG BIG { get; set; }
[Pos(3)]
public List<NTE> NTE { get; set; }
EDI position numbers are marked with the PosAttribute. All EDI loops, segments and data elements are positional and the order in which they can appear is driven by the specification. Classes can contain only ordered public properties in the exact sequence as prescribed by the guidelines for every EDI transaction.
It is possible to have multiple items at the same position, or a choice of items, only one of which is allowed at certain position. For this use AllAttribute and OneOfAttribute.
Repeat Count
public List<NTE> NTE { get; set; }
EDI repeat count is represented as generic C# List<>. EDI loops, segments and data elements can repeat according to the guideline. Whenever the parser encounters a property that is defined as a List<> it will automatically treat it as a repeating EDI item.
EDI Loops
[Group(typeof(N1))]
public class TS810_N1Loop1
EDI loops (or EDI groups) are marked with the GroupAttribute. The only parameter is the type of the first (trigger) segment in the group. Every group must contain at least a mandatory non-repeating segment in the first position.
EDI Segments
[Segment("BHT", typeof(X12_ID_1005), typeof(X12_ID_353))]
public class BHT
EDI segments are marked with the SegmentAttribute. The first parameter is the EDI identifier of the segment. The second parameter is a reference to the class defining the EDI code set for the first data element in the segment. If the first data element is not a code set then this is null. The last parameter is a reference to the class defining the EDI code set for the second data element in the segment. If the second data element is not a code set then this is null.
For X12 HL segments the last parameter is a reference to the class defining the EDI code set for the third data element in the segment.
The code sets are used by the EDI parser when searching for matching segments from the inbound EDI document to the EDI class.
Logical groups at the same position
[All()]
public class All_NM1
EDI items that can either apper in any order, or at the same position, are marked with the AllAttribute. These logical groups are simply containers for segments and have no trigger segment. The position of the logical group is the same as the position of all its items.
The AllAttribute can only be applied to loops or segments, and only if the grouping is uniform, e.g. to group either loops or segment, but not loops and segments.
Groups without trigger segment
[SeqOf()]
public class All_1_TSADRA19
EDI groups of segments without a trigger segment, are marked with the SeqOfAttribute. These groups are containers for segments and have no trigger segment. The group is identified by the unique tags of the segments it contains.
The SeqOfAttribute can only be applied for the NCPDP Telecommunications standard.
Choice of items at the same position
[OneOf()]
public class All_1_TSEHCE01
A choice of EDI items, only one of which is allowed at a certain position, are marked with the SeqOfAttribute. These groups are containers for segments that can appear at the same position.
The OneOfAttribute is usualy applied to items in the HL7 standard.
EDI Composite Data Elements
[Composite("C108")]
public class C108
EDI composite data elements are marked with the CompositeAttribute. The first parameter is the EDI identifier of the composite element.
EDI Data Elements
public string TransactionTypeCode_07 { get; set; }
EDI simple data elements and EDI component data elements are represented as C# strings. Data elements can repeat in segments and in composite data elements.
EDI Code Sets
[EdiCodes(",00,18,")]
public class X12_ID_353
EDI code sets are represented as classes marked with the EdiCodesAttribute. The only parameter is a string containing all of the allowed EDI codes, delimited with a comma.
Convert EDI Guide to EDI Template
There are always two levels of details that every EDI implementation guideline provides - the hierarchical transaction/loop level, and then the definition of each segment.
-
EDI transaction and loops
- Correct position of the segment\loop, represented by the PosAttribute
- Segment names, represented by the class name
- Loop names, represented by the name of the first segment in the loop
- Correct usage, represented by the RequiredAttribure if mandatory and no attribute if optional
- Correct number of repetitions, represented by the ListCountAttribute
-
EDI segments
- Correct position of complex and simple data elements, represented by the PosAttribute
- Complex data element names, represented by the class name
- Correct usage, represented by the RequiredAttribure if mandatory and no attribute if optional
- Correct number of repetitions, represented by the ListCountAttribute
- Correct data element code, represented by the DataElementAttribute, first argument
- Correct data element type, represented by the DataElementAttribute, second argument
- Correct values for EDI codes, represented by EdiCodesAttribute
- Correct data element length, represented by the StringLenghtAttribute
Additional Information
To learn how to install EDI templates, head on to the How to install EDI templates tutorial.
To learn how to modify EDI templates and match any custom partner specification, go to the How to modify EDI templates tutorial.
Comments
0 comments
Please sign in to leave a comment.