private async void btnSearch_Click(object sender, EventArgs e) { Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); if (string.IsNullOrEmpty(config.AppSettings.Settings["clientId"].Value)) { MessageBox.Show("You did not set clientId and clientSecret key-value in AppSettings from App.Config file. Please set your clientId and clientSecret, which can be obtained from ICD-11 API Home Page!"); return; } if (txtInput.Text.Trim() == "") { // MessageBox.Show("Please input at least one term"); return; } txtInput.Text = txtInput.Text.Trim(); string q_chapters = ""; for (int i = 0; i < clChapter.Items.Count; i++) { if (clChapter.GetItemChecked(i)) { q_chapters += chlist[i].ChapterNo + ";"; } } tvResult.Nodes.Clear(); btnSearch.Text = "Searching..."; btnSearch.Enabled = false; // apiClient.Authorize(); // apiClient.SearchTerm("liver diseases"); apiClient = new ICD11ApiClient(); List <ICD11Entity> icd11list = await apiClient.GetResult(txtInput.Text, q_chapters); // begin filter chapter FilterChapater(icd11list, q_chapters); ///end filter //begin sort icd11list.Sort((x, y) => { return(y.Score.CompareTo(x.Score)); }); ///end sort for (int i = 0; i < icd11list.Count; i++) { Console.WriteLine(icd11list[i].Title); string[] row = { icd11list[i].Code, icd11list[i].Title }; TreeNode tn = new TreeNode(" - " + icd11list[i].Code + " " + ReplaceHtmlTag(icd11list[i].Title)); tn.ForeColor = Color.OrangeRed; tn.Tag = icd11list[i].Data; tvResult.Nodes.Add(tn); for (int j = 0; j < icd11list[i].PVList.Count; j++) { PV subentity = icd11list[i].PVList[j]; TreeNode n1 = new TreeNode(ReplaceHtmlTag(subentity.Label)); n1.Tag = subentity.Data; tn.Nodes.Add(n1); } for (int j = 0; j < icd11list[i].Children.Count; j++) { ICD11Entity subentity = icd11list[i].Children[j]; TreeNode tn1 = new TreeNode(" - " + subentity.Code + " " + ReplaceHtmlTag(subentity.Title)); tn1.ForeColor = Color.OrangeRed; tn1.Tag = subentity.Data; tn.Nodes.Add(tn1); } } tvResult.ExpandAll(); if (tvResult.Nodes.Count > 0) { tvResult.SelectedNode = tvResult.Nodes[0]; } btnSearch.Text = "Search"; btnSearch.Enabled = true; List <WordCandidate> wlist = await apiClient.GetWordList(txtInput.Text, q_chapters); lbWord.Items.Clear(); for (int i = 0; i < wlist.Count; i++) { lbWord.Items.Add(wlist[i].Label); } for (int i = 0; i < chlist.Count; i++) { int count = GetChapterCount(icd11list, chlist[i].ChapterNo); chlist[i].Freq = count; } //begin sort chlist.Sort((x, y) => { return(y.Freq.CompareTo(x.Freq)); }); clChapter.Items.Clear(); for (int i = 0; i < chlist.Count; i++) { clChapter.Items.Add(chlist[i].ChapterName + " (" + chlist[i].Freq + ")"); if (apiClient.ChapterList != null) { if (apiClient.ChapterList.Contains(chlist[clChapter.Items.Count - 1].ChapterNo)) { clChapter.SetItemChecked(clChapter.Items.Count - 1, true); } else { clChapter.SetItemChecked(clChapter.Items.Count - 1, false); } } else { clChapter.SetItemChecked(clChapter.Items.Count - 1, false); } } ///end sort }
public async Task <List <ICD11Entity> > GetResult(string term, string chapterlist) { try { List <ICD11Entity> icd11list = new List <ICD11Entity>(); dynamic searchResult = await Search(term); foreach (var de in searchResult.DestinationEntities) { Console.WriteLine(de.TheCode + " " + de.Title); ICD11Entity ie = new ICD11Entity(); ie.Code = de.TheCode; ie.Title = de.Title; ie.Score = Convert.ToDouble(de.Score); string Id = de.Id; ie.Id = Id; ie.Data = de; ie.Chapter = de.Chapter; foreach (var pv in de.MatchingPVs) { Console.WriteLine("-" + pv.Label); //string pv_id = pv.PVIWE.Id; PV p1 = new PV(); // p1.Id = pv_id; p1.Label = pv.Label; p1.Data = de; p1.Score = pv.Score; ie.PVList.Add(p1); } foreach (var des in de.Descendants) { Console.WriteLine("--" + des.Title + " " + des.TheCode); ICD11Entity ie1 = new ICD11Entity(); ie1.Code = des.TheCode; ie1.Title = des.Title; ie1.Data = des; ie1.Id = des.Id; ie1.Score = des.Score; ie1.Chapter = des.Chapter; foreach (var pv1 in des.MatchingPVs) { Console.WriteLine("-" + pv1.Label); // string pv1_id = pv1.PVIWE.Id; PV p2 = new PV(); // p2.Id = pv1_id; p2.Label = pv1.Label; p2.Data = des; p2.Score = pv1.Score; ie1.PVList.Add(p2); } ie.Children.Add(ie1); } icd11list.Add(ie); } return(icd11list); } catch (Exception ex) { Console.WriteLine(ex.Message); return(new List <ICD11Entity>()); } }