Combining EDI Data in NodeJS

In this tutorial we’ll discuss how to combine separate EDI data using the EDIFileJoiner component and NodeJS.  We can combine data at the Functional Group (GS) or the Transaction Header level (ST).  The basic flow is demonstrated in the diagram below.

 

EDIFileJoiner

 

In this example we’re going to combine two files ( read in as strings) at the Transaction Header level.  This means that after combining the data there will only be one Interchange (ISA-IEA) containing one Functional Group (GS-GE) which will contain all the Transactions (ST-SE) from each file.

We will be combining two 4010 834 EDI files.  Each of these files contain only one transaction (ST-SE).

File 1

ISA*00* *01*SUBPASSWOR*ZZ*APPSENDERID *ZZ*APPRECID *061218*1234*U*00401*000000000*0*T*:~
GS*BE*123*456*20061218*1234*1*X*004010X095A1~
ST*834*12345~
BGN*01*12456*19980520*1200****2~
N1*P5**FI*999888777~
N1*IN**FI*654456654~
INS*Y*18*021*20*A***FT~
REF*0F*123456789~
REF*1L*123456001~
DTP*356*D8*19960523~
NM1*IL*1*DOE*JOHN*P***34*123456789~
PER*IP**HP*7172343334*WP*7172341240~
N3*100 MARKET ST*APT 3G~
N4*CAMP HILL*PA*17011**CY*CUMBERLAND~
DMG*D8*19400816*M~
HD*021**HLT~
DTP*348*D8*19960601~
COB*P*890111*5~
N1*IN*ABC INSURANCE CO~
HD*021**DEN~
DTP*348*D8*19960601~
HD*021**VIS~
DTP*348*D8*19960601~
SE*22*12345~
GE*1*1~
IEA*2*000000000~

File 2

ISA*00* *01*SUBPASSWOR*ZZ*APPSENDERID *ZZ*APPRECID *061218*1234*U*00401*000000001*0*T*:~
GS*BE*123*456*20061218*1234*1*X*004010X095A2~
ST*834*12346~
BGN*02*12456*19980520*1200****2~
N1*P5**FI*999888777~
N1*IN**FI*654456654~
INS*Y*18*021*20*A***FT~
REF*0F*202443307~
REF*1L*123456001~
DTP*356*D8*19960112~
NM1*IL*1*SMITH*WILLIAM****34*202443307~
PER*IP**HP*7172343334*WP*7172341240~
N3*1715 SOUTHWIND AVENUE~
N4*ANYTOWN*PA*171110000~
DMG*D8*19700614~
HD*021**HMO~
DTP*348*D8*19960601~
LX*01~
NM1*P3*1*BROWN*BERNARD**DR****25~
SE*18*12346~
GE*1*2~
IEA*1*000000001~

The Code

const edi = require(‘rdpcrystal-edi-library’);
 
//First document
let ediDoc1 = “ISA*00*…”;
 
//Second Document
let ediDoc2 = “ISA*00*…”;
 
let joiner = new edi.EDIFileJoiner();
 
//Join these two documents at the Transactions Level (ST) level
joiner.FileJoinLevel = edi.FileJoinLevel.HEADER;
 
//Join the two documents
let joinedDocument = joiner.join([ediDoc1,ediDoc2]);
 
console.log(joinedDocument);

Joined Document

ISA*00* *01*SUBPASSWOR*ZZ*APPSENDERID *ZZ*APPRECID *061218*1234*U*00401*000000000*0*T*:~
GS*BE*123*456*20061218*1234*1*X*004010X095A1~
ST*834*12345~
BGN*01*12456*19980520*1200****2~
N1*P5**FI*999888777~
N1*IN**FI*654456654~
INS*Y*18*021*20*A***FT~
REF*0F*123456789~
REF*1L*123456001~
DTP*356*D8*19960523~
NM1*IL*1*DOE*JOHN*P***34*123456789~
PER*IP**HP*7172343334*WP*7172341240~
N3*100 MARKET ST*APT 3G~
N4*CAMP HILL*PA*17011**CY*CUMBERLAND~
DMG*D8*19400816*M~
HD*021**HLT~
DTP*348*D8*19960601~
COB*P*890111*5~
N1*IN*ABC INSURANCE CO~
HD*021**DEN~
DTP*348*D8*19960601~
HD*021**VIS~
DTP*348*D8*19960601~
SE*22*12345~
ST*834*12346~

BGN*02*12456*19980520*1200****2~
N1*P5**FI*999888777~
N1*IN**FI*654456654~
INS*Y*18*021*20*A***FT~
REF*0F*202443307~
REF*1L*123456001~
DTP*356*D8*19960112~
NM1*IL*1*SMITH*WILLIAM****34*202443307~
PER*IP**HP*7172343334*WP*7172341240~
N3*1715 SOUTHWIND AVENUE~
N4*ANYTOWN*PA*171110000~
DMG*D8*19700614~
HD*021**HMO~
DTP*348*D8*19960601~
LX*01~
NM1*P3*1*BROWN*BERNARD**DR****25~
SE*18*12346~
GE*2*1~
IEA*1*000000000~

Notice in the combined file that the GE segment first element (GE01) correctly says that there are 2 transactions. 

Now that was easy!

 

Take Charge Of EDI

RDPCrystal EDI Library

trial2