-
Notifications
You must be signed in to change notification settings - Fork 16
Parsing An 837 Transaction
An 837 is a Claim for medical services transaction. The 837P is the most common of the 3 claim types: Dental, Professional and Institutional. The following example will show you how to:
- Take an 837 file and create X12 XML that shows the hieararchical relationships of the X12 segments with comments related to their values.
- Take an 837 file and format it as X12 to reveal it's heirarchical relationship.
- Transform an 837 into HTML for presentation as X12 with tool tips.
A sample 837 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~
SE*42*0021~
GE*1*1~
IEA*1*000000905~
This can be parsed with the following lines of C# code:
using System;
using System.IO;
using OopFactory.X12.Parsing;
using OopFactory.X12.Parsing.Model;
public class Program
{
FileStream fstream = new FileStream("Sample1.txt", FileMode.Open, FileAccess.Read);
var parser = new X12Parser();
Interchange interchange = parser.Parse(fstream);
string xml = interchange.Serialize();
}
The resulting output xml will look like this:
<?xml version="1.0"?>
<Interchange>
<ISA>
<!--Author Information Qualifier-->
<ISA01>00<!--No Authorization Information Present--></ISA01>
<!--Author Information-->
<ISA02> </ISA02>
<!--Security Information Qualifer-->
<ISA03>01<!--Password--></ISA03>
<!--Security Information-->
<ISA04>SECRET </ISA04>
<!--Interchange ID Qualifier-->
<ISA05>ZZ<!--Mutually Defined--></ISA05>
<!--Interchange Sender ID-->
<ISA06>SUBMITTERS.ID </ISA06>
<!--Interchange ID Qualifier-->
<ISA07>ZZ<!--Mutually Defined--></ISA07>
<!--Interchange Receiver ID-->
<ISA08>RECEIVERS.ID </ISA08>
<!--Interchange Date-->
<ISA09>030101</ISA09>
<!--Interchange Time-->
<ISA10>1253</ISA10>
<!--Inter Control Standards Identifier-->
<ISA11>^</ISA11>
<!--Inter Control Version Number-->
<ISA12>00501</ISA12>
<!--Inter Control Number-->
<ISA13>000000905</ISA13>
<!--Acknowlegment Requested-->
<ISA14>1<!--Interchange Acknowledgment Requested--></ISA14>
<!--Usage Indicator-->
<ISA15>T<!--Test Data--></ISA15>
<!--Component Element Separator-->
<ISA16>
<ISA1601 />
<ISA1602 />
</ISA16>
</ISA>
<FunctionGroup>
<GS>
<!--Functional Identifier Code-->
<GS01>HC<!--Health Care--></GS01>
<!--Application Sender's Code-->
<GS02>SENDER CODE</GS02>
<!--Application Receiver's Code-->
<GS03>RECEIVER CODE</GS03>
<!--Date-->
<GS04>19991231</GS04>
<!--Time-->
<GS05>0802</GS05>
<!--Group Control Number-->
<GS06>1</GS06>
<!--Responsible Agency Code-->
<GS07>X<!--Accredited Standards Committee X12--></GS07>
<!--Version/Release/Industry Identifier Code-->
<GS08>005010X222</GS08>
</GS>
<Transaction ControlNumber="0021">
<!---Additional Data--->
</Transaction>
<GE>
<!--Number of Transaction Sets Included-->
<GE01>1</GE01>
<!--Group Control Number-->
<GE02>1</GE02>
</GE>
</FunctionGroup>
<IEA>
<!--Number of Included Functional Groups-->
<IEA01>1</IEA01>
<!--Interchange Control Number-->
<IEA02>000000905</IEA02>
</IEA>
</Interchange>
In some cases you may only want to be able to see the hierarchy in the X12 without the need for it to be xml. You can use the following code snippet to add whitespace to the stream:
FileStream fstream = new FileStream("Sample1.txt", FileOpen.Open, FileAccess.Read);
var parser = new X12Parser();
Interchange interchange = parser.Parse(fstream);
string x12 = interchange.SerializeToX12(true);
This will produce the following output:
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~
If your output is to the web and you want the html to take advantage of style and tool tips, you can use the following code for a more rich output.
var htmlService = new X12HtmlTransformationService(new X12EdiParsingService(suppressComments: false));
Stream ediFile = new FileStream("c:\\5010_Example1_HealthInsurance.txt", FileMode.Open, FileAccess.Read);
string html = htmlService.Transform(new StreamReader(ediFile).ReadToEnd());
The divs have the following class names that will allow you to add some of your own style through CSS:
- interchange
- function-group
- transaction
- hierarchical-loop
- loop
- first-segment
- segment
- element
- element-value
- component