EDIdEv - Electronic Data Interchange Development

Validating while translating an EDI file

This page will explain how to create a C# program that will validate a HIPAA 834 EDI file while it's being translated. But, in this case, when an error is found, the entire transaction set will not be rejected, but only the records with the errors while the rest of the file continues to get processed.

 

Overview

The algorithm of this project will be quite similar to the program that translates an EDI file (see Creating an EDI Translator):

  1. Create an EDI document object.

  2. Load the SEF file and EDI file into the EDI document object.

  3. Starting with the first segment, traverse through each segment of the EDI document object.

  4. Validate, identify and interrogate each segment to get the values from their data elements.

  5. Process obtained values accordingly.

Note that the Framework EDI (FREDI) automatically validates EDI files when they are loaded. In a ForwardOnly cursor type, the validation occurs when a segment is read e.g. at the get next segment command line:

  ediDataSegment.Set(ref oSegment, oSegment.Next());

To get the result of a validation of a segment in the middle of an EDI translation, we would need to add an Event Handler in our ediDocument object.

 

Validation Event Handler

To be able to handle events triggered by the ediDocument object, we first have to add a delegate that points to the oEdiDoc_EventNotify procedure.

 oEdiDoc.EventNotify += new EventNotifyDelegate(oEdiDoc_EventNotify);

This means that whenever an error is found by the the FREDI component while it's validating each segment, it will call the procedure oEdiDoc_EventNotify

  void oEdiDoc_EventNotify(ediEventNotify EventNotify)

We can then interrogate the EventNotify parameter to check for the type of error that was asserted.

  if (EventNotify.Severity == EventIDConstants.Event_Warning)
  {
       nErrCode = EventNotify.ErrorCode;
       sErrDesc = EventNotify.ErrorDescription;

       if (sLoopSection.StartsWith("INS"))
       {
             // Only interested with errors inside INS loop
             bErrorFound = true;
       }
       else
       {
             bErrorFound = false;
       }
  }

Note that we are only interested with the validation of segments inside the INS loop because for this particular transaction set we have determined that the INS segment is the starting point of the Insurance Benefit record.
If an error is found, we set the ErrorFound flag variable to true.

 

Accepting and Rejecting Records

Note that values extracted from data elements of segments under the INS loop are not processed immediately, but are stored in variables.  Only until the entire INS loop is read, which would constitute one record, would we accept or reject the record by checking the the ErrorFound flag variable.

The condition that checks for the ErrorFlag is placed in the SE segment because this is the ending point of the last record, but we also put another condition in the INS loop because the beginning of a new record also indicates the end of a previous record.

  if (sSegmentID == "SE")
  {
     if (bErrorFound)
     {
         if (sInsRec != "")
         {
             ProcessRejectedRec();
             sInsRec = "";
         }
         bErrorFound = false;
     }
     else
     {
         if (sInsRec != "")
         {
             ProcessAcceptedRec();
             sInsRec = "";
         }
     }
  }

View entire source code

To download the complete program, click here.

For more examples that process HIPAA EDI files, click here.

 

    Click here to download a trial version of the Framework EDI