예제 #1
0
        public DiseaseSearchResultViewModel GetSearchResult(IEnumerable<string> selectedSymptomsIdsAsString, DiseaseTargetType targetGroup)
        {
            var selectedSymptomsSet = new HashSet<Symptom>();
            var relatedDiseasesSet = new HashSet<Disease>();

            this.BuildDiseasesList(selectedSymptomsIdsAsString, selectedSymptomsSet, relatedDiseasesSet, targetGroup);
            var result = this.BuildSearchResultList(selectedSymptomsSet, relatedDiseasesSet);

            return result;
        }
예제 #2
0
        public ActionResult SearchResult(IEnumerable<string> selectedSymptomsNames, DiseaseTargetType TargetGroup)
        {
            var selectedSymptomsIds = this.Symptoms.GetSymptomsIdsByNames(selectedSymptomsNames);

            this.Symptoms.AddToLastSearches(selectedSymptomsIds, TargetGroup);

            var cacheKey = this.GetCacheKeyFromSymptomsList(selectedSymptomsIds, TargetGroup);

            var model = this.Cache.Get(
                cacheKey,
                () => this.Diseases.GetSearchResult(selectedSymptomsIds, TargetGroup),
                20 * 60);

            return this.View(model);
        }
예제 #3
0
        public void BuildDiseasesList(
            IEnumerable<string> selectedSymptomsIdsAsString,
            HashSet<Symptom> selectedSymptomsSet,
            HashSet<Disease> relatedDiseasesSet,
            DiseaseTargetType targetGroup)
        {

            foreach (var selectedSymptomIdAsString in selectedSymptomsIdsAsString)
            {
                // TODO: Validation if string can be parsed
                var selectedSymptomId = int.Parse(selectedSymptomIdAsString);

                var symptom = this.Symptoms.All()
                    .Include(x => x.Diseases)
                    .FirstOrDefault(x => x.SymptomId == selectedSymptomId);

                if (symptom != null && symptom.Diseases.Count > 0)
                {
                    if (!selectedSymptomsSet.Contains(symptom))
                    {
                        selectedSymptomsSet.Add(symptom);
                    }

                    foreach (var disease in symptom.Diseases)
                    {
                        if (targetGroup.Equals(DiseaseTargetType.Both) || disease.Target.Equals(targetGroup))
                        {
                            if (!relatedDiseasesSet.Contains(disease))
                            {
                                relatedDiseasesSet.Add(disease);
                            }
                        }
                    }
                }
            }
        }
예제 #4
0
        public void AddToLastSearches(IEnumerable<string> selectedSymptomsIds, DiseaseTargetType targetGroup)
        {
            var lastSearches = this.Cache.Get(
                ServicesConstants.SymptomsLastSearchedCacheKey,
                () => { return new List<SearchViewModel>(); },
                24 * 60 * 60);

            var search = new SearchViewModel()
            {
                SearchedOn = DateTime.UtcNow,
                TargetGroup = targetGroup,
                SymptomsSearched = new List<SymptomViewModel>()
            };

            foreach (var selectedSymptomIdAsString in selectedSymptomsIds)
            {
                var selectedSymptomId = int.Parse(selectedSymptomIdAsString);
                var symptom = this.Symptoms.All().SingleOrDefault(x => x.SymptomId == selectedSymptomId);
                var symptomViewModel = this.Mapper.Map<SymptomViewModel>(symptom);
                search.SymptomsSearched.Add(symptomViewModel);
            }

            // If the search has valid symptoms &
            // If the same item does not exist in the list
            // Insert the search request
            if (search.SymptomsSearchedIds.Count > 0 &&
                !lastSearches.Contains(search, new SearchViewModelEqualityComparer()))
            {
                lastSearches.Add(search);

                if (lastSearches.Count > 10)
                {
                    var itemToRemove = lastSearches.FirstOrDefault();
                    lastSearches.Remove(itemToRemove);
                }
            }
        }
예제 #5
0
        public string GetCacheKeyFromSymptomsList(IEnumerable<string> selectedSymptomsIds, DiseaseTargetType TargetGroup)
        {
            var cacheKeyBuilder = new StringBuilder();
            cacheKeyBuilder.Append(TargetGroup.GetDisplayName());

            selectedSymptomsIds = selectedSymptomsIds.OrderBy(x => x);
            foreach (var symptomId in selectedSymptomsIds)
            {
                cacheKeyBuilder.Append(symptomId);
                cacheKeyBuilder.Append('/');
            }

            return cacheKeyBuilder.ToString();
        }