protected void CanCancelHealthPointClaim() { string reftag = UrlRefTag; if (reftag == null) { throw new Exception("Invalid url field reftag"); } TyroHealthClaim tyroHealthClaim = TyroHealthClaimDB.GetByRefTag(reftag); if (tyroHealthClaim == null) { Response.Write("Error: Invalid reftag"); return; } if (tyroHealthClaim.OutResult != "APPROVED") { Response.Write("Non-approved claims can not be cancelled"); return; } if (tyroHealthClaim.DateCancelled != DateTime.MinValue) { Response.Write("This claim has already been cancelled"); return; } Response.Write("OK"); }
public static TyroHealthClaim[] GetByInvoice(int invoice_id, bool onlyApproved = true, bool excCancelled = true) { string sql = JoinedSql + " WHERE invoice_id = " + invoice_id + (onlyApproved ? " AND out_result = 'APPROVED' " : "") + (excCancelled ? " AND date_cancelled IS NULL " : ""); DataTable tbl = DBBase.ExecuteQuery(sql).Tables[0]; TyroHealthClaim[] list = new TyroHealthClaim[tbl.Rows.Count]; for (int i = 0; i < tbl.Rows.Count; i++) list[i] = Load(tbl.Rows[i]); return list; }
public static TyroHealthClaim[] GetByInvoice(int invoice_id, bool onlyApproved = true, bool excCancelled = true) { string sql = JoinedSql + " WHERE invoice_id = " + invoice_id + (onlyApproved ? " AND out_result = 'APPROVED' " : "") + (excCancelled ? " AND date_cancelled IS NULL " : ""); DataTable tbl = DBBase.ExecuteQuery(sql).Tables[0]; TyroHealthClaim[] list = new TyroHealthClaim[tbl.Rows.Count]; for (int i = 0; i < tbl.Rows.Count; i++) { list[i] = Load(tbl.Rows[i]); } return(list); }
public TyroHealthClaimItem( int tyro_health_claim_item_id, int tyro_health_claim_id, decimal out_claimAmount, decimal out_rebateAmount, string out_serviceCode, string out_description, string out_serviceReference, string out_patientId, DateTime out_serviceDate, string out_responseCodeString) { this.tyro_health_claim_item_id = tyro_health_claim_item_id; this.tyro_health_claim = tyro_health_claim_id == -1 ? null : new TyroHealthClaim(tyro_health_claim_id); this.out_claimAmount = out_claimAmount; this.out_rebateAmount = out_rebateAmount; this.out_serviceCode = out_serviceCode; this.out_description = out_description; this.out_serviceReference = out_serviceReference; this.out_patientId = out_patientId; this.out_serviceDate = out_serviceDate; this.out_responseCodeString = out_responseCodeString; }
protected void Page_Load(object sender, EventArgs e) { try { if (!IsPostBack) { string invoiceID = Request.QueryString["invoice"]; if (invoiceID == null || !Regex.IsMatch(invoiceID, @"^\d+$")) { throw new CustomMessageException("No valid invoice in URL"); } Invoice invoice = InvoiceDB.GetByID(Convert.ToInt32(invoiceID)); if (invoice == null) { throw new CustomMessageException("Invalid invoice in URL"); } if (invoice.Booking == null) { throw new CustomMessageException("Invalid invoice in URL - invoice not attached to a booking"); } string refTag = Request.QueryString["reftag"]; if (refTag != null) { lblHeading.InnerHtml = "Cancel Tyro Payment"; TyroHealthClaim tyroHealthClaim = TyroHealthClaimDB.GetByRefTag(refTag); if (tyroHealthClaim == null) { throw new CustomMessageException("Invalid reftag in URL"); } if (tyroHealthClaim.InvoiceID != invoice.InvoiceID) { throw new CustomMessageException("Invoice and reftag in URL do not match"); } if (tyroHealthClaim.OutResult != "APPROVED") { throw new CustomMessageException("Non-approved claims can not be cancelled"); } if (tyroHealthClaim.DateCancelled != DateTime.MinValue) { throw new CustomMessageException("This claim has already been cancelled"); } btnInitiateHealthPointClaim.Visible = false; btnCancelHealthPointClaim.Visible = true; } if (refTag == null && (invoice.IsPaID || invoice.TotalDue <= 0)) { throw new CustomMessageException("Invoice already paid"); } if (refTag == null && invoice.ReceiptsTotal > 0) { throw new CustomMessageException("Invoice already has a payment on it"); } SetInvoiceInfo(invoice); } } catch (CustomMessageException ex) { if (IsPostBack) { SetErrorMessage(ex.Message); } else { HideTableAndSetErrorMessage(ex.Message); } } catch (Exception ex) { if (IsPostBack) { SetErrorMessage("", ex.ToString()); } else { HideTableAndSetErrorMessage("", ex.ToString()); } } }
protected void Save(SaveType saveType) { if (Request.QueryString["debug"] != null && Request.QueryString["debug"] == "1") { lblXML.Text = "<pre>" + hiddenResponse.Value.Replace("<", "<").Replace(">", ">").Replace(Environment.NewLine, "<br />") + "</pre>"; } Invoice invoice = InvoiceDB.GetByID(Convert.ToInt32(Request.QueryString["invoice"])); InvoiceLine[] invLines = InvoiceLineDB.GetByInvoiceID(invoice.InvoiceID); using (XmlReader reader = XmlReader.Create(new StringReader(hiddenResponse.Value))) { reader.ReadToFollowing("detail"); string tyro_transaction_id = reader.GetAttribute("tyro_transaction_id"); string result = reader.GetAttribute("result"); string healthpointErrorCode = reader.GetAttribute("healthpointErrorCode"); string healthpointErrorDescription = reader.GetAttribute("healthpointErrorDescription"); string healthpointRefTag = reader.GetAttribute("healthpointRefTag"); string healthpointTotalBenefitAmount = reader.GetAttribute("healthpointTotalBenefitAmount"); string healthpointSettlementDateTime = reader.GetAttribute("healthpointSettlementDateTime"); string healthpointTerminalDateTime = reader.GetAttribute("healthpointTerminalDateTime"); string healthpointMemberNumber = reader.GetAttribute("healthpointMemberNumber"); string healthpointProviderId = reader.GetAttribute("healthpointProviderId"); string healthpointServiceType = reader.GetAttribute("healthpointServiceType"); string healthpointGapAmount = reader.GetAttribute("healthpointGapAmount"); string healthpointPhfResponseCode = reader.GetAttribute("healthpointPhfResponseCode"); string healthpointPhfResponseCodeDescription = reader.GetAttribute("healthpointPhfResponseCodeDescription"); if (result != "APPROVED") { var errMsg = "<br />Result: <b>" + result + "</b>"; if (healthpointErrorCode != "" && healthpointErrorDescription != "") { errMsg += "<br />" + healthpointErrorDescription + " (Error Code " + healthpointErrorCode + ")"; } else if (healthpointErrorCode != "") { errMsg += "<br />Error Code: " + healthpointErrorCode; } else if (healthpointErrorDescription != "") { errMsg += "<br />Error: " + healthpointErrorDescription; } lblErrorMessage.Text = errMsg; // Email alert this return; } if (saveType == SaveType.Claim) { DateTime _healthpointSettlementDateTime; if (healthpointSettlementDateTime == "undefined") { _healthpointSettlementDateTime = DateTime.MinValue; } else if (!DateTime.TryParseExact(healthpointSettlementDateTime, "yyyyMMddHHmmss", CultureInfo.InvariantCulture, DateTimeStyles.None, out _healthpointSettlementDateTime)) { throw new Exception("healthpointSettlementDateTime not in correct format: " + healthpointSettlementDateTime); } DateTime _healthpointTerminalDateTime; if (healthpointTerminalDateTime == "undefined") { _healthpointTerminalDateTime = DateTime.MinValue; } else if (!DateTime.TryParseExact(healthpointTerminalDateTime, "yyyyMMddHHmmss", CultureInfo.InvariantCulture, DateTimeStyles.None, out _healthpointTerminalDateTime)) { throw new Exception("healthpointTerminalDateTime not in correct format: " + healthpointTerminalDateTime); } decimal paymentAmount = Convert.ToDecimal(healthpointTotalBenefitAmount) / 100; decimal gapAmount = saveType == SaveType.Claim ? Convert.ToDecimal(healthpointGapAmount) / 100 : 0; TyroHealthClaimDB.UpdateByTyroTransactionID( tyro_transaction_id, result, healthpointRefTag, paymentAmount, _healthpointSettlementDateTime, _healthpointTerminalDateTime, healthpointMemberNumber, healthpointProviderId, healthpointServiceType, gapAmount, healthpointPhfResponseCode, healthpointPhfResponseCodeDescription); TyroHealthClaim tyroHealthClaim = TyroHealthClaimDB.GetByByTyroTransactionID(tyro_transaction_id); while (reader.ReadToFollowing("claimItem")) { string claimAmount = reader.GetAttribute("claimAmount"); string rebateAmount = reader.GetAttribute("rebateAmount"); string serviceCode = reader.GetAttribute("serviceCode"); string description = reader.GetAttribute("description"); string serviceReference = reader.GetAttribute("serviceReference"); string patientId = reader.GetAttribute("patientId"); string serviceDate = reader.GetAttribute("serviceDate"); string responseCode = reader.GetAttribute("responseCode"); DateTime _serviceDate; if (serviceDate == "undefined") { _serviceDate = DateTime.MinValue; } else if (!DateTime.TryParseExact(serviceDate, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None, out _serviceDate)) { throw new Exception("serviceDate not in correct format: " + serviceDate); } TyroHealthClaimItemDB.Insert( tyroHealthClaim.TyroHealthClaimID, Convert.ToDecimal(claimAmount) / 100, Convert.ToDecimal(rebateAmount) / 100, serviceCode, description, serviceReference, patientId, _serviceDate, responseCode); } if (result == "APPROVED") { decimal totalOwed = invoice.TotalDue - paymentAmount; bool isOverPaid = totalOwed < 0; bool isPaid = totalOwed <= 0; ReceiptDB.Insert(null, 365, tyroHealthClaim.InvoiceID, paymentAmount, 0, false, isOverPaid, DateTime.MaxValue, -8); if (isPaid) { InvoiceDB.UpdateIsPaid(null, invoice.InvoiceID, true); } if (isOverPaid) { // send email to someone .. to fix up the overpayment.... Emailer.SimpleAlertEmail( "Tyro healthpoint invoice late payment added and is overpaid.<br />tyro_health_claim_id: " + tyroHealthClaim.TyroHealthClaimID + "<br />Invoice: " + invoice.InvoiceID + "<br />DB: " + Session["DB"], "Tyro Healthpoint Invoice OverPaid: " + invoice.InvoiceID, true); } } string cancelLink = "<a href='TyroHealthPointClaimV2.aspx?invoice=" + invoice.InvoiceID + "&reftag=" + healthpointRefTag + "'>Click Here</a>"; lblResult.Text = "Result: " + result + (result == "APPROVED" ? "<br />Updated Paid Amounts Shown Above<br />To Cancel This Claim " + cancelLink : "") + "<br /><br />"; } else { if (result == "APPROVED") { TyroHealthClaimDB.UpdateCancelled(healthpointRefTag); // set receipt as reversed TyroHealthClaim tyroHealthClaim = TyroHealthClaimDB.GetByRefTag(healthpointRefTag); Receipt[] receipts = ReceiptDB.GetByInvoice(tyroHealthClaim.InvoiceID, false); if (receipts.Length != 1 || receipts[0].ReceiptPaymentType.ID != 365) { Emailer.SimpleAlertEmail( "Tyro claim reversed (by Tyro) but multiple receipts or receipt not of type 'Tyro HC Claim'.<br />healthpointRefTag = " + healthpointRefTag + "<br />DB: " + Session["DB"], "Tyro claim reversed (by Tyro) but multiple receipts or receipt not of type 'Tyro HC Claim'", true ); } ReceiptDB.Reverse(receipts[0].ReceiptID, Convert.ToInt32(Session["StaffID"])); } lblResult.Text = "Cancellation Result: " + result + (result == "APPROVED" ? "<br />Updated Paid Amounts Shown Above" : "") + "<br /><br />"; } } SetInvoiceInfo(InvoiceDB.GetByID(invoice.InvoiceID)); }
protected void Reconcile(string xml) { StringBuilder debutOutput = new StringBuilder(); bool claimsExist = false; bool unavailable = false; using (XmlReader reader = XmlReader.Create(new StringReader(xml))) { claimsExist = reader.ReadToFollowing("claim"); } using (XmlReader reader = XmlReader.Create(new StringReader(xml))) { unavailable = reader.ReadToFollowing("unavailable"); } //debutOutput.AppendLine("claimsExist: " + claimsExist + "<br />"); //debutOutput.AppendLine("unavailable: " + unavailable + "<br />"); //debutOutput.AppendLine("<br />"); using (XmlReader reader = XmlReader.Create(new StringReader(xml))) { reader.ReadToFollowing("claims-reconciliation-response"); reader.ReadToFollowing("claims-reconciliation"); ArrayList allFieldsList = new ArrayList(); // ordered list of all keys through all hashtables Hashtable allFieldsHash = new Hashtable(); // hashtable of all keys through all hashtables Hashtable hash = ReadSubtree(reader.ReadSubtree(), ref allFieldsList, ref allFieldsHash); string terminalID = hash["healthpoint-terminal-id"].ToString(); string claimDateStr = hash["claim-date"].ToString(); DateTime?claimDate = GetDateFromString(claimDateStr, "yyyyMMdd"); if (claimDate != null) { claimDateStr = claimDate.Value.ToString("d MMM, yyyy"); } debutOutput.AppendLine("<br/>"); debutOutput.AppendLine("Terminal ID: <b>" + terminalID + "</b></br />" + Environment.NewLine); debutOutput.AppendLine("Claim Date: <b>" + claimDateStr + "</b></br />" + Environment.NewLine); if (unavailable) { debutOutput.AppendLine("<b>Report For This Date Does Not Exist.</b>"); } else if (!claimsExist) { debutOutput.AppendLine("<b>No Claims On This Date.</b>"); } else if (claimsExist) { ArrayList list = new ArrayList(); // list of hashtables of claims allFieldsList = new ArrayList(); // ordered list of all keys through all hashtables allFieldsHash = new Hashtable(); // hashtable of all keys through all hashtables // put each claim into their own hashtable while (reader.ReadToFollowing("claim")) { hash = ReadSubtree(reader.ReadSubtree(), ref allFieldsList, ref allFieldsHash); list.Add(hash); } // put all hashtables of claims into a table to display string table = "<table border=1 class=\"table table-bordered table-white table-grid table-grid-top-bottum-padding-normal auto_width block_center\">" + Environment.NewLine; // add ordered number of payments showing 1,2,3,.... table += "<tr><td></td>"; for (int i = 0; i < list.Count; i++) { table += "<td style=\"text-align:center;\">" + (i + 1) + "</td>"; } table += "</tr>" + Environment.NewLine; // add invoice line string refTagKey = "ref-tag"; table += "<tr><td></td>"; foreach (Hashtable claimHash in list) { string field = string.Empty; if (claimHash[refTagKey] != null) { TyroHealthClaim tyroHealthClaim = TyroHealthClaimDB.GetByRefTag(claimHash[refTagKey].ToString()); if (tyroHealthClaim != null) { string invLink = "Invoice_ViewV2.aspx?invoice_id=" + tyroHealthClaim.InvoiceID; string invHref = "<a href=\"" + invLink + "\" onclick=\"open_new_tab('" + invLink + "')\" >Invoice</a>"; field += " " + invHref; } } table += "<td style=\"text-align:center;\">" + field + "</td>"; } table += "</tr>" + Environment.NewLine; // add all other information foreach (string key in allFieldsList) { table += "<tr><td>" + key + "</td>"; foreach (Hashtable claimHash in list) { string field; if (claimHash[key] == null) { field = string.Empty; } else if (!key.EndsWith("date-time")) { field = claimHash[key].ToString(); } else { DateTime?date = GetDateFromString(claimHash[key].ToString(), "yyyyMMddHHmmss"); field = (date == null) ? field = claimHash[key].ToString() : date.Value.ToString("d MMM, yyyy hh:mm"); } table += "<td>" + field + "</td>"; } table += "</tr>" + Environment.NewLine; } table += "</table>" + Environment.NewLine; debutOutput.AppendLine(table); } } lblReadableOutput.Text = debutOutput.ToString();; }