Private Sub cmdGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGenerate.Click
'This is just an example program to demonstrate how to generate an 835 EDI file
'in VB .NET using the Framework EDI .NET hybrid component
Dim oEdiDoc As ediDocument
Dim oInterchange As ediInterchange
Dim oGroup As ediGroup
Dim oTransactionset As ediTransactionSet
Dim oSegment As ediDataSegment
Dim oSchemas As ediSchemas
Dim sSefFile As String
Dim sEdiFile As String
Dim i As Integer
Dim nCount As Integer
Dim sPath As String
Dim sEntity As String
Dim nIndex As Integer
Dim iItemCount As Integer
Dim sInstance As String
Me.Cursor = Cursors.WaitCursor
sPath = AppDomain.CurrentDomain.BaseDirectory
sSefFile = "835_X091.sef"
sEdiFile = "835OUTPUT.x12"
oEdiDoc = New ediDocument
'Change the cursor type from dynamic to forward to improve speed performance
oEdiDoc.CursorType = DocumentCursorTypeConstants.Cursor_ForwardWrite
'Disable the internal standard reference library to be memory effecient
oSchemas = oEdiDoc.GetSchemas
oSchemas.EnableStandardReference = False
'Load the SEF file
oEdiDoc.ImportSchema(sPath & sSefFile, 0)
'define the terminators
oEdiDoc.SegmentTerminator = "~" & vbCrLf
oEdiDoc.ElementTerminator = "*"
oEdiDoc.CompositeTerminator = ":"
'create the interchange (ISA segment)
oInterchange = oEdiDoc.CreateInterchange("X", "004010")
oSegment = oInterchange.GetDataSegmentHeader
oSegment.DataElementValue(1) = "00" 'Authorization Information Qualifier
oSegment.DataElementValue(2) = " " 'Authorization Information
oSegment.DataElementValue(3) = "00" 'Security Information Qualifier
oSegment.DataElementValue(4) = " " 'Security Information
oSegment.DataElementValue(5) = "12" 'Interchange ID Qualifier
oSegment.DataElementValue(6) = "Sender " 'Interchange Sender ID
oSegment.DataElementValue(7) = "12" 'Interchange ID Qualifier
oSegment.DataElementValue(8) = "ReceiverID " 'Interchange Receiver ID
oSegment.DataElementValue(9) = "010821" 'Interchange Date
oSegment.DataElementValue(10) = "1548" 'Interchange Time
oSegment.DataElementValue(11) = "U" 'Interchange Control Standards Identifier
oSegment.DataElementValue(12) = "00401" 'Interchange Control Version Number
oSegment.DataElementValue(13) = "000000020" 'Interchange Control Number
oSegment.DataElementValue(14) = "0" 'Acknowledgment Requested
oSegment.DataElementValue(15) = "T" 'Usage Indicator
oSegment.DataElementValue(16) = ":" 'Component Element Separator
'create the functional group (GS segment)
oGroup = oInterchange.CreateGroup("004010X091")
oSegment.Set(oSegment, oGroup.GetDataSegmentHeader) 'oSegment = oGroup.GetDataSegmentHeader
oSegment.DataElementValue(1) = "HP" 'Functional Identifier Code
oSegment.DataElementValue(2) = "SenderDept" 'Application Sender's Code
oSegment.DataElementValue(3) = "ReceiverDept" 'Application Receiver's Code
oSegment.DataElementValue(4) = "20010821" 'Date
oSegment.DataElementValue(5) = "1548" 'Time
oSegment.DataElementValue(6) = "000001" 'Group Control Number
oSegment.DataElementValue(7) = "X" 'Responsible Agency Code
oSegment.DataElementValue(8) = "004010X091" 'Version / Release / Industry Identifier Code
'create the transaction set (ST segment)
oTransactionset = oGroup.CreateTransactionSet("835")
oSegment.Set(oSegment, oTransactionset.GetDataSegmentHeader) 'oSegment = oTransactionset.GetDataSegmentHeader
oSegment.DataElementValue(1) = "835" 'Transaction Set Identifier Code
oSegment.DataElementValue(2) = "00001" 'Transaction Set Control Number
'create the BPR segment
oSegment.Set(oSegment, oTransactionset.CreateDataSegment("BPR")) 'oSegment = oTransactionset.CreateDataSegment("BPR")
oSegment.DataElementValue(1) = "C" 'Transaction Handling Code
oSegment.DataElementValue(2) = "150000" 'Monetary Amount
oSegment.DataElementValue(3) = "C" 'Credit/Debit Flag Code
oSegment.DataElementValue(4) = "ACH" 'Payment Method Code
oSegment.DataElementValue(5) = "CTX" 'Payment Format Code
oSegment.DataElementValue(6) = "01" '(DFI) ID Number Qualifier
oSegment.DataElementValue(7) = "999999992" '(DFI) Identification Number
oSegment.DataElementValue(8) = "DA" 'Account Number Qualifier
oSegment.DataElementValue(9) = "123456" 'Account Number
oSegment.DataElementValue(10) = "512345678 " 'Originating Company Identifier
oSegment.DataElementValue(12) = "01" '(DFI) ID Number Qualifier
oSegment.DataElementValue(13) = "999988880" '(DFI) Identification Number
oSegment.DataElementValue(14) = "DA" 'Account Number Qualifier
oSegment.DataElementValue(15) = "98765" 'Account Number
oSegment.DataElementValue(16) = "19960913" 'Date
'create the TRN segment
oSegment.Set(oSegment, oTransactionset.CreateDataSegment("TRN")) 'oSegment = oTransactionset.CreateDataSegment("TRN")
oSegment.DataElementValue(1) = "1" 'Trace Type Code
oSegment.DataElementValue(2) = "98765" 'Reference Identification
oSegment.DataElementValue(3) = "512345678 " 'Originating Company Identifier
'PRODUCTION DATE
oSegment.Set(oSegment, oTransactionset.CreateDataSegment("DTM"))
oSegment.DataElementValue(1) = "405" 'Date/Time Qualifier
oSegment.DataElementValue(2) = "19960913" 'Date
'PAYER ID INFO LOOP
'create the N1 segment in the N1 loop
oSegment.Set(oSegment, oTransactionset.CreateDataSegment("N1\N1"))
oSegment.DataElementValue(1) = "PR" 'Entity Identifier Code
oSegment.DataElementValue(2) = "Insurance Company of Timbucktu" 'Name
'create the N3 segment in the N1 loop
oSegment.Set(oSegment, oTransactionset.CreateDataSegment("N1\N3"))
oSegment.DataElementValue(1) = "1 Main Street" 'Address Information
'create the N4 segment in the N1 loop
oSegment.Set(oSegment, oTransactionset.CreateDataSegment("N1\N4"))
oSegment.DataElementValue(1) = "Timbucktu" 'City Name
oSegment.DataElementValue(2) = "AK" 'State or Province Code
oSegment.DataElementValue(3) = "89111" 'Postal Code
'create the REF segment in the N1 loop
oSegment.Set(oSegment, oTransactionset.CreateDataSegment("N1\REF"))
oSegment.DataElementValue(1) = "2U" 'Reference Identification Qualifier
oSegment.DataElementValue(2) = "999" 'Reference Identification
'PAYEE ID INFO LOOP
'create the N1 segment in the second instance of the N1 loop
oSegment.Set(oSegment, oTransactionset.CreateDataSegment("N1(2)\N1"))
oSegment.DataElementValue(1) = "PE" 'Entity Identifier Code
oSegment.DataElementValue(2) = "Cybil Mental Hospital" 'Name
oSegment.DataElementValue(3) = "XX" 'Identification Code Qualifier
oSegment.DataElementValue(4) = "6543210903" 'Identification Code
'INPATIENT PROVIDER SUMMARY INFO
'create the LX segment in the LX loop
oSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX\LX"))
oSegment.DataElementValue(1) = "961221" 'Assigned Number
'INPATIENT PROVIDER SUMMARY INFO
'create the TS3 segment in the LX loop
oSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX\TS3"))
oSegment.DataElementValue(1) = "6543210903" 'Reference Identification
oSegment.DataElementValue(2) = "11" 'Facility Code Value
oSegment.DataElementValue(3) = "19961231" 'Date
oSegment.DataElementValue(4) = "1" 'Quantity
oSegment.DataElementValue(5) = "211366.97" 'Monetary Amount
oSegment.DataElementValue(6) = "138018.40" 'Monetary Amount
oSegment.DataElementValue(9) = "138018.40" 'Monetary Amount
oSegment.DataElementValue(11) = "73348.57" 'Monetary Amount
'PROVIDER SUPPLEMENTAL SUMMARY INFO
'create the TS2 segment in the LX loop
oSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX\TS2"))
oSegment.DataElementValue(1) = "2178.45" 'Monetary Amount
oSegment.DataElementValue(2) = "1919.71" 'Monetary Amount
oSegment.DataElementValue(4) = "56.82" 'Monetary Amount
oSegment.DataElementValue(5) = "197.69" 'Monetary Amount
oSegment.DataElementValue(6) = "4.23" 'Monetary Amount
'INPATIENT CLAIM PAYMENT INFO
'create the CLP segment in the CLP loop nested in the LX loop
oSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX\CLP\CLP"))
oSegment.DataElementValue(1) = "666123" 'Claim Submitter's Identifier
oSegment.DataElementValue(2) = "1" 'Claim Status Code
oSegment.DataElementValue(3) = "211366.97" 'Monetary Amount
oSegment.DataElementValue(4) = "138018.40" 'Monetary Amount
oSegment.DataElementValue(6) = "MA" 'Claim Filing Indicator Code
oSegment.DataElementValue(7) = "1999999444444" 'Reference Identification
oSegment.DataElementValue(8) = "11" 'Facility Code Value
oSegment.DataElementValue(9) = "1" 'Claim Frequency Type Code
'INPATIENT CLAIM ADJUSTMENT
'create the CAS segment in the CLP loop nested in the LX loop
oSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX\CLP\CAS"))
oSegment.DataElementValue(1) = "CO" 'Claim Adjustment Group Code
oSegment.DataElementValue(2) = "A2" 'Claim Adjustment Reason Code
oSegment.DataElementValue(3) = "73348.57" 'Monetary Amount
'INPATIENT CLAIM ADJUSTMENT
'create the NM1 segment in the CLP loop nested in the LX loop
oSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX\CLP\NM1"))
oSegment.DataElementValue(1) = "QC" 'Entity Identifier Code
oSegment.DataElementValue(2) = "1" 'Entity Type Qualifier
oSegment.DataElementValue(3) = "Shepard" 'Name Last or Organization Name
oSegment.DataElementValue(4) = "Sam" 'Name First
oSegment.DataElementValue(5) = "O" 'Name Middle
oSegment.DataElementValue(8) = "HN" 'Identification Code Qualifier
oSegment.DataElementValue(9) = "666-66-6666A" 'Identification Code
'INPATIENT ADJUDICATION
'create the MIA segment in the CLP loop nested in the LX loop
oSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX\CLP\MIA"))
oSegment.DataElementValue(1) = "0" 'Quantity
oSegment.DataElementValue(4) = "138018.40" 'Monetary Amount
'INPATIENT CLAIM DATE
'create the first instance of a DTP segment in the CLP loop nested in the LX loop
oSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX\CLP\DTM"))
oSegment.DataElementValue(1) = "232"
oSegment.DataElementValue(2) = "19960816"
'create the second instance of a DTP segment in the CLP loop nested in the LX loop
oSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX\CLP\DTM(2)"))
oSegment.DataElementValue(1) = "233" 'Date/Time Qualifier
oSegment.DataElementValue(2) = "19960824"
'CLAIM SUPPLEMENTAL INFO QUANTITY
'create the QTY segment in the CLP loop nested in the LX loop
oSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX\CLP\QTY"))
oSegment.DataElementValue(1) = "CA" 'Quantity Qualifier
oSegment.DataElementValue(2) = "8" 'Quantity
'OUTPATIENT PROVIDER INFO
'create the LX segment in the second instance of the LX loop
oSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX(2)\LX"))
oSegment.DataElementValue(1) = "961213" 'Assigned Number
'OUTPATIENT PROVIDER INFO
'create the TS3 segment in the second instance of the LX loop
oSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX(2)\TS3"))
oSegment.DataElementValue(1) = "6543210903" 'Reference Identification
oSegment.DataElementValue(2) = "13" 'Facility Code Value
oSegment.DataElementValue(3) = "19961231" 'Date
oSegment.DataElementValue(4) = "15000" 'Quantity
oSegment.DataElementValue(5) = "15000" 'Monetary Amount
oSegment.DataElementValue(6) = "11980.33" 'Monetary Amount
oSegment.DataElementValue(9) = "138018.40" 'Monetary Amount
oSegment.DataElementValue(11) = "3019.67" 'Monetary Amount
'OUTPATIENT CLAIM PAYMENT INFO
'create the CLP segment in the CLP loop nested in the second instance of the LX loop
oSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX(2)\CLP\CLP"))
oSegment.DataElementValue(1) = "777777" 'Claim Submitter's Identifier
oSegment.DataElementValue(2) = "1" 'Claim Status Code
oSegment.DataElementValue(3) = "15000" 'Monetary Amount
oSegment.DataElementValue(4) = "11980.33" 'Monetary Amount
oSegment.DataElementValue(6) = "MB" 'Claim Filing Indicator Code
oSegment.DataElementValue(7) = "1999999444445" 'Reference Identification
oSegment.DataElementValue(8) = "13" 'Facility Code Value
oSegment.DataElementValue(9) = "1" 'Claim Frequency Type Code
'OUTPATIENT CLAIM ADJUSTMENT
'create the CAS segment in the CLP loop nested in the second instance of the LX loop
oSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX(2)\CLP\CAS"))
oSegment.DataElementValue(1) = "CO" 'Claim Adjustment Group Code
oSegment.DataElementValue(2) = "A2" 'Claim Adjustment Reason Code
oSegment.DataElementValue(3) = "3019.67" 'Monetary Amount
'OUTPATIENT NAME
'create the NM1 segment in the CLP loop nested in the second instance of the LX loop
oSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX(2)\CLP\NM1"))
oSegment.DataElementValue(1) = "QC" 'Entity Identifier Code
oSegment.DataElementValue(2) = "1" 'Entity Type Qualifier
oSegment.DataElementValue(3) = "Borden" 'Name Last or Organization Name
oSegment.DataElementValue(4) = "Liz" 'Name First
oSegment.DataElementValue(5) = "E" 'Name Middle
oSegment.DataElementValue(8) = "HN" 'Identification Code Qualifier
oSegment.DataElementValue(9) = Replace("996-66-9999B", "-", "") 'Identification Code
'OUTPATIENT ADJUDICATION INFO
'create the MOA segment in the CLP loop nested in the second instance of the LX loop
oSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX(2)\CLP\MOA"))
oSegment.DataElementValue(3) = "MA02" 'Reference Identification
'OUTPATIENT CLAIM DATE
'create the DTM segment in the CLP loop nested in the second instance of the LX loop
oSegment.Set(oSegment, oTransactionset.CreateDataSegment("LX(2)\CLP\DTM"))
oSegment.DataElementValue(1) = "232" 'Date/Time Qualifier
oSegment.DataElementValue(2) = "19960512"
'PROVIDER ADJUSTMENT
'create the PLB segment
oSegment.Set(oSegment, oTransactionset.CreateDataSegment("PLB"))
oSegment.DataElementValue(1) = "6543210903" 'Reference Identification
oSegment.DataElementValue(2) = "19961231" 'Date
oSegment.DataElementValue(3, 1) = "CV" 'Adjustment Reason Code
oSegment.DataElementValue(3, 2) = "CP" 'Reference Identification
oSegment.DataElementValue(4) = "1.27" 'Monetary Amount
'save to a string
txtEdiString.Text = oEdiDoc.GetEdiString
'save to a file
oEdiDoc.Save(sPath & sEdiFile)
Me.Cursor = Cursors.Default
MsgBox("Done. File output = " & sPath & sEdiFile)
cmdGenerate.Enabled = False
End Sub