internal bool MatchFirstName(int sequence, string input, string requestToken, List <Patient> patList) { bool status = false; try { List <Patient> matchedSearches = new List <Patient>(); matchedSearches = FuzzySearch.Search(input.ToLower(), patList, 0.29); if (matchedSearches.Count > 0) { var insertPatientSearchLogQuery = QueryBuilder.InsertPatientSearchLog(requestToken, sequence, input, "1"); int queryStatus = dA.executeInsertSqlStatement(insertPatientSearchLogQuery); if (queryStatus == 1) { var patientSearchLogID = QueryBuilder.GetPatientSearchLogID(requestToken, sequence); var patientSearchLogIDResult = dA.executeSqlStatement(patientSearchLogID).Tables[0].Rows[0]["PatientSearchLogID"].ToString(); //foreach (DataRow patient in queryResult.Tables[0].Rows) foreach (var patient in matchedSearches) { try { //var insertPatientSearchLogDetailQuery = QueryBuilder.InsertPatientSearchLogDetail(patientSearchLogIDResult, patient["PAPATID"].ToString()); var insertPatientSearchLogDetailQuery = QueryBuilder.InsertPatientSearchLogDetail(patientSearchLogIDResult, patient.ID.ToString()); dA.executeInsertSqlStatement(insertPatientSearchLogDetailQuery); } catch (Exception) { } } } WebApiApplication.getPatFirstName = matchedSearches; status = true; } else { var sqlQuery = QueryBuilder.InsertPatientSearchLog(requestToken, sequence, input, "0"); int queryStatus = dA.executeInsertSqlStatement(sqlQuery); } } catch (Exception ex) { } return(status); }
public void RicercaPersone() { var info = new Gipasoft.Business.Sfera.Repository.UserInfo {Azienda = Login.Instance.CurrentLogin().Azienda}; var soggetti = SferaServiceProxy.Instance.CurrentService().GetSoggettiCondominioByCondominio(119, info); var person = new SearchableDictionary<int>(); var fuzzy = new FuzzySearch<int>(); var query = new Query(QuerySearchOption.And, new NameSynonymThesaurusReader(), 0.75); var scope = new IntellisenseScope<int>(); var dict = new Dictionary<int, PersonaDTO>(); foreach (var soggetto in soggetti.Distinct()) { var persona = SferaServiceProxy.Instance.CurrentService().GetPersonaByID(soggetto.IdPersona, info); if (!dict.ContainsKey(persona.ID)) { person.Add(persona.ID, String.Format("{0} {1} {2}", persona.IndirizzoResidenza.Indirizzo, persona.IndirizzoResidenza.DescrizioneComune, persona.IndirizzoResidenza.Civico)); fuzzy.Add(persona.ID, "Via", persona.IndirizzoResidenza.Indirizzo); fuzzy.Add(persona.ID, "Comune", persona.IndirizzoResidenza.DescrizioneComune); fuzzy.Add(persona.ID, "Civico", persona.IndirizzoResidenza.Civico); dict.Add(persona.ID, persona); } } query.Clear(); var condominio = SferaServiceProxy.Instance.CurrentService().GetCondominioById(119, true, false, info); query.CreateSearchTerm("Via", condominio.Indirizzo.Indirizzo, 0.20, true); query.CreateSearchTerm("Comune", condominio.Indirizzo.DescrizioneComune); query.CreateSearchTerm("Civico", condominio.Indirizzo.Civico); var fuzzyResult = fuzzy.Search(query, scope, dict.Count); foreach (var searchResult in fuzzyResult) { var split = person[searchResult.Key].Split(new[] { ' ' }); var via = split[0]; // table.Rows.Add(new object[] { searchResult.Rank, searchResult.Key, split[0], split[1], split[2] }); } }
/// <summary> /// Consente di individuare se il condomino è residente confrontando l'indirizzo della persona con quello del condominio /// </summary> /// <remarks>Per stabilire se gli indirizzi corrispondono viene usato un componente di terze parti <see cref="http://www.shuffletext.com/Default.aspx"/></remarks> /// <param name="soggetto">Condomino</param> /// <returns>Ritorna true se è residente altrimenti false</returns> public bool IsResidente(SoggettoCondominio soggetto) { if (soggetto != null && soggetto.IsResidente == null && soggetto.UnitaImmobiliare != null && soggetto.UnitaImmobiliare.GruppoStabileRiferimento != null && soggetto.Persona != null && soggetto.Persona.IndirizzoResidenza != null && !string.IsNullOrEmpty(soggetto.Persona.IndirizzoResidenza.Indirizzo)) { try { var condominio = soggetto.UnitaImmobiliare.GruppoStabileRiferimento.PalazzinaRiferimento.CondominioRiferimento; if (condominio.Indirizzo != null) { var person = new SearchableDictionary<int>(); var fuzzy = new FuzzySearch<int>(); var query = new Query(QuerySearchOption.And, new NameSynonymThesaurusReader(), 0.75); var scope = new IntellisenseScope<int>(); var persona = soggetto.Persona; var indirizzoSoggetto = persona.IndirizzoResidenza.GetIndirizzoCompleto(); var indirizzoCondominio = condominio.Indirizzo.GetIndirizzoCompleto(); if (!string.IsNullOrEmpty(indirizzoSoggetto) && !string.IsNullOrEmpty(indirizzoCondominio)) { person.Add(persona.ID, string.Format("{0}", indirizzoSoggetto)); fuzzy.Add(persona.ID, "Indirizzo", indirizzoSoggetto); query.Clear(); query.CreateSearchTerm("Indirizzo", indirizzoCondominio, 0.20, true); var fuzzyResult = fuzzy.Search(query, scope, 1); return fuzzyResult.Count > 0 && fuzzyResult[0].Rank > 1; } return true; } } catch (Exception ex) { _log.Warn("Errore inaspettato durante il set di residente - " + Library.Utility.GetMethodDescription(), ex); return false; } } return false; }
public SearchResultViewModel Search(string query, IEnumerable <Event> events, string sortBy = "relevant") { SearchResultViewModel foundEvent = new SearchResultViewModel(); if (!String.IsNullOrEmpty(query)) { foreach (Event evt in events) { List <String> splittedEvent = new List <String>(); String eventName = evt.EventName; for (var i = 0; i <= eventName.Length - query.Length; i++) { splittedEvent.Add(eventName.Substring(i, query.Length)); } List <string> foundbyTitle = FuzzySearch.Search(query.ToLower(), splittedEvent, 0.50); List <String> splittedArtist = new List <String>(); List <string> foundbyArtist = new List <string>(); if (evt.Artist != null) { String Artist = evt.Artist; for (var i = 0; i <= Artist.Length - query.Length; i++) { splittedArtist.Add(Artist.Substring(i, query.Length)); } foundbyArtist = FuzzySearch.Search(query.ToLower(), splittedArtist, 0.5); } if (foundbyTitle.Count > 0 || foundbyArtist.Count > 0) { ResultEvent Event = new ResultEvent(evt); Event.EventName.Matches = Utils.ReduceRedundancy(foundbyTitle); Event.Artist.Matches = Utils.ReduceRedundancy(foundbyArtist); foundEvent.Result.Add(Event); } else { if (Utils.ConvertVN(evt.EventName).ToLower().Contains(Utils.ConvertVN(query.ToLower()))) { ResultEvent Event = new ResultEvent(evt); Event.EventName.Matches = new List <string> { query }; Event.IsFuzz = false; foundEvent.Result.Add(Event); } } } ResultEventComparer comparer = new ResultEventComparer(); if (sortBy == "relevant") { comparer.ComparisonMethod = ResultEventComparer.ComparisonType.Relevant; foundEvent.Result.Sort(comparer); } else if (sortBy == "HoldDate") { comparer.ComparisonMethod = ResultEventComparer.ComparisonType.HoldDate; foundEvent.Result.Sort(comparer); } return(foundEvent); } return(null); }