///<summary>If the message text is X12, then it always normalizes it to include carriage returns for better readability.</summary> public static string GetMessageText(long etransMessageTextNum) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { return(Meth.GetString(MethodBase.GetCurrentMethod(), etransMessageTextNum)); } if (etransMessageTextNum == 0) { return(""); } string command = "SELECT MessageText FROM etransmessagetext WHERE EtransMessageTextNum=" + POut.Long(etransMessageTextNum); string msgText = Db.GetScalar(command); if (!X12object.IsX12(msgText)) { return(msgText); } Match match = Regex.Match(msgText, "~[^(\n)(\r)]"); while (match.Success) { msgText = msgText.Substring(0, match.Index) + "~\r\n" + msgText.Substring(match.Index + 1); match = Regex.Match(msgText, "~[^(\n)(\r)]"); } return(msgText); //MatchCollection matches=Regex.Matches(msgText,"~[^(\n)(\r)]"); //for(int i=0;i<matches.Count;i++) { //Regex. // matches[i]. //} //msgText=Regex.Replace(msgText,"~[^(\r\n)(\n)(\r)]","~\r\n"); }
///<summary>This function is used to enhance readabilty of the X12 message when displayed. ///This function is specifically for X12 messages and not for other formats (ex not for Canadian).</summary> private static string TidyMessageTextX12(string msgText) { if (!X12object.IsX12(msgText)) { return(msgText); } Match match = Regex.Match(msgText, "~[^(\n)(\r)]"); while (match.Success) { msgText = msgText.Substring(0, match.Index) + "~\r\n" + msgText.Substring(match.Index + 1); match = Regex.Match(msgText, "~[^(\n)(\r)]"); } return(msgText); }
///<summary>Etrans type will be figured out by this class. Either TextReport, Acknowledge_997, Acknowledge_999, or StatusNotify_277.</summary> public static void ProcessIncomingReport(DateTime dateTimeTrans, long clearinghouseNum, string messageText) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { Meth.GetVoid(MethodBase.GetCurrentMethod(), dateTimeTrans, clearinghouseNum, messageText); return; } Etrans etrans = new Etrans(); etrans.DateTimeTrans = dateTimeTrans; etrans.ClearingHouseNum = clearinghouseNum; EtransMessageText etransMessageText = new EtransMessageText(); etransMessageText.MessageText = messageText; EtransMessageTexts.Insert(etransMessageText); etrans.EtransMessageTextNum = etransMessageText.EtransMessageTextNum; string command; if (X12object.IsX12(messageText)) { X12object Xobj = new X12object(messageText); if (Xobj.IsAckInterchange()) { etrans.Etype = EtransType.Ack_Interchange; Etranss.Insert(etrans); //At some point in the future, we should use TA101 to match to batch number and TA104 to get the ack code, //then update historic etrans entries like we do for 997s, 999s and 277s. } else if (Xobj.Is997()) { X997 x997 = new X997(messageText); etrans.Etype = EtransType.Acknowledge_997; etrans.BatchNumber = x997.GetBatchNumber(); Etranss.Insert(etrans); string batchack = x997.GetBatchAckCode(); if (batchack == "A" || batchack == "R") //accepted or rejected { command = "UPDATE etrans SET AckCode='" + batchack + "', " + "AckEtransNum=" + POut.Long(etrans.EtransNum) + " WHERE BatchNumber=" + POut.Long(etrans.BatchNumber) + " AND ClearinghouseNum=" + POut.Long(clearinghouseNum) + " AND DateTimeTrans > " + POut.DateT(dateTimeTrans.AddDays(-14)) + " AND DateTimeTrans < " + POut.DateT(dateTimeTrans.AddDays(1)) + " AND AckEtransNum=0"; Db.NonQ(command); } else //partially accepted { List <int> transNums = x997.GetTransNums(); string ack; for (int i = 0; i < transNums.Count; i++) { ack = x997.GetAckForTrans(transNums[i]); if (ack == "A" || ack == "R") //accepted or rejected { command = "UPDATE etrans SET AckCode='" + ack + "', " + "AckEtransNum=" + POut.Long(etrans.EtransNum) + " WHERE BatchNumber=" + POut.Long(etrans.BatchNumber) + " AND TransSetNum=" + POut.Long(transNums[i]) + " AND ClearinghouseNum=" + POut.Long(clearinghouseNum) + " AND DateTimeTrans > " + POut.DateT(dateTimeTrans.AddDays(-14)) + " AND DateTimeTrans < " + POut.DateT(dateTimeTrans.AddDays(1)) + " AND AckEtransNum=0"; Db.NonQ(command); } } } //none of the other fields make sense, because this ack could refer to many claims. } else if (Xobj.Is999()) { X999 x999 = new X999(messageText); etrans.Etype = EtransType.Acknowledge_999; etrans.BatchNumber = x999.GetBatchNumber(); Etranss.Insert(etrans); string batchack = x999.GetBatchAckCode(); if (batchack == "A" || batchack == "R") //accepted or rejected { command = "UPDATE etrans SET AckCode='" + batchack + "', " + "AckEtransNum=" + POut.Long(etrans.EtransNum) + " WHERE BatchNumber=" + POut.Long(etrans.BatchNumber) + " AND ClearinghouseNum=" + POut.Long(clearinghouseNum) + " AND DateTimeTrans > " + POut.DateT(dateTimeTrans.AddDays(-14)) + " AND DateTimeTrans < " + POut.DateT(dateTimeTrans.AddDays(1)) + " AND AckEtransNum=0"; Db.NonQ(command); } else //partially accepted { List <int> transNums = x999.GetTransNums(); string ack; for (int i = 0; i < transNums.Count; i++) { ack = x999.GetAckForTrans(transNums[i]); if (ack == "A" || ack == "R") //accepted or rejected { command = "UPDATE etrans SET AckCode='" + ack + "', " + "AckEtransNum=" + POut.Long(etrans.EtransNum) + " WHERE BatchNumber=" + POut.Long(etrans.BatchNumber) + " AND TransSetNum=" + POut.Long(transNums[i]) + " AND ClearinghouseNum=" + POut.Long(clearinghouseNum) + " AND DateTimeTrans > " + POut.DateT(dateTimeTrans.AddDays(-14)) + " AND DateTimeTrans < " + POut.DateT(dateTimeTrans.AddDays(1)) + " AND AckEtransNum=0"; Db.NonQ(command); } } } //none of the other fields make sense, because this ack could refer to many claims. } else if (X277.Is277(Xobj)) { X277 x277 = new X277(messageText); etrans.Etype = EtransType.StatusNotify_277; Etranss.Insert(etrans); List <string> claimTrackingNumbers = x277.GetClaimTrackingNumbers(); for (int i = 0; i < claimTrackingNumbers.Count; i++) { string ack = x277.GetClaimInfo(claimTrackingNumbers[i])[3]; long claimNum = Claims.GetClaimNumForIdentifier(claimTrackingNumbers[i]); //Locate the latest etrans entries for the claim based on DateTimeTrans with EType of ClaimSent or Claim_Ren and update the AckCode and AckEtransNum. //We overwrite existing acks from 997s, 999s and older 277s. command = "UPDATE etrans SET AckCode='" + ack + "', " + "AckEtransNum=" + POut.Long(etrans.EtransNum) + " WHERE EType IN (0,3) " //ClaimSent and Claim_Ren + " AND ClaimNum=" + POut.Long(claimNum) + " AND ClearinghouseNum=" + POut.Long(clearinghouseNum) + " AND DateTimeTrans > " + POut.DateT(dateTimeTrans.AddDays(-14)) + " AND DateTimeTrans < " + POut.DateT(dateTimeTrans.AddDays(1)); Db.NonQ(command); } ////none of the other fields make sense, because this ack could refer to many claims. } else //unknown type of X12 report. { etrans.Etype = EtransType.TextReport; Etranss.Insert(etrans); } } else //not X12 { etrans.Etype = EtransType.TextReport; Etranss.Insert(etrans); } }
///<summary>Etrans type will be figured out by this class. Either TextReport, Acknowledge_997, or StatusNotify_277.</summary> public static void ProcessIncomingReport(DateTime dateTimeTrans, long clearinghouseNum, string messageText) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { Meth.GetVoid(MethodBase.GetCurrentMethod(), dateTimeTrans, clearinghouseNum, messageText); return; } Etrans etrans = new Etrans(); etrans.DateTimeTrans = dateTimeTrans; etrans.ClearingHouseNum = clearinghouseNum; EtransMessageText etransMessageText = new EtransMessageText(); etransMessageText.MessageText = messageText; EtransMessageTexts.Insert(etransMessageText); etrans.EtransMessageTextNum = etransMessageText.EtransMessageTextNum; string command; if (X12object.IsX12(messageText)) { X12object Xobj = new X12object(messageText); if (Xobj.Is997()) { X997 x997 = new X997(messageText); etrans.Etype = EtransType.Acknowledge_997; etrans.BatchNumber = x997.GetBatchNumber(); Etranss.Insert(etrans); string batchack = x997.GetBatchAckCode(); if (batchack == "A" || batchack == "R") //accepted or rejected { command = "UPDATE etrans SET AckCode='" + batchack + "', " + "AckEtransNum=" + POut.Long(etrans.EtransNum) + " WHERE BatchNumber=" + POut.Long(etrans.BatchNumber) + " AND ClearinghouseNum=" + POut.Long(clearinghouseNum) + " AND DateTimeTrans > " + POut.DateT(dateTimeTrans.AddDays(-14)) + " AND DateTimeTrans < " + POut.DateT(dateTimeTrans.AddDays(1)) + " AND AckEtransNum=0"; Db.NonQ(command); } else //partially accepted { List <int> transNums = x997.GetTransNums(); string ack; for (int i = 0; i < transNums.Count; i++) { ack = x997.GetAckForTrans(transNums[i]); if (ack == "A" || ack == "R") //accepted or rejected { command = "UPDATE etrans SET AckCode='" + ack + "', " + "AckEtransNum=" + POut.Long(etrans.EtransNum) + " WHERE BatchNumber=" + POut.Long(etrans.BatchNumber) + " AND TransSetNum=" + POut.Long(transNums[i]) + " AND ClearinghouseNum=" + POut.Long(clearinghouseNum) + " AND DateTimeTrans > " + POut.DateT(dateTimeTrans.AddDays(-14)) + " AND DateTimeTrans < " + POut.DateT(dateTimeTrans.AddDays(1)) + " AND AckEtransNum=0"; Db.NonQ(command); } } } //none of the other fields make sense, because this ack could refer to many claims. } else if (X277U.Is277U(Xobj)) { etrans.Etype = EtransType.StatusNotify_277; //later: analyze to figure out which e-claim is being referenced. Etranss.Insert(etrans); } else //unknown type of X12 report. { etrans.Etype = EtransType.TextReport; Etranss.Insert(etrans); } } else //not X12 { etrans.Etype = EtransType.TextReport; Etranss.Insert(etrans); } }