'This is a an example program to demonstrate how one can create an application 'that generates an EDI 837 X098 EDI file using the FREDI component Option Explicit Private oEdiDoc As Fredi.ediDocument Private oSchema As Fredi.ediSchema Private oSchemas As Fredi.ediSchemas Private oInterchange As Fredi.ediInterchange Private oGroup As Fredi.ediGroup Private oTransactionset As Fredi.ediTransactionSet Private oSegment As Fredi.ediDataSegment Private sSefFile As String Private Sub cmdGenerate_Click() Dim i As Integer Dim nCount As Integer Dim sPath As String Dim sEntity As String Dim nIndex As Integer Dim sSefFile As String Dim sEdiFile As String Dim sEdiXmlFile As String Dim iItemCount As Integer Dim sInstance As String Dim nTsCounter As Integer Dim nTsCount As Integer Dim nInfoSources As Integer Dim nInfoSourceCounter As Integer Dim nSubscribers As Integer Dim nSubscriberCounter As Integer Dim nDependents As Integer Dim nDependentCounter As Integer Dim nServices As Integer Dim nServiceCounter As Integer Dim nHlCounter As Integer Dim nHlSubscriberParent As Integer Dim nHlDependentParent As Integer Me.MousePointer = vbHourglass sPath = App.Path & "\" sSefFile = "837_X098.SEF" sEdiFile = "837_X098_OUTPUT.x12" 'instantiate edi document object Set oEdiDoc = New Fredi.ediDocument 'changing cursor type from the defaul dynamic to forward uses less RAM and improves performance oEdiDoc.CursorType = Cursor_ForwardWrite 'disable internal Standard Reference Library to make certain Sef is used by component Set oSchemas = oEdiDoc.GetSchemas oSchemas.EnableStandardReference = False 'Load Sef file Set oSchema = oEdiDoc.ImportSchema(sPath & sSefFile, 0) 'set terminators oEdiDoc.SegmentTerminator = "~" & vbCrLf oEdiDoc.ElementTerminator = "*" oEdiDoc.CompositeTerminator = ":" 'CREATE INTERCHANGE Set oInterchange = oEdiDoc.CreateInterchange("X", "004010") Set oSegment = oInterchange.GetDataSegmentHeader oSegment.DataElementValue(1) = "00" oSegment.DataElementValue(3) = "00" oSegment.DataElementValue(5) = "12" oSegment.DataElementValue(6) = "Sender" oSegment.DataElementValue(7) = "12" oSegment.DataElementValue(8) = "ReceiverID" oSegment.DataElementValue(9) = "010821" oSegment.DataElementValue(10) = "1548" oSegment.DataElementValue(11) = "U" oSegment.DataElementValue(12) = "00401" oSegment.DataElementValue(13) = "000000020" oSegment.DataElementValue(14) = "0" oSegment.DataElementValue(15) = "T" oSegment.DataElementValue(16) = ":" 'CREATE GROUP Set oGroup = oInterchange.CreateGroup("004010X098") Set oSegment = oGroup.GetDataSegmentHeader oSegment.DataElementValue(1) = "HC" oSegment.DataElementValue(2) = "SenderDept" oSegment.DataElementValue(3) = "ReceiverDept" oSegment.DataElementValue(4) = "20010821" oSegment.DataElementValue(5) = "1548" oSegment.DataElementValue(6) = "1" oSegment.DataElementValue(7) = "X" oSegment.DataElementValue(8) = "004010X098" 'HEADER 'ST TRANSACTION SET HEADER Set oTransactionset = oGroup.CreateTransactionSet("837") Set oSegment = oTransactionset.GetDataSegmentHeader oSegment.DataElementValue(2) = Right("00000" & Trim(Str(nTsCounter)), 5) 'BHT BEGINNING OF HIERARCHICAL TRANSACTION Set oSegment = oTransactionset.CreateDataSegment("BHT") oSegment.DataElementValue(1) = "0019" oSegment.DataElementValue(2) = "00" oSegment.DataElementValue(3) = "244579" oSegment.DataElementValue(4) = "19981015" oSegment.DataElementValue(5) = "1023" oSegment.DataElementValue(6) = "CH" 'REF TRANSMISSION TYPE IDENTIFICATION Set oSegment = oTransactionset.CreateDataSegment("REF") oSegment.DataElementValue(1) = "87" oSegment.DataElementValue(2) = "004010X098" '1000A SUBMITTER 'NM1 SUBMITTER Set oSegment = oTransactionset.CreateDataSegment("NM1\NM1") oSegment.DataElementValue(1) = "41" oSegment.DataElementValue(2) = "2" oSegment.DataElementValue(3) = txtBillingProviderName.Text oSegment.DataElementValue(8) = "46" oSegment.DataElementValue(9) = txtBillingProviderEDI.Text 'PER SUBMITTER EDI CONTACT INFORMATION Set oSegment = oTransactionset.CreateDataSegment("NM1\PER") oSegment.DataElementValue(1) = "IC" oSegment.DataElementValue(2) = "Jerry" oSegment.DataElementValue(3) = "TE" oSegment.DataElementValue(4) = "3055552222" '1000B RECEIVER 'NM1 RECEIVER NAME Set oSegment = oTransactionset.CreateDataSegment("NM1(2)\NM1") 'Including the loop instance counter (NM1(2)) is not necessary when cursor type is forwardwrite oSegment.DataElementValue(1) = "40" oSegment.DataElementValue(2) = "2" oSegment.DataElementValue(3) = txtReceiverName.Text oSegment.DataElementValue(8) = "46" oSegment.DataElementValue(9) = txtReceiverEDINo.Text nInfoSources = 1 nInfoSourceCounter = 1 nSubscribers = 1 nSubscriberCounter = 1 nDependents = 1 nDependentCounter = 1 nHlCounter = 0 '************************************************************************************************* 'DETAIL INFORMATION SOURCE LEVEL Do While nInfoSourceCounter <= nInfoSources nHlCounter = nHlCounter + 1 nHlSubscriberParent = nHlCounter '2000A BILLING/PAY-TO PROVIDER HL LOOP 'HL-BILLING PROVIDER Set oSegment = oTransactionset.CreateDataSegment("HL\HL") oSegment.DataElementValue(1) = "1" oSegment.DataElementValue(3) = "20" oSegment.DataElementValue(4) = "1" '2010AA BILLING PROVIDER 'NM1 BILLING PROVIDER NAME Set oSegment = oTransactionset.CreateDataSegment("HL\NM1\NM1") oSegment.DataElementValue(1) = "85" oSegment.DataElementValue(2) = "2" oSegment.DataElementValue(3) = txtBillingProviderName oSegment.DataElementValue(8) = "24" oSegment.DataElementValue(9) = txtBillingProviderTIN.Text 'N3 BILLING PROVIDER ADDRESS Set oSegment = oTransactionset.CreateDataSegment("HL\NM1\N3") oSegment.DataElementValue(1) = txtBillingProviderAddress.Text 'N4 BILLING PROVIDER LOCATION Set oSegment = oTransactionset.CreateDataSegment("HL\NM1\N4") oSegment.DataElementValue(1) = txtBillingProviderCity.Text oSegment.DataElementValue(2) = txtBillingProviderState.Text oSegment.DataElementValue(3) = txtBillingProviderZip.Text 'REF BILLING PROVIDER SECONDARY IDENTIFICATION Set oSegment = oTransactionset.CreateDataSegment("HL\NM1\REF") oSegment.DataElementValue(1) = "G2" oSegment.DataElementValue(2) = txtBillingProviderKeyIns.Text '2010AB PAY-TO PROVIDER 'NM1 PAY-TO PROVIDER NAME Set oSegment = oTransactionset.CreateDataSegment("HL\NM1(2)\NM1") oSegment.DataElementValue(1) = "87" oSegment.DataElementValue(2) = "2" oSegment.DataElementValue(3) = txtPayToName.Text oSegment.DataElementValue(8) = "24" oSegment.DataElementValue(9) = txtPayToTIN.Text 'N3 PAY-TO PROVIDER ADDRESS Set oSegment = oTransactionset.CreateDataSegment("HL\NM1(2)\N3") oSegment.DataElementValue(1) = txtPayToAddress.Text 'N4 PAY-TO PROVIDER CITY Set oSegment = oTransactionset.CreateDataSegment("HL\NM1(2)\N4") oSegment.DataElementValue(1) = txtPayToCity.Text oSegment.DataElementValue(2) = txtPayToState.Text oSegment.DataElementValue(3) = txtPayToZip.Text 'REF PAY-TO PROVIDER SECONDARY IDENTIFICATION Set oSegment = oTransactionset.CreateDataSegment("HL\NM1(2)\REF") oSegment.DataElementValue(1) = "G2" oSegment.DataElementValue(2) = txtPayToKeyIns.Text '************************************************************************************************* 'DETAIL SUBSCRIBER LEVEL Do While nSubscriberCounter <= nSubscribers nHlCounter = nHlCounter + 1 nHlDependentParent = nHlCounter '2000B SUBSCRIBER HL LOOP 'HL-SUBSCRIBER Set oSegment = oTransactionset.CreateDataSegment("HL\HL") oSegment.DataElementValue(1) = nHlCounter oSegment.DataElementValue(2) = nHlSubscriberParent oSegment.DataElementValue(3) = "22" If nDependents > 0 Then oSegment.DataElementValue(4) = "1" Else oSegment.DataElementValue(4) = "0" End If 'SBR SUBSCRIBER INFORMATION Set oSegment = oTransactionset.CreateDataSegment("HL\SBR") oSegment.DataElementValue(1) = "P" oSegment.DataElementValue(2) = "" oSegment.DataElementValue(3) = txtSubscriberGroupNo.Text oSegment.DataElementValue(9) = "CI" '2010BA SUBSCRIBER 'NM1 SUBSCRIBER NAME Set oSegment = oTransactionset.CreateDataSegment("HL\NM1\NM1") oSegment.DataElementValue(1) = "IL" oSegment.DataElementValue(2) = "1" oSegment.DataElementValue(3) = txtSubscriberLastname.Text oSegment.DataElementValue(4) = txtSubscriberFirstname.Text oSegment.DataElementValue(8) = "MI" oSegment.DataElementValue(9) = Replace(txtSubscriberSSN.Text, "-", "") Set oSegment = oTransactionset.CreateDataSegment("HL\NM1\N3") oSegment.DataElementValue(1) = txtSubscriberAddress.Text Set oSegment = oTransactionset.CreateDataSegment("HL\NM1\N4") oSegment.DataElementValue(1) = txtSubscriberCity.Text oSegment.DataElementValue(2) = txtSubscriberState.Text oSegment.DataElementValue(3) = txtSubscriberZip.Text 'DMG SUBSCRIBER DEMOGRAPHIC INFORMATION Set oSegment = oTransactionset.CreateDataSegment("HL\NM1\DMG") oSegment.DataElementValue(1) = "D8" oSegment.DataElementValue(2) = Format(txtSubscriberDOB.Text, "YYYYMMDD") oSegment.DataElementValue(3) = txtSubscriberSex.Text '2010BB PAYER 'NM1 PAYER NAME Set oSegment = oTransactionset.CreateDataSegment("HL\NM1(2)\NM1") oSegment.DataElementValue(1) = "PR" oSegment.DataElementValue(2) = "2" oSegment.DataElementValue(3) = txtPayerName.Text oSegment.DataElementValue(8) = "PI" oSegment.DataElementValue(9) = txtRenderingTIN.Text 'N3 PAYER ADDRESS Set oSegment = oTransactionset.CreateDataSegment("HL\NM1(2)\N3") oSegment.DataElementValue(1) = txtPayerAddress.Text 'N4 PAYER CITY/STATE/ZIP CODE Set oSegment = oTransactionset.CreateDataSegment("HL\NM1(2)\N4") oSegment.DataElementValue(1) = txtPayerCity.Text oSegment.DataElementValue(2) = txtPayerState.Text oSegment.DataElementValue(3) = txtPayerZip.Text If nDependents = 0 Then '2300 CLAIM 'CLM CLAIM LEVEL INFORMATION Set oSegment = oTransactionset.CreateDataSegment("HL\CLM\CLM") oSegment.DataElementValue(1) = Replace(txtPatientAccountNo.Text, "-", "") oSegment.DataElementValue(2) = txtTotalChargeAmount.Text oSegment.DataElementValue(5, 1) = "11" oSegment.DataElementValue(5, 3) = "1" oSegment.DataElementValue(6) = "Y" oSegment.DataElementValue(7) = "A" oSegment.DataElementValue(8) = "Y" oSegment.DataElementValue(9) = "Y" oSegment.DataElementValue(10) = "S" 'REF CLEARING HOUSE CLAIM NUMBER Set oSegment = oTransactionset.CreateDataSegment("HL\CLM\REF") oSegment.DataElementValue(1) = "D9" oSegment.DataElementValue(2) = "17312345600006351" 'HI HEALTH CARE DIAGNOSIS CODES Set oSegment = oTransactionset.CreateDataSegment("HL\CLM\HI") oSegment.DataElementValue(1, 1) = "BK" oSegment.DataElementValue(1, 2) = "0340" oSegment.DataElementValue(2, 1) = "BF" oSegment.DataElementValue(2, 2) = "V7389" '2310B RENDERING PROVIDER 'NM1 RENDERING PROVIDER NAME Set oSegment = oTransactionset.CreateDataSegment("HL\CLM\NM1\NM1") oSegment.DataElementValue(1) = "82" oSegment.DataElementValue(2) = "1" oSegment.DataElementValue(3) = txtRenderingLastname.Text oSegment.DataElementValue(4) = txtRenderingFirstname.Text oSegment.DataElementValue(8) = "24" oSegment.DataElementValue(9) = Replace(txtRenderingTIN.Text, "-", "") 'PRV RENDERING PROVIDER INFORMATION Set oSegment = oTransactionset.CreateDataSegment("HL\CLM\NM1\PRV") oSegment.DataElementValue(1) = "PE" oSegment.DataElementValue(2) = "ZZ" oSegment.DataElementValue(3) = "203BF0100Y" 'REF RENDERING PROVIDER SECONDARY IDENTIFICATION Set oSegment = oTransactionset.CreateDataSegment("HL\CLM\NM1\REF") oSegment.DataElementValue(1) = "G2" oSegment.DataElementValue(2) = txtRenderingKeyIns.Text '2310D SERVICE LOCATION 'NM1 SERVICE FACILITY LOCATION Set oSegment = oTransactionset.CreateDataSegment("HL\CLM\NM1(2)\NM1") oSegment.DataElementValue(1) = "77" oSegment.DataElementValue(2) = "2" oSegment.DataElementValue(3) = txtPayToName.Text oSegment.DataElementValue(8) = "24" oSegment.DataElementValue(9) = txtPayToTIN.Text 'N3 SERVICE FACILITY ADDRESS Set oSegment = oTransactionset.CreateDataSegment("HL\CLM\NM1(2)\N3") oSegment.DataElementValue(1) = txtPayToAddress.Text 'N4 SERVICE FACILITY CITY/STATE/ZIP Set oSegment = oTransactionset.CreateDataSegment("HL\CLM\NM1(2)\N4") oSegment.DataElementValue(1) = txtPayToCity.Text oSegment.DataElementValue(2) = txtPayToState.Text oSegment.DataElementValue(3) = txtPayToZip.Text '2400 SERVICE LINE nServices = 4 nServiceCounter = 1 Do While nServiceCounter <= nServices If Len(Trim(txtChargesDesc(nServiceCounter - 1).Text)) > 0 Then 'LX SERVICE LINE COUNTER Set oSegment = oTransactionset.CreateDataSegment("HL\CLM\LX\LX") oSegment.DataElementValue(1) = iItemCount 'SV1 PROFESSIONAL SERVICE Set oSegment = oTransactionset.CreateDataSegment("HL\CLM\LX\SV1") oSegment.DataElementValue(1, 1) = "HC" oSegment.DataElementValue(1, 2) = txtChargesDesc(nServiceCounter - 1).Text oSegment.DataElementValue(2) = txtChargesAmount(nServiceCounter - 1).Text oSegment.DataElementValue(3) = "UN" oSegment.DataElementValue(4) = "1" oSegment.DataElementValue(7, 1) = txtChargesDesc(nServiceCounter - 1).Tag oSegment.DataElementValue(9) = "N" 'DTP DATE - SERVICE DATE(S) Set oSegment = oTransactionset.CreateDataSegment("HL\CLM\LX\DTP") oSegment.DataElementValue(1) = "472" oSegment.DataElementValue(2) = "D8" oSegment.DataElementValue(3) = Format(txtChargeDate(nServiceCounter - 1).Text, "YYYYMMDD") End If nServiceCounter = nServiceCounter + 1 Loop End If 'nDependents = 0 '************************************************************************************************* 'DETAIL DEPENDENT LEVEL Do While nDependentCounter <= nDependents nHlCounter = nHlCounter + 1 '2000C PATIENT HL LOOP 'HL -Patient Set oSegment = oTransactionset.CreateDataSegment("HL\HL") oSegment.DataElementValue(1) = nHlCounter oSegment.DataElementValue(2) = nHlDependentParent oSegment.DataElementValue(3) = "23" oSegment.DataElementValue(4) = "0" 'PAT PATIENT INFORMATION Set oSegment = oTransactionset.CreateDataSegment("HL\PAT") oSegment.DataElementValue(1) = "19" '2010CA PATIENT 'NM1 PATIENT NAME Set oSegment = oTransactionset.CreateDataSegment("HL\NM1\NM1") oSegment.DataElementValue(1) = "QC" oSegment.DataElementValue(2) = "1" oSegment.DataElementValue(3) = txtPatientLastname.Text oSegment.DataElementValue(4) = txtPatientFirstname.Text oSegment.DataElementValue(8) = "MI" oSegment.DataElementValue(9) = txtPatientKeyIns.Text 'N3 PATIENT ADDRESS Set oSegment = oTransactionset.CreateDataSegment("HL\NM1\N3") oSegment.DataElementValue(1) = txtPatientAddress.Text 'N4 PATIENT CITY/STATE/ZIP CODE Set oSegment = oTransactionset.CreateDataSegment("HL\NM1\N4") oSegment.DataElementValue(1) = txtPatientCity.Text oSegment.DataElementValue(2) = txtPatientState.Text oSegment.DataElementValue(3) = txtPatientZip.Text 'DMG PATIENT DEMOGRAPHIC INFORMATION Set oSegment = oTransactionset.CreateDataSegment("HL\NM1\DMG") oSegment.DataElementValue(1) = "D8" oSegment.DataElementValue(2) = Format(txtPatientDOB.Text, "YYYYMMDD") oSegment.DataElementValue(3) = txtPatientSex.Text 'REF PATIENT SECONDARY IDENTIFICATION Set oSegment = oTransactionset.CreateDataSegment("HL\NM1\REF") oSegment.DataElementValue(1) = "SY" oSegment.DataElementValue(2) = Replace(txtPatientSSN.Text, "-", "") '2300 CLAIM 'CLM CLAIM LEVEL INFORMATION Set oSegment = oTransactionset.CreateDataSegment("HL\CLM\CLM") oSegment.DataElementValue(1) = Replace(txtPatientAccountNo.Text, "-", "") oSegment.DataElementValue(2) = txtTotalChargeAmount.Text oSegment.DataElementValue(5, 1) = "11" oSegment.DataElementValue(5, 3) = "1" oSegment.DataElementValue(6) = "Y" oSegment.DataElementValue(7) = "A" oSegment.DataElementValue(8) = "Y" oSegment.DataElementValue(9) = "Y" oSegment.DataElementValue(10) = "S" 'REF CLEARING HOUSE CLAIM NUMBER Set oSegment = oTransactionset.CreateDataSegment("HL\CLM\REF") oSegment.DataElementValue(1) = "D9" oSegment.DataElementValue(2) = "17312345600006351" 'HI HEALTH CARE DIAGNOSIS CODES Set oSegment = oTransactionset.CreateDataSegment("HL\CLM\HI") oSegment.DataElementValue(1, 1) = "BK" oSegment.DataElementValue(1, 2) = "0340" oSegment.DataElementValue(2, 1) = "BF" oSegment.DataElementValue(2, 2) = "V7389" '2310B RENDERING PROVIDER 'NM1 RENDERING PROVIDER NAME Set oSegment = oTransactionset.CreateDataSegment("HL\CLM\NM1\NM1") oSegment.DataElementValue(1) = "82" oSegment.DataElementValue(2) = "1" oSegment.DataElementValue(3) = txtRenderingLastname.Text oSegment.DataElementValue(4) = txtRenderingFirstname.Text oSegment.DataElementValue(8) = "24" oSegment.DataElementValue(9) = Replace(txtRenderingTIN.Text, "-", "") 'PRV RENDERING PROVIDER INFORMATION Set oSegment = oTransactionset.CreateDataSegment("HL\CLM\NM1\PRV") oSegment.DataElementValue(1) = "PE" oSegment.DataElementValue(2) = "ZZ" oSegment.DataElementValue(3) = "203BF0100Y" 'REF RENDERING PROVIDER SECONDARY IDENTIFICATION Set oSegment = oTransactionset.CreateDataSegment("HL\CLM\NM1\REF") oSegment.DataElementValue(1) = "G2" oSegment.DataElementValue(2) = txtRenderingKeyIns.Text '2310D SERVICE LOCATION 'NM1 SERVICE FACILITY LOCATION Set oSegment = oTransactionset.CreateDataSegment("HL\CLM\NM1(2)\NM1") oSegment.DataElementValue(1) = "77" oSegment.DataElementValue(2) = "2" oSegment.DataElementValue(3) = txtPayToName.Text oSegment.DataElementValue(8) = "24" oSegment.DataElementValue(9) = txtPayToTIN.Text 'N3 SERVICE FACILITY ADDRESS Set oSegment = oTransactionset.CreateDataSegment("HL\CLM\NM1(2)\N3") oSegment.DataElementValue(1) = txtPayToAddress.Text 'N4 SERVICE FACILITY CITY/STATE/ZIP Set oSegment = oTransactionset.CreateDataSegment("HL\CLM\NM1(2)\N4") oSegment.DataElementValue(1) = txtPayToCity.Text oSegment.DataElementValue(2) = txtPayToState.Text oSegment.DataElementValue(3) = txtPayToZip.Text '2400 SERVICE LINE nServices = 4 nServiceCounter = 1 Do While nServiceCounter <= nServices If Len(Trim(txtChargesDesc(nServiceCounter - 1).Text)) > 0 Then 'LX SERVICE LINE COUNTER Set oSegment = oTransactionset.CreateDataSegment("HL\CLM\LX\LX") oSegment.DataElementValue(1) = nServiceCounter 'SV1 PROFESSIONAL SERVICE Set oSegment = oTransactionset.CreateDataSegment("HL\CLM\LX\SV1") oSegment.DataElementValue(1, 1) = "HC" oSegment.DataElementValue(1, 2) = txtChargesDesc(nServiceCounter - 1).Text oSegment.DataElementValue(2) = txtChargesAmount(nServiceCounter - 1).Text oSegment.DataElementValue(3) = "UN" oSegment.DataElementValue(4) = "1" oSegment.DataElementValue(7, 1) = txtChargesDesc(nServiceCounter - 1).Tag oSegment.DataElementValue(9) = "N" 'DTP DATE - SERVICE DATE(S) Set oSegment = oTransactionset.CreateDataSegment("HL\CLM\LX\DTP") oSegment.DataElementValue(1) = "472" oSegment.DataElementValue(2) = "D8" oSegment.DataElementValue(3) = Format(txtChargeDate(nServiceCounter - 1).Text, "YYYYMMDD") End If nServiceCounter = nServiceCounter + 1 Loop nDependentCounter = nDependentCounter + 1 Loop 'nDependents nSubscriberCounter = nSubscriberCounter + 1 Loop 'nSubscribers nInfoSourceCounter = nInfoSourceCounter + 1 Loop 'nInfoSources 'save edi document object to file oEdiDoc.Save sPath & sEdiFile Me.MousePointer = vbNormal MsgBox ("Done. Output = " & sPath & sEdiFile) cmdGenerate.Enabled = False End Sub