protected string SetSubmitterName(DataRow x, string strDefaultSep, string strEOS) { MNBilling oNM1 = new MNBilling(); NM1_SubmitterName_1000A Q = new NM1_SubmitterName_1000A(); try { Q.NM101__EntityIdentifierCode = NM1_SubmitterName_1000ANM101__EntityIdentifierCode.Item41; Q.NM102__EntityTypeQualifier = NM1_SubmitterName_1000ANM102__EntityTypeQualifier.Item2; Q.NM103__SubmitterLastOrOrganizationName = x["Biller"].ToString(); Q.NM104__SubmitterFirstName = ""; Q.NM105__SubmitterMiddleNameOrInitial = ""; Q.NM106 = ""; Q.NM107 = ""; Q.NM108__IdentificationCodeQualifier = NM1_SubmitterName_1000ANM108__IdentificationCodeQualifier.Item46; Q.NM109__SubmitterIdentifier = x["NPI"].ToString(); return("NM1" + strDefaultSep + "41" + strDefaultSep + "2" + strDefaultSep + Q.NM103__SubmitterLastOrOrganizationName + strDefaultSep + Q.NM104__SubmitterFirstName + strDefaultSep + Q.NM105__SubmitterMiddleNameOrInitial + strDefaultSep + Q.NM106 + strDefaultSep + Q.NM107 + strDefaultSep + "46" + strDefaultSep + Q.NM109__SubmitterIdentifier + strEOS); } catch (Exception ex) { throw ex; } }
protected string SetReceiverName(DataRow x, string strDefaultSep, string strEOS) { MNBilling oNM1 = new MNBilling(); NM1_ReceiverName_1000B Q = new NM1_ReceiverName_1000B(); try { Q.NM101__EntityIdentifierCode = NM1_ReceiverName_1000BNM101__EntityIdentifierCode.Item40; Q.NM102__EntityTypeQualifier = NM1_ReceiverName_1000BNM102__EntityTypeQualifier.Item2; Q.NM103__ReceiverName = x["Payer"].ToString(); Q.NM104 = ""; Q.NM105 = ""; Q.NM106 = ""; Q.NM107 = ""; Q.NM108__IdentificationCodeQualifier = NM1_ReceiverName_1000BNM108__IdentificationCodeQualifier.Item46; Q.NM109__ReceiverPrimaryIdentifier = x["PayerID"].ToString(); return("NM1" + strDefaultSep + "40" + strDefaultSep + "2" + strDefaultSep + Q.NM103__ReceiverName + strDefaultSep + Q.NM104 + strDefaultSep + Q.NM105 + strDefaultSep + Q.NM106 + strDefaultSep + Q.NM107 + strDefaultSep + "46" + strDefaultSep + Q.NM109__ReceiverPrimaryIdentifier + strEOS); } catch (Exception ex) { throw ex; } }
protected string SetBillingProviderName(DataRow x, string strDefaultSep, string strEOS) { MNBilling oNM1 = new MNBilling(); NM1_BillingProviderName_2010AA Q = new NM1_BillingProviderName_2010AA(); try { Q.NM101__EntityIdentifierCode = NM1_BillingProviderName_2010AANM101__EntityIdentifierCode.Item85; Q.NM102__EntityTypeQualifier = NM1_BillingProviderName_2010AANM102__EntityTypeQualifier.Item2; Q.NM103__BillingProviderLastOrOrganizationalName = x["Biller"].ToString(); Q.NM104__BillingProviderFirstName = ""; Q.NM105__BillingProviderMiddleNameOrInitial = ""; Q.NM106 = ""; Q.NM107__BillingProviderNameSuffix = ""; Q.NM108__IdentificationCodeQualifier = NM1_BillingProviderName_2010AANM108__IdentificationCodeQualifier.XX; Q.NM109__BillingProviderIdentifier = x["NPI"].ToString(); return("NM1" + strDefaultSep + "85" + strDefaultSep + "2" + strDefaultSep + Q.NM103__BillingProviderLastOrOrganizationalName + strDefaultSep + Q.NM104__BillingProviderFirstName + strDefaultSep + Q.NM105__BillingProviderMiddleNameOrInitial + strDefaultSep + Q.NM106 + strDefaultSep + Q.NM107__BillingProviderNameSuffix + strDefaultSep + "XX" + strDefaultSep + Q.NM109__BillingProviderIdentifier + strEOS); } catch (Exception ex) { throw ex; } }
protected string SetST(string strControlNo, string strDefaultSep, string strEOS) { MNBilling oST = new MNBilling(); try { oST.ST_TransactionSetHeader = new ST_TransactionSetHeader(); oST.ST_TransactionSetHeader.ST02__TransactionSetControlNumber = strControlNo; oST.ST_TransactionSetHeader.ST01__TransactionSetIdentifierCode = ST_TransactionSetHeaderST01__TransactionSetIdentifierCode.Item837; oST.ST_TransactionSetHeader.ST03__ImplementationGuideVersionName = "005010X222A1"; return("ST" + strDefaultSep + "837" + strDefaultSep + oST.ST_TransactionSetHeader.ST02__TransactionSetControlNumber + strDefaultSep + oST.ST_TransactionSetHeader.ST03__ImplementationGuideVersionName + strEOS); } catch (Exception ex) { throw ex; } }
protected string SetBillingProviderLevel(int intHID, string strDefaultSep, string strEOS) { MNBilling oHL = new MNBilling(); HL_BillingProviderHierarchicalLevel_2000A Y = new HL_BillingProviderHierarchicalLevel_2000A(); try { Y.HL01__HierarchicalIDNumber = "1"; Y.HL02 = ""; Y.HL03__HierarchicalLevelCode = HL_BillingProviderHierarchicalLevel_2000AHL03__HierarchicalLevelCode.Item20; Y.HL04__HierarchicalChildCode = HL_BillingProviderHierarchicalLevel_2000AHL04__HierarchicalChildCode.Item1; return("HL" + strDefaultSep + Y.HL01__HierarchicalIDNumber + strDefaultSep + Y.HL02 + strDefaultSep + "20" + strDefaultSep + "1" + strEOS); } catch (Exception ex) { throw ex; } }
protected string SetBHT(string strControlNo, string strDefaultSep, string strEOS) { MNBilling oBHT = new MNBilling(); BHT_BeginningOfHierarchicalTransaction P = new BHT_BeginningOfHierarchicalTransaction(); try { P.BHT01__HierarchicalStructureCode = BHT_BeginningOfHierarchicalTransactionBHT01__HierarchicalStructureCode.Item0019; P.BHT02__TransactionSetPurposeCode = BHT_BeginningOfHierarchicalTransactionBHT02__TransactionSetPurposeCode.Item00; P.BHT03__OriginatorApplicationTransactionIdentifier = System.DateTime.Now.ToString("yyyyMMddHHmmss"); P.BHT04__TransactionSetCreationDate = System.DateTime.Now.ToString("yyyyMMdd"); P.BHT05__TransactionSetCreationTime = System.DateTime.Now.ToString("HHmm"); P.BHT06__ClaimOrEncounterIdentifier = BHT_BeginningOfHierarchicalTransactionBHT06__ClaimOrEncounterIdentifier.CH; return("BHT" + strDefaultSep + "0019" + strDefaultSep + "00" + strDefaultSep + P.BHT03__OriginatorApplicationTransactionIdentifier + strDefaultSep + P.BHT04__TransactionSetCreationDate + strDefaultSep + P.BHT05__TransactionSetCreationTime + strDefaultSep + "CH" + 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; } }