private void btnTranslate271X279_Click(object sender, System.EventArgs e) { ediDocument oEdiDoc = null; ediSchemas oSchemas = null; ediDataSegment oSegment = null; ediDataElement oElement = null; string sSegmentID; string sLoopSection; int nArea; string sValue; string sLoopHLQlfr = ""; Cursor = Cursors.WaitCursor; //CREATES EDIDOC OBJECT ediDocument.Set(ref oEdiDoc, new ediDocument()); //THIS MAKES CERTAIN THAT FREDI ONLY USES THE SEF FILE PROVIDED, AND THAT IT DOES //NOT USE ITS BUILT-IN STANDARD REFERENCE TABLE TO TRANSLATE THE EDI FILE. ediSchemas.Set(ref oSchemas,(ediSchemas) oEdiDoc.GetSchemas()); //oSchemas = (ediSchemas) oEdiDoc.GetSchemas(); oSchemas.EnableStandardReference = false; //THIS OPTIONS STOPS FREDI FROM KEEPING ALL THE SEGMENTS IN MEMORY oEdiDoc.CursorType = DocumentCursorTypeConstants.Cursor_ForwardOnly; //LOADS THE SEF FILE oEdiDoc.ImportSchema("271_005010X279A1.SemRef.EVAL0.SEF", 0); //LOADS THE EDI FILE oEdiDoc.LoadEdi("271_322ResponseRepeatExample.txt"); //GETS THE FIRST DATA SEGMENT ediDataSegment.Set(ref oSegment, (ediDataSegment) oEdiDoc.FirstDataSegment); //oSegment = (ediDataSegment) oEdiDoc.FirstDataSegment //LOOP THAT WILL TRAVERSE THRU EDI FILE FROM TOP TO BOTTOM while ( oSegment != null ) { //DATA SEGMENTS WILL BE IDENTIFIED BY THEIR ID, THE LOOP SECTION AND AREA //(OR TABLE) NUMBER THAT THEY ARE IN. sSegmentID = oSegment.ID; sLoopSection = oSegment.LoopSection; nArea = oSegment.Area; if (nArea == 0) { if (sLoopSection == "") { if (sSegmentID == "ISA") { sValue = oSegment.get_DataElementValue(1,0); //Authorization Information Qualifier sValue = oSegment.get_DataElementValue(2,0); //Authorization Information sValue = oSegment.get_DataElementValue(3,0); //Security Information Qualifier sValue = oSegment.get_DataElementValue(4,0); //Security Information sValue = oSegment.get_DataElementValue(5,0); //Interchange ID Qualifier sValue = oSegment.get_DataElementValue(6,0); //Interchange Sender ID sValue = oSegment.get_DataElementValue(7,0); //Interchange ID Qualifier sValue = oSegment.get_DataElementValue(8,0); //Interchange Receiver ID sValue = oSegment.get_DataElementValue(9,0); //Interchange Date sValue = oSegment.get_DataElementValue(10,0); //Interchange Time sValue = oSegment.get_DataElementValue(11,0); //Repetition Separator sValue = oSegment.get_DataElementValue(12,0); //Interchange Control Version Number listBox1.Items.Add("Interchange Control Number = " + oSegment.get_DataElementValue(13,0)); //Interchange Control Number sValue = oSegment.get_DataElementValue(14,0); //Acknowledgment Requested sValue = oSegment.get_DataElementValue(15,0); //Usage Indicator sValue = oSegment.get_DataElementValue(16,0); //Component Element Separator } else if (sSegmentID == "GS") { sValue = oSegment.get_DataElementValue(1,0); //Functional Identifier Code sValue = oSegment.get_DataElementValue(2,0); //Application Sender's Code sValue = oSegment.get_DataElementValue(3,0); //Application Receiver's Code sValue = oSegment.get_DataElementValue(4,0); //Date sValue = oSegment.get_DataElementValue(5,0); //Time listBox1.Items.Add("Group Control Number = " + oSegment.get_DataElementValue(6,0)); //Group Control Number sValue = oSegment.get_DataElementValue(7,0); //Responsible Agency Code sValue = oSegment.get_DataElementValue(8,0); //Version / Release / Industry Identifier Code } //sSegmentID } //sLoopSection } else if (nArea == 1) { if (sLoopSection == "") { if (sSegmentID == "ST") { sValue = oSegment.get_DataElementValue(1,0); //Transaction Set Identifier Code listBox1.Items.Add("Transaction Set Control Number = " + oSegment.get_DataElementValue(2,0)); //Transaction Set Control Number sValue = oSegment.get_DataElementValue(3,0); //Implementation Convention Reference } else if (sSegmentID == "BHT") { sValue = oSegment.get_DataElementValue(1,0); //Hierarchical Structure Code sValue = oSegment.get_DataElementValue(2,0); //Transaction Set Purpose Code listBox1.Items.Add("Response Reference Identification = " + oSegment.get_DataElementValue(3,0)); //Reference Identification listBox1.Items.Add("Date = " + oSegment.get_DataElementValue(4,0)); //Date sValue = oSegment.get_DataElementValue(5,0); //Time } //sSegmentID } //sLoopSection } else if (nArea == 2) { if (sLoopSection == "HL") { if (sSegmentID == "HL") { sLoopHLQlfr = oSegment.get_DataElementValue(3,0); //In most cases the loop qualifier is the first element of the first segment in the loop, but not necessarily } } if (sLoopHLQlfr == "20") //Information Source { if (sLoopSection == "HL") { if (sSegmentID == "HL") { sValue = oSegment.get_DataElementValue(1,0); //Hierarchical ID Number sValue = oSegment.get_DataElementValue(2,0); //Hierarchical Parent ID Number sValue = oSegment.get_DataElementValue(3,0); //Hierarchical Level Code sValue = oSegment.get_DataElementValue(4,0); //Hierarchical Child Code } //Segment ID } else if (sLoopSection == "HL;NM1") { if (sSegmentID == "NM1") { sValue = oSegment.get_DataElementValue(1,0); //Entity Identifier Code sValue = oSegment.get_DataElementValue(2,0); //Entity Type Qualifier listBox1.Items.Add("Payer Name = " + oSegment.get_DataElementValue(3,0)); //Name Last or Organization Name sValue = oSegment.get_DataElementValue(4,0); //Name First sValue = oSegment.get_DataElementValue(5,0); //Name Middle sValue = oSegment.get_DataElementValue(6,0); //Name Prefix sValue = oSegment.get_DataElementValue(7,0); //Name Suffix sValue = oSegment.get_DataElementValue(8,0); //Identification Code Qualifier listBox1.Items.Add("Payer ID = " + oSegment.get_DataElementValue(9,0)); //Identification Code } } //sLoopSection } //sLoopHLQlfr == "20" else if (sLoopHLQlfr == "21") //Information Receiver { if (sLoopSection == "HL") { if (sSegmentID == "HL") { sValue = oSegment.get_DataElementValue(1,0); //Hierarchical ID Number sValue = oSegment.get_DataElementValue(2,0); //Hierarchical Parent ID Number sValue = oSegment.get_DataElementValue(3,0); //Hierarchical Level Code sValue = oSegment.get_DataElementValue(4,0); //Hierarchical Child Code } //Segment ID } else if (sLoopSection == "HL;NM1") { if (sSegmentID == "NM1") { sValue = oSegment.get_DataElementValue(1,0); //Entity Identifier Code sValue = oSegment.get_DataElementValue(2,0); //Entity Type Qualifier listBox1.Items.Add("Provider Name = " + oSegment.get_DataElementValue(3,0)); //Name Last or Organization Name sValue = oSegment.get_DataElementValue(4,0); //Name First sValue = oSegment.get_DataElementValue(5,0); //Name Middle sValue = oSegment.get_DataElementValue(6,0); //Name Prefix sValue = oSegment.get_DataElementValue(7,0); //Name Suffix sValue = oSegment.get_DataElementValue(8,0); //Identification Code Qualifier listBox1.Items.Add("Service Provider Identification = " + oSegment.get_DataElementValue(9,0)); //Identification Code } } //sLoopSection } //sLoopHLQlfr == "21" else if (sLoopHLQlfr == "22") //Subscriber { if (sLoopSection == "HL") { if (sSegmentID == "HL") { sValue = oSegment.get_DataElementValue(1,0); //Hierarchical ID Number sValue = oSegment.get_DataElementValue(2,0); //Hierarchical Parent ID Number sValue = oSegment.get_DataElementValue(3,0); //Hierarchical Level Code sValue = oSegment.get_DataElementValue(4,0); //Hierarchical Child Code } //Segment ID } else if (sLoopSection == "HL;NM1") { if (sSegmentID == "NM1") { sValue = oSegment.get_DataElementValue(1,0); //Entity Identifier Code sValue = oSegment.get_DataElementValue(2,0); //Entity Type Qualifier sValue = oSegment.get_DataElementValue(3,0); //Name Last or Organization Name listBox1.Items.Add("Subscriber Name = " + oSegment.get_DataElementValue(4,0)); //Name First sValue = oSegment.get_DataElementValue(5,0); //Name Middle sValue = oSegment.get_DataElementValue(6,0); //Name Prefix sValue = oSegment.get_DataElementValue(7,0); //Name Suffix sValue = oSegment.get_DataElementValue(8,0); //Identification Code Qualifier listBox1.Items.Add("Subscriber Member Identification = " + oSegment.get_DataElementValue(9,0)); //Identification Code } else if (sSegmentID == "N3") { listBox1.Items.Add("Subscriber Address = " + oSegment.get_DataElementValue(1,0)); //Address Information sValue = oSegment.get_DataElementValue(2,0); //Address Information } else if (sSegmentID == "N4") { listBox1.Items.Add("Subscriber City = " + oSegment.get_DataElementValue(1,0)); //City Name sValue = oSegment.get_DataElementValue(2,0); //State or Province Code sValue = oSegment.get_DataElementValue(3,0); //Postal Code } else if (sSegmentID == "DMG") { sValue = oSegment.get_DataElementValue(1,0); //Date Time Period Format Qualifier sValue = oSegment.get_DataElementValue(2,0); //Date Time Period sValue = oSegment.get_DataElementValue(3,0); //Gender Code } } //sLoopSection } //sLoopHLQlfr == "22" else if (sLoopHLQlfr == "23") //Dependent { if (sLoopSection == "HL") { if (sSegmentID == "HL") { sValue = oSegment.get_DataElementValue(1,0); //Hierarchical ID Number sValue = oSegment.get_DataElementValue(2,0); //Hierarchical Parent ID Number sValue = oSegment.get_DataElementValue(3,0); //Hierarchical Level Code sValue = oSegment.get_DataElementValue(4,0); //Hierarchical Child Code } //Segment ID } else if (sLoopSection == "HL;NM1") { if (sSegmentID == "NM1") { sValue = oSegment.get_DataElementValue(1,0); //Entity Identifier Code sValue = oSegment.get_DataElementValue(2,0); //Entity Type Qualifier listBox1.Items.Add("Dependent Lastname = " + oSegment.get_DataElementValue(3,0)); //Name Last or Organization Name listBox1.Items.Add("Dependent Firstname = " + oSegment.get_DataElementValue(4,0)); //Name First sValue = oSegment.get_DataElementValue(5,0); //Name Middle sValue = oSegment.get_DataElementValue(6,0); //Name Prefix sValue = oSegment.get_DataElementValue(7,0); //Name Suffix sValue = oSegment.get_DataElementValue(8,0); //Identification Code Qualifier sValue = oSegment.get_DataElementValue(9,0); //Identification Code } else if (sSegmentID == "N3") { sValue = oSegment.get_DataElementValue(1,0); //Address Information sValue = oSegment.get_DataElementValue(2,0); //Address Information } else if (sSegmentID == "N4") { sValue = oSegment.get_DataElementValue(1,0); //City Name sValue = oSegment.get_DataElementValue(2,0); //State or Province Code sValue = oSegment.get_DataElementValue(3,0); //Postal Code } else if (sSegmentID == "DMG") { sValue = oSegment.get_DataElementValue(1,0); //Date Time Period Format Qualifier sValue = oSegment.get_DataElementValue(2,0); //Date Time Period sValue = oSegment.get_DataElementValue(3,0); //Gender Code } else if (sSegmentID == "INS") { sValue = oSegment.get_DataElementValue(1,0); //Yes/No Condition or Response Code listBox1.Items.Add("Dependent Relationship = " + oSegment.get_DataElementValue(2,0)); //Individual Relationship Code } else if (sSegmentID == "DTP") { sValue = oSegment.get_DataElementValue(1,0); //Date/Time Qualifier sValue = oSegment.get_DataElementValue(2,0); //Date Time Period Format Qualifier sValue = oSegment.get_DataElementValue(3,0); //Date Time Period } //Segment ID } //sLoopSection else if (sLoopSection == "HL;NM1;EB") { if (sSegmentID == "EB") { listBox1.Items.Add("Eligibility or Benefit Information = " + oSegment.get_DataElementValue(1,0)); //Eligibility or Benefit Information sValue = oSegment.get_DataElementValue(2,0); //Coverage Level Code //************************ repeating element ******************************************************************************************* ediDataElement.Set(ref oElement, oSegment.get_DataElement(3)); //repeating element int nRepeat = oElement.RepeatCount; // get repeating element count for (int i = 1; i <= nRepeat; i++) { listBox1.Items.Add("Service Type Code " + Convert.ToString(i) + " = " + oSegment.get_DataElementValue(3,0,i)); //Service Type Code } oElement.Dispose(); //******************************************************************************************************************************** sValue = oSegment.get_DataElementValue(4,0); //Insurance Type Code sValue = oSegment.get_DataElementValue(5,0); //Plan Coverage Description } else if (sSegmentID == "LS") { sValue = oSegment.get_DataElementValue(1,0); //Loop Identifier Code } //Segment ID } else if (sLoopSection == "HL;NM1;EB;NM1") { if (sSegmentID == "NM1") { sValue = oSegment.get_DataElementValue(1,0); //Entity Identifier Code sValue = oSegment.get_DataElementValue(2,0); //Entity Type Qualifier listBox1.Items.Add("Primary Care Lastname = " + oSegment.get_DataElementValue(3,0)); //Name Last or Organization Name listBox1.Items.Add("Primary Care Firstname = " + oSegment.get_DataElementValue(4,0)); //Name First sValue = oSegment.get_DataElementValue(5,0); //Name Middle sValue = oSegment.get_DataElementValue(6,0); //Name Prefix sValue = oSegment.get_DataElementValue(7,0); //Name Suffix sValue = oSegment.get_DataElementValue(8,0); //Identification Code Qualifier sValue = oSegment.get_DataElementValue(9,0); //Identification Code } //sSegmentID } //sLoopSection } //sLoopHLQlfr == "23" } //nArea //GETS THE NEXT DATA SEGMENT ediDataSegment.Set(ref oSegment, (ediDataSegment) oSegment.Next()); //oSegment = (ediDataSegment) oSegment.Next(); } //while Cursor = Cursors.Default; MessageBox.Show("Done."); }