protected string SetIEASegment(string strDefaultSep, string strEOS, string strControlNo) { MNBilling.IEA_InterchangeControlTrailer IEA = new MNBilling.IEA_InterchangeControlTrailer(); try { IEA.FunctionalGroupCount = 1; IEA.ControlNo = strControlNo; return("IEA" + strDefaultSep + "1" + strDefaultSep + strControlNo + strEOS); } catch (Exception ex) { throw ex; } }
public string Build837P(DataSet dsRawData) { try { string strWellFormed837P = ""; ArrayList o837P = new ArrayList(); HIPAAComponents.MNBilling oBills = new MNBilling(); MNBilling.GE_FunctionalGroupTrailer oGE = new MNBilling.GE_FunctionalGroupTrailer(); MNBilling.IEA_InterchangeControlTrailer oIEA = new MNBilling.IEA_InterchangeControlTrailer(); int intSegmentCount; int intSVCLineCount; int intParent; int intHLLevel; string strBatchFilter; string strClaimsAndBatchFilter; //This section is used to set the header information required for all claims in all batches to be processed. intInterchangeID = int.Parse(dsRawData.Tables[intEDIHeader].Rows[0]["intInterchangeID"].ToString()); strSenderIDQual = dsRawData.Tables[intEDIHeader].Rows[0]["strSenderIDQual"].ToString(); strSenderID = dsRawData.Tables[intEDIHeader].Rows[0]["strSenderID"].ToString(); strReceiverID = dsRawData.Tables[intEDIHeader].Rows[0]["strReceiverID"].ToString(); strReceiverIDQual = dsRawData.Tables[intEDIHeader].Rows[0]["strReceiverIDQual"].ToString(); blnAcknowledgement = bool.Parse(dsRawData.Tables[intEDIHeader].Rows[0]["blnAcknowledgement"].ToString()); strRepetitionSeparator = dsRawData.Tables[intEDIHeader].Rows[0]["strRepetitionSeparator"].ToString(); strElementSeparator = dsRawData.Tables[intEDIHeader].Rows[0]["strElementSeparator"].ToString(); strUsage = dsRawData.Tables[intEDIHeader].Rows[0]["strUsage"].ToString(); intSubmitterEDIContactID = int.Parse(dsRawData.Tables[intEDIHeader].Rows[0]["intSubmitterEDIContactID"].ToString()); strContactFunctionCode = dsRawData.Tables[intEDIHeader].Rows[0]["strContactFunctionCode"].ToString(); strContactName = dsRawData.Tables[intEDIHeader].Rows[0]["strContactName"].ToString(); strCommunicationNumberID = dsRawData.Tables[intEDIHeader].Rows[0]["strCommunicationNumberID"].ToString(); strCommunicationNumber = dsRawData.Tables[intEDIHeader].Rows[0]["strCommunicationNumber"].ToString(); strCommunicationNumberID2 = dsRawData.Tables[intEDIHeader].Rows[0]["strCommunicationNumberID2"].ToString(); strcommunicationNumber2 = dsRawData.Tables[intEDIHeader].Rows[0]["strcommunicationNumber2"].ToString(); strCommunicationNumberID3 = dsRawData.Tables[intEDIHeader].Rows[0]["strCommunicationNumberID3"].ToString(); strcommunicationNumber3 = dsRawData.Tables[intEDIHeader].Rows[0]["strCommunicationNumber3"].ToString(); //************************************************************************************************************ oBills.DefaultSep = "*"; oBills.EndOfSegment = "~"; oBills.AckRequested = blnAcknowledgement; //This section starts the building of an 837P. The process starts //with collecting all of the batches to be processes. This is normally //1 but it is possible to include more that 1 per file if the payer //will accept it that way. foreach (DataRow b in dsRawData.Tables[intBatches].Rows) { intSegmentCount = 10; intSVCLineCount = 1; intParent = 1; intHLLevel = 2; o837P.Add(SetISA(b["BatchNumber"].ToString(), oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetGS(b["BatchNumber"].ToString(), oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetST(b["BatchNumber"].ToString(), oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetBHT(b["BatchNumber"].ToString(), oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetSubmitterName(b, oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetEDIContact(oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetReceiverName(b, oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetBillingProviderLevel(1, oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetBillingProviderName(b, oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetBillingProviderAddress(b, oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetCityStateZip(b, oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetTaxID(b, oBills.DefaultSep, oBills.EndOfSegment)); strBatchFilter = "BatchNumber=" + b["BatchNumber"].ToString(); //**************************************************************************************************************** //This section start iterating through each claim in a batch. foreach (DataRow c in dsRawData.Tables[intClaimsinBatch].Select(strBatchFilter)) { o837P.Add(SetSubscriberLevel(intHLLevel, intParent, oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetSBRSegment(b, oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetSubscriberName(c, oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetBillingSubscriberAddress(c, oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetSubscriberCityStateZip(c, oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetSubscriberDemographics(c, oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetPayerName(c, oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetClaimSegment(c, oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetPriorAuthorization(c, oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetHISegment(c, oBills.DefaultSep, oBills.EndOfSegment)); strClaimsAndBatchFilter = "BatchNumber=" + b["BatchNumber"].ToString() + " And SubscriberID=" + c["ClaimsBatchID"].ToString(); //*************************************************************************************************************** foreach (DataRow s in dsRawData.Tables[intSVCLines4Claim].Select(strClaimsAndBatchFilter)) { o837P.Add(SetLXSegment(intSVCLineCount, oBills.DefaultSep, oBills.EndOfSegment)); intSVCLineCount += 1; o837P.Add(SetSV1Segment(s, oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetServiceDate(s, oBills.DefaultSep, oBills.EndOfSegment)); intSegmentCount = intSegmentCount + 3; } intSegmentCount = intSegmentCount + 10; intHLLevel += 1; intSVCLineCount = 1; } intSegmentCount = intSegmentCount + 1; o837P.Add(SetSESegment(intSegmentCount, b["BatchNumber"].ToString(), oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetGESegment(oBills.DefaultSep, oBills.EndOfSegment, b["BatchNumber"].ToString())); o837P.Add(SetIEASegment(oBills.DefaultSep, oBills.EndOfSegment, b["BatchNumber"].ToString())); } foreach (string strResult in o837P) { strWellFormed837P = strWellFormed837P + strResult; } return(strWellFormed837P); } catch (Exception ex) { throw ex; } }
/// <summary> /// Build Well-Formed 837P /// </summary> protected void build837Batches() { HIPAAComponents.MNBilling oBills = new MNBilling(); MNBilling.GE_FunctionalGroupTrailer oGE = new MNBilling.GE_FunctionalGroupTrailer(); MNBilling.IEA_InterchangeControlTrailer oIEA = new MNBilling.IEA_InterchangeControlTrailer(); SqlClientDataOperations oSalient = new SqlClientDataOperations(); DataSet oBatchDS = new DataSet(); DataSet oClaimsDS = new DataSet(); DataSet oLinesDS = new DataSet(); //string[] o837P; ArrayList o837P = new ArrayList(); int intSegmentCount; int intSVCLineCount; int intParent; int intHLLevel; try { oSalient.ConnectionString = ConfigurationManager.ConnectionStrings["HIPAAComponents"].ConnectionString; oSalient.LoadDataSetFromStoredProc("usp_GetBatches2Process").Fill(oBatchDS); oBills.DefaultSep = "*"; oBills.EndOfSegment = "~"; oBills.AckRequested = blnAcknowledgement; foreach (DataRow x in oBatchDS.Tables[0].Rows) { intSegmentCount = 10; intSVCLineCount = 1; intParent = 1; intHLLevel = 2; o837P.Add(SetISA(x["BatchNumber"].ToString(), oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetGS(x["BatchNumber"].ToString(), oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetST(x["BatchNumber"].ToString(), oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetBHT(x["BatchNumber"].ToString(), oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetSubmitterName(x, oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetEDIContact(oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetReceiverName(x, oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetBillingProviderLevel(1, oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetBillingProviderName(x, oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetBillingProviderAddress(x, oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetCityStateZip(x, oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetTaxID(x, oBills.DefaultSep, oBills.EndOfSegment)); ArrayList oParams = new ArrayList(); oParams.Add(new System.Data.SqlClient.SqlParameter("@BatchNumber", x["BatchNumber"].ToString())); oSalient.LoadDataSet(oParams, "usp_GetClaimsByBatchNumber").Fill(oClaimsDS); foreach (DataRow y in oClaimsDS.Tables[0].Rows) { o837P.Add(SetSubscriberLevel(intHLLevel, intParent, oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetSBRSegment(x, oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetSubscriberName(y, oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetBillingSubscriberAddress(y, oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetSubscriberCityStateZip(y, oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetSubscriberDemographics(y, oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetPayerName(y, oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetClaimSegment(y, oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetPriorAuthorization(y, oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetHISegment(y, oBills.DefaultSep, oBills.EndOfSegment)); ArrayList oSVCParams = new ArrayList(); oSVCParams.Add(new System.Data.SqlClient.SqlParameter("@BatchNumber", x["BatchNumber"].ToString())); oSVCParams.Add(new System.Data.SqlClient.SqlParameter("@SubscriberID", y["ClaimsBatchID"].ToString())); oSalient.LoadDataSet(oSVCParams, "usp_GetSVCLinesByBatchAndClaim").Fill(oLinesDS); foreach (DataRow q in oLinesDS.Tables[0].Rows) { o837P.Add(SetLXSegment(intSVCLineCount, oBills.DefaultSep, oBills.EndOfSegment)); intSVCLineCount += 1; o837P.Add(SetSV1Segment(q, oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetServiceDate(q, oBills.DefaultSep, oBills.EndOfSegment)); intSegmentCount = intSegmentCount + 3; } intSegmentCount = intSegmentCount + 10; intHLLevel += 1; oLinesDS.Clear(); intSVCLineCount = 1; } intSegmentCount = intSegmentCount + 1; o837P.Add(SetSESegment(intSegmentCount, x["BatchNumber"].ToString(), oBills.DefaultSep, oBills.EndOfSegment)); o837P.Add(SetGESegment(oBills.DefaultSep, oBills.EndOfSegment, x["BatchNumber"].ToString())); o837P.Add(SetIEASegment(oBills.DefaultSep, oBills.EndOfSegment, x["BatchNumber"].ToString())); int intBuffer = o837P[0].ToString().Length *(intSegmentCount + 6); StreamWriter oFS = new StreamWriter(ConfigurationManager.AppSettings["ResultsPath"].ToString() + x["NPI"].ToString() + "_837P_" + System.DateTime.Now.ToString("yyyyMMdd") + ".dat"); foreach (string z in o837P) { oFS.Write(z); oFS.Flush(); ArrayList oInsertParam = new ArrayList(); oInsertParam.Add(new System.Data.SqlClient.SqlParameter("@ControlNumber", x["BatchNumber"].ToString())); oInsertParam.Add(new System.Data.SqlClient.SqlParameter("@LineSegment", z.ToString())); //oSalient.ExecuteNonQuery(oInsertParam, "usp_InsertClaimLine"); } } } catch (Exception ex) { throw ex; } }