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.
RDPCrystal EDI Library is used by Fortune 100/500 and companies all over the world to handle X12 EDI documents.
Examples projects are located in the /examples folder
Send any support questions to support@rdpcrystal.com
Installation
npm i rdpcrystal-edi-library
Usage
Validate an X12 EDI File
const fs = require('fs');
const edi = require('rdpcrystal-edi-library');
let validator = new edi.EDIValidator();
validator.LoadValidatedData = true;
let validationRules = fs.readFileSync('Rules_5010_270_005010X279A1.Rules').toString();
validator.EDIRulesFileData = validationRules;
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");
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
});
}
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();
doc.Delimiters.ElementTerminatorCharacter = STAR;
doc.Delimiters.CompositeTerminatorCharacter = COLON;
doc.Delimiters.SegmentTerminatorCharacter = TILDA;
doc.AutoPlaceCorrectNumOfSegments = true;
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");
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");
console.log(doc.generateEDIData());
Generate X12 EDI 999 Acknowlegements
const fs = require('fs');
const edi = require('rdpcrystal-edi-library');
let validator = new edi.EDIValidator();
validator.LoadValidatedData = true;
let validationRules = fs.readFileSync('Rules_5010_270_005010X279A1.Rules').toString();
validator.EDIRulesFileData = validationRules;
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->");
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");
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');
let original ="ISA*00* *00* *ZZ*133052274 *ZZ*311279999 ...";
let splitter = new edi.EDIFileSplitter();
splitter.FileSplitLevel = edi.FileSplitLevel.HEADER;
splitter.NumberOfItemsPerFile = 1;
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');
let ediDoc1 = "ISA*00* *00* *ZZ*133052274 *ZZ*311279999...";
let ediDoc2 = "ISA*00* *00* *ZZ*133052274 *ZZ*311279999...";
let documents = [ediDoc1, ediDoc2];
let joiner = new edi.EDIFileJoiner();
joiner.FileJoinLevel = edi.FileJoinLevel.FUNCTIONALGROUP;
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');
let dataToLoad = "ISA*00* *00* *ZZ*133052274 *ZZ*311279999...";
let fileLoader = new edi.EDIFileLoader();
fileLoader.EDIDataString = dataToLoad;
let flatDoc = fileLoader.load();
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");
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/