public static int Run() { dbAccess = new Edi834DataAccess(); Extras.Logging log = new Extras.Logging(); string sEdiFile = ""; ; ediDocument oEdiDoc = null; ediSchema oSchema = null; ediSchemas oSchemas = null; ediInterchange oInterchange = null; ediGroup oGroup = null; ediTransactionSet oTransactionset = null; ediDataSegment oSegment = null; // ediAcknowledgment oAck = null; // ediWarning oWarning = null; // ediWarnings oWarnings = null; string sPath = AppDomain.CurrentDomain.BaseDirectory; string sSefFile = "834_005010X220A1.SemRef.SEF"; string InterchangeControlNumber = "0000000000"; //For temp testing purpose DataTable dt = dbAccess.GetEnrollmentData(); string sDate = DateTime.Now.ToString("yyyyMMdd"); string sTime = DateTime.Now.ToString("HHmm"); try { string fileLastName = ""; // Used to ensure that no more than 1 edi message is generated a second when batching (which we never seem to do; but this prepares us) // This ensures that the batch file names are unique by making sure that only one file name is generated per second // However, the performance hit on ImportSchemas seems to limit it as well while (fileLastName == (sEdiFile = "834_X220A1_" + System.DateTime.Now.Year.ToString() + System.DateTime.Now.Month.ToString().PadLeft(2, '0') + System.DateTime.Now.Day.ToString().PadLeft(2, '0') + System.DateTime.Now.Hour.ToString().PadLeft(2, '0') + System.DateTime.Now.Minute.ToString().PadLeft(2, '0') + System.DateTime.Now.Second.ToString().PadLeft(2, '0') + ".txt")) { System.Threading.Thread.Sleep(100); } fileLastName = sEdiFile; // Create the new EDI_SndMsg Record //InterchangeControlNumber = dbAccess.AddMsg(oFacility.FacilityID, "", sEdiFile, 0); #region Create Edi document 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 oSchema = oEdiDoc.ImportSchema(sPath + sSefFile, 0); // Set termintors oEdiDoc.SegmentTerminator = "~"; oEdiDoc.ElementTerminator = "*"; oEdiDoc.CompositeTerminator = ":"; #endregion Create Edi document #region Create File Header // ISA Interchange Control Header Segment ediInterchange.Set(ref oInterchange, (ediInterchange)oEdiDoc.CreateInterchange("X", "005010")); // 5010 Change ediDataSegment.Set(ref oSegment, (ediDataSegment)oInterchange.GetDataSegmentHeader()); oSegment.set_DataElementValue(1, 0, Valence.ISASegment.InfoQualifier); //Authorization Information Qualifier oSegment.set_DataElementValue(2, 0, " "); //Authorization Information oSegment.set_DataElementValue(3, 0, Valence.ISASegment.InfoQualifier); //Security Information Qualifier oSegment.set_DataElementValue(4, 0, " "); //Security Information oSegment.set_DataElementValue(5, 0, Valence.ISASegment.InterchangeIDQualifier); //Interchange ID Qualifier oSegment.set_DataElementValue(6, 0, "582335921".PadRight(15, ' ')); //Interchange Sender ID oSegment.set_DataElementValue(7, 0, Valence.ISASegment.InterchangeIDQualifier); //Interchange ID Qualifier oSegment.set_DataElementValue(8, 0, "582335921".PadRight(15, ' ')); //Interchange Receiver ID oSegment.set_DataElementValue(9, 0, sDate.Substring(2)); //Interchange Date oSegment.set_DataElementValue(10, 0, sTime); //Interchange Time oSegment.set_DataElementValue(11, 0, "^"); //Interchange Control Standards Identifier oSegment.set_DataElementValue(12, 0, "00501"); //Interchange Control Version Number // 5010 Change oSegment.set_DataElementValue(13, 0, InterchangeControlNumber); //Interchange Control Number oSegment.set_DataElementValue(14, 0, "1"); //Acknowledgment Requested //oSegment.set_DataElementValue(15, 0, InstaMed.ISASegment.Environment.Testing); //Usage Indicator //oSegment.set_DataElementValue(15, 0, InstaMed.ISASegment.Environment.Production); //Usage Indicator oSegment.set_DataElementValue(15, 0, ConfigurationManager.AppSettings["Environment"]); //Usage Indicator oSegment.set_DataElementValue(16, 0, ":"); //Component Element Separator // GS Functional Group Header Segment ediGroup.Set(ref oGroup, (ediGroup)oInterchange.CreateGroup("005010X220A1"));// 5010 Change ediDataSegment.Set(ref oSegment, (ediDataSegment)oGroup.GetDataSegmentHeader()); oSegment.set_DataElementValue(1, 0, Valence.GSSegment.FunctionalIdentifierCode); //Functional Identifier Code oSegment.set_DataElementValue(2, 0, "582335921"); //Application Sender's Code oSegment.set_DataElementValue(3, 0, "582335921"); //Application Receiver's Code oSegment.set_DataElementValue(4, 0, sDate); //Date oSegment.set_DataElementValue(5, 0, sTime); //Time oSegment.set_DataElementValue(6, 0, Valence.GSSegment.GroupControlNumber); //Group Control Number oSegment.set_DataElementValue(7, 0, "X"); //Responsible Agency Code oSegment.set_DataElementValue(8, 0, "005010X220A1"); //Version / Release / Industry Identifier Code // 5010 Change #endregion Create File Header int count=0; foreach (DataRow dr in dt.Rows) { if (!validateData(dr)) continue; #region LOOP ID - 2000 Member Level Detail Member oMember = setupMember(dr); if (oMember == null) // Status = General error/invaid claim { //dbAccess.UpdateClaimStatus(Convert.ToInt32(dsClaims.Tables[0].Rows[iClaim]["EDIClaimID"].ToString()), cCLAIMSTATUS_ERRORGENERAL, InterchangeControlNumber); log.writeToAppLog("INVALID CLAIM", "Updating status to errored. Enrollment is missing required fields.\t\n" + dr["PolicyID"] + "\t" + dr["LastName"] + "\t" + dr["FirstName"] + "\t" + dr["MiddleName"] + "\t" + dr["SSN"] + "\t" + dr["Phone"] + "\t" + dr["Address"] + "\t" + dr["City"] + "\t" + dr["State"] + "\t" + dr["Zip"] + "\t" + dr[" DOB"] + "\t" + dr["Gender"] + "\t" + dr["PlanName"] + "\t" + dr["StartDate"] + "\r\n", "", ""); continue; } ediTransactionSet.Set(ref oTransactionset, (ediTransactionSet)oGroup.CreateTransactionSet("834")); ediDataSegment.Set(ref oSegment, (ediDataSegment)oTransactionset.GetDataSegmentHeader()); oSegment.set_DataElementValue(1, 0, "834"); //Transaction Set Identifier Code count++; oSegment.set_DataElementValue(2, 0,count+"" ); //Transaction Set Control Number oSegment.set_DataElementValue(3, 0, "005010X220A1"); ediDataSegment.Set(ref oSegment, (ediDataSegment)oTransactionset.CreateDataSegment("BGN")); oSegment.set_DataElementValue(1, 0, "00"); //"00"-Original oSegment.set_DataElementValue(2, 0, "12345"); //An ID for this transaction set, need to be generated oSegment.set_DataElementValue(3, 0, sDate); oSegment.set_DataElementValue(4, 0, sTime); oSegment.set_DataElementValue(5, 0, "CT");//Time Zone oSegment.set_DataElementValue(8, 0, ConfigurationManager.AppSettings["ActionCode"]); //2-Change, 4-Verify, RX-Replace //ediDataSegment.Set(ref oSegment, (ediDataSegment)oTransactionset.CreateDataSegment("REF")); //oSegment.set_DataElementValue(1, 0, "38"); //oSegment.set_DataElementValue(2, 0, "ALL"); #region LOOP ID - 1000A Sponsor Name //N1 Plan Sponsor ediDataSegment.Set(ref oSegment, (ediDataSegment)oTransactionset.CreateDataSegment("N1\\N1")); oSegment.set_DataElementValue(1, 0, "P5"); //P5-Plan Sponsor oSegment.set_DataElementValue(2, 0, "Alliant Health Plans");//Free-form Name oSegment.set_DataElementValue(3, 0, "FI"); //Frderal Tax ID oSegment.set_DataElementValue(4, 0, "582335921"); #endregion #region LOOP ID - 1000B Payer Name //N1 Plan Sponsor ediDataSegment.Set(ref oSegment, (ediDataSegment)oTransactionset.CreateDataSegment("N1\\N1")); oSegment.set_DataElementValue(1, 0, "IN"); //IN-Insurer oSegment.set_DataElementValue(2, 0, "PHR"); oSegment.set_DataElementValue(3, 0, "FI");//Frderal Tax ID oSegment.set_DataElementValue(4, 0, "582335921"); #endregion #region LOOP ID - 1000C Broker Name //ediDataSegment.Set(ref oSegment, (ediDataSegment)oTransactionset.CreateDataSegment("N1\\N1")); //oSegment.set_DataElementValue(1, 0, "BO"); //BO-Broker //oSegment.set_DataElementValue(2, 0, ""); //Broker Name //oSegment.set_DataElementValue(1, 0, "94"); //94-National Producer Number (NPN) //oSegment.set_DataElementValue(2, 0, ""); //Broker NPN #endregion //// HL Counters for loops //int nHlCounter = 1; //int nHlSubscriberParent = 1; //int nHlDependentParent = 0; //Subscriber ediDataSegment.Set(ref oSegment, (ediDataSegment)oTransactionset.CreateDataSegment("INS\\INS")); oSegment.set_DataElementValue(1, 0, oMember.Yes_No_Condition); oSegment.set_DataElementValue(2, 0, oMember.IndividualRelationshipCode); //18-Self oSegment.set_DataElementValue(3, 0, oMember.MaintenanceTypeCode_MLD);//021-Addition /*INS03 Maintainance Type 001 = Change (change existing record) 021 = Addition (used to add subscriber or dependent) 024 = Cancellation or Termination 025 = Reinstatement 030 = Audit or Compare (BGN08 = 4 or RX)*/ oSegment.set_DataElementValue(4, 0,oMember.MaintenanceReasonCode); //Maintainance Reason, leave blank oSegment.set_DataElementValue(5, 0, oMember.BenefitStatusCode); /*INS05 Benefit Status Code A = Active C = Cobra S = Surviving Insured T = Tax Equity and Fiscal Responsibility Act (TEFRA) */ oSegment.set_DataElementValue(8, 0, oMember.EmploymentStatusCode); //FT- Full-time ediDataSegment.Set(ref oSegment, (ediDataSegment)oTransactionset.CreateDataSegment("INS\\REF")); oSegment.set_DataElementValue(1, 0, oMember.SubscriberNumber); //OF-Subscriber Number oSegment.set_DataElementValue(2, 0, oMember.ReferenceNumber); ediDataSegment.Set(ref oSegment, (ediDataSegment)oTransactionset.CreateDataSegment("INS\\REF")); oSegment.set_DataElementValue(1, 0, oMember.MemberPolicyNumber); //1L-Group oSegment.set_DataElementValue(2, 0, oMember.ReferenceIdentification_MPM); foreach(EDIModel.Member.MemberIdentification identification in oMember.MemberIdentificationNumber) { ediDataSegment.Set(ref oSegment, (ediDataSegment)oTransactionset.CreateDataSegment("INS\\REF")); oSegment.set_DataElementValue(1, 0, identification.MemberIdentificationNumber); //23-Person Code oSegment.set_DataElementValue(2, 0, identification.ReferenceIdentification); //Reference Identification } #region LOOP ID - 2100A Member Name ediDataSegment.Set(ref oSegment, (ediDataSegment)oTransactionset.CreateDataSegment("INS\\NM1\\NM1")); oSegment.set_DataElementValue(1, 0, oMember.EntityIdentifierCode_Member); //IL-Insured or Subscriber oSegment.set_DataElementValue(2, 0,oMember.EntityTypeQualifier_Member); //1 -Person oSegment.set_DataElementValue(3, 0, oMember.NameLast); //indiviual last name oSegment.set_DataElementValue(4, 0, oMember.NameFirst); oSegment.set_DataElementValue(5, 0, oMember.NameMiddle); oSegment.set_DataElementValue(8, 0, oMember.IdentificationCodeQualifier); //34-Social Security Number oSegment.set_DataElementValue(9, 0, oMember.IdentificationCode); ediDataSegment.Set(ref oSegment, (ediDataSegment)oTransactionset.CreateDataSegment("INS\\NM1\\PER")); oSegment.set_DataElementValue(1, 0, oMember.ContactFunctionCode); //IP -Insured Party oSegment.set_DataElementValue(3, 0, oMember.CommunicationNumberQualifier_1); //Telephone oSegment.set_DataElementValue(4, 0, oMember.CommunicationNumber_1); oSegment.set_DataElementValue(5, 0, oMember.CommunicationNumberQualifier_2); oSegment.set_DataElementValue(6, 0, oMember.CommunicationNumber_2); //oSegment.set_DataElementValue(5, 0, "TE"); //Communication Number Qualifier TE - Telephone ediDataSegment.Set(ref oSegment, (ediDataSegment)oTransactionset.CreateDataSegment("INS\\NM1\\N3")); oSegment.set_DataElementValue(1, 0, oMember.AddressLine_1); oSegment.set_DataElementValue(2, 0, oMember.AddressLine_2); ediDataSegment.Set(ref oSegment, (ediDataSegment)oTransactionset.CreateDataSegment("INS\\NM1\\N4")); oSegment.set_DataElementValue(1, 0, oMember.City); oSegment.set_DataElementValue(2, 0, oMember.State); oSegment.set_DataElementValue(3, 0, oMember.PostalCode); ediDataSegment.Set(ref oSegment, (ediDataSegment)oTransactionset.CreateDataSegment("INS\\NM1\\DMG")); oSegment.set_DataElementValue(1, 0, oMember.Date_Time_FormatQualifier_MD); //D8 - Date Expressed in Format CCYYMMDD oSegment.set_DataElementValue(2, 0, oMember.Date_Time_Period_MD); oSegment.set_DataElementValue(3, 0, oMember.GenderCode); #endregion LOOP 2100a #region LOOP ID - 2300 Health Coverage foreach (Member.HealthCoverage hc in oMember.HealthCoverages ) { ediDataSegment.Set(ref oSegment, (ediDataSegment)oTransactionset.CreateDataSegment("INS\\HD\\HD")); oSegment.set_DataElementValue(1, 0,hc.MaintenanceTypeCode ); //021- Addition oSegment.set_DataElementValue(3, 0, hc.InsuranceLineCode); //HLT -Health oSegment.set_DataElementValue(4, 0, hc.PlanCoverageDescription); // oSegment.set_DataElementValue(5, 0, "IND"); //IND- Individual foreach(Member.HealthCoverage_Dates date in hc.HealthCoverageDates) { ediDataSegment.Set(ref oSegment, (ediDataSegment)oTransactionset.CreateDataSegment("INS\\HD\\DTP")); oSegment.set_DataElementValue(1, 0, date.Date_Time_Qualifier); //348-Benefit Begin oSegment.set_DataElementValue(2, 0, date.Date_Time_FormatQualifier_HCD); oSegment.set_DataElementValue(3, 0, date.Date_Time_Period_HCD); } } #endregion LOOP 2300 #endregion LOOP 2000 } oEdiDoc.Save(DIR_Valence_Out + sEdiFile); oEdiDoc.Dispose(); }//try catch (Exception ex) { log.writeToAppLog("ERROR", ex.ToString() + "r\n", "", ""); throw new Exception(ex.ToString()); } return 0; // return Total Number of Claims }