Socket
Socket
Sign inDemoInstall

rdpcrystal-edi-library

Package Overview
Dependencies
0
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    rdpcrystal-edi-library

ASCII X12 EDI Library, Create, Parse, Load, Validate, View, Edit, Split, Join And Scrub EDI Data


Version published
Maintainers
1
Install size
3.65 MB
Created

Readme

Source

RDPCrystal EDI Library

RDPCrystal EDI Library is a NodeJS library that is used to Create, Parse, Load, Validate, View, Edit, Split, Join and Scrub EDI data. RDPCrystal EDI Library is located at rdpcrystal.com. Full documentation can be found here.

Examples projects are located in the /examples folder

Installation

npm i rdpcrystal-edi-library

Usage

Validate an X12 EDI File

const fs = require('fs');
const edi = require('rdpcrystal-edi-library');

//Create a new validator
let validator = new edi.EDIValidator();

//While validating also load the data in memory
validator.LoadValidatedData = true;

//Load a 5010 270 validation rules
let validationRules = fs.readFileSync('Rules_5010_270_005010X279A1.Rules').toString();

validator.EDIRulesFileData = validationRules;

//Set the EDI data to validate and load.  This can also be read in from a file
validator.EDIDataString = "ISA*00*..........*01*SECRET....*ZZ*SUBMITTERS.ID..*ZZ*RECEIVERS.ID...*030101*1253*^*00501*000000905*1*T*:~" +
    "GS*Hk*SENDER CODE*RECEIVERCODE*19991231*0802*1*X*005010X279A1~" +
    "ST*271*1234*005010X279A1~" +
    "BHT*0022*13*10001234*20060501*1319~" +
    "HL*1**20*1~" +
    "NM1*PR*2*ABC COMPANY*****PI*842610001~" +
    "HL*2*1*21*1~" +
    "NM1*1P*2*BONE AND JOINT CLINIC*****SV*2000035~" +
    "HL*3*2*22*0~" +
    "TRN*1*93175-012547*9877281234~" +
    "NM1*IL*1*SMITH*ROBERT****MI*11122333301~" +
    "DMG*D8*19430519~" +
    "DTP*291*D8*20060501~" +
    "EQ*30~" +
    "SE*13*1234~" +
    "GE*1*1~" +
    "IEA*1*000000905~";

console.log("Validating 5010 271 EDI Files");
validator.validate();

console.log("Errors Found");
//Get all errors from the EDI data
for (let i = 0; i < validator.Errors.Count; i++) {
    let error = validator.Errors.getItem(i);

    console.log(
        {
            Type: "Error",
            Line: error.LineNumber,
            Transaction: "",
            SnipLevel: error.SnipLevel,  //SnipTestLevel Enum
            Message: error.Message, //EDIValidationMessage Enum
            Loop: error.Loop,
            Segment: error.Segment,
            Element: error.ElementOrdinal,
            Composite: error.CompositeElementOrdinal,
            Description: error.Description,
            Ordinal: error.SegmentOrdinal
        });
}

Create An X12 EDI File

const edi = require('rdpcrystal-edi-library');

const STAR = 42; //'*'
const COLON = 58 //':'
const TILDA = 126 //'~'

let doc = new edi.EDILightWeightDocument();

//Set the delimiters
doc.Delimiters.ElementTerminatorCharacter = STAR;
doc.Delimiters.CompositeTerminatorCharacter = COLON;
doc.Delimiters.SegmentTerminatorCharacter = TILDA;

//Automatically set current segment count in SE01
doc.AutoPlaceCorrectNumOfSegments = true;

//Write each segment in a new line
doc.EachSegmentInNewLine = true;

let interchangeLoop = doc.createLoop("Interchange header");
let isa = interchangeLoop.createSegment("ISA");
isa.addElement("00");
isa.addElement(" ");
isa.addElement("00");
isa.addElement(" ");
isa.addElement("ZZ");
isa.addElement("InterchangeSenderID");
isa.addElement("ZZ");
isa.addElement("InterchangeReceiverID");
isa.addElement("070303");
isa.addElement("1804");
isa.addElement("U");
isa.addElement("00401");
isa.addElement("1");
isa.addElement("1");
isa.addElement("T");
isa.addElement(":");

let functionalGroup = interchangeLoop.createLoop("FunctionalGroup");
let gs = functionalGroup.createSegment("GS");

gs.addElement("T");
gs.addElement("SH");
gs.addElement("ApplicationSenderCode");
gs.addElement("ApplicationReceiverCode");
gs.addElement("2005");
gs.addElement("132334");
gs.addElement("1");
gs.addElement("X");
gs.addElement("004010");

//Create a new sample composite element
let compositeElement = new edi.LightWeightElement();
compositeElement.addCompositeElement("aa");
compositeElement.addCompositeElement("bb");

gs.elements.add(compositeElement);

let transaction = functionalGroup.createLoop("Transaction Header");
let st = transaction.createSegment("ST");
st.addElement("837");
st.addElement("123");
st.addElement("005010X222A1");

let se = transaction.createSegment("SE");
se.addElement("0");
se.addElement("123");

let endfunctionalGroup = functionalGroup.createLoop("EndFunctionalGroup");
let ge = endfunctionalGroup.createSegment("GE");
ge.addElement("0");
ge.addElement("1");

let endInterchange = interchangeLoop.createLoop("EndInterchange");
let iea = endInterchange.createSegment("IEA");
iea.addElement("0");
iea.addElement("1");

//Display the new EDI document
console.log(doc.generateEDIData());

Generate X12 EDI 999 Acknowlegements

const fs = require('fs');
const edi = require('rdpcrystal-edi-library');

//Create a new validator
let validator = new edi.EDIValidator();

//While validating also load the data in memory
validator.LoadValidatedData = true;

//Load a 5010 270 validation rules
let validationRules = fs.readFileSync('Rules_5010_270_005010X279A1.Rules').toString();

validator.EDIRulesFileData = validationRules;

//Set the EDI data to validate and load.  This can also be read in from a file
validator.EDIDataString = "ISA*00*..........*01*SECRET....*ZZ*SUBMITTERS.ID..*ZZ*RECEIVERS.ID...*030101*1253*^*00501*000000905*1*T*:~" +
    "GS*Hk*SENDER CODE*RECEIVERCODE*19991231*0802*1*X*005010X279A1~" +
    "ST*271*1234*005010X279A1~" +
    "BHT*0022*13*10001234*20060501*1319~" +
    "HL*1**20*1~" +
    "NM1*PR*2*ABC COMPANY*****PI*842610001~" +
    "HL*2*1*21*1~" +
    "NM1*1P*2*BONE AND JOINT CLINIC*****SV*2000035~" +
    "HL*3*2*22*0~" +
    "TRN*1*93175-012547*9877281234~" +
    "NM1*IL*1*SMITH*ROBERT****MI*11122333301~" +
    "DMG*D8*19430519~" +
    "DTP*291*D8*20060501~" +
    "EQ*30~" +
    "SE*13*1234~" +
    "GE*1*1~" +
    "IEA*1*000000905~";

console.log("Validating 5010 271 EDI Files");
validator.validate();

console.log("Errors Found->");

//Get all errors from the EDI data
for (let i = 0; i < validator.Errors.Count; i++) {
    let error = validator.Errors.getItem(i);

    console.log(
        {
            Type: "Error",
            Line: error.LineNumber,
            Transaction: "",
            SnipLevel: error.SnipLevel,
            Message: error.Message,
            Loop: error.Loop,
            Segment: error.Segment,
            Element: error.ElementOrdinal,
            Composite: error.CompositeElementOrdinal,
            Description: error.Description,
            Ordinal: error.SegmentOrdinal
        });
}

console.log("Generated 5010 999 Acknowledgment File");

//Generate 5010 999 Acknowledgment File
let ack999Generator = new edi.Ack999Generator();
let ackDocument = ack999Generator.generate(validator);

console.log(ackDocument.generateEDIData());

Spit an X12 EDI File

const edi = require('rdpcrystal-edi-library');

//original document with 2 Transactions (ST) - 
//PLEASE ADD YOUR OWN EDI DATA HERE
let original ="ISA*00*          *00*          *ZZ*133052274      *ZZ*311279999 ...";

let splitter = new edi.EDIFileSplitter();

//Split the document at the ST header
splitter.FileSplitLevel = edi.FileSplitLevel.HEADER;

//Put 1 ST-SE loop in each file
splitter.NumberOfItemsPerFile = 1;

//split the orginal document
let splitDocs = splitter.split(original);

console.log("First Split Document");
console.log(splitDocs[0]);

console.log("Second Split Document");
console.log(splitDocs[1]);

Join an EDI File

const edi = require('rdpcrystal-edi-library');

//First document
//PLEASE ADD YOUR OWN EDI DATA HERE
let ediDoc1 = "ISA*00*          *00*          *ZZ*133052274      *ZZ*311279999...";

//Second Document
//PLEASE ADD YOUR OWN EDI DATA HERE
let ediDoc2 = "ISA*00*          *00*          *ZZ*133052274      *ZZ*311279999...";

let documents = [ediDoc1, ediDoc2];

let joiner = new edi.EDIFileJoiner();

//This these two documents at the functional group (GS) level
joiner.FileJoinLevel = edi.FileJoinLevel.FUNCTIONALGROUP;

//Join the two documents
let joinedDocuments = joiner.join(documents);

console.log("Joined document by Functional Group");
console.log(joinedDocuments);

Load an X12 EDI File

const edi = require('rdpcrystal-edi-library');

//PLEASE ADD YOUR OWN EDI DATA HERE
let dataToLoad = "ISA*00*          *00*          *ZZ*133052274      *ZZ*311279999...";

let fileLoader = new edi.EDIFileLoader();

//Load EDI data
fileLoader.EDIDataString = dataToLoad;

let flatDoc = fileLoader.load();

//Build a visual representation of the EDI document
writeDocumentTree(flatDoc.Loops.getItem(0), 0);

function writeDocumentTree(loop, indent) {
    if (loop != null) {

        for (let i = 0; i < indent; i++) {
            process.stdout.write("   ");
        }

        console.log(loop.Name);

        indent++;
        writeSegment(loop.Segments, indent);

        if (loop.Loops != null) {
            for (let i = 0; i < loop.Loops.Count; i++) {
                writeDocumentTree(loop.Loops.getItem(i), indent);
            }

            indent++;
        }
    }
}

function writeSegment(segments, indent) {
    for (let i = 0; i < segments.Count; i++) {
        let seg = segments.getItem(i);
        for (let i = 0; i < indent; i++) {
            process.stdout.write("      ");
        }

        console.log(seg.Name);

        writeElement(seg.Elements, indent);
    }
}

function writeElement(elements, indent) {
    for (let i = 0; i < elements.Count; i++) {
        let elem = elements.getItem(i);

        for (let i = 0; i < indent; i++) {
            process.stdout.write("       ");
        }
        if (elem.Composite) {
            console.log("Composite");
            //Check for composite elements
            if (elem.Elements != null && elem.Elements.Count > 0) {
                writeElement(elem.Elements, ++indent);
                indent--;
            }

        } else {
            console.log("[" + elem.DataValue + "]");
        }
    }
}

License

http://www.rdpcrystal.com/free-trial/

Keywords

FAQs

Last updated on 10 Mar 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc