Exemple #1
0
        public static string BuildWherePatientName(string data, int SearchIndex)
        {
            const int STARTSWITHSEARCHTYPEINDEX = 2;
            const int EXACTSEARCHTYPEINDEX      = 3;

            if (data == "")
            {
                return("");
            }
            else
            {
                string toReturn = " AND (";
                data = data.Replace(",", "");
                data = data.Replace("%", "");
                data = data.Trim();
                CommonFunctions.FormattedName formattedName = CommonFunctions.GetFormattedName(data);



                if (formattedName.LastName != "")
                {
                    toReturn += "((patient_first_name LIKE '%" + formattedName.FirstName.Replace("'", "''") + "%'";
                    toReturn += " AND patient_last_name LIKE '%" + formattedName.LastName.Replace("'", "''") + "%')";
                    toReturn += " OR (patient_first_name LIKE '%" + formattedName.LastName.Replace("'", "''") + "%'";
                    toReturn += " AND patient_last_name LIKE '%" + formattedName.FirstName.Replace("'", "''") + "%'))";
                    toReturn += " OR patient_last_name LIKE '%" + data.Replace("'", "''") + "%'";
                }
                else
                {
                    toReturn += "patient_first_name LIKE '%" + formattedName.FirstName.Replace("'", "''") + "%'";
                    toReturn += " OR patient_first_name LIKE '%" + data.Replace("'", "''") + "%'";
                    toReturn += " OR patient_last_name LIKE '%" + data.Replace("'", "''") + "%'";
                }

                if (SearchIndex == STARTSWITHSEARCHTYPEINDEX) // Starts With
                {
                    // Remove the last % sign
                    toReturn = toReturn.Replace("'%", "'");
                }
                else if (SearchIndex == EXACTSEARCHTYPEINDEX)
                {
                    // Remove all % signs
                    toReturn = toReturn.Replace("%", "");
                }

                toReturn += ")";

                return(toReturn);
            }
        }