/// <summary> /// This method is a public call /// It calls the database query and uses the preferred name to get the previous /// and next term names. /// </summary> /// <param name="di"></param> /// <param name="nRows"></param> public static void GetTermNeighbors(DrugDictionaryDataItem di, int nRows) { try { // Call the database layer and get data DataTable dt = DrugDictionaryQuery.GetTermNeighbors( di.PreferredName, nRows); // use Linq to move information from the dataTable // into the DrugDictionaryDataItem di.PreviousNeighbors.AddRange( from entry in dt.AsEnumerable() where entry["isPrevious"].ToString() == "Y" select GetEntryFromDR(entry) ); // use Linq to move information from the dataTable // into the DrugDictionaryDataItem di.NextNeighbors.AddRange( from entry in dt.AsEnumerable() where entry["isPrevious"].ToString() == "N" select GetEntryFromDR(entry) ); } catch (Exception ex) { CancerGovError.LogError("DrugDictionatyManager", 2, ex); throw ex; } }
/// <summary> /// Extracts information from a DataRow and builds a new /// DrugDictionaryDataItem /// </summary> /// <param name="dr"></param> /// <returns>DrugDictionaryDataItem</returns> private static DrugDictionaryDataItem GetEntryFromDR(DataRow dr) { // return the new object DrugDictionaryDataItem ddi = new DrugDictionaryDataItem( Strings.ToInt(dr["TermID"]), Strings.Clean(dr["PreferredName"]), Strings.Clean(dr["OtherName"]), Strings.Clean(dr["DefinitionHTML"]), Strings.Clean(dr["PrettyURL"]) ); // return the created object return(ddi); }
/// <summary> /// This method calls the database layer for a single item and returns /// the drugDictionaryDataItem /// </summary> /// <param name="termID"></param> /// <returns></returns> public static DrugDictionaryDataItem GetDefinitionByTermID(int termID) { DrugDictionaryDataItem di = null; try { // Call the database layer and get data DataSet ds = DrugDictionaryQuery.GetDefinitionByTermID(termID); // Only do something if we have data if (ds.Tables.Count > 0) { // Get the entry record if (ds.Tables[0].Rows.Count == 1) { DataRow dr = ds.Tables[0].Rows[0]; dr["TermID"] = termID; // build the data item di = GetEntryFromDR(ds.Tables[0].Rows[0]); // Get the display names if (ds.Tables.Count > 1) { GetDisplayNames(di, ds.Tables[1]); } } else if (ds.Tables[0].Rows.Count > 0) { throw new Exception("GetDefinitionByTermID returned more than 1 record."); } } } catch (Exception ex) { CancerGovError.LogError("DrugDictionaryManager", 2, ex); throw ex; } return(di); }
/// <summary> /// This method is a public call for use by the GetDefinitionByTermID method /// It takes the information from the second table in the call to usp_GetTermDefinition /// This builds the DisplayName dictionary list /// </summary> /// <param name="di"></param> /// <param name="dt"></param> private static void GetDisplayNames(DrugDictionaryDataItem di, DataTable dt) { try { // Initialize our vars string lastDisplayName = string.Empty; List <string> listOfNames = null; // We will not use Linq since this is a more complex list foreach (DataRow dr in dt.Rows) { if (!lastDisplayName.Equals(dr["displayName"].ToString())) { // Save anything that we might have if (!lastDisplayName.Equals(string.Empty)) { di.DisplayNames.Add(lastDisplayName, listOfNames); } // Get a new list of names lastDisplayName = dr["displayName"].ToString(); listOfNames = new List <string>(); } // Add the name to the list listOfNames.Add(dr["otherName"].ToString()); } // See if we need to add anything to the dictionary if (!lastDisplayName.Equals(string.Empty)) { di.DisplayNames.Add(lastDisplayName, listOfNames); } } catch (Exception ex) { CancerGovError.LogError("DrugDictionatyManager", 2, ex); throw ex; } }