public static int Parse(Edi834DataAccess dbAccess,string content) { 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; // Int32 nWarningsCount; string sPath = AppDomain.CurrentDomain.BaseDirectory; string sSefFile = "834_005010X220A1.SemRef.SEF"; ediAcknowledgment oAck = null; //string sValue; //string sHlEntity = ""; //string sNm1Entity = ""; //string sQlfr; //CREATES EDIDOC OBJECT oEdiDoc = new ediDocument(); oEdiDoc.EventNotify += new EventNotifyDelegate(oEdiDoc_EventNotify); //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. oSchemas = (ediSchemas)oEdiDoc.GetSchemas(); oSchemas.EnableStandardReference = false; oAck = (ediAcknowledgment)oEdiDoc.GetAcknowledgment(); oAck.EnableInterchangeAcknowledgment = true; //THIS OPTIONS STOPS FREDI FROM KEEPING ALL THE SEGMENTS IN MEMORY oEdiDoc.CursorType = DocumentCursorTypeConstants.Cursor_ForwardOnly; //LOADS THE SEF FILE oEdiDoc.LoadSchema(sPath + sSefFile, SchemaTypeIDConstants.Schema_Standard_Exchange_Format); //LOADS THE EDI FILE oEdiDoc.LoadEdiString(content); //GETS THE FIRST DATA SEGMENT ediDataSegment.Set(ref oSegment, (ediDataSegment)oEdiDoc.FirstDataSegment); MsgHeader msg_header=null; MsgTrailer msg_trailer =null; Int64 msg_HeaderID = 0; Int64 msg_transID = 0; TransactionHeader trans_Header = null; TransactionTrailer trans_Trailer = null; Member.HealthCoverage health_coverage=null; Member.MemberReport member_report=null; Member msg_Member = null; while (oSegment != null) { sSegmentID = oSegment.ID; sLoopSection = oSegment.LoopSection; nArea = oSegment.Area; // Debug.WriteLine("segment id ="+ sSegmentID+"\t section ="+sLoopSection+" \t nArea= "+nArea+"\r\t"); if (nArea == 0) { if (sLoopSection == "") { if (sSegmentID == "ISA") { if (msg_header == null) msg_header = new MsgHeader(); msg_header.InterchangeControlHeader=oSegment.get_DataElementValue(1, 0); msg_header.AuthorizationInformation = oSegment.get_DataElementValue(2, 0); msg_header.SecurityInformationQualifier = oSegment.get_DataElementValue(3, 0); msg_header.SecurityInformation = oSegment.get_DataElementValue(4, 0); msg_header.InterchangeIDQualifier_1 = oSegment.get_DataElementValue(5, 0); msg_header.InterchangeSenderID = oSegment.get_DataElementValue(6, 0); msg_header.InterchangeIDQualifier_2 = oSegment.get_DataElementValue(7, 0); msg_header.InterchangeReceiverID = oSegment.get_DataElementValue(8, 0); msg_header.IntegerchangeDate = oSegment.get_DataElementValue(9, 0); msg_header.IntegerchangeTime = oSegment.get_DataElementValue(10, 0); msg_header.RepetitionSeperator = oSegment.get_DataElementValue(11, 0); msg_header.InterchangeControlVersionNumber = oSegment.get_DataElementValue(12, 0); msg_header.InterchangeControlNumber_header = oSegment.get_DataElementValue(13, 0); msg_header.AcknowledgementRequest = oSegment.get_DataElementValue(14, 0); msg_header.UsageIdentifier = oSegment.get_DataElementValue(15, 0); msg_header.ComponentElementSeparator = oSegment.get_DataElementValue(16, 0); } else if (sSegmentID == "GS") { if (msg_header == null) msg_header = new MsgHeader(); msg_header.FunctionalGroupHeader_header=oSegment.get_DataElementValue(1,0); msg_header.ApplicationSendersCode=oSegment.get_DataElementValue(2,0); msg_header.ApplicationReceiversCode=oSegment.get_DataElementValue(3,0); msg_header.Date=oSegment.get_DataElementValue(4,0); msg_header.Time=oSegment.get_DataElementValue(5,0); msg_header.GroupControlNumber_header=oSegment.get_DataElementValue(6,0); msg_header.ResponsibleAgencyCode=oSegment.get_DataElementValue(7,0); msg_header.IndustryIndentifierCode=oSegment.get_DataElementValue(8,0); dbAccess.InsertNewMessageHeader(msg_header); //insert it into the database; msg_header = null; msg_HeaderID = dbAccess.getHeaderID(); //get the header id; } else if (sSegmentID == "GE") { if (msg_trailer == null) msg_trailer = new MsgTrailer(); msg_trailer.FunctionalGroupHeader_trailer = oSegment.get_DataElementValue(1, 0); msg_trailer.GroupControlNumber_trailer = oSegment.get_DataElementValue(2, 0); } else if (sSegmentID == "IEA") { msg_trailer.InterchangeControlTrailer = oSegment.get_DataElementValue(1, 0); msg_trailer.InterchangeControlNumber_trailer = oSegment.get_DataElementValue(2, 0); dbAccess.insertNewMessageTrailer(msg_trailer,msg_HeaderID); msg_trailer = null; } else { Debug.WriteLine("segment id ="+ sSegmentID+"\t section ="+sLoopSection+" \t nArea= "+nArea+" is not be recorded"); } } } else if (nArea == 1) { if (trans_Header == null) trans_Header = new TransactionHeader(); if (sLoopSection == "") { if (sSegmentID == "ST") { trans_Header.HeaderID = msg_HeaderID; trans_Header.TransactionSetIdentifier = oSegment.get_DataElementValue(1, 0); trans_Header.TranscationSetControlNumber = oSegment.get_DataElementValue(2, 0); trans_Header.ImplementationConventionReference = oSegment.get_DataElementValue(3, 0); } else if (sSegmentID == "BGN") { if (trans_Header == null) trans_Header = new TransactionHeader(); trans_Header.TransactionSetPurposeCode = oSegment.get_DataElementValue(1, 0); trans_Header.ReferenceIdentification_BS = oSegment.get_DataElementValue(2, 0); trans_Header.Date = oSegment.get_DataElementValue(3, 0); trans_Header.Time = oSegment.get_DataElementValue(4, 0); trans_Header.ActionCode = oSegment.get_DataElementValue(5, 0); } else if (sSegmentID == "REF") {if (trans_Header == null) trans_Header = new TransactionHeader(); trans_Header.ReferenceIdentificationQualifier = oSegment.get_DataElementValue(1, 0); trans_Header.ReferenceIdentification = oSegment.get_DataElementValue(2, 0); } else if(sSegmentID=="DTP") { //LOOP EDIModel.TransactionHeader.FileDate file_date; file_date.Date_TimeQualifier=oSegment.get_DataElementValue(1,0); file_date.DateTimePeriodFormatQualifier=oSegment.get_DataElementValue(2,0); file_date.DateTimePeriod=oSegment.get_DataElementValue(3,0); trans_Header.FileEffectiveDate.AddLast(file_date); } else if (sSegmentID == "QTY") { EDIModel.TransactionHeader.TransactionSets trans_set; trans_set.QuantityQualifier = oSegment.get_DataElementValue(1, 0); trans_set.Quantity = oSegment.get_DataElementValue(2, 0); trans_Header.TransactionSetControlTotals.AddLast(trans_set); } } else if (sLoopSection == "N1") { if (sSegmentID == "N1" ) { string EntityIdentifier = oSegment.get_DataElementValue(1, 0); if (EntityIdentifier == "P5") { trans_Header.EntityIdentifierCode_Sponsor = oSegment.get_DataElementValue(1, 0); trans_Header.Name_Sponsor = oSegment.get_DataElementValue(2, 0); trans_Header.IdentificationCodeQualifier_Sponsor = oSegment.get_DataElementValue(3, 0); //optional trans_Header.IdentificationCode_Sponsor = oSegment.get_DataElementValue(4, 0); } else if (EntityIdentifier =="IN") { trans_Header.EntityIdentifierCode_Payer= oSegment.get_DataElementValue(1, 0); trans_Header.Name_Payer = oSegment.get_DataElementValue(2, 0); trans_Header.IdentificationCodeQualifier_Payer = oSegment.get_DataElementValue(3, 0); trans_Header.IdentificationCode_Payer = oSegment.get_DataElementValue(4, 0); } else { //LOOP EDIModel.TransactionHeader.TPABroker tpa_broker; tpa_broker.EntityIdentityCode = oSegment.get_DataElementValue(1, 0); tpa_broker.Name_TPA_Broker = oSegment.get_DataElementValue(2, 0); tpa_broker.IdentificationCodeQualifier_TPA_Broker = oSegment.get_DataElementValue(3, 0); tpa_broker.IdentificationCode_TPA_Broker = oSegment.get_DataElementValue(4, 0); trans_Header.TPABrokerAccount.AddLast(tpa_broker); } } } } else if (nArea == 2) { if (trans_Header != null) { dbAccess.insertNewTransaction(trans_Header); //insert the header into database msg_transID = dbAccess.getTransactionID(); dbAccess.insertNewTransaction_FileDate(trans_Header.FileEffectiveDate, msg_transID); dbAccess.insertNewTransaction_Sets(trans_Header.TransactionSetControlTotals, msg_transID); dbAccess.insertNewTransaction_TPABroker(trans_Header.TPABrokerAccount, msg_transID); trans_Header = null; } if (sLoopSection == "INS") { if (sSegmentID == "INS") { //Start to import the memeber information; msg_Member = null; msg_Member = new Member(); msg_Member.Yes_No_Condition = oSegment.get_DataElementValue(1, 0); msg_Member.IndividualRelationshipCode = oSegment.get_DataElementValue(2, 0); msg_Member.MaintenanceTypeCode_MLD = oSegment.get_DataElementValue(3, 0); //Optional msg_Member.MaintenanceReasonCode = oSegment.get_DataElementValue(4, 0); msg_Member.BenefitStatusCode = oSegment.get_DataElementValue(5, 0); //Optional msg_Member.EmploymentStatusCode = oSegment.get_DataElementValue(8, 0); } else if (sSegmentID == "REF") { string SubscriberNumber = oSegment.get_DataElementValue(1, 0); if (SubscriberNumber == "0F") { msg_Member.SubscriberNumber = oSegment.get_DataElementValue(1, 0); //Optional msg_Member.ReferenceNumber = oSegment.get_DataElementValue(2, 0); } else if (SubscriberNumber == "1L") { msg_Member.MemberPolicyNumber = oSegment.get_DataElementValue(1, 0); msg_Member.ReferenceIdentification_MPM = oSegment.get_DataElementValue(2, 0); } else { //LOOP EDIModel.Member.MemberIdentification member_Identification; member_Identification.MemberIdentificationNumber = oSegment.get_DataElementValue(1, 0); member_Identification.ReferenceIdentification = oSegment.get_DataElementValue(2, 0); msg_Member.MemberIdentificationNumber.AddLast(member_Identification); } } else if (sSegmentID == "DTP") { EDIModel.Member.MemberDate member_level_date; //optional member_level_date.Date_Time_Qualifier = oSegment.get_DataElementValue(1, 0); //optional member_level_date.Date_Time_Format = oSegment.get_DataElementValue(2, 0); //optional member_level_date.Date_Time_Period = oSegment.get_DataElementValue(3, 0); msg_Member.MemberLevelDate.AddLast(member_level_date); } else if (sSegmentID == "LS") { msg_Member.LoopIdentifierCode = oSegment.get_DataElementValue(1, 0); } else if (sSegmentID == "LE") { msg_Member.LoopIdentifierCode = oSegment.get_DataElementValue(1, 0); } } else if (sLoopSection == "") { if (sSegmentID == "SE") { //Insert into database; if (health_coverage != null) { msg_Member.HealthCoverages.AddLast(health_coverage); health_coverage = null; } if (member_report != null) { msg_Member.MemberReportingCategories.AddLast(member_report); member_report = null; } dbAccess.insertNewMember(msg_Member, msg_transID);// insert the member into the database if (trans_Trailer == null) trans_Trailer = new TransactionTrailer(); trans_Trailer.NumberOfIncludedSegments = oSegment.get_DataElementValue(1, 0); trans_Trailer.TransactionSetControlNumber = oSegment.get_DataElementValue(2, 0); dbAccess.insertNewTransactionTrailer(trans_Trailer, msg_transID); trans_Trailer = null; } } else if (sLoopSection == "INS;NM1") { if (sSegmentID == "NM1") { msg_Member.EntityIdentifierCode_Member = oSegment.get_DataElementValue(1, 0); msg_Member.EntityTypeQualifier_Member = oSegment.get_DataElementValue(2, 0); msg_Member.NameLast = oSegment.get_DataElementValue(3, 0); msg_Member.NameFirst = oSegment.get_DataElementValue(4, 0); //optional msg_Member.NameMiddle = oSegment.get_DataElementValue(5, 0); msg_Member.IdentificationCodeQualifier = oSegment.get_DataElementValue(8, 0); //optional msg_Member.IdentificationCode = oSegment.get_DataElementValue(9, 0); } else if (sSegmentID == "PER") { msg_Member.ContactFunctionCode = oSegment.get_DataElementValue(1, 0); //keep empty if not given msg_Member.CommunicationNumberQualifier_1 = oSegment.get_DataElementValue(3, 0); msg_Member.CommunicationNumber_1 = oSegment.get_DataElementValue(4, 0); msg_Member.CommunicationNumberQualifier_2 = oSegment.get_DataElementValue(5, 0); msg_Member.CommunicationNumber_2 = oSegment.get_DataElementValue(6, 0); msg_Member.CommunicationNumberQualifier_3 = oSegment.get_DataElementValue(7, 0); msg_Member.CommunicationNumber_3 = oSegment.get_DataElementValue(8, 0); } else if (sSegmentID == "N3") { //Keep Empty if not Given msg_Member.AddressLine_1 = oSegment.get_DataElementValue(1, 0); //optional msg_Member.AddressLine_2 = oSegment.get_DataElementValue(2, 0); } else if (sSegmentID == "N4") { msg_Member.City = oSegment.get_DataElementValue(1, 0); msg_Member.State = oSegment.get_DataElementValue(2, 0); msg_Member.PostalCode = oSegment.get_DataElementValue(3, 0); //Optional msg_Member.LocationQualifier = oSegment.get_DataElementValue(5, 0); //optional msg_Member.LocationIdentifier = oSegment.get_DataElementValue(6, 0); } else if (sSegmentID == "DMG") { msg_Member.Date_Time_FormatQualifier_MD = oSegment.get_DataElementValue(1, 0); msg_Member.Date_Time_Period_MD = oSegment.get_DataElementValue(2, 0); msg_Member.GenderCode = oSegment.get_DataElementValue(3, 0); //optional msg_Member.MaritalStatusCode = oSegment.get_DataElementValue(4, 0); msg_Member.CompositeRaceOrEthnicityInformation = oSegment.get_DataElementValue(5, 0); } else if (sSegmentID == "HLH") { //optional msg_Member.HealthRelatedCode = oSegment.get_DataElementValue(1, 0); } } else if (sLoopSection == "INS;HD") { if (sSegmentID == "HD") { //LOOP Class if (health_coverage == null) health_coverage = new Member.HealthCoverage(); else { msg_Member.HealthCoverages.AddLast(health_coverage); health_coverage = new Member.HealthCoverage(); } health_coverage.MaintenanceTypeCode = oSegment.get_DataElementValue(1, 0); health_coverage.InsuranceLineCode = oSegment.get_DataElementValue(3, 0); //should set to be empty health_coverage.PlanCoverageDescription = oSegment.get_DataElementValue(4, 0); } else if (sSegmentID == "DTP") { EDIModel.Member.HealthCoverage_Dates health_date; health_date.Date_Time_Qualifier = oSegment.get_DataElementValue(1, 0); health_date.Date_Time_FormatQualifier_HCD = oSegment.get_DataElementValue(2, 0); health_date.Date_Time_Period_HCD = oSegment.get_DataElementValue(3, 0); health_coverage.HealthCoverageDates.AddLast(health_date); } else if (sSegmentID == "REF") { EDIModel.Member.HealthPolicyNum policy_num; policy_num.ReferenceIdentificationQualifier = oSegment.get_DataElementValue(1, 0); policy_num.ReferenceIdentification = oSegment.get_DataElementValue(2, 0); health_coverage.PolicyNumber.AddLast(policy_num); } } else if (sLoopSection == "INS;LX") { if (sSegmentID == "LX") { if (member_report == null) member_report = new Member.MemberReport(); else { msg_Member.MemberReportingCategories.AddLast(member_report); member_report = new Member.MemberReport(); } member_report.AssignedNumber = oSegment.get_DataElementValue(1, 0); } } else if (sLoopSection == "INS;LX;N1") { if (sSegmentID == "N1") { member_report.EntityIdentifierCode = oSegment.get_DataElementValue(1, 0); member_report.Name = oSegment.get_DataElementValue(2, 0); } else if (sSegmentID == "REF") { member_report.ReferenceIdentificationQualifier = oSegment.get_DataElementValue(1, 0); member_report.ReferenceIdentification = oSegment.get_DataElementValue(2, 0); } } } ediDataSegment.Set(ref oSegment, (ediDataSegment)oSegment.Next()); } //dbAccess.getHeaderTrailerID(); //Console.ReadKey(); string sFileName = "TA1_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"; oAck.Save(DIR_TA1_OUT+ sFileName); oSchemas.Dispose(); oEdiDoc.Dispose(); return 0; }
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 }