Scrub EDI Data – JS

Index

    Scrub EDI Data

    EDIFileScrubber allows developers to scrub EDI data to hide sensitive information.

    Example

    const edi = require(‘rdpcrystal-edi-library’);
     
    //Characters Constants
    const Q = 81; //ASCII letter ‘Q’
     
    //Element values will be replaced by the character ‘X’
    const X = 88 //ACSII letter ‘X’
     
    let data = “ISA*00*          *00*          *ZZ*133052274 *ZZ*311279999…”;
     
    //Create a new EDIFileScrubber
    let scrubber = new edi.EDIFileScrubber();
     
    //We will create a scrub rule and apply it to the ISA segment position 1 and 2
    let isaRule = new edi.ScrubRule();
    isaRule.SegmentName = “ISA”;
    isaRule.ReplaceCharacter = Q;
     
    //Element values will be replaced by the character ‘Q’
    let sp01 = new edi.ScrubPosition();
    sp01.ElementNumber = 0; //Apply to element 1
    isaRule.addPosition(sp01);
     
    let sp02 = new edi.ScrubPosition();
    sp02.ElementNumber = 1; //Apply to element 2
    isaRule.addPosition(sp02);
     
    //We will create a scrub rule and apply it to the NM1 segment position 8
    let nm1Rule = new edi.ScrubRule();
    nm1Rule.SegmentName = “NM1”;
    nm1Rule.ReplaceCharacter = X;
     
    //Element values will be replaced by the character ‘Q’
    let nm08 = new edi.ScrubPosition();
    nm08.ElementNumber = 8; //Apply to element 1
    nm1Rule.addPosition(nm08);
     
    //Add the rules to the scubber
    scrubber.addRule(isaRule);
    scrubber.addRule(nm1Rule);
     
    let scrubbedDocument = scrubber.scrub(data);
     
    console.log(scrubbedDocument.generateEDIData());

    Output

    When this file is scrubbed the ISA and NM1 segments will look like the following.

    ISA*QQ*QQQQQQQQQQ*00*          *ZZ*133052274 *ZZ*311279999      *120419*2125*^*00501*000002120*0*P*<~
    NM1*41*2*CS*****46*XXXXXXXXX~

    We can see the element 1 and 2 of the ISA segment is replaced by the letter Q and element 8 of NM1 is replaced by the character X.

    in EDI File Scrubber – JS
    Did this article answer your question?