Example #1
0
        public Maybe <IValueSet> GetValueSet(string valueSetUniqueId, IEnumerable <string> codeSystemCodes)
        {
            var codeSystemCDs = codeSystemCodes as string[] ?? codeSystemCodes.ToArray();
            var cached        = this.Cache.GetCachedValueSetWithAllCodes(valueSetUniqueId, codeSystemCDs);

            if (cached != null)
            {
                return(Maybe.From(cached));
            }

            var dto = this.DbSet.Where(GetBaseExpression()).FirstOrDefault(vs => vs.ValueSetUniqueID == valueSetUniqueId);

            if (dto == null)
            {
                return(Maybe <IValueSet> .Not);
            }

            var mapper = new ValueSetFullCodeListMapper(
                this.isCustomValue,
                this.Cache,
                this.valueSetCodeRepository.GetValueSetCodes,
                codeSystemCDs);

            return(Maybe.From(mapper.Map(dto)));
        }
Example #2
0
        public IReadOnlyCollection <IValueSet> GetValueSets(
            IEnumerable <string> valueSetUniqueIds,
            IEnumerable <string> codeSystemCodes,
            bool includeAllValueSetCodes = false)
        {
            var setIds = valueSetUniqueIds as string[] ?? valueSetUniqueIds.ToArray();
            var cached = setIds.Select(vsid => this.Cache.GetCachedValueSetWithAllCodes(vsid, codeSystemCodes))
                         .Where(vs => vs != null)
                         .ToList();

            var remaining = setIds.Except(cached.Select(s => s.ValueSetUniqueId));

            var dtos = this.DbSet.Where(GetBaseExpression()).Where(dto => remaining.Contains(dto.ValueSetUniqueID)).ToList();

            if (dtos.Any())
            {
                var mapper = new ValueSetFullCodeListMapper(
                    this.isCustomValue,
                    this.Cache,
                    this.valueSetCodeRepository.GetValueSetCodes,
                    codeSystemCodes);
                cached.AddRange(dtos.Select(mapper.Map).Where(mapped => mapped != null));
            }

            return(cached.OrderBy(vs => vs.Name).ToList().AsReadOnly());
        }
Example #3
0
        private async Task <PagedCollection <IValueSet> > CreatePagedCollectionAsync(
            IQueryable <ValueSetDescriptionDto> source,
            IPagerSettings pagerSettings,
            IEnumerable <string> codeSystemCodes,
            bool includeAllValueSetCodes = false)
        {
            this.pagingStrategy.EnsurePagerSettings(pagerSettings);

            var count = await source.CountAsync();

            var items = await source.OrderBy(this.SortExpression)
                        .Skip((pagerSettings.CurrentPage - 1) * pagerSettings.ItemsPerPage)
                        .Take(pagerSettings.ItemsPerPage)
                        .ToListAsync();

            var valueSetUniqueIds = items.Select(item => item.ValueSetUniqueID).ToArray();

            IModelMapper <ValueSetDescriptionDto, IValueSet> mapper;

            if (includeAllValueSetCodes)
            {
                mapper = new ValueSetFullCodeListMapper(
                    this.isCustomValue,
                    this.Cache,
                    this.valueSetCodeRepository.GetValueSetCodes,
                    codeSystemCodes);
            }
            else
            {
                // remove any valueSetIds for valuesets already cached from partition query
                var cachedValueSets = this.Cache
                                      .GetItems(valueSetUniqueIds.Select(id => CacheKeys.ValueSetKey(id, codeSystemCodes)).ToArray())
                                      .Select(obj => obj as IValueSet)
                                      .Where(vs => vs != null);

                valueSetUniqueIds = valueSetUniqueIds.Where(id => !cachedValueSets.Select(vs => vs.ValueSetUniqueId).Contains(id))
                                    .ToArray();

                // partition query
                var systemCodes = codeSystemCodes as string[] ?? codeSystemCodes.ToArray();
                var lookup      = await this.valueSetCodeRepository.LookupValueSetCodes(valueSetUniqueIds, systemCodes);

                var cachedValueSetDictionary = cachedValueSets.ToDictionary(vs => vs.ValueSetUniqueId, vs => vs);

                mapper = new ValueSetShortCodeListMapper(
                    this.isCustomValue,
                    this.Cache,
                    lookup,
                    cachedValueSetDictionary,
                    this.valueSetCodeRepository.CountValueSetCodes,
                    systemCodes);
            }

            return(this.pagingStrategy.CreatePagedCollection(items, count, pagerSettings, mapper));
        }
Example #4
0
        internal Maybe <IValueSet> GetCustomValueSet(string valueSetUniqueId)
        {
            var dto = this.ClientTermContext.ValueSetDescriptions.AsNoTracking().SingleOrDefault(x => x.ValueSetUniqueID == valueSetUniqueId);

            if (dto == null)
            {
                return(Maybe <IValueSet> .Not);
            }

            var mapper = new ValueSetFullCodeListMapper(
                this.isCustomValue,
                this.Cache,
                ((SqlValueSetCodeRepository)this.valueSetCodeRepository).GetCustomValueSetCodes,
                Enumerable.Empty <string>());

            return(Maybe.From(mapper.Map(dto)));
        }