Finding Closest Segment To Errors – JS

Index

    Finding Closest Segment To Errors

    When an error is generated while validating EDI data it may be helpful to find a nearby segment that could help developers get more information about the error.  For example, many HIPAA developers want to know the actual claim (CLM Segment) where errors were generated.  They can then use the claim id to find out which claim to fix.

    The AssociateClosestSegmentToErrorAndWarnings method can be used in this scenario.  When this method is called after validation EDIValidator will find the closest segment to errors and warnings and assign it to the error/warning’s ClosestSegment property.

    Example

    validator.validate();
    var closestSegment = new RDPCrystalEDILibrary.ClosestSegmentToError();
    closestSegment.Name = ‘CLM’;
    validator.associateClosestSegmentToErrorsAndWarnings(closestSegment);

    //Get all errors from the EDI data
    for (let i = 0; i < validator.Errors.Count; i++) {
        let error = validator.Errors.getItem(i);
        let claimID = ‘NA’;
        if (error.ClosestSegment != null ) {
          //get the claim id (first element) of the claim segment
          claimID = error.ClosestSegment.Elements.getItem(0).DataValue;
        }
    }

    Now when an error occurs the closest CLM segment will be assigned to the ClosestSegment property on the error or warning.  This will enable developers to know what claim the error occurred in.

    Additionally if there are multiple segments that could be close to the error and they only differ by element data the additional properties on the ClosestSegmentToError  object can be used to find the closest segment given the element index and value

    Example

    var closestSegment = new RDPCrystalEDILibrary.ClosestSegmentToError();
    closestSegment.Name = ‘NM1‘;
    closestSegment.ElementIndex = 2;
    closestSegment.CompareValue = “Some Value;
    validator.associateClosestSegmentToErrorsAndWarnings(closestSegment);
    Now when an error occurs the closest NM1 segment whose second element value is “Some Value” will be assigned to the ClosestSegment of the error.
    Did this article answer your question?