protected void FillPatientGrid()
    {
        UserView userView = UserView.GetInstance();

        lblHeading.Text = !userView.IsAgedCareView ? "Patients" : "Residents";


        int    regRefID = IsValidFormRef() ? GetFormRef(false) : -1;
        int    orgID    = IsValidFormOrg() ? GetFormOrg(false) : 0;
        string orgIDs   = orgID != 0 ? orgID.ToString() : (IsValidFormOrgs() ? GetFormOrgs(false) : string.Empty);


        DataTable dt = null;

        if (regRefID != -1)
        {
            dt = PatientReferrerDB.GetDataTable_PatientsOf(regRefID, false, false, userView.IsClinicView, userView.IsGPView, txtSearchSurname.Text.Trim(), chkSurnameSearchOnlyStartWith.Checked);
        }
        else if (orgIDs != string.Empty)
        {
            dt = RegisterPatientDB.GetDataTable_PatientsOf(false, orgIDs, false, false, userView.IsClinicView, userView.IsGPView, txtSearchSurname.Text.Trim(), chkSurnameSearchOnlyStartWith.Checked);
        }
        else
        {
            dt = PatientDB.GetDataTable(false, false, userView.IsClinicView, userView.IsGPView, txtSearchSurname.Text.Trim(), chkSurnameSearchOnlyStartWith.Checked);
        }

        // update AjaxLivePatientSurnameSearch and PatientListV2.aspx and PatientListPopup to disallow providers to see other patients.
        if (userView.IsProviderView)  // remove any patients who they haven't had bookings with before
        {
            Patient[] patients = BookingDB.GetPatientsOfBookingsWithProviderAtOrg(Convert.ToInt32(Session["StaffID"]), Convert.ToInt32(Session["OrgID"]));
            System.Collections.Hashtable hash = new System.Collections.Hashtable();
            foreach (Patient p in patients)
            {
                hash[p.PatientID] = 1;
            }

            for (int i = dt.Rows.Count - 1; i >= 0; i--)
            {
                if (hash[Convert.ToInt32(dt.Rows[i]["patient_id"])] == null)
                {
                    dt.Rows.RemoveAt(i);
                }
            }
        }

        Session["patientinfo_data"] = dt;

        if (dt.Rows.Count > 0)
        {
            if (IsPostBack && Session["patientinfo_sortexpression"] != null && Session["patientinfo_sortexpression"].ToString().Length > 0)
            {
                DataView dataView = new DataView(dt);
                dataView.Sort         = Session["patientinfo_sortexpression"].ToString();
                GrdPatient.DataSource = dataView;
            }
            else
            {
                GrdPatient.DataSource = dt;
            }

            try
            {
                GrdPatient.DataBind();
                GrdPatient.PagerSettings.FirstPageText = "1";
                GrdPatient.PagerSettings.LastPageText  = GrdPatient.PageCount.ToString();
                GrdPatient.DataBind();
            }
            catch (Exception ex)
            {
                this.lblErrorMessage.Visible = true;
                this.lblErrorMessage.Text    = ex.ToString();
            }
        }
        else
        {
            dt.Rows.Add(dt.NewRow());
            GrdPatient.DataSource = dt;
            GrdPatient.DataBind();

            int TotalColumns = GrdPatient.Rows[0].Cells.Count;
            GrdPatient.Rows[0].Cells.Clear();
            GrdPatient.Rows[0].Cells.Add(new TableCell());
            GrdPatient.Rows[0].Cells[0].ColumnSpan = TotalColumns;
            GrdPatient.Rows[0].Cells[0].Text       = "No Record Found";
        }
    }
Ejemplo n.º 2
0
    public void CreateXML(Invoice[] invoices, bool validate = true)
    {
        if (validate)
        {
            Invoice[] tooOldList = GetInvoicesTooOldToClaim(invoices);
            if (tooOldList.Length > 0)
            {
                string invalids = string.Empty;
                foreach (Invoice i in tooOldList)
                {
                    invalids += (invalids.Length == 0 ? "" : ",") + i.InvoiceID.ToString();
                }
                throw new Exception("The following invoices are too old to claim: " + "<br />" + invalids);
            }
        }

        // get bulk invoice lines for less db calls in individual invoice create xml method  [invoiceID => list of invoicelines]
        Hashtable bulkInvoiceLineHash = InvoiceLineDB.GetBulkInvoiceLinesByInvoiceID(invoices);

        ArrayList allInvoiceLines = new ArrayList();

        foreach (DictionaryEntry pair in bulkInvoiceLineHash)
        {
            allInvoiceLines.AddRange((InvoiceLine[])pair.Value);
        }

        // get bluk health cards  [patientID=>healthcard]
        //
        // NB:
        // A DVA invoice can only use a DVA card
        // A Medicare invoice can only use a Medicare card
        // The system can only create a DVA invoice is if DVA is set as the active card (vice versa for Medicare)
        // So when a DVA invoice is created the DVA card was active, and then someone switches it to be the Medicare card thatis active.
        // So, it's correct to get only the DVA cards for DVA invoices (and Medicare cards for Medicare invoices), and also would be correct to ignore the active flag and just get the most recent.
        int[]     allPatientIDs      = GetAllPatientIDs((InvoiceLine[])allInvoiceLines.ToArray(typeof(InvoiceLine)));
        Hashtable bulkHealthCardHash = PatientsHealthCardsCacheDB.GetBullkMostRecent(allPatientIDs, claimType == ClaimType.Medicare ? -1 : -2);

        // get bluk staff provider numbers from registerstaff table
        int[]     allProviderStaffIDs   = GetAllProviderStaffIDs(invoices);
        Hashtable bulkRegisterStaffHash = RegisterStaffDB.Get2DHashByStaffIDOrgID(allProviderStaffIDs);
        Hashtable bulkStaffHash         = StaffDB.GetAllInHashtable(false, true, false, false);

        // get bluk healthcard actions to get EPC signed dates
        Hashtable bulkHealthCardActionsHash = HealthCardActionDB.GetReceivedActionsByPatientIDs(allPatientIDs);

        // get bluk epcreferrers
        Hashtable bulkEPCReferrersHash = PatientReferrerDB.GetEPCReferrersOf(allPatientIDs, false);

        // get all sites in one call
        Hashtable bulkSites = SiteDB.GetAllInHashtable();


        Hashtable claimNumberInvoiceGroups = new Hashtable();

        for (int i = 0; i < invoices.Length; i++)
        {
            if (claimNumberInvoiceGroups[(invoices[i]).HealthcareClaimNumber] == null)
            {
                claimNumberInvoiceGroups[(invoices[i]).HealthcareClaimNumber] = new ArrayList();
            }

            ((ArrayList)claimNumberInvoiceGroups[(invoices[i]).HealthcareClaimNumber]).Add(invoices[i]);
        }


        string noPatientFailures    = string.Empty;
        string noHealthcardFailures = string.Empty;

        foreach (string claimNbr in claimNumberInvoiceGroups.Keys)
        {
            Invoice[] invoiceList = (Invoice[])((ArrayList)claimNumberInvoiceGroups[claimNbr]).ToArray(typeof(Invoice));

            try
            {
                CreateXML(invoiceList, bulkInvoiceLineHash, bulkHealthCardHash, bulkRegisterStaffHash, bulkStaffHash, bulkSites, bulkHealthCardActionsHash, bulkEPCReferrersHash);
            }
            catch (HINXNoPatientOnInvoiceLineException ex)
            {
                noPatientFailures += (noPatientFailures.Length == 0 ? "" : "<br />") + ex.Message;
            }
            catch (HINXNoHealthcardException ex)
            {
                noHealthcardFailures += (noHealthcardFailures.Length == 0 ? "" : "<br />") + ex.Message;
            }
        }



        string errors = string.Empty;

        if (noPatientFailures.Length > 0)
        {
            errors += (errors.Length == 0 ? "" : "<br /><br />") + "The following invoices have invoices lines with no patient set (Fix this and re-generate): <br />" + noPatientFailures;
        }
        if (noHealthcardFailures.Length > 0)
        {
            errors += (errors.Length == 0 ? "" : "<br /><br />") + "The following invoices have patients with no " + (claimType == ClaimType.Medicare ? "Medicare" : "DVA") + " card set (Fix this and re-generate): <br />" + noHealthcardFailures;
        }
        if (errors.Length > 0)
        {
            throw new HINXUnsuccessfulItemsException(errors);
        }
    }
    protected void setReferrersList(PatientReferrer currentPatRegReferrer = null)
    {
        if (currentPatRegReferrer == null)
        {
            PatientReferrer[] patientReferrer = PatientReferrerDB.GetEPCPatientReferrersOf(this.PatientID);
            if (patientReferrer.Length > 0)
            {
                currentPatRegReferrer = patientReferrer[patientReferrer.Length - 1];
            }
        }

        int nItems = ddlReferrer.Items.Count;

        for (int i = 0; i < nItems; i++)
        {
            ddlReferrer.Items.RemoveAt(0);
        }

        DataTable rr = RegisterReferrerDB.GetDataTable(0, -1, false, new int[] { 191 });

        if (currentPatRegReferrer != null)
        {
            // if refererrer set as inactive (ie user set as deleted, but is still in system)
            // then it will show the referrer as his referrer, but when hitting update, the list will not contain it, and throws an error
            // so if set as inactive (deleted), then add to the list
            bool isDeletedReferrer = rr.Select("register_referrer_id=" + currentPatRegReferrer.RegisterReferrer.RegisterReferrerID).Length == 0;
            if (isDeletedReferrer)
            {
                DataRow newRow = rr.NewRow();
                newRow["surname"]              = currentPatRegReferrer.RegisterReferrer.Referrer.Person.Surname;
                newRow["firstname"]            = currentPatRegReferrer.RegisterReferrer.Referrer.Person.Firstname;
                newRow["middlename"]           = currentPatRegReferrer.RegisterReferrer.Referrer.Person.Middlename;
                newRow["name"]                 = currentPatRegReferrer.RegisterReferrer.Organisation.Name;
                newRow["register_referrer_id"] = currentPatRegReferrer.RegisterReferrer.RegisterReferrerID;

                bool inserted = false;
                for (int i = rr.Rows.Count - 1; i >= 0; i--)
                {
                    if (currentPatRegReferrer.RegisterReferrer.Referrer.Person.Surname.CompareTo(rr.Rows[i]["surname"].ToString()) < 0)
                    {
                        continue;
                    }
                    if (currentPatRegReferrer.RegisterReferrer.Referrer.Person.Surname.CompareTo(rr.Rows[i]["surname"].ToString()) == 0)
                    {
                        if (currentPatRegReferrer.RegisterReferrer.Referrer.Person.Firstname.CompareTo(rr.Rows[i]["firstname"].ToString()) < 0)
                        {
                            continue;
                        }
                        if (currentPatRegReferrer.RegisterReferrer.Referrer.Person.Middlename.CompareTo(rr.Rows[i]["surname"].ToString()) == 0)
                        {
                            if (currentPatRegReferrer.RegisterReferrer.Referrer.Person.Firstname.CompareTo(rr.Rows[i]["middlename"].ToString()) < 0)
                            {
                                continue;
                            }
                        }
                    }

                    // now insert before this one

                    if (i == rr.Rows.Count)
                    {
                        rr.Rows.Add(newRow);
                    }
                    else
                    {
                        rr.Rows.InsertAt(newRow, i + 1);
                    }

                    inserted = true;
                    break;
                }

                if (!inserted)
                {
                    if (rr.Rows.Count == 0)
                    {
                        rr.Rows.Add(newRow);
                    }
                    else
                    {
                        rr.Rows.InsertAt(newRow, 0);
                    }
                }
            }
        }
        foreach (DataRowView row in rr.DefaultView)
        {
            ddlReferrer.Items.Add(new ListItem(row["surname"].ToString() + ", " + row["firstname"].ToString() + " [" + row["name"].ToString() + "]", row["register_referrer_id"].ToString()));
        }

        if (currentPatRegReferrer != null)
        {
            ddlReferrer.SelectedValue = currentPatRegReferrer.RegisterReferrer.RegisterReferrerID.ToString();
        }
    }
    protected void FillGrid()
    {
        string searchSurname = "";

        if (Request.QueryString["surname_search"] != null && Request.QueryString["surname_search"].Length > 0)
        {
            searchSurname         = Request.QueryString["surname_search"];
            txtSearchSurname.Text = Request.QueryString["surname_search"];
        }
        bool searchSurnameOnlyStartsWith = true;

        if (Request.QueryString["surname_starts_with"] != null && Request.QueryString["surname_starts_with"].Length > 0)
        {
            searchSurnameOnlyStartsWith           = Request.QueryString["surname_starts_with"] == "0" ? false : true;
            chkSurnameSearchOnlyStartWith.Checked = searchSurnameOnlyStartsWith;
        }
        else
        {
            chkSurnameSearchOnlyStartWith.Checked = searchSurnameOnlyStartsWith;
        }

        string searchProviderNbr = "";

        if (Request.QueryString["provider_nbr_search"] != null && Request.QueryString["provider_nbr_search"].Length > 0)
        {
            searchProviderNbr         = Request.QueryString["provider_nbr_search"];
            txtSearchProviderNbr.Text = Request.QueryString["provider_nbr_search"];
        }
        bool searchProviderNbrOnlyStartsWith = true;

        if (Request.QueryString["provider_nbr_starts_with"] != null && Request.QueryString["provider_nbr_starts_with"].Length > 0)
        {
            searchProviderNbrOnlyStartsWith           = Request.QueryString["provider_nbr_starts_with"] == "0" ? false : true;
            chkProviderNbrSearchOnlyStartWith.Checked = searchProviderNbrOnlyStartsWith;
        }
        else
        {
            chkProviderNbrSearchOnlyStartWith.Checked = searchProviderNbrOnlyStartsWith;
        }

        string searchPhoneNbr = "";

        if (Request.QueryString["phone_nbr_search"] != null && Request.QueryString["phone_nbr_search"].Length > 0)
        {
            searchPhoneNbr         = Request.QueryString["phone_nbr_search"];
            txtSearchPhoneNbr.Text = Request.QueryString["phone_nbr_search"];
        }
        bool searchPhoneNbrOnlyStartsWith = true;

        if (Request.QueryString["phone_nbr_starts_with"] != null && Request.QueryString["phone_nbr_starts_with"].Length > 0)
        {
            searchPhoneNbrOnlyStartsWith           = Request.QueryString["phone_nbr_starts_with"] == "0" ? false : true;
            chkPhoneNbrSearchOnlyStartWith.Checked = searchPhoneNbrOnlyStartsWith;
        }
        else
        {
            chkPhoneNbrSearchOnlyStartWith.Checked = searchPhoneNbrOnlyStartsWith;
        }

        DataTable dt = RegisterReferrerDB.GetDataTable(0, -1, chkShowDeleted.Checked, new int[] { 191 }, searchSurname, searchSurnameOnlyStartsWith, "", "", searchProviderNbr, searchProviderNbrOnlyStartsWith, searchPhoneNbr, searchPhoneNbrOnlyStartsWith);

        Hashtable regRefHash = PatientReferrerDB.GetHashtableByRegRef(true, false, false);

        dt.Columns.Add("count", typeof(int));
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            int regRefID = Convert.ToInt32(dt.Rows[i]["register_referrer_id"]);
            dt.Rows[i]["count"] = regRefHash[regRefID] == null ? 0 : ((PatientReferrer[])regRefHash[regRefID]).Length;
        }


        // add suburb_name

        Hashtable entityIDsHash = new Hashtable();

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            entityIDsHash[Convert.ToInt32(dt.Rows[i]["organisation_entity_id"])] = 1;
        }

        int[] entityIDs = new int[entityIDsHash.Keys.Count];
        entityIDsHash.Keys.CopyTo(entityIDs, 0);

        Hashtable emailHash = PatientsContactCacheDB.GetBullkAddress(entityIDs, -1);

        dt.Columns.Add("suburb_name", typeof(string));
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            int    entityID   = Convert.ToInt32(dt.Rows[i]["organisation_entity_id"]);
            string suburbName = GetSuburb(emailHash, entityID);
            dt.Rows[i]["suburb_name"] = suburbName == null ? "" : suburbName;
        }


        Session["referrerinfolist_data"] = dt;

        if (dt.Rows.Count > 0)
        {
            if (IsPostBack && Session["referrerinfolist_sortexpression"] != null && Session["referrerinfolist_sortexpression"].ToString().Length > 0)
            {
                DataView dataView = new DataView(dt);
                dataView.Sort          = Session["referrerinfolist_sortexpression"].ToString();
                GrdReferrer.DataSource = dataView;
            }
            else
            {
                GrdReferrer.DataSource = dt;
            }


            try
            {
                GrdReferrer.DataBind();
                GrdReferrer.PagerSettings.FirstPageText = "1";
                GrdReferrer.PagerSettings.LastPageText  = GrdReferrer.PageCount.ToString();
                GrdReferrer.DataBind();
            }
            catch (Exception ex)
            {
                HideTableAndSetErrorMessage("", ex.ToString());
            }
        }
        else
        {
            dt.Rows.Add(dt.NewRow());
            GrdReferrer.DataSource = dt;
            GrdReferrer.DataBind();

            int TotalColumns = GrdReferrer.Rows[0].Cells.Count;
            GrdReferrer.Rows[0].Cells.Clear();
            GrdReferrer.Rows[0].Cells.Add(new TableCell());
            GrdReferrer.Rows[0].Cells[0].ColumnSpan = TotalColumns;
            GrdReferrer.Rows[0].Cells[0].Text       = "No Record Found";
        }
    }
    protected void InitForm(int patientID)
    {
        HideAllRows();

        string url     = "/PatientReferrerHistoryPopupV2.aspx?id=" + patientID;
        string text    = "History";
        string onclick = @"onclick=""open_new_tab('" + url + @"');return false;""";

        lblPatientReferrerHistoryPopup.Text = "<a " + onclick + " href=\"\">" + text + "</a>";


        PatientReferrer[] patientReferrer = PatientReferrerDB.GetActiveEPCPatientReferrersOf(patientID);  // = PatientReferrerDB.GetEPCPatientReferrersOf(patient.PatientID);
        if (patientReferrer.Length > 0)
        {
            PatientReferrer  currentPatRegReferrer = patientReferrer[patientReferrer.Length - 1]; // get latest
            RegisterReferrer curRegReferrer        = currentPatRegReferrer.RegisterReferrer;

            displayHaveReferrerRow.Visible = true;

            // only allow removing a referrer if no EPC set [ie no active healthcard, or healthcard with neither date set]
            HealthCard hc          = HealthCardDB.GetActiveByPatientID(patientID);
            bool       allowDelete = hc == null || !hc.HasEPC();
            btnDelete.Visible = allowDelete;
            lblDeleteRegistrationReferrerBtnSeperator.Visible = allowDelete;

            //lblReferrer.Text = curRegReferrer.Referrer.Person.Surname + ", " + curRegReferrer.Referrer.Person.Firstname + " [" + curRegReferrer.Organisation.Name + "]" + " [" + currentPatRegReferrer.PatientReferrerDateAdded.ToString("dd-MM-yyyy") + "]";

            string phNumTxt = string.Empty;

            if (Utilities.GetAddressType().ToString() == "Contact")
            {
                Contact[] phNums = ContactDB.GetByEntityID(2, curRegReferrer.Organisation.EntityID);
                for (int i = 0; i < phNums.Length; i++)
                {
                    phNumTxt += (i > 0 ? "<br />" : "") + Utilities.FormatPhoneNumber(phNums[i].AddrLine1) + " &nbsp;&nbsp; (" + phNums[i].ContactType.Descr + ")";
                }
            }
            else if (Utilities.GetAddressType().ToString() == "ContactAus")
            {
                ContactAus[] phNums = ContactAusDB.GetByEntityID(2, curRegReferrer.Organisation.EntityID);
                for (int i = 0; i < phNums.Length; i++)
                {
                    phNumTxt += (i > 0 ? "<br />" : "") + Utilities.FormatPhoneNumber(phNums[i].AddrLine1) + " &nbsp;&nbsp; (" + phNums[i].ContactType.Descr + ")";
                }
            }
            else
            {
                throw new Exception("Unknown AddressType in config: " + Utilities.GetAddressType().ToString().ToString());
            }

            lblReferrer.Text = curRegReferrer.Referrer.Person.Surname + ", " + curRegReferrer.Referrer.Person.Firstname + (curRegReferrer.Organisation.Name.Length == 0 ? "" : " [" + curRegReferrer.Organisation.Name + "]") + "<br />" + Environment.NewLine +
                               "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">" + Environment.NewLine +
                               "<tr><td>" + "Provider Nbr:" + "</td><td style=\"width:12px\"></td><td><font color=\"#A52A2A\">" + currentPatRegReferrer.RegisterReferrer.ProviderNumber + "</font></td></tr>" + Environment.NewLine +
                               "<tr><td>" + "Date Added:" + "</td><td style=\"width:12px\"></td><td><font color=\"#A52A2A\">" + currentPatRegReferrer.PatientReferrerDateAdded.ToString("dd-MM-yyyy") + "</font></td></tr>" + Environment.NewLine +
                               "</table>" + Environment.NewLine +
                               (phNumTxt.Length == 0 ? "" : phNumTxt + "<br />"); // put in referrers fax and phone numbers

            lblReferrerRegisterID.Text = curRegReferrer.RegisterReferrerID.ToString();
        }
        else
        {
            displayNoReferrerRow.Visible = true;
        }
    }