/// <summary> /// Method used to query database for English language results. This will return the /// data in XML format. There is no way to create an additional WebGet so that we /// can return the same data in JSON format. /// </summary> /// <param name="criteria">The partial text used to query the database</param> /// <param name="maxRows">The maximum number of rows that the database will return. a value of zero will return the entire set</param> /// <param name="contains">Indicator on whether the text is to be search from the beginning of the text or anywhere in the string</param> /// <returns>Returns the search results</returns> private DrugDictionaryServiceCollection Search(string criteria, int maxRows, bool contains) { // create the collection variable DrugDictionaryServiceCollection sc = new DrugDictionaryServiceCollection(); try { // Call the database query DrugDictionaryCollection dc = DrugDictionaryManager.SearchNameOnly(criteria, maxRows, contains); // Use Linq to extract the data from the business layer and create // the service data objects var collection = dc.ConvertAll(entry => new DrugDictionaryServiceItem( entry.TermID, entry.PreferredName, string.Empty )); sc.AddRange(collection); } catch (Exception ex) { // Log the error that occured CancerGovError.LogError("DrugDictionary", 2, ex); } return(sc); }
/// <summary> /// This method takes the collection of Datarows and combines all the "otherName" fields into /// a single field for the same termID, creating one DataItem. /// </summary> /// <param name="dt">The DataTable that contains the rows</param> /// <param name="dc">The Collection object we will add the Data Items</param> private static void concatenateDuplicateEntries(DataTable dt, DrugDictionaryCollection dc) { if (dt.Rows.Count > 0) { // Get the first row DataRow dr = dt.Rows[0]; // Set our new names to an empty string string newNames = string.Empty; // Walk the data table foreach (DataRow aDR in dt.Rows) { // Get the value from the data row so we don't have to always look it up var otherName = aDR["OtherName"]; // If we have a match concatenate the otherName if ((int)dr["TermID"] == (int)aDR["TermID"]) { // Only do this if the otherName has a value if (!DBNull.Value.Equals(otherName) && !string.IsNullOrEmpty(otherName.ToString())) { // Attach the next other Name to this one if (!string.IsNullOrEmpty(newNames)) { newNames += "; "; } // concatenate the new 'other name' newNames += otherName.ToString(); } } else { // Now create a new data item and put it into the new collection dr["OtherName"] = newNames; dc.Add(GetEntryFromDR(dr)); // Set the other data row dr = aDR; // Get the first other name newNames = (DBNull.Value.Equals(otherName) ? string.Empty : otherName.ToString()); } } // Get the last one // Now create a new data item and put it into the new collection dr["OtherName"] = newNames; dc.Add(GetEntryFromDR(dr)); } }
/// <summary> /// This methods filters the information passed to it in order to refine the query /// that will be called in the database layer. /// </summary> /// <param name="criteria">The partial text used to query the database</param> /// <param name="maxRows">The maximum number of rows that the database will return. a value of zero will return the entire set</param> /// <param name="contains">indicator as to whether the text is to be searched starting from the beginning or anywhere /// in the string</param> /// <returns>Returns the search results</returns> public static DrugDictionaryCollection SearchNameOnly(string criteria, int maxRows, bool contains) { DrugDictionaryCollection dc = new DrugDictionaryCollection(); // Find out how we should search for the string if (Strings.Clean(criteria) != null) { // put the '%' at the end to indicate that the search starts // with the criteria passed. criteria += "%"; // put the '%' at the beginning to indicate that the search // data contains the criteria passed if (contains) { criteria = "%" + criteria; } // The stored procedure needs to change to reflect a 0 number of // rows to mean the entire set. if (maxRows <= 0) { maxRows = 9999; } try { // Call the database layer and get data DataTable dt = DrugDictionaryQuery.SearchNameOnly(criteria, maxRows); // use Linq to move information from the dataTable // into the DrugDictionaryCollection dc.AddRange( from entry in dt.AsEnumerable() select GetEntryFromDR(entry) ); } catch (Exception ex) { CancerGovError.LogError("DrugDictionatyManager", 2, ex); throw ex; } } // return the collection return(dc); }
/// <summary> /// This methods filters the information passed to it in order to refine the query /// that will be called in the database layer. /// </summary> /// <param name="criteria">The partial text used to query the database</param> /// <param name="maxRows">The maximum number of rows that the database will return. a value of zero will return the entire set</param> /// <param name="contains">indicator as to whether the text is to be searched starting from the beginning or anywhere /// in the string</param> /// <returns>Returns the search results</returns> public static DrugDictionaryCollection Search(string criteria, int maxRows, int curPage, bool bOtherNames, bool contains) { DrugDictionaryCollection dc = new DrugDictionaryCollection(); // Find out how we should search for the string if (Strings.Clean(criteria) != null) { // replace any '[' with '[[]' //criteria = criteria.Replace("[", "[[]"); // put the '%' at the end to indicate that the search starts // with the criteria passed. criteria += "%"; // put the '%' at the beginning to indicate that the search // data contains the criteria passed if (contains) { criteria = "%" + criteria; } // The stored procedure needs to change to reflect a 0 number of // rows to mean the entire set. if (maxRows <= 0) { maxRows = 9999; } // The stored procedure need to reflect a cur pag of 0 to be 1 if (curPage == 0) { curPage = 1; } try { int queryCount; int matchCount = 0; // Call the database layer and get data DataTable dt = DrugDictionaryQuery.Search( criteria, maxRows, curPage, (bOtherNames ? 'Y' : 'N'), out matchCount ); // Set the value on the collection dc.matchCount = matchCount; // Now get a new collection with only one unique termIDs in the collection if (bOtherNames) { concatenateDuplicateEntries(dt, dc); } else { // use Linq to move information from the dataTable // into the DrugDictionaryCollection dc.AddRange( from entry in dt.AsEnumerable() select GetEntryFromDR(entry) ); } } catch (Exception ex) { CancerGovError.LogError("DrugDictionatyManager", 2, ex); throw ex; } } // return the collection return(dc); }