public string[] UploadHAADTransactionFile(EclaimFile eclaimFile) { string[] result = new string[3]; int UploadResult; int transactionStatus, claimsStatus; string Filename = eclaimFile.FileName; string errorFileName = Path.GetFileNameWithoutExtension(eclaimFile.FileName) + "-error.txt"; string errorPath = Path.GetDirectoryName(eclaimFile.FileLocation) + "\\" + errorFileName; string errorMsg = ""; byte[] filecontent, errorReport; filecontent = Encoding.UTF8.GetBytes(eclaimFile.XmlData); UploadResult = HAADSrv.UploadTransaction("national general", "ngihnt", filecontent, Filename, out errorMsg, out errorReport); if (UploadResult == 0 || UploadResult == 1) { transactionStatus = 1; //upload success claimsStatus = 4; //resubmisson success } else { if (errorReport != null) { File.WriteAllBytes(errorPath, errorReport); } transactionStatus = 2; // upload fiald claimsStatus = 5; //resubmisson fiald } result[0] = transactionStatus.ToString(); result[1] = claimsStatus.ToString(); result[2] = errorMsg; return(result); }
public string DownloadClaimSubmissionFile(EclaimFile eFile) { byte[] filedata; string filename, error; int result = DHPOSrv.DownloadTransactionFile("ngiuae", "ngi2012", eFile.FileID, out filename, out filedata, out error); string FilePath = ConfigurationSettings.AppSettings["DHPOClaims"].ToString() + "\\" + eFile.TransactionDate.ToString("yyyyMMdd") + "\\" + eFile.SenderID; if (!Directory.Exists(FilePath)) { Directory.CreateDirectory(FilePath); } bool Existed = false; int count = 1; string FileName = FilePath + "\\" + Path.GetFileNameWithoutExtension(filename); string tmpFileName = FileName + ".xml"; while (File.Exists(tmpFileName)) { Existed = true; tmpFileName = FileName + "-" + count + ".xml"; count++; } if (!Existed) { FileName = FileName + ".xml"; } else { FileName = tmpFileName; } //Write the file byte to file system File.WriteAllBytes(FileName, filedata); return(FileName); }
public void WritePriorAuthorizationRequestFilesLogToDB(EclaimFile file, int TransactionType, int TransactionStatus, string TransactionError, int SYS_FILE_SOURCE) { string InsertQuery = "INSERT INTO AUTH_BATCH_FILES (SYS_ID,FILE_ID, FILE_NAME, SENDER_ID, RECEIVER_ID, TRANSACTION_DATE, " + " RECORD_COUNT, TRANSACTION_TYPE, TRANSACTION_ERROR, FILE_LOCATION, STATUS, SYS_FILE_SOURCE) VALUES " + "((SELECT NVL(MAX(SYS_ID),0)+1 FROM AUTH_BATCH_FILES),'" + file.FileID + "','" + Path.GetFileName(file.FileLocation) + "','" + file.SenderID + "', " + "'" + file.ReceiverID + "', " + " To_Date('" + file.TransactionDate.Day + "/" + file.TransactionDate.Month + "/" + file.TransactionDate.Year + "','DD/MM/RRRR')," + file.RecordCount + "," + 6 + ", " + " '" + TransactionError + "','" + Path.GetDirectoryName(file.FileLocation) + "'," + TransactionStatus + "," + 6 + ")"; _db.Execute(InsertQuery); }
public void DownloadDHAClaims(string SDate, string EDate, int TransactionStatus) { DAL Obj = new DAL(); string Files, ErrorMessage; int result = DHPOSrv.SearchTransactions("ngiuae", "ngi2012", 2, "", "", 2, TransactionStatus, "", SDate, EDate, -1, -1, out Files, out ErrorMessage); if (Files != "" && Files != null) { Files = Files.Replace("&", @"&"); // Read File Information DataSet ds = new DataSet(); StringReader reader = new StringReader(Files.Replace("&", "&")); ds.ReadXml(reader); int i = 0; if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { foreach (DataRow file in ds.Tables[0].Rows) { try { EclaimFile eFile = new EclaimFile(); eFile.FileID = file["FileID"].ToString(); eFile.FileName = file["FileName"].ToString(); eFile.SenderID = file["SenderID"].ToString(); eFile.ReceiverID = file["ReceiverID"].ToString(); eFile.TransactionDate = ValueHandler.ToClaimDate(file["TransactionDate"]); eFile.RecordCount = Convert.ToInt32(file["RecordCount"]); eFile.IsDownloaded = Convert.ToBoolean(file["IsDownloaded"]); if (!Obj.CheckIfFileExist(eFile.FileID, 1)) { string FilePath = DownloadClaimSubmissionFile(eFile); eFile.FileLocation = FilePath; Obj.WriteEclaimFilesLogToDB(eFile, 1, 1, "", 1); } } catch { continue; } i++; } } } }
public string WriteEclaimFilesLogToDB(EclaimFile file, int TransactionType, int TransactionStatus, string TransactionError, int SYS_FILE_SOURCE) { string Result = ""; try { string InsertQuery = "INSERT INTO ECLAIM_BATCH_FILES (SYS_ID,FILE_ID, FILE_NAME, SENDER_ID, RECEIVER_ID, TRANSACTION_DATE, " + " RECORD_COUNT, TRANSACTION_TYPE, TRANSACTION_ERROR, FILE_LOCATION, STATUS, SYS_FILE_SOURCE) VALUES " + "((SELECT NVL(MAX(SYS_ID),0)+1 FROM ECLAIM_BATCH_FILES),'" + file.FileID + "','" + Path.GetFileName(file.FileLocation) + "','" + file.SenderID + "', " + "'" + file.ReceiverID + "', " + " To_Date('" + file.TransactionDate.Day + "/" + file.TransactionDate.Month + "/" + file.TransactionDate.Year + "','DD/MM/RRRR')," + file.RecordCount + "," + TransactionType + ", " + " '" + TransactionError + "','" + Path.GetDirectoryName(file.FileLocation) + "'," + TransactionStatus + "," + SYS_FILE_SOURCE + ")"; _db.Execute(InsertQuery); Result = "S"; } catch (Exception e) { Result = e.Message; } return(Result); }
public EclaimFile GenarateDHAXmlRemittanceFile(string ReceiverID, DataSet ds, out int[] eclaimID, out double PaymentAmount) { EclaimFile file = new EclaimFile(); StringBuilder builder = new StringBuilder(); StringBuilder builder2 = new StringBuilder(); string path = "remittanceFile" + DateTime.Now.ToString("yyyyMMddHHmmssss") + ".xml"; string str3 = DateTime.Now.ToString(ConfigurationSettings.AppSettings["UploadDateFormat"]); string str = ConfigurationSettings.AppSettings["DispositionFlag"].ToString(); int num = 0; int index = 0; DataRow[] source = null; eclaimID = new int[0]; PaymentAmount = 0; List <long> ClaimIDs = new List <long>(); if (ds.Tables.Count > 1) { source = (ReceiverID != null) ? ds.Tables[0].Select("SENDER_ID='" + ReceiverID + "'") : ds.Tables[0].Select(); eclaimID = new int[source.Count <DataRow>()]; if (eclaimID.Length > 0) { source[0]["SENDER_ID"].ToString(); builder.Clear(); builder.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<Remittance.Advice xmlns:tns='http://www.eclaimlink.ae/DataDictionary/CommonTypes' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='https://www.eclaimlink.ae/DataDictionary/CommonTypes/RemittanceAdvice.xsd'>\n\t"); builder.Append("<Header>\n\t\t"); builder.Append("<SenderID>" + source[0]["RECEIVER_ID"].ToString() + "</SenderID>\n\t\t"); builder.Append("<ReceiverID>" + source[0]["SENDER_ID"].ToString() + "</ReceiverID>\n\t\t"); builder.Append("<TransactionDate>" + str3 + "</TransactionDate>\n\t\t"); builder.Append("<RecordCount>" + num + "</RecordCount>\n\t\t"); builder.Append("<DispositionFlag>" + str + "</DispositionFlag>\n\t"); builder.Append("</Header>\n"); foreach (DataRow row in source) { try { builder2.Clear(); DataRow[] rowArray2 = ds.Tables[1].Select("SYS_CLAIM_ID='" + row["SYS_CLAIM_ID"].ToString() + "'"); builder2.Append("\t<Claim>\n\t\t"); builder2.Append("" + this.DBToXMLString(row["CLAIM_ID"].ToString(), "ID") + "\n\t\t"); builder2.Append("" + this.DBToXMLString(row["ID_PAYER"].ToString(), "IDPayer") + "\n\t\t"); if (row["PROVIDER_ID"].ToString() != string.Empty) { builder2.Append("" + this.DBToXMLString(row["PROVIDER_ID"].ToString(), "ProviderID") + "\n\t\t"); } builder2.Append("" + this.DBToXMLString(row["PAYMENT_REFERENCE"].ToString(), "PaymentReference") + "\n"); builder2.Append("" + this.DBToXMLDate(row["Date_Settlement"], "DateSettlement") + "\n\t"); eclaimID[index] = Convert.ToInt32(row["SYS_CLAIM_ID"]); if (row["ENCOUNTER_FACILITY_ID"].ToString() != string.Empty) { builder2.Append("<Encounter>\n\t\t"); builder2.Append("<FacilityID>" + row["ENCOUNTER_FACILITY_ID"].ToString() + "</FacilityID>\n\t"); builder2.Append("</Encounter>\n\t"); } foreach (DataRow row2 in rowArray2) { builder2.Append("<Activity>\n\t\t"); builder2.Append("" + this.DBToXMLString(row2["ACTIVITY_ID"].ToString(), "ID") + "\n\t\t"); builder2.Append("" + this.DBToXMLDate(row2["ACTIVITY_START"].ToString(), "Start") + "\n\t\t"); builder2.Append("" + this.DBToXMLString(row2["ACTIVITY_TYPE"].ToString(), "Type") + "\n\t\t"); builder2.Append("" + this.DBToXMLString(row2["ACTIVITY_CODE"].ToString(), "Code") + "\n\t\t"); builder2.Append("" + this.DBToXMLString(row2["QUANTITY"].ToString(), "Quantity") + "\n\t\t"); builder2.Append("" + this.DBToXMLString(row2["ACTIVITY_NET"].ToString(), "Net") + "\n\t\t"); if (row2["ACTIVITY_LIST"].ToString() != string.Empty) { builder2.Append("" + this.DBToXMLString(row2["ACTIVITY_LIST"].ToString(), "List") + "\n\t\t"); } builder2.Append("" + this.DBToXMLString(row2["CLINICIAN"].ToString(), "Clinician") + "\n\t\t"); if (row2["PRIOR_AUTHORIZATION_ID"].ToString() != string.Empty) { builder2.Append("" + this.DBToXMLString(row2["PRIOR_AUTHORIZATION_ID"].ToString(), "PriorAuthorizationID") + "\n\t\t"); } if (row2["ACTIVITY_GROSS"].ToString() != string.Empty) { builder2.Append("" + this.DBToXMLString(row2["ACTIVITY_GROSS"].ToString(), "Gross") + "\n\t\t"); } builder2.Append("<PatientShare>0</PatientShare>\n\t\t"); builder2.Append("" + this.DBToXMLString(row2["ACTIVITY_PAYMENT_AMOUNT"].ToString(), "PaymentAmount") + "\n\t\t"); if (row2["ACTIVITY_PAYMENT_AMOUNT"].ToString() != row2["ACTIVITY_NET"].ToString()) { if (row2["ACTIVITY_DENIAL_CODE"].ToString() != string.Empty) { builder2.Append("" + this.DBToXMLString(row2["ACTIVITY_DENIAL_CODE"].ToString(), "DenialCode") + "\n"); } } builder2.Append("</Activity>\n\t"); } builder2.Append("</Claim>\n"); num++; builder.Append(builder2.ToString()); index++; } catch { } } builder.Replace("&", "&"); builder.Replace("<RecordCount>0", "<RecordCount>" + num.ToString()); builder.Append("</Remittance.Advice>"); } } if (num > 0) { int PaymentType = Convert.ToInt16(source[0]["PAYMENTTYPE"].ToString()); file.SenderID = source[0]["SENDER_ID"].ToString(); file.ReceiverID = source[0]["RECEIVER_ID"].ToString(); file.TransactionDate = DateTime.Now; file.RecordCount = num; file.FileLocation = path; file.FileName = Path.GetFileName(path); file.TransactionError = "1"; file.XmlData = builder.ToString(); return(file); } file.TransactionError = "0"; return(file); }
public void UploadHAADClaims() { int[] eclaimIDs; string[] UploadResult; double PaymentAmount; DataTable Headers = new DataTable(); DataTable PaymentHeaders = new DataTable(); List <string> FileLocation = new List <string>(); DataView view; DataView paymentview; DAL Obj = new DAL(); try { DataSet dsp = Obj.GetDataSet("Select Distinct Payment_Reference From EClaims Where Sys_Claim_Status = 3 And Sys_Claim_Source = 2"); if (dsp.Tables.Count > 0) { paymentview = new DataView(dsp.Tables[0]); PaymentHeaders = paymentview.ToTable(true, "PAYMENT_REFERENCE"); } foreach (DataRow paymentfile in PaymentHeaders.Rows) { DataSet ds = Obj.GetClaims(paymentfile["PAYMENT_REFERENCE"].ToString(), 2); if (ds.Tables.Count > 0) { view = new DataView(ds.Tables[0]); Headers = view.ToTable(true, "SENDER_ID"); } foreach (DataRow file in Headers.Rows) { EclaimFile efile = new EclaimFile(); efile = GenarateHAADXmlRemittanceFile(file["SENDER_ID"].ToString(), ds, out eclaimIDs, out PaymentAmount); if (efile.TransactionError == "1")//1= File Generated Successfully { try { efile.FileLocation = WriteGeneratedXmlFile(efile.ReceiverID, efile.SenderID, efile.XmlData, efile.TransactionDate.ToString("yyyyMMdd"), 1); efile.FileName = Path.GetFileName(efile.FileLocation); efile.FileID = "1"; //log File To database Obj.WriteEclaimFilesLogToDB(efile, 2, 1, "", 2); //Upload Transaction File, Log File to db and Relate between File and it's claims UploadResult = UploadDHATransactionFile(efile); if (Convert.ToInt64(UploadResult[0]) == 1 && Convert.ToInt64(UploadResult[1]) == 4) // Upload or Resubmission Success { foreach (var ID in eclaimIDs) { Obj.ExecuteQuery("Update Eclaims Set Sys_Claim_Status = 4,RAUploadDate = SysDate Where Sys_Claim_ID = " + ID); } } else { foreach (var ID in eclaimIDs) { Obj.ExecuteQuery("Update Eclaims Set Sys_Claim_Status = 5,RAUploadDate = Null Where Sys_Claim_ID = " + ID); } } } catch { } } } } } catch { } }