-
Notifications
You must be signed in to change notification settings - Fork 16
Unbundling An X12 File By Loop ID
The X12 format was designed to eliminate redundant information in an effort to make the transmission as small as possible. This was historically necessary when transmissions were very expensive and carriers charged for every byte transmitted.
Though this format is best for transmission it means that the information that you need for one unit of work, such as a claim, shares segments with other units.
When receiving a file your system can handle the entire file as a batch by processing it and laying it out into a database with the shared segments normalized into tables. However, this can take hours on a large file and it might be useful for you to unbundle the file so that each discrete unit can be operated on separately. This could be helpful for the following reasons:
- You will be making modifications on the unit and need to maintain version history on each one individually. You want to do this by storing the raw EDI and want to use a plain-text diff tool to show changes.
- You have large files that you want to unbundle quickly, and use multiple processors to operate on each unit simultaneously to increase scalability.
- You do not want an error in one unit to cause a reject of the entire file. You want to separate the units first and create acknowledgements at the unit level to return to the sender.
- You want to store each unit of work in the file system and make each a separate file that retains all of it's parent loops.
The X12 Parser 2.1 will allow you to do this at any loop by specifying the LoopId. For example, the LoopId for a claim is "2300" and the code for unbundling an 837 would look like the following:
X12Parser parser = new X12Parser();
Interchange interchange = parser.Parse(new FileStream("C:\\Temp\\5010_Example1,2, And 3 Combined.txt", FileMode.Open, FileAccess.Read));
var list = parser.UnbundleByLoop(interchange, "2300");
foreach (var item in list)
{
Trace.WriteLine("...");
Trace.WriteLine(item.SerializeToX12(true));
}
The method UnbundleByLoop will return a List which you can serialize back to X12. The true arguments adds the whitespace so that you can see the hierarchical structure more clearly. Use false if you want it back to the condensed X12 format.
An X12 file that looks like this:
ISA*00* *01*SECRET *ZZ*SUBMITTERS.ID *ZZ*RECEIVERS.ID *030101*1253*^*00501*000000905*1*T*:~
GS*HC*SENDER CODE*RECEIVER CODE*19991231*0802*1*X*005010X222~
ST*837*0021*005010X222~
BHT*0019*00*244579*20061015*1023*CH~
NM1*41*2*PREMIER BILLING SERVICE*****46*TGJ23~
PER*IC*JERRY*TE*3055552222*EX*231~
NM1*40*2*KEY INSURANCE COMPANY*****46*66783JJT~
HL*1**20*1~
PRV*BI*PXC*203BF0100Y~
NM1*85*2*BEN KILDARE SERVICE*****XX*9876543210~
N3*234 SEAWAY ST~
N4*MIAMI*FL*33111~
REF*EI*587654321~
NM1*87*2~
N3*2345 OCEAN BLVD~
N4*MAIMI*FL*33111~
HL*2*1*22*1~
SBR*P**2222-SJ******CI~
NM1*IL*1*SMITH*JANE****MI*JS00111223333~
DMG*D8*19430501*F~
NM1*PR*2*KEY INSURANCE COMPANY*****PI*999996666~
REF*G2*KA6663~
HL*3*2*23*0~
PAT*19~
NM1*QC*1*SMITH*TED~
N3*236 N MAIN ST~
N4*MIAMI*FL*33413~
DMG*D8*19730501*M~
CLM*26463774*100***11:B:1*Y*A*Y*I~
REF*D9*17312345600006351~
HI*BK:0340*BF:V7389~
LX*1~
SV1*HC:99213*40*UN*1***1~
DTP*472*D8*20061003~
LX*2~
SV1*HC:87070*15*UN*1***1~
DTP*472*D8*20061003~
LX*3~
SV1*HC:99214*35*UN*1***2~
DTP*472*D8*20061010~
LX*4~
SV1*HC:86663*10*UN*1***2~
DTP*472*D8*20061010~
HL*4**20*1~
NM1*85*1*KILDARE*BEN****XX*1999996666~
N3*1234 SEAWAY ST~
N4*MIAMI*FL*33111~
REF*EI*123456789~
PER*IC*CONNIE*TE*3055551234~
NM1*87*2~
N3*2345 OCEAN BLVD~
N4*MIAMI*FL*33111~
HL*5*4*22*1~
SBR*P*******CI~
NM1*IL*1*SMITH*JANE****MI*111223333~
DMG*D8*19430501*F~
NM1*PR*2*KEY INSURANCE COMPANY*****PI*999996666~
N3*3333OCEAN ST~
N4*SOUTH MIAMI*FL*33000~
REF*G2*PBS3334~
HL*6*5*23*0~
PAT*19~
NM1*QC*1*SMITH*TED~
N3*236 N MAIN ST~
N4*MIAMI*FL*33413~
DMG*D8*19730501*M~
CLM*26407789*79.04***11:B:1*Y*A*Y*I*P~
HI*BK:4779*BF:2724*BF:2780*BF:53081~
NM1*82*1*KILDARE*BEN****XX*1999996666~
PRV*PE*PXC*204C00000X~
REF*G2*KA6663~
NM1*77*2*KILDARE ASSOCIATES*****XX*1581234567~
N3*2345 OCEAN BLVD~
N4*MIAMI*FL*33111~
SBR*S*01*******CI~
DMG*D8*19430501*F~
OI***Y*P**Y~
NM1*IL*1*SMITH*JACK****MI*T55TY666~
N3*236 N MAIN ST~
N4*MIAMI*FL*33111~
NM1*PR*2*KEY INSURANCE COMPANY*****PI*999996666~
LX*1~
SV1*HC:99213*43*UN*1***1:2:3:4~
DTP*472*D8*20051003~
LX*2~
SV1*HC:90782*15*UN*1***1:2~
DTP*472*D8*20051003~
LX*3~
SV1*HC:J3301*21.04*UN*1***1:2~
DTP*472*D8*20051003~
SE*89*0021~
ST*837*0022*005010X222~
BHT*0019*00*0123*20061015*1023*RP~
NM1*41*2*PREMIER BILLING SERVICE*****46*TGJ23~
PER*IC*JERRY*TE*3055552222*EX*231~
NM1*40*2*AHLIC*****46*66783JJT~
HL*1**20*1~
PRV*BI*PXC*203BF0100Y~
NM1*85*2*BEN KILDARE SERVICE*****XX*9876543210~
N3*234 SEAWAY ST~
N4*MIAMI*FL*33111~
REF*EI*587654321~
NM1*87*2~
N3*2345 OCEAN BLVD~
N4*MIAMI*FL*33111~
HL*2*1*22*0~
SBR*P*18*12312-A******HM~
NM1*IL*1*SMITH*TED****MI*00221111~
N3*236 N MAIN ST~
N4*MIAMI*FL*33413~
DMG*D8*19430501*M~
NM1*PR*2*ALLIANCE HEALTH AND LIFE INSURANCE*****PI*741234~
CLM*26462967*100***11:B:1*Y*A*Y*I~
DTP*431*D8*19981003~
REF*D9*17312345600006351~
HI*BK:0340*BF:V7389~
NM1*77*2*KILDARE ASSOCIATES*****XX*5812345679~
N3*2345 OCEAN BLVD~
N4*MIAMI*FL*33111~
LX*1~
SV1*HC:99213*40*UN*1***1~
DTP*472*D8*20061003~
LX*2~
SV1*HC:87072*15*UN*1***1~
DTP*472*D8*20061003~
LX*3~
SV1*HC:99214*35*UN*1***2~
DTP*472*D8*20061010~
LX*4~
SV1*HC:86663*10*UN*1***2~
DTP*472*D8*20061010~
SE*41*0022~
GE*2*1~
IEA*1*000000905~
Will unbundle it into three individual Interchange objects that can serialized back into X12 that looks the next three blocks. Note that not only have the claim loops been separated in a way where their header information is retained, but the SE transaction trailer segment and GE function group segment has been updated to correctly reflect the number of segments in the transaction and the number of transactions in the function group so the resulting x12 is still valid.
#Claim #17312345600006351
ISA*00* *01*SECRET *ZZ*SUBMITTERS.ID *ZZ*RECEIVERS.ID *030101*1253*^*00501*000000905*1*T*:~
GS*HC*SENDER CODE*RECEIVER CODE*19991231*0802*1*X*005010X222~
ST*837*0021*005010X222~
BHT*0019*00*244579*20061015*1023*CH~
NM1*41*2*PREMIER BILLING SERVICE*****46*TGJ23~
PER*IC*JERRY*TE*3055552222*EX*231~
NM1*40*2*KEY INSURANCE COMPANY*****46*66783JJT~
HL*1**20*1~
PRV*BI*PXC*203BF0100Y~
NM1*85*2*BEN KILDARE SERVICE*****XX*9876543210~
N3*234 SEAWAY ST~
N4*MIAMI*FL*33111~
REF*EI*587654321~
NM1*87*2~
N3*2345 OCEAN BLVD~
N4*MAIMI*FL*33111~
HL*2*1*22*1~
SBR*P**2222-SJ******CI~
NM1*IL*1*SMITH*JANE****MI*JS00111223333~
DMG*D8*19430501*F~
NM1*PR*2*KEY INSURANCE COMPANY*****PI*999996666~
REF*G2*KA6663~
HL*3*2*23*0~
PAT*19~
NM1*QC*1*SMITH*TED~
N3*236 N MAIN ST~
N4*MIAMI*FL*33413~
DMG*D8*19730501*M~
CLM*26463774*100***11:B:1*Y*A*Y*I~
REF*D9*17312345600006351~
HI*BK:0340*BF:V7389~
LX*1~
SV1*HC:99213*40*UN*1***1~
DTP*472*D8*20061003~
LX*2~
SV1*HC:87070*15*UN*1***1~
DTP*472*D8*20061003~
LX*3~
SV1*HC:99214*35*UN*1***2~
DTP*472*D8*20061010~
LX*4~
SV1*HC:86663*10*UN*1***2~
DTP*472*D8*20061010~
SE*42*0021~
GE*1*1~
IEA*1*000000905~
ISA*00* *01*SECRET *ZZ*SUBMITTERS.ID *ZZ*RECEIVERS.ID *030101*1253*^*00501*000000905*1*T*:~
GS*HC*SENDER CODE*RECEIVER CODE*19991231*0802*1*X*005010X222~
ST*837*0021*005010X222~
BHT*0019*00*244579*20061015*1023*CH~
NM1*41*2*PREMIER BILLING SERVICE*****46*TGJ23~
PER*IC*JERRY*TE*3055552222*EX*231~
NM1*40*2*KEY INSURANCE COMPANY*****46*66783JJT~
HL*4**20*1~
NM1*85*1*KILDARE*BEN****XX*1999996666~
N3*1234 SEAWAY ST~
N4*MIAMI*FL*33111~
REF*EI*123456789~
PER*IC*CONNIE*TE*3055551234~
NM1*87*2~
N3*2345 OCEAN BLVD~
N4*MIAMI*FL*33111~
HL*5*4*22*1~
SBR*P*******CI~
NM1*IL*1*SMITH*JANE****MI*111223333~
DMG*D8*19430501*F~
NM1*PR*2*KEY INSURANCE COMPANY*****PI*999996666~
N3*3333OCEAN ST~
N4*SOUTH MIAMI*FL*33000~
REF*G2*PBS3334~
HL*6*5*23*0~
PAT*19~
NM1*QC*1*SMITH*TED~
N3*236 N MAIN ST~
N4*MIAMI*FL*33413~
DMG*D8*19730501*M~
CLM*26407789*79.04***11:B:1*Y*A*Y*I*P~
HI*BK:4779*BF:2724*BF:2780*BF:53081~
NM1*82*1*KILDARE*BEN****XX*1999996666~
PRV*PE*PXC*204C00000X~
REF*G2*KA6663~
NM1*77*2*KILDARE ASSOCIATES*****XX*1581234567~
N3*2345 OCEAN BLVD~
N4*MIAMI*FL*33111~
SBR*S*01*******CI~
DMG*D8*19430501*F~
OI***Y*P**Y~
NM1*IL*1*SMITH*JACK****MI*T55TY666~
N3*236 N MAIN ST~
N4*MIAMI*FL*33111~
NM1*PR*2*KEY INSURANCE COMPANY*****PI*999996666~
LX*1~
SV1*HC:99213*43*UN*1***1:2:3:4~
DTP*472*D8*20051003~
LX*2~
SV1*HC:90782*15*UN*1***1:2~
DTP*472*D8*20051003~
LX*3~
SV1*HC:J3301*21.04*UN*1***1:2~
DTP*472*D8*20051003~
SE*53*0021~
GE*1*1~
IEA*1*000000905~
ISA*00* *01*SECRET *ZZ*SUBMITTERS.ID *ZZ*RECEIVERS.ID *030101*1253*^*00501*000000905*1*T*:~
GS*HC*SENDER CODE*RECEIVER CODE*19991231*0802*1*X*005010X222~
ST*837*0022*005010X222~
BHT*0019*00*0123*20061015*1023*RP~
NM1*41*2*PREMIER BILLING SERVICE*****46*TGJ23~
PER*IC*JERRY*TE*3055552222*EX*231~
NM1*40*2*AHLIC*****46*66783JJT~
HL*1**20*1~
PRV*BI*PXC*203BF0100Y~
NM1*85*2*BEN KILDARE SERVICE*****XX*9876543210~
N3*234 SEAWAY ST~
N4*MIAMI*FL*33111~
REF*EI*587654321~
NM1*87*2~
N3*2345 OCEAN BLVD~
N4*MIAMI*FL*33111~
HL*2*1*22*0~
SBR*P*18*12312-A******HM~
NM1*IL*1*SMITH*TED****MI*00221111~
N3*236 N MAIN ST~
N4*MIAMI*FL*33413~
DMG*D8*19430501*M~
NM1*PR*2*ALLIANCE HEALTH AND LIFE INSURANCE*****PI*741234~
CLM*26462967*100***11:B:1*Y*A*Y*I~
DTP*431*D8*19981003~
REF*D9*17312345600006351~
HI*BK:0340*BF:V7389~
NM1*77*2*KILDARE ASSOCIATES*****XX*5812345679~
N3*2345 OCEAN BLVD~
N4*MIAMI*FL*33111~
LX*1~
SV1*HC:99213*40*UN*1***1~
DTP*472*D8*20061003~
LX*2~
SV1*HC:87072*15*UN*1***1~
DTP*472*D8*20061003~
LX*3~
SV1*HC:99214*35*UN*1***2~
DTP*472*D8*20061010~
LX*4~
SV1*HC:86663*10*UN*1***2~
DTP*472*D8*20061010~
SE*41*0022~
GE*1*1~
IEA*1*000000905~