protected void btnUpdateReferrersFromClinic_Click(object sender, EventArgs e)
    {
        int          orgID = Convert.ToInt32(hiddenUpdateReferrersFromClinic_OrgID.Value);
        Organisation org   = OrganisationDB.GetByID(orgID);

        if (org != null)
        {
            string    referrerIDs     = hiddenReferrerIDsList.Value; // comma seperated
            Hashtable referrerIDsHash = new Hashtable();
            if (referrerIDs.Length > 0)
            {
                foreach (string referrerID in referrerIDs.Split(','))
                {
                    referrerIDsHash[Convert.ToInt32(referrerID)] = 1;
                }
            }


            // add all new ones (not including those already in there)
            RegisterReferrer[] refs = RegisterReferrerDB.GetAllActiveRegRefByPatientsOfInternalOrg(orgID);
            for (int i = 0; i < refs.Length; i++)
            {
                if (referrerIDsHash[refs[i].RegisterReferrerID] == null)
                {
                    hiddenReferrerIDsList.Value += (hiddenReferrerIDsList.Value.Length == 0 ? "" : ",") + refs[i].RegisterReferrerID; // add to hiddenfield list of id's
                    referrerIDsHash[refs[i].RegisterReferrerID] = 1;                                                                  // add to hash
                }
            }


            // clear and re-set all (in alphabetical order)

            ArrayList newList   = new ArrayList();
            DataTable referrers = RegisterReferrerDB.GetDataTable();
            for (int i = 0; i < referrers.Rows.Count; i++)
            {
                newList.Add(RegisterReferrerDB.LoadAll(referrers.Rows[i]));
            }

            RegisterReferrer[] allReferrers = (RegisterReferrer[])newList.ToArray(typeof(RegisterReferrer));

            ArrayList referrersAdded = new ArrayList();
            lstReferrers.Items.Clear();
            for (int i = 0; i < allReferrers.Length; i++)
            {
                if (referrerIDsHash[allReferrers[i].RegisterReferrerID] != null)
                {
                    string text = allReferrers[i].Referrer.Person.FullnameWithoutMiddlename + " [" + allReferrers[i].Organisation.Name + "]";
                    lstReferrers.Items.Add(new ListItem(text, allReferrers[i].RegisterReferrerID.ToString()));

                    referrersAdded.Add(allReferrers[i]);
                }
            }


            int hasBothMobileEmail    = 0;
            int hasMobileNoEmail      = 0;
            int hasEmailNoMobile      = 0;
            int hasNeitherMobileEmail = 0;
            RegisterReferrerDB.GetCountsByEmailMobile(
                (RegisterReferrer[])referrersAdded.ToArray(typeof(RegisterReferrer)),
                ref hasBothMobileEmail,
                ref hasMobileNoEmail,
                ref hasEmailNoMobile,
                ref hasNeitherMobileEmail);

            lblReferrersWithMobileAndEmailTotal.Text       = hasBothMobileEmail.ToString();
            lblReferrersWithMobileNoEmailTotal.Text        = hasMobileNoEmail.ToString();
            lblReferrersWithEmailNoMobileTotal.Text        = hasEmailNoMobile.ToString();
            lblReferrersWithNeitherMobileOrEmailTotal.Text = hasNeitherMobileEmail.ToString();
            lblReferrerCount.Text = lstReferrers.Items.Count.ToString();

            // -----------------------------------------------
        }

        hiddenUpdateReferrersFromClinic_OrgID.Value = string.Empty;
    }