/// <summary>
        /// Searches the specified filter.
        /// </summary>
        /// <param name="filter">The filter.</param>
        /// <returns></returns>
        public async Task <IList <SearchEntryResponseViewModel> > GlobalSearch(GlobalSearchDto filter)
        {
            var token = authDataStorage.GetToken();

            var resuts = await healthLibraryService.GlobalSearch(token, CustomerContext.Current.Customer.Id, filter);

            return(Mapper.Map <IList <SearchEntryDto>, IList <SearchEntryResponseViewModel> >(resuts));
        }
Пример #2
0
        public async Task <IHttpActionResult> Search(
            int customerId,
            [FromUri] GlobalSearchDto request
            )
        {
            var result = await searchControllerHelper.Search(customerId, request);

            return(Ok(result));
        }
Пример #3
0
        /// <summary>
        /// Returns list of tags to display in tags cloud for conditions.
        /// Rate = assigned programs + assigned protocols.
        /// </summary>
        /// <returns></returns>
        public async Task <IList <CloudTagViewModel> > GetConditionsTags()
        {
            var token             = this.authDataStorage.GetToken();
            var customerId        = this.customerContext.Customer.Id;
            var careElementFilter = new GlobalSearchDto
            {
                Categories = new List <SearchCategoryType>
                {
                    SearchCategoryType.Program,
                    SearchCategoryType.Protocol
                }
            };
            var careElements = await this.healthLibraryService.GlobalSearch(token, customerId, careElementFilter);

            var tags = careElements.SelectMany(e => e.Tags).Distinct();

            return(tags.Select(tag => new CloudTagViewModel
            {
                Name = tag,
                Rate = careElements.Count(e => e.Tags.Contains(tag))
            })
                   .Where(m => m.Rate > 0)
                   .ToList());
        }
Пример #4
0
        /// <summary>
        /// Globals the search.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <param name="customerId">The customer identifier.</param>
        /// <param name="filter">The filter.</param>
        /// <returns></returns>
        public async Task <IList <SearchEntryDto> > GlobalSearch(
            string token,
            int customerId,
            GlobalSearchDto filter
            )
        {
            var tagsQueryString = filter == null || filter.Tags == null
                ? string.Empty
                : filter.Tags.Select(t => string.Format("tags={0}", t)).Aggregate((t1, t2) => string.Format("{0}&{1}", t1, t2));

            var categoriesQueryString = filter == null || filter.Categories == null
                ? string.Empty
                : filter.Categories.Select(c => string.Format("categories={0}", c)).Aggregate((c1, c2) => string.Format("{0}&{1}", c1, c2));

            if (!string.IsNullOrEmpty(tagsQueryString) && !string.IsNullOrEmpty(categoriesQueryString))
            {
                categoriesQueryString = "&" + categoriesQueryString;
            }

            var url         = string.Format("/api/{0}/search?{1}{2}", customerId, tagsQueryString, categoriesQueryString);
            var pagedResult = await apiClient.SendRequestAsync <PagedResult <SearchEntryDto> >(url, filter, Method.GET, null, token);

            return(pagedResult.Results);
        }
        /// <summary>
        /// Searches the specified search request.
        /// </summary>
        /// <param name="customerId">The customer identifier.</param>
        /// <param name="searchRequest">The search request.</param>
        /// <returns></returns>
        public async Task <PagedResultDto <SearchEntryDto> > Search(int customerId, GlobalSearchDto searchRequest)
        {
            var allCachedEntries = await globalSearchCacheHelper.GetAllCachedEntries(customerId);

            Expression <Func <SearchEntryDto, bool> > expression = PredicateBuilder.True <SearchEntryDto>();

            if (searchRequest != null)
            {
                if (searchRequest.Tags != null && searchRequest.Tags.Any())
                {
                    Expression <Func <SearchEntryDto, bool> > tagsExpression = PredicateBuilder.False <SearchEntryDto>();;

                    foreach (var tag in searchRequest.Tags)
                    {
                        tagsExpression = tagsExpression.Or(se => se.Tags.Any(t => t.ToLower() == tag.ToLower()));
                    }

                    expression = expression.And(tagsExpression);
                }

                if (!string.IsNullOrEmpty(searchRequest.Q))
                {
                    var terms = searchRequest.Q.Split(' ').Where(r => !string.IsNullOrWhiteSpace(r));

                    foreach (var term in terms)
                    {
                        expression = expression.And(se => se.Name.ToLower().Contains(term.ToLower()));
                    }
                }

                if (searchRequest.Categories != null && searchRequest.Categories.Any())
                {
                    Expression <Func <SearchEntryDto, bool> > innerCategoryExpression = PredicateBuilder.False <SearchEntryDto>();

                    foreach (var category in searchRequest.Categories)
                    {
                        innerCategoryExpression = innerCategoryExpression.Or(se => se.Type == category);
                    }

                    expression = expression.And(innerCategoryExpression);
                }
            }

            var filteredEntries = allCachedEntries
                                  .Values
                                  .Where(expression.Compile())
                                  .OrderBy(e => e.Type)
                                  .ThenBy(e => e.Name)
                                  .ToList();

            var total = filteredEntries.LongCount();

            if (searchRequest != null)
            {
                filteredEntries = filteredEntries.Skip(searchRequest.Skip).Take(searchRequest.Take).ToList();
            }

            return(new PagedResultDto <SearchEntryDto>()
            {
                Results = filteredEntries,
                Total = total
            });
        }
        public async Task <ActionResult> GlobalSearch(GlobalSearchDto filter)
        {
            var searchResult = await careBuilderManager.GlobalSearch(filter);

            return(Json(searchResult, JsonRequestBehavior.AllowGet));
        }
        /// <summary>
        /// Globals the search.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <param name="customerId">The customer identifier.</param>
        /// <param name="filter">The filter.</param>
        /// <returns></returns>
        public async Task <IList <SearchEntryDto> > GlobalSearch(string token, int customerId, GlobalSearchDto filter)
        {
            var result = await healthLibraryDataProvider.GlobalSearch(token, customerId, filter);

            return(result);
        }