edirulesformat

The EDIValidator component uses rules files in order to correctly parse, validate and load EDI data.  There is one rules file, for example, for every EDI implementation guide.  These implementation guides includes but are not limited to HIPAA.  For example, 820, 837, 834, 997, 999 etc

The EDI rule file format governs the structure of a specific implementation guide.  It contains all the segments, elements, composite segments, code lists, formats, summary elements, rules, accepted element values and mostly importantly the structure of the EDI file.

EDI Rules Creator Studio enables the creation of EDI rules files.  It is highly recommended that developers use this tool to create and edit EDI rule files.  We have all the 4010 and 5010 HIPAA rules files created and available for purchase.

A EDI rules file has the following sections that appear in the following order

FILE DATA

Contains any custom data.  This data is not used in the validation of EDI files.  Developers usually place any metadata in this section

Format

Example

ELEMENT DEFINITIONS

Contains all the elements and their definitions.  Their definitions include their number, type ,min and max lengths, and any description

Format

Example 1

Example 2

Possible Type include:

A    Alphabetic Characters
AN    String
ID    Identifiers
NO    Numeric (Integers)
PN    Positive Integers
NN    Negative Integers
R    Decimal ( for currency)
DT    Dates
TM    Times

COMPOSITE ELEMENT DEFINITIONS

Contains all the definitions for composite segments.  Composite elements are elements that contain other elements

Format

Example

Usage can be Required (M), Optional (O) and Not Used (N). By default element are Optional.

SEGMENT DEFINITIONS

Contains definitions for all segments

Format

Example

General segments can contain regular elements and composite elements.  Some items that you can see above are:
The HI Segment contains only composite elements (C022).
Segment GS contains 8 elements that are all Required (M)
Usage can be Required (M), Optional (O) and Not Used (N). By default element are Optional.

SEGMENT SELF RULES

Contains rules that apply to the usage of elements within a segment based on the value(s) of elements in that same segment

Format

Example 1

Example 2

Example 3

Example 4

Example 5

The possible Operator values are:

1. EQ -Equals, default
2. NE – Not equals
3. LT -Less than
4. LE – Less than or equal to
5. GT – Greater than
6. GE – Greater than or equal to

COMPOSITE SEGMENT SELF RULES

This section is the same as section SEGMENT SELF RULES however it is for composite element self rules

CODELISTS

EDI element data can be validated against code lists.  For example zip codes, ICD 10 codes etc.

External Code List Format

External Code List Example

Internal Code List Format

Internal Code List Example

FORMATS

Contains named regular expressions used to validate the contents of EDI elements.  If data elements don’t conform to specified formats an error will be raised

Format

Example

The format names can be referred to in the ELEMENT FORMATS section

EDI FILE STRUCTURE

Contains a tree-like structure of the EDI file in terms of loops and segments

Format

Example

Each segment that appears in the structure has an implicit ordinal value beginning with 1.  For example segment ISA has an ordinal value of 1, segment GS has an ordinal value of 2, ST has an ordinal value of 3 and BHT has an ordinal value of 4.  This ordinal value is what uniquely identifies each segment in the structure.

ELEMENT CODES

Contains the code values accepted by elements in the EDI file.  If an element has an accepted value(s) list and data in the element is not in that list then an error will be generated

Format

Example

ELEMENT FORMATS

Used to specify element formats

Format

Example

SUMMARY

Contains the summary elements.  Summary (balance) elements are elements whose values contain the sum of other elements

Format

Example

ELEMENT EQUALITY

Element equality conditions are used to specify that two element values must be equal.  Element equality conditions are usually used to check if EDI transaction numbers are the same at the beginning and ending of an EDI file.

Format

Example

RULES

Semantic rules. These rules are for dependent segments whose usage is based on the existence or values of other segments or elements

Format

27=26:2'EQ'18!USAGE!0!1
31=26:2'EQ'18!USAGE!2!0
40=26:2'EQ'18!USAGE!2!1
146=140:1'EQ'R,S!USAGE!2!0
207=26:2'NE'18!USAGE!2!1
321=315:1'EQ'R,S!USAGE!2!0
The following USAGE numbers can be used to change the usage of a segment or element:

0 Optional
1 Not Used
2 Required
3 Recommended
4 Not Recommended

The following conditions can be used:

EQ Equal
NE Not Equal
GT Greater Than
GE Greater Than or Equal To
LT Less Than
LE Less Than or Equal To
EXISTS Exists
NEXIST Does not exists

The different parts of the rule are separated by an exclamation character (!)

Rule

24=23:2'EQ'18!USAGE!0!1

Condition = 23:2'EQ'18 (If segment 23 element 2’s value is EQUAL to 18)
Action type=USAGE (We are going to modify the usage of segment 24)
True Usage = 0 (segment 24 is optional)
Default Usage = 1 (segment 24 is not used)

Meaning:If segment 23 element 2’s value is EQUAL to 18 then segment 24 usage is OPTIONAL else segment 24 is NOT USED

Rule

28=23:2'EQ'18!USAGE!2!0

Condition = 28:2’EQ’18 (If segment 23 element 2’s value is EQUAL to 18)
Action type=USAGE (We are going to modify the usage of segment 28)
True Usage = 2 (segment 28 is required)
Default Usage = 0 (segment 28 is optional)

Meaning: If segment 23 element 2’s value is EQUAL to 18 then segment 28 usage is REQUIRED else segment 28 is OPTIONAL

Rule

40=23:2'EQ'18!USAGE!2!1

Meaning: If segment 23 element 2’s value is EQUAL to 18 then segment 40 usage is REQUIRED else segment 40 is NOT USED

Rule

212=23:2'NE'18!USAGE!2!1

Meaning: If segment 23 element 2’s value is NOT EQUAL to 18 then segment 212 usage is REQUIRED else segment 212 is NOT USED

The condition can have more than one values

212=23:2'EQ'18,19!USAGE!2!1

Here we can see that the condition states that if segment 23 element 2 is equal to 18 OR 19 then segment 212 is REQUIRED else it is NOT USED.

Rule

149:2=23:2'NE'18!USAGE!2!1

Meaning: If segment 23 element 2’s value is NOT EQUAL to 18 then segment 149 element 2 usage is REQUIRED else NOT USED

Rule

97:2=23'EXISTS'!USAGE!2!1

Meaning: If segment 23 EXISTS then segment 97 element 2 usage is REQUIRED else NOT USED

LOCAL CODE

Rule

149:2=23:2'NE'18!LOCALCODE!2,3,4,5,6!7,8,9,10

Meaning: If segment 23 element 2’s value is NOT EQUAL to 18 then segment 149 element 2 accepted value are 2,3,4,5,6 else the default accepted values are 7,8,9,10

RDPCrystal EDI Library version 7.1 and higher

As of version 7.1 of RDPCrystal EDI Library more complete rules can be used with multiple conditions and more easy to use syntax
Example

+SegPos[27] = if (SegPos[26:2] == "18") then Usage[OPTIONAL] else Usage[NOTUSED] end
+SegPos[27] = if ((SegPos[26:2] == "18") or ((SegPos[26:2] != "2") )) then Usage[OPTIONAL] else Usage[NOTUSED] end

These rules were added directly in the EDI rules file. Notice that there is a ‘+’ sign in front of them to distinguish from the old rule format above

+SegPos[27] = if (SegPos[26:2] == "18") then Usage[OPTIONAL] else Usage[NOTUSED] end
+SegPos[31] = if (SegPos[26:2] == "18") then Usage[REQUIRED] else Usage[OPTIONAL] end
+SegPos[40] = if (SegPos[26:2] == "18") then Usage[REQUIRED] else Usage[NOTUSED] end
+SegPos[146] = if ((SegPos[140:1] == "R") or (SegPos[140:1] == "S")) then Usage[REQUIRED] else Usage[OPTIONAL] end
+SegPos[207] = if (SegPos[26:2] != "18") then Usage[REQUIRED] else Usage[NOTUSED] end
+SegPos[322] = if ((SegPos[316:1] == "R") or (SegPos[316:1] == "S")) then Usage[REQUIRED] else Usage[OPTIONAL] end

Rules can also be created that generate errors.  This is a very powerful feature as you can now create your own errors based on conditions

Changing Accepted Values/Local Codes

+SegPos[3:1]=if ( SegPos[3:1] ==  "837" ) then LocalCode["we","w9"] else LocalCode["837"] end

Creating Custom Validation Errors

+SegPos[135:5] = if (SegPos[135:5] == SegPos[40:5:1]) then Error[ElementHasWrongValue,"SV105 must be different from 2300 CLM05-01"] end

+SegPos[104:9] = if ((SegPos[26:9] != "") and (SegPos[104:9] != "")) then Error[ElementHasWrongValue,"SBR09 is used It should not be used after National PlanID is mandated"] end

Error types that can be generated include: ElementHasWrongValue, ElementNotUsed, ElementRecommended, ElementNotRecommended, ElementMissing, CompositeElementHasWrongValue, CompositeElementNotUsed, CompositeElementRecommended, CompositeElementNotRecommended, CompositeElementMissing

Note: All EDI element values are strings. Therefore comparisons are always against strings as seen in the above examples.

Boolean Operations

or
Or
and
And

Operators

==
Equals
!=
Not Equals
>
Greater Than
<
Less Than
>=
Greater Than Or Equal To
<=
Less Than Or Equal To

Usages

REQUIRED
Required
OPTIONAL
Optional
NOTUSED
Not Used

Conditions are always surrounded parenthesis and in statements with multiple conditions the proper nesting of parenthesis must be used

ELEMENT COUNTERS

Element counters are elements in certain segments that keep count of the current repetition of the loop that it is in.  A great example of this is the LX segment in an 837 transaction.

Format

Example

ELEMENT CODE DESCRIPTION

Contains the description of each value an element can have.  This section is is rarely used

LOOP DESCRIPTIONS

Contains the descriptions of the loop used in the EDI file

Format

Example

SEGMENT DESCRIPTIONS

Contains the descriptions of the segment used in the EDI file based on their ordinal numbers

Format

Example

Complete EDI Rule File

Rules File