Exemple #1
0
    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");
    }
Exemple #2
0
    protected void InsertHealthPoint()
    {
        Invoice invoice = UrlInvoice;
        decimal?amount  = UrlAmount;

        if (invoice == null)
        {
            throw new Exception("Invalid url field invoice_id");
        }
        if (amount == null)
        {
            throw new Exception("Invalid url field amount");
        }


        if (invoice.IsPaID)
        {
            Response.Write("ISPAID");
            return;
        }
        if (invoice.ReceiptsTotal > 0)
        {
            Response.Write("HASPAYMENT");
            return;
        }

        Tuple <int, string> dbFieds = TyroHealthClaimDB.Insert(invoice.InvoiceID, Session["DB"].ToString(), amount.Value);

        Response.Write(dbFieds.Item2);  // tyro_transaction_id
    }
    protected void lstReceipts_ItemCreated(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            DataRowView dr = (DataRowView)e.Item.DataItem;
            if (dr == null || dr.Row == null)
            {
                return;
            }
            DataRow row = dr.Row;


            Label       lnkViewReceipt             = (Label)e.Item.FindControl("lnkViewReceipt");
            Label       lblPaidBy                  = (Label)e.Item.FindControl("lblPaidBy");
            Label       lblReceiptDate             = (Label)e.Item.FindControl("lblReceiptDate");
            Label       lblPaymentType             = (Label)e.Item.FindControl("lblPaymentType");
            Label       lblReceiptTotal            = (Label)e.Item.FindControl("lblReceiptTotal");
            Label       lblReceiptAmountReconciled = (Label)e.Item.FindControl("lblReceiptAmountReconciled");
            Label       lblStatus                  = (Label)e.Item.FindControl("lblStatus");
            Label       lnkReconcile               = (Label)e.Item.FindControl("lnkReconcile");
            LinkButton  lnkReverse                 = (LinkButton)e.Item.FindControl("lnkReverse");
            HiddenField lblHiddenReceiptID         = (HiddenField)e.Item.FindControl("lblHiddenReceiptID");


            lnkViewReceipt.Text             = row["receipt_url"].ToString();
            lblPaidBy.Text                  = "<a href=javascript:void(0)'  style='text-decoration:none;' onclick='return false;' title='Entered By: " + row["person_firstname"] + " " + row["person_surname"] + "'> * </a>";
            lblReceiptDate.Text             = Convert.ToDateTime(row["receipt_date_added"]).ToString("dd-MM-yyyy");
            lblPaymentType.Text             = row["descr"].ToString();
            lblReceiptTotal.Text            = row["total"].ToString();
            lblReceiptAmountReconciled.Text = row["amount_reconciled"].ToString();

            lblStatus.Text    = row["status"].ToString();
            lblStatus.Visible = row["show_status"].ToString() == "1";

            lnkReconcile.Text    = row["reconcile_link"].ToString() + "<br />";
            lnkReconcile.Visible = row["show_reconcile_link"].ToString() == "1";

            lnkReverse.CommandArgument = row["receipt_id"].ToString();
            lnkReverse.Visible         = row["show_reverse_link"].ToString() == "1";
            lnkReverse.OnClientClick   = "javascript:if (!confirm('Are you sure you want to reverse this record?')) return false;";
            lblHiddenReceiptID.Value   = row["receipt_id"].ToString();


            // if tyro healthclaim invoice .. then open new tab to remove claim throught tyro
            Receipt receipt = ReceiptDB.GetByID(Convert.ToInt32(row["receipt_id"]));
            if (receipt.ReceiptPaymentType.ID == 365 && !receipt.IsReversed)  // Tyro HC Claim
            {
                TyroHealthClaim[] claims = TyroHealthClaimDB.GetByInvoice(receipt.Invoice.InvoiceID);
                //if (true)
                if (claims.Length != 1)
                {
                    Emailer.SimpleAlertEmail(
                        "Receipt " + receipt.ReceiptPaymentType.ID + " is of type 'Tyro HC Claim' but " + claims.Length + " approved uncancelled rows found in TyroHealthClaimDB<br />DB:" + Session["DB"],
                        "Tyro Problem - Multiple Approved Uncancelled TyroPayment Rows Found For Single Receipt",
                        true);

                    lnkReverse.OnClientClick = "alert('Receipt " + receipt.ReceiptPaymentType.ID + " is of type 'Tyro HC Claim' but " + claims.Length + " approved uncancelled rows found in TyroHealthClaimDB.\r\nPlease contact the system administrator to check into this');return false;";
                }
                else
                {
                    lnkReverse.OnClientClick = "open_new_tab('TyroHealthPointClaimV2.aspx?invoice=" + receipt.Invoice.InvoiceID + "&reftag=" + claims[0].OutHealthpointRefTag + "');return false;";
                }
            }
        }
    }
    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("<", "&lt;").Replace(">", "&gt;").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();;
    }