In this tutorial we’ll discuss how to consume loaded EDI data using TypedDocuments and C#.NetOnce EDI data is loaded using either EDIValidator or EDIFileLoader that data is in memory and is available for use.  One possible usage is to save it into a database.  TypedDocuments provide an object oriented view over the EDI data and enables developers to access it with a well defined API.  

Please refer to our How To Parse, Load and Validate using .Net tutorial on how to first load EDI data.  Once data is loaded and validated, it exists in memory as an EDILightWeightDocument.

The Code


//Create a Typed Documents from the raw EDI data
Typed5010Document doc = new Typed5010Document(ediValidator.EDILightWeightDocument);
DocumentLoop stHeaderLoop = doc.MainSection.GetLoop(“INTERCHANGE HEADER/FUNCTIONAL GROUP/ST HEADER”);
//Get Loop 2000A (Billing/Pay-To Provider Hierarchical Level). Then get all the subscribers and claims information.  This is in loop 2000B
List<DocumentLoop> subscriberAndClaimsSections = stHeaderLoop.GetLoops(“2000A/2000B”);

SaveAllClaims(subscriberAndClaimsSections );

private void SaveAllClaims(List<DocumentLoop> claims){
   foreach (DocumentLoop claimSection in claims){
    SBR subscriber = claimSection.GetSegment<SBR>();
    DocumentLoop subscriberInfo = claimSection.GetLoop(“2010BA”);
    NM1 subName = subscriberInfo.GetSegment<NM1>();
    DMG demographics = subscriberInfo.GetSegment<DMG>();

            DocumentLoop insuranceInfoSection = claimSection.GetLoop(“2010BB”);
    NM1 insuranceName = insuranceInfoSection.GetSegment<NM1>();
    List<DocumentLoop> claimLoopSections = claimSection.GetLoops(“2300”);
    foreach (DocumentLoop cl in claimLoopSections){
      CLM clm = cl.GetSegment<CLM>();
      HI hi = cl.GetSegment<HI>();
      string diagnosisCode = hi.HealthCareCodeInformation1.IndustryCode1;
      List<DocumentLoop> serviceLineSections = cl.GetLoops(“2400”);
      foreach (DocumentLoop sl in serviceLineSections){
       //Get the service line segment
       SV1 sv1 = sl.GetSegment<SV1>();
       DTP serviceDate = sl.GetSegment<DTP>();

All typed segments contain properties with names just like in the implementation guides.

Now that was easy!

Take Charge Of EDI

RDPCrystal EDI Library