EDI Tools for .NET validates EDI documents by annotating their respective EDI templates with validation attributes and then invoking the validation by calling the IsValid() method of EdiMessage. For more information on how to validate EDI documents head on to the Validate EDI with templates article.
A ValidationSettings object can be passed to the IsValid() method of EdiMessage to control how EDI transactions are being validated.
Common EDI validation settings
- ComponentDataElement - To exclude a separator when validating alpha-numeric AN-type elements.
- SkipTrailerValidation - Whether to skip trailer validation in messages ('false' by default). This is useful when building a new EDI message, and you haven't created the trailer segments, such as SE or UNZ, because the EdiWriter will automatically append them. This flag tells the validator to skip over any validation that includes message trailer segments.
- DecimalPoint - The decimal point for EDIFACT only ('.' by default).
- SyntaxSet - The syntax set used to validate alphanumeric data types (not set by default). Read about EDIFACT data element validation and X12 data element validation for additional information.
- DataElementTypeMap - Allows you to apply different sets of EDI Codes than the ones in the EDI Template.
- DataElementCodesMap - Allows you to import external EDI codes at runtime.
- DateFormat - This option overrides the date format on the template for all elements with a DT type. It must be a valid C# DateTime format.
- DisableHLSegmentSequenceValidation - Whether to disable the validating if HL segments have sequential IDs starting from 1. This needs DisableHLSegmentValidation to be false before it takes effect.
- DisableHLSegmentValidation - Whether to validate HL segments. This includes parent-child relationships, sequential segments, and correct parent references.
- SkipSeqCountValidation - Whether to skip seq count validation in LX/ENT segments ('false' by default). This validation is enabled by the SeqCount attribute applied in the templates.
- TimeFormat - This option overrides the time format on the template for all elements with a TM type. It must be a valid C# TimeSpan. ParseExact format.
-
ValidationLevel - The validation level. Modeled after HIPAA SNIP levels. Each level includes validating all previous levels in ascending order from 1. By default, this is set to LimitsAndCodes_SNIP2. For more information, read the How to validate HIPAA SNIP levels article. The options are:
- SyntaxOnly_SNIP1
- LimitsAndCodes_SNIP2
- Balancing_SNIP3
- InterSegment_SNIP4
Apply validation settings to IsValid
ValidationSettings settings = new ValidationSettings();
settings.SkipTrailerValidation= true;
settings.DecimalPoint = '.';
settings.SyntaxSet = new Basic();
settings.DataElementTypeMap = new Dictionary<Type, Type>();
settings.DataElementCodesMap = new public Dictionary<string, List<string>>();
ediMessage.IsValid(out errorContext, settings);
What is SyntaxSet?
EDI data element data types such as alpha and alphanumeric are not validated by default. You need to explicitly enable this type of validation that checks if the value of data elements matches the list of allowed characters.
EDI code sets
[EdiCodes(",00,18,19,")]
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.
What is DataElementCodesMap?
Let's illustrate this for Transaction Set Purpose Code, represented by the X12_ID_353 class in the X12 EDI template in version 4010, however, the principle is the same for any EDI code set.
The standard X12_ID_353 code set is defined as allowing the following values: 00, 18, and 19.
///
/// Transaction Set Purpose Code
///
[Serializable()]
[DataContract()]
[EdiCodes(",00,18,19,")]
public class X12_ID_353
Let's assume that a fictional partner A requires a custom set of EDI codes for X12_ID_35, instead of the standard ones, which only allows the following values: 00, PA, and PB.
The templates using this class can be changed to use a new class, for partner A, however, the validation can be configured without any changes to the existing EDI template. The new values can be configured as a DataElementCodesMap in the ValidationSettings. This way IsValid() will match the new values instead of the standard values.
var codeSetMap = new Dictionary<string, List<string>>();
codeSetMap.Add("X12_ID_353", new List<string> { "00", "PA", "PB" });
ediMessage.IsValid(out errorContext,
new ValidationSettings { DataElementCodesMap = codeSetMap });
Use this method to dynamically load external code sets from a file, database, or another configuration source. No redeployment is required and the correct value resolution (by the code set class name) occurs at runtime.
Examples in GitHub:
- Validate X12 transactions with external EDI codes
- Validate EDIFACT transactions with external EDI codes
- Validate HL7 transactions with external EDI codes
- Validate NCPDP Telco transactions with external EDI codes
- Validate NCPDP SCRIPT transactions with external EDI codes
What is DataElementTypeMap?
Similar to the DatElementCodesMap, DataElementTypeMap allows you to validate EDI codes without having to change the whole EDI template, but only the code sets' portion of it. If we continue the example for partner A and X12_ID_353 from the previous sections, a new code set class will need to be created for the values expected by partner A, let's name it X12_ID_353_PartnerA:
///
/// Transaction Set Purpose Code
///
[Serializable()]
[DataContract()]
[EdiCodes(",00,PA,PB,")]
public class X12_ID_353_PartnerA
{
}
Then configure a DataElementTypeMap, which tells the validation to use the new code set class instead of the original one.
Dictionary<Type, Type> codeSetMap = new Dictionary<Type, Type>();
codeSetMap.Add(typeof(X12_ID_353), typeof(X12_ID_353_PartnerA));
ediMessage.IsValid(out errorContext,
new ValidationSettings { DataElementTypeMap = codeSetMap });
Use this method to statically load external code at design time. Redeployment is required and the correct code class resolution (by the code set type) occurs at runtime.
Comments
0 comments
Please sign in to leave a comment.