Tuesday, February 23, 2016

Create 270 X12 Eligibility Request Message using C# (MS .NET)

Introduction:


Health Care Eligibility Benefit Inquiry and Response (270/271)



This post helps the provider to determine whether the information source (payer) has a particular subscriber or dependent on file and the health care eligibility and/or benefit information about that subscriber and/or dependent(s). 

The post provides the provider with the information at the time the patient checks in and makes the information available instantaneously, which is not possible through other methods like paper and phone. 

1.Create 270 Request using C#


Sample 270 Eligibility Request:

ISA*00* *00* *ZZ*SUBMITTERID *ZZ*CMS *140831*0734*^*00501*000005014*1*P*|~
GS*HS*SUBMITTERID*CMS*20140831*073411*5014*X*005010X279A1~
ST*270*000000001*005010X279A1~
BHT*0022*13*TRANSA*20140831*073411~
HL*1**20*1~
NM1*PR*2*CMS*****PI*CMS~
HL*2*1*21*1~
NM1*1P*2*IRNAME*****XX*1234567893~
HL*3*2*22*0~
TRN*1*TRACKNUM*ABCDEFGHIJ~
NM1*IL*1*LNAME*FNAME****MI*123456789A~
DMG*D8*19400401~
DTP*291*RD8*20140201-20141031~
EQ*10^14^30^42^45^48^67^A7^AD^AE^AG^BF^BG~
EQ**HC|80061~
EQ**HC|G0117~
SE*15*000000001~
GE*1*5014~

IEA*1*000005014~

I have created Main Class called as ManualX12Creation and it will call other segments  classes like ISAIEA and NM1 etc..

public class ManualX12Creation
{
        Patient patient;
        Provider provider;
        Payer payer;
        DTP dtp;
        public ManualX12Creation(Patient opatient, Provider oprovider, Payer opayer,DTP odtp)
        {

            patient = opatient;
            provider = oprovider;
            payer = opayer;
            dtp = odtp;

        }

 public string CreateISA(string row, string[] X12info, string SegTerminator, stringElementSeparator, string sep)
        {
            ISA isa = new ISA();
            string[] ISA = new string[16];

            ISA[0] = "ISA";           // Interchange Control Header Segment ID 

            ISA[1] = "00";              // Author Info Qualifier 

            ISA[2] = String.Format("{0,10}", " "); //"".PadRight(10, ' ');          // Author Information 

            //ISA[2] = ISA[2].Substring(0, 10);

            ISA[3] = "00";                          //   Security Information Qualifier
            //   MEDI-CAL NOTE: For Leased-Line & Dial-Up use '01', 
            //   for BATCH use '00'.
            //   '00' No Security Information Present 
            //   (No Meaningful Information in I04)


            ISA[4] = String.Format("{0,10}", " ");//"".PadRight(10, ' ');    // Security Information 

            //ISA[4] = ISA[4].Substring(0, 10);

            ISA[5] = "ZZ".PadRight(2, ' ');             // Interchange ID Qualifier

            ISA[6] = isa.InterchangeSenderID.PadRight(15, ' '); //X12info[2].PadRight(15, ' ');      // INTERCHANGE SENDER ID 

            ISA[7] = "ZZ".PadRight(2, ' ');             // Interchange ID Qualifier 

            ISA[8] = isa.InterchangeReceiverID.PadRight(15, ' ');//X12info[3].PadRight(15, ' ');      // INTERCHANGE RECEIVER ID 

            ISA[9] = isa.InterchangeDate; //DateTime.Parse("2008/08/16").ToString("yyMMdd");//    // Interchange Date (YYMMDD) 

            ISA[10] = isa.InterchangeTime; //DateTime.Now.ToString("HHmm");//.PadRight(4, ' ');               // Interchange Time (HHMM)

            ISA[11] = "^";                                                          // Interchange Control Standards Identifier 

            ISA[12] = isa.InterchangeControlVersionNumber.PadRight(5, ' '); //"00501".PadRight(5, ' ');                                 // Interchange Control Version Number 

            ISA[13] = isa.InterchangeControlNumber.PadRight(9, ' '); //"000000001".PadRight(9, ' ');                             // INTERCHANGE CONTROL NUMBER   

            ISA[14] = "0".PadRight(1, ' ');                                         // Acknowledgment Request [0= not requested, 1= requested]  

            ISA[15] = isa.UsageIndicatorProductionOrTest.PadRight(1, ' '); //"P".PadRight(1, ' ');                         // Usage Indicator [ P = Production Data, T = Test Data ]


            // string sep = "*";                                       // Data Element Separator 
            string sCreatedISA = String.Join(sep, ISA);
            sCreatedISA = sCreatedISA + "*";
            sCreatedISA = sCreatedISA + SegTerminator + ElementSeparator;

            return sCreatedISA.Trim();



        }


 // GS Segment  - EDI(x12 for A)-270 format 
        public string CreateGS(string row, string[] X12info, string SegTerminator,string ElementSeparator, string sep)
        {
            GS gs = new GS();

            string[] GS = new string[9];

            GS[0] = "GS";                       // Functional Group Header Segment ID 

            GS[1] = "HS";                       // Functional ID Code [ HS = Eligibility, Coverage or Benefit Inquiry (270) ] 

            GS[2] = gs.GSApplicationSenderID; //X12info[2];                 // Application Sender's ID 

            GS[3] = gs.GSApplicationReceiverID; //X12info[3];                 // Application Receiver's ID 

            GS[4] = gs.GSDate; //DateTime.Parse("2007/08/16").ToString("yyyyMMdd");            // Date [CCYYMMDD] 

            GS[5] = gs.GSTime; //DateTime.Now.ToString("HHmmss");       // Time [HHMM] Group Creation Time  

            GS[6] = gs.GSGroupControlNumber; //"107018";                                           // Group Control Number 

            GS[7] = "X";                                                // Responsible Agency Code Accredited Standards Committee X12 ] 

            GS[8] = "005010X279A1";                                     // Version Release / Industry[ Identifier Code Query 

            //string sep = "*";
            string sCreatedGS = String.Join(sep, GS);
            sCreatedGS = sCreatedGS + ElementSeparator;

            return sCreatedGS.Trim();
        }


// ST Segment  - EDI(X12 A)-270 format 
        public string CreateST(string row, string[] X12info, string SegTerminator,string ElementSeparator, string sep)
        {
            ST st = new ST();
            string[] ST = new string[4];
            ST[0] = "ST";                   // Transaction Set Header Segment ID 

            ST[1] = st.TransactionSetIdentifierCode; //"270";                  // Transaction Set Identifier Code (Inquiry Request) 

            ST[2] = st.STControlNumber; //"0001";                 // Transaction set control number must match SE

            ST[3] = "005010X279A1";

            // string sep = "*";
            string sCreatedST = String.Join(sep, ST);
            sCreatedST = sCreatedST + ElementSeparator;

            return sCreatedST.Trim();

        }


 // BHT Segment  - EDI(X12 A)-270 format 
        public string CreateBHT(string row, string[] X12info, string SegTerminator,string ElementSeparator, string sep)
        {
            BHT bht = new BHT();
            string[] BHT = new string[6];

            BHT[0] = "BHT";                         // Beginning of Hierarchical Transaction Segment ID 

            BHT[1] = bht.SubscriberStructureCode; //"0022";                        // Subscriber Structure Code 

            BHT[2] = bht.PurposeCode; //"13";                          // Purpose Code - This is a Request   

            BHT[3] = bht.SubmitterTransactionIdentifier; //"TSG123";                      //  Submitter Transaction Identifier  
            //This information is required by the information Receiver 
            //when using Real Time transactions. 
            //For BATCH this can be used for optional information.

            BHT[4] = bht.TransactionCreatedDate; //DateTime.Parse("2007/08/16").ToString("yyyyMMdd");      // Date Transaction Set Created 

            BHT[5] = bht.TransactionCreatedTime; //DateTime.Now.ToString("HHmmss").ToString();    // Time Transaction Set Created 

            //string sep = "*";
            string sCreatedBHT = String.Join(sep, BHT);
            sCreatedBHT = sCreatedBHT + ElementSeparator;

            return sCreatedBHT.Trim();


        }

 // HL Segment  - EDI-270 format 
        public string CreateHL(string row, int nHLCounter, string[] X12info, stringSegTerminator, string ElementSeparator, string sep)
        {
            HL hl = new HL();
            string[] HL = new string[5];
            HL[0] = "HL";
            //HL_LEN[0] =  2;

            HL[1] = Convert.ToString(nHLCounter);               // Hierarchical ID No. 


            if (nHLCounter == 1)
            {
                HL[2] = "";
                HL[3] = hl.HLCounter1Value1; //"20"; // Description: Identifies the payor, maintainer, or source of the information.
                HL[4] = hl.HLCounter1Value2; //"1"; // 1 Additional Subordinate HL Data Segment in This Hierarchical Structure. 
            }
            else if (nHLCounter == 2)
            {
                HL[2] = hl.HLCounter2Value0; //"1"; // Hierarchical Parent ID Number 
                HL[3] = hl.HLCounter2Value1; //"21"; // Hierarchical Level Code. '21' Information Receiver
                HL[4] = hl.HLCounter2Value2; //"1"; // 1 Additional Subordinate HL Data Segment in This Hierarchical Structure. 
            }
            else
            {
                HL[2] = hl.HLCounter3Value0; //"2";
                HL[3] = hl.HLCounter3Value1; //"22"; // Hierarchical Level Code.'22' Subscriber 
                HL[4] = hl.HLCounter3Value2; //"0"; // 0 no Additional Subordinate in the Hierarchical Structure. 
            }

            //string sep = "*";
            string sCreatedHL = String.Join(sep, HL);
            sCreatedHL = sCreatedHL + ElementSeparator;

            return sCreatedHL.Trim();

        }


 public string CreateNM1(string row, string NM1Cast, string[] X12info, stringSegTerminator, string ElementSeparator, string sep)
        {
            NM1 nm1 = new NM1();
            string[] NM1 = new string[10];

            NM1[0] = "NM1";

            if (NM1Cast == nm1.NM1PR)//nm1.NM1PR
            {
                NM1[1] = "PR"; // Entity ID Code - Payer [PR Payer] 
                NM1[2] = "2"; // Entity Type - Non-Person 
                NM1[3] = payer.PayerName;            // Organizational Name 
                NM1[4] = ""; // Data Element not required.
                NM1[5] = ""; // Data Element not required.
                NM1[6] = ""; // Data Element not required.
                NM1[7] = ""; // Data Element not required.
                NM1[8] = "PI"; // 46 - Electronic Transmitter Identification Number (ETIN) 
                NM1[9] = payer.PayerID; //"ABC123";//X12info[3]; // Application Sender's ID 
            }
            else if (NM1Cast == nm1.NM1P1)//nm1.1P
            {
                NM1[1] = "1P"; // Entity ID Code - Provider [1P Provider]
                NM1[2] = "2"; // Entity Type - Person 
                NM1[3] = provider.ProviderName; //"TestOrg..";               //row['facility_name']; // Organizational Name 
                //NM1[4] = row['provider_lname']; // Data Element not required.
                //NM1[5] = row['provider_fname']; // Data Element not required.
                NM1[4] = ""; // Data Element not required.
                NM1[5] = ""; // Data Element not required.
                NM1[6] = ""; // Data Element not required.
                NM1[7] = ""; // Data Element not required.
                NM1[8] = "XX";
                NM1[9] = provider.NPI; //"ABC123";                           //row['provider_npi'];
            }
            else if (NM1Cast == nm1.NM1IL)////nm1.IL
            {
                NM1[1] = "IL"; // Insured or Subscriber 
                NM1[2] = "1"; // Entity Type - Person 
                // NM1[3] = "Khan";   patient.LastName    
                NM1[3] = patient.LastName; //row['lname']; // last Name
                NM1[4] = patient.FirstName;//"Aifaz";           //row['fname']; // first Name
                NM1[5] = "";                   //row['mname']; // middle Name
                NM1[6] = ""; // data element 
                NM1[7] = ""; // data element 
                NM1[8] = "MI"; // Identification Code Qualifier 
                NM1[9] = patient.IdentificationCode; //"12345";            //row['subscriber_ss']; // Identification Code 
            }

            //string sep = "*";
            string sCreatedNM1 = String.Join(sep, NM1);
            sCreatedNM1 = sCreatedNM1 + ElementSeparator;

            return sCreatedNM1.Trim();


        }

  public string CreateREF(string row, string sref, string[] X12info, stringSegTerminator, string ElementSeparator, string sep)
        {
            REF oref = new REF();
            string[] REF = new string[3];
            REF[0] = "REF";

            if (sref == "1P")
            {
                REF[1] = "4A";  // Reference Identification Qualifier 
                REF[2] = oref.REFProviderPIN;//"ABC123"; // Provider Pin. 
            }
            else
            {
                REF[1] = "TJ"; // 'EJ' for Patient Account Number 
                REF[2] = oref.REFPatAccountNO; //"ABC123"; // Patient Account No. 
            }

            // string sep = "*";
            string sCreatedREF = String.Join(sep, REF);
            sCreatedREF = sCreatedREF + ElementSeparator;

            return sCreatedREF.Trim();
        }

public string CreateTRN(string row, string trancNO, string refIdentifier, string[] X12info, string SegTerminator, string ElementSeparator, string sep)
        {
            TRN trn = new TRN();
            // trn.TraceNumber = trancNO;
            string[] TRN = new string[5];
            TRN[0] = "TRN";
            TRN[1] = "1";
            TRN[2] = trn.TraceNumber; //trancNO;               // Trace Number 
            TRN[3] = trn.CompanyID; //"9000000000";         // Originating Company ID  must be 10 positions in length 
            TRN[4] = trn.RefIdentifier; //refIdentifier;         // Additional Entity Identifier (i.e. Subdivision) 

            // string sep = "*";
            string sCreatedTRN = String.Join(sep, TRN);
            sCreatedTRN = sCreatedTRN + ElementSeparator;

            return sCreatedTRN.Trim();
        }

//Demographics


    public string CreateDMG(string row, string[] X12info, string SegTerminator,string ElementSeparator)

        {


            string[] DMG = new string[4];

            DMG[0] = "DMG";
            DMG[1] = "D8";              // Date Format Qualifier - (D8 means CCYYMMDD)
            DMG[2] = patient.DOB;//"1990/01/01";        // Subscriber's Birth date
            DMG[3] = patient.Gender;
            string sep = "*";
            string sCreatedDMG = String.Join(sep, DMG);
            sCreatedDMG = sCreatedDMG + ElementSeparator;

            return sCreatedDMG.Trim();

        }


 public string CreateDTP(string row, string qual, string[] X12info, stringSegTerminator, string ElementSeparator, string sep)
        {
            //DTP dtp = new DTP();
            //qual=291
            //dtp.Qualifier = qual;
            string[] DTP = new string[4];
            DTP[0] = "DTP";

            DTP[1] = dtp.Qualifier; //qual; // Qualifier - Date of Service 

            DTP[2] = dtp.DateFormatQualifier; // Date Format Qualifier - (D8 means CCYYMMDD) 

            if (qual == "102")
            {
                DTP[3] = dtp.EventDate; //"Date";//row['date']; // Date 
            }
            else
            {
                DTP[3] = dtp.EventDate; //"1990/01/01";//row['pc_eventDate']; // Date of Service 
            }

            //string sep = "*";
            string sCreatedDTP = String.Join(sep, DTP);
            sCreatedDTP = sCreatedDTP + ElementSeparator;

            return sCreatedDTP.Trim();
        }

 public string CreateEQ(string row, string[] X12info, string SegTerminator, stringElementSeparator)
        {
            EQ eq = new EQ();
            string[] EQ = new string[2];
            EQ[0] = "EQ";
            EQ[1] = eq.ServiceTypeCode; //"30";               // Service Type Code 

            string sep = "*";
            string sCreatedEQ = String.Join(sep, EQ);
            sCreatedEQ = sCreatedEQ + ElementSeparator;

            return sCreatedEQ.Trim();


        }

  public string CreateSE(string row, string SegmentCount, string[] X12info, stringSegTerminator, string ElementSeparator, string sep)
        {
            //SegmentCount=14
            SE se = new SE();
            // se.SegmentCount = SegmentCount;
            string[] SE = new string[3];

            SE[0] = "SE";

            SE[1] = se.SegmentCount;// SegmentCount;       // Segment Count 

            SE[2] = se.TransactionSetControlNumber; //"0001"; // Transaction Set Control Number - Must match ST's 

            //string sep = "*";
            string sCreatedSE = String.Join(sep, SE);
            sCreatedSE = sCreatedSE + ElementSeparator;

            return sCreatedSE.Trim();

        }

 public string CreateGE(string row, string[] X12info, string SegTerminator, stringElementSeparator, string sep)
        {
            GE ge = new GE();
            string[] GE = new string[3];

            GE[0] = "GE";
            GE[1] = ge.NumberofIncludedTrans; //"1";                // Number of included Transaction Sets 
            GE[2] = ge.GroupControlNumber; //"1048";                 // Group Control Number match with GS06

            //string sep = "*";
            string sCreatedGE = String.Join(sep, GE);
            sCreatedGE = sCreatedGE + ElementSeparator;

            return sCreatedGE.Trim();

        }

 public string CreateIEA(string row, string[] X12info, string SegTerminator, stringElementSeparator, string sep)
        {
            IEA iea = new IEA();

            string[] IEA = new string[3];

            IEA[0] = "IEA";

            IEA[1] = iea.NumberofIncludedTrans; //"1";                               // Number of included Functional Groups 

            IEA[2] = iea.InterchangeControlNumber; //"000000001"; // Interchange Control Number 

            //string sep = "*";
            string sCreatedIEA = String.Join(sep, IEA);
            sCreatedIEA = sCreatedIEA + ElementSeparator;

            return sCreatedIEA.Trim();

        }


 public string PrintEDI(string row, string res, string[] X12info, string SegTerminator,string ElementSeparator)

        {

            int i = 1;

            StringBuilder sbEDI = new StringBuilder();
            string PatEDI = "";

            // For Header Segment 
            int segmentcount = 1;
            int nHlCounter = 1;
            int rowCount = 1;
            int trcNo = 1234501;
            int refiden = 5432101;

            //while (row = sqlFetchArray(res)) 
            while (i == rowCount)
            {
                if (nHlCounter == 1)
                {
                    // create ISA 

                    sbEDI.AppendLine(CreateISA(row, X12info, SegTerminator, ElementSeparator, "*"));
                    // create GS 

                    sbEDI.AppendLine(CreateGS(row, X12info, SegTerminator, ElementSeparator, "*"));
                    // create ST 

                    sbEDI.AppendLine(CreateST(row, X12info, SegTerminator, ElementSeparator, "*"));
                    // create BHT 

                    sbEDI.AppendLine(CreateBHT(row, X12info, SegTerminator, ElementSeparator, "*"));

                    // For Payer Segment 


                    sbEDI.AppendLine(CreateHL(row, 1, X12info, SegTerminator, ElementSeparator, "*"));

                    sbEDI.AppendLine(CreateNM1(row, "PR", X12info, SegTerminator, ElementSeparator, "*"));

                    // For Provider Segment 


                    sbEDI.AppendLine(CreateHL(row, 2, X12info, SegTerminator, ElementSeparator, "*"));

                    sbEDI.AppendLine(CreateNM1(row, "1P", X12info, SegTerminator, ElementSeparator, "*"));

                    sbEDI.AppendLine(CreateREF(row, "TJ", X12info, SegTerminator, ElementSeparator, "*"));//1P initially

                    nHlCounter = nHlCounter + 2;

                    segmentcount = 7; // segement counts - start from ST 
                }


                // For Subscriber Segment 

                // PatEDI += CreateHL(row, nHlCounter, X12info, SegTerminator, ElementSeparator);
                sbEDI.AppendLine(CreateHL(row, nHlCounter, X12info, SegTerminator, ElementSeparator, "*"));

                sbEDI.AppendLine(CreateTRN(row, Convert.ToString(trcNo), Convert.ToString(refiden), X12info, SegTerminator, ElementSeparator, "*"));

                sbEDI.AppendLine(CreateNM1(row, "IL", X12info, SegTerminator, ElementSeparator, "*"));

                // sbEDI.AppendLine(CreateREF(row, "IL", X12info, SegTerminator, ElementSeparator, "*")); //Commented repeating

                sbEDI.AppendLine(CreateDMG(row, X12info, SegTerminator, ElementSeparator));

                sbEDI.AppendLine(CreateDTP(row, "472", X12info, SegTerminator, ElementSeparator, "*"));

                sbEDI.AppendLine(CreateEQ(row, X12info, SegTerminator, ElementSeparator));

                segmentcount = segmentcount + 7;
                nHlCounter = nHlCounter + 1;
                rowCount = rowCount + 1;
                trcNo = trcNo + 1;
                refiden = refiden + 1;
                //i = i + 1;
                //if(rowCount == sqlNumRows(res))
                if (i == 1)
                {
                    segmentcount = segmentcount + 1;
                    // PatEDI += CreateSE(row, Convert.ToString(segmentcount), X12info, SegTerminator, ElementSeparator);
                    sbEDI.AppendLine(CreateSE(row, Convert.ToString(segmentcount), X12info, SegTerminator, ElementSeparator, "*"));
                    // PatEDI += CreateGE(row, X12info, SegTerminator, ElementSeparator);
                    sbEDI.AppendLine(CreateGE(row, X12info, SegTerminator, ElementSeparator, "*"));
                    //PatEDI += CreateIEA(row, X12info, SegTerminator, ElementSeparator);
                    sbEDI.AppendLine(CreateIEA(row, X12info, SegTerminator, ElementSeparator, "*"));
                }

            }
            //print $PATEDI;
            return PatEDI = sbEDI.ToString();
        }

    } // End of ManualX12Creation Class
}

Segments Classes:



















































Similarly we create other segments classes as like above and passed it to above main class.

To input data into 270 string using class








































And finally invoke class as below

ManualX12Creation objManualX12Creation = new ManualX12Creation(oPatient, oProvider, oPayer, oDTP);
            string[] X12info = new string[5];


            string FileContent = objManualX12Creation.PrintEDI("row", "res", X12info, ":", "~");

No comments :

Post a Comment