Exemple #1
0
        public ActionResult <IEnumerable <ValueSetForRetrievalDto> > GetValueSetConcepts(
            [FromRoute] DomainRouteParameters routeParameters,
            [FromQuery] ValueSetConceptPaginationParameters paginationParameters)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // Get the items from the database
            var valueSetConceptEntities = _valueSetConceptRepository.GetValueSetConcepts(paginationParameters);

            // Get pagination metadata
            var previousPageLink = CreateValueSetResourceUri(routeParameters, paginationParameters, ResourceUriType.PreviousPage);
            var nextPageLink     = CreateValueSetResourceUri(routeParameters, paginationParameters, ResourceUriType.NextPage);

            var paginationMetadata = new
            {
                totalCount       = valueSetConceptEntities.TotalCount,
                pageSize         = valueSetConceptEntities.PageSize,
                currentPage      = valueSetConceptEntities.CurrentPage,
                totalPages       = valueSetConceptEntities.TotalPages,
                previousPageLink = valueSetConceptEntities.HasPrevious ? previousPageLink : string.Empty,
                nextPageLink     = valueSetConceptEntities.HasNext ? nextPageLink : string.Empty
            };

            Response.Headers.Add("X-Pagination", Newtonsoft.Json.JsonConvert.SerializeObject(paginationMetadata));

            var valueSetConceptsToReturn = Mapper.Map <IEnumerable <ValueSetConceptForRetrievalDto> >(valueSetConceptEntities);

            return(Ok(valueSetConceptsToReturn));
        }
Exemple #2
0
        private ValueSet BuildValueSet(Entities.ValueSetVersion valueSetVersionFromRepo, Entities.ValueSet valueSetFromRepo, bool includeConcepts = true)
        {
            var valueSet = new Hl7.Fhir.Model.ValueSet();

            valueSet.Url = Url.Link(
                nameof(GetVersionedValueSetById),
                new
            {
                type = "ValueSet",
                id   = valueSetFromRepo.ValueSetCode,
                vid  = valueSetVersionFromRepo.ValueSetVersionNumber.ToString()
            });
            valueSet.Identifier = new List <Identifier>()
            {
                new Identifier()
                {
                    Use    = Identifier.IdentifierUse.Official,
                    Value  = valueSetVersionFromRepo.ValueSetVersionID.ToString(),
                    System = "urn:ietf:rfc:3986"
                },
                new Identifier()
                {
                    Use   = Identifier.IdentifierUse.Secondary,
                    Value = valueSetVersionFromRepo.ValueSetOID
                },
                new Identifier()
                {
                    Use   = Identifier.IdentifierUse.Secondary,
                    Value = valueSetVersionFromRepo.ValueSetCode
                }
            };
            valueSet.Name        = valueSetFromRepo.ValueSetCode;
            valueSet.Title       = valueSetFromRepo.ValueSetName;
            valueSet.Description = new Markdown(valueSetFromRepo.DefinitionText);
            valueSet.Publisher   = "PHIN_VADS";
            valueSet.DateElement = new FhirDateTime(valueSetVersionFromRepo.StatusDate);
            valueSet.Version     = valueSetVersionFromRepo.ValueSetVersionNumber.ToString();
            valueSet.VersionId   = valueSetVersionFromRepo.ValueSetVersionID.ToString();
            valueSet.Status      = PublicationStatus.Active;

            if (includeConcepts)
            {
                valueSet.Expansion = new ValueSet.ExpansionComponent()
                {
                    Identifier       = Guid.NewGuid().ToString(),
                    TimestampElement = new FhirDateTime(DateTimeOffset.Now),
                    Contains         = new List <ValueSet.ContainsComponent>()
                };

                var paginationParameters = new ValueSetConceptPaginationParameters()
                {
                    ValueSetVersionId     = valueSetVersionFromRepo.ValueSetVersionID,
                    ValueSetVersionNumber = valueSetVersionFromRepo.ValueSetVersionNumber.ToString(),
                    PageSize = 1000
                };

                var valueSetConceptEntities = _valueSetConceptRepository.GetValueSetConcepts(paginationParameters);
                foreach (var conceptFromRepo in valueSetConceptEntities)
                {
                    var component = new ValueSet.ContainsComponent()
                    {
                        Code      = conceptFromRepo.ConceptCode,
                        Display   = conceptFromRepo.CDCPreferredDesignation,
                        System    = $"urn:oid:{conceptFromRepo.CodeSystemOID}",
                        Extension = new List <Extension>()
                        {
                            new Extension()
                            {
                                Value = new FhirString(conceptFromRepo.HL70396Identifier)
                            }
                        }
                    };
                    valueSet.Expansion.Contains.Add(component);
                }

                valueSet.Expansion.Total  = valueSet.Expansion.Contains.Count;
                valueSet.Expansion.Offset = (paginationParameters.PageNumber - 1) * paginationParameters.PageSize;
            }

            return(valueSet);
        }
        public PagedList <ValueSetConcept> GetValueSetConcepts(ValueSetConceptPaginationParameters parameters)
        {
            var collection = _context.ValueSetConcepts
                             .Join(_context.ValueSetVersions,
                                   vsc => vsc.ValueSetVersionID,
                                   vsv => vsv.ValueSetVersionID,
                                   (vsc, vsv) => new ValueSetConcept()
            {
                ValueSetConceptID             = vsc.ValueSetConceptID,
                CodeSystemConceptName         = vsc.CodeSystemConceptName,
                ValueSetConceptStatusCode     = vsc.ValueSetConceptStatusCode,
                ValueSetConceptStatusDate     = vsc.ValueSetConceptStatusDate,
                ValueSetConceptDefinitionText = vsc.ValueSetConceptDefinitionText != "NULL" ? vsc.ValueSetConceptDefinitionText : string.Empty,
                CDCPreferredDesignation       = vsc.CDCPreferredDesignation,
                ScopeNoteText         = vsc.ScopeNoteText,
                ValueSetVersionID     = vsc.ValueSetVersionID,
                CodeSystemOID         = vsc.CodeSystemOID,
                ConceptCode           = vsc.ConceptCode,
                Sequence              = vsc.Sequence,
                ValueSetOID           = vsv.ValueSetOID,
                ValueSetVersionNumber = vsv.ValueSetVersionNumber
            })
                             .Join(_context.ValueSets,
                                   vsc => vsc.ValueSetOID,
                                   vs => vs.ValueSetOID,
                                   (vsc, vs) => new ValueSetConcept()
            {
                ValueSetConceptID             = vsc.ValueSetConceptID,
                CodeSystemConceptName         = vsc.CodeSystemConceptName,
                ValueSetConceptStatusCode     = vsc.ValueSetConceptStatusCode,
                ValueSetConceptStatusDate     = vsc.ValueSetConceptStatusDate,
                ValueSetConceptDefinitionText = vsc.ValueSetConceptDefinitionText,
                CDCPreferredDesignation       = vsc.CDCPreferredDesignation,
                ScopeNoteText         = vsc.ScopeNoteText,
                ValueSetVersionID     = vsc.ValueSetVersionID,
                CodeSystemOID         = vsc.CodeSystemOID,
                ConceptCode           = vsc.ConceptCode,
                Sequence              = vsc.Sequence,
                ValueSetOID           = vsc.ValueSetOID,
                ValueSetVersionNumber = vsc.ValueSetVersionNumber,
                ValueSetCode          = vs.ValueSetCode
            })
                             .Join(_context.CodeSystems,
                                   vsc => vsc.CodeSystemOID,
                                   cs => cs.CodeSystemOID,
                                   (vsc, cs) => new ValueSetConcept()
            {
                ValueSetConceptID             = vsc.ValueSetConceptID,
                CodeSystemConceptName         = vsc.CodeSystemConceptName,
                ValueSetConceptStatusCode     = vsc.ValueSetConceptStatusCode,
                ValueSetConceptStatusDate     = vsc.ValueSetConceptStatusDate,
                ValueSetConceptDefinitionText = vsc.ValueSetConceptDefinitionText,
                CDCPreferredDesignation       = vsc.CDCPreferredDesignation,
                ScopeNoteText         = vsc.ScopeNoteText,
                ValueSetVersionID     = vsc.ValueSetVersionID,
                CodeSystemOID         = vsc.CodeSystemOID,
                ConceptCode           = vsc.ConceptCode,
                Sequence              = vsc.Sequence,
                ValueSetOID           = vsc.ValueSetOID,
                ValueSetVersionNumber = vsc.ValueSetVersionNumber,
                ValueSetCode          = vsc.ValueSetCode,
                HL70396Identifier     = cs.HL70396Identifier
            });

            if (!string.IsNullOrWhiteSpace(parameters.ValueSetCode))
            {
                collection = collection.Where(c =>
                                              c.ValueSetCode != null ?
                                              c.ValueSetCode.Equals(parameters.ValueSetCode, StringComparison.OrdinalIgnoreCase) :
                                              true
                                              );
            }
            if (!string.IsNullOrWhiteSpace(parameters.ValueSetOid))
            {
                collection = collection.Where(c =>
                                              c.ValueSetOID != null ?
                                              c.ValueSetOID.Equals(parameters.ValueSetOid) :
                                              true
                                              );
            }
            if (!string.IsNullOrWhiteSpace(parameters.ConceptCode))
            {
                collection = collection.Where(c =>
                                              c.ConceptCode != null ?
                                              c.ConceptCode.Equals(parameters.ConceptCode) :
                                              true
                                              );
            }
            if (parameters.ValueSetVersionId != null)
            {
                collection = collection.Where(c =>
                                              c.ValueSetVersionID != null ?
                                              c.ValueSetVersionID == parameters.ValueSetVersionId :
                                              true
                                              );
            }
            if (!string.IsNullOrWhiteSpace(parameters.SearchQuery))
            {
                var searchQueryStringForWhereClause = string.Empty;
                searchQueryStringForWhereClause = parameters.SearchQuery.Trim().ToLowerInvariant();

                if (parameters.SearchType == MatchType.Contains)
                {
                    collection = collection.Where(v =>
                                                  v.ValueSetConceptDefinitionText.ToLowerInvariant().Contains(searchQueryStringForWhereClause) ||
                                                  v.CDCPreferredDesignation.ToLowerInvariant().Contains(searchQueryStringForWhereClause)
                                                  );
                }
                else if (parameters.SearchType == MatchType.StartsWith)
                {
                    collection = collection.Where(v =>
                                                  v.ValueSetConceptDefinitionText.ToLowerInvariant().StartsWith(searchQueryStringForWhereClause) ||
                                                  v.CDCPreferredDesignation.ToLowerInvariant().StartsWith(searchQueryStringForWhereClause)
                                                  );
                }
            }

            if (parameters.ValueSetVersionNumber != null)
            {
                int versionNumber = 1;

                if (parameters.ValueSetVersionNumber.Equals("latest", StringComparison.OrdinalIgnoreCase))
                {
                    var max = collection.Max(v => v.ValueSetVersionNumber);
                    if (max.HasValue)
                    {
                        versionNumber = max.Value;
                    }
                }
                else
                {
                    int.TryParse(parameters.ValueSetVersionNumber, out versionNumber);
                }

                collection = collection.Where(c =>
                                              c.ValueSetVersionNumber != null ?
                                              c.ValueSetVersionNumber == versionNumber :
                                              true
                                              );
            }

            return(PagedList <ValueSetConcept> .Create(collection,
                                                       parameters.PageNumber,
                                                       parameters.PageSize));
        }
Exemple #4
0
        private string CreateValueSetResourceUri(DomainRouteParameters domainParameters, ValueSetConceptPaginationParameters parameters, ResourceUriType type)
        {
            switch (type)
            {
            case ResourceUriType.PreviousPage:
                return(Url.Link(nameof(GetValueSetConcepts),
                                new
                {
                    searchQuery = parameters.SearchQuery,
                    valueSetOid = parameters.ValueSetOid,
                    valueSetCode = parameters.ValueSetCode,
                    valueSetVersionId = parameters.ValueSetVersionId,
                    valueSetVersionNumber = parameters.ValueSetVersionNumber,
                    conceptCode = parameters.ConceptCode,
                    domain = domainParameters.Domain,
                    pageNumber = parameters.PageNumber - 1,
                    pageSize = parameters.PageSize
                }));

            case ResourceUriType.NextPage:
                return(Url.Link(nameof(GetValueSetConcepts),
                                new
                {
                    searchQuery = parameters.SearchQuery,
                    valueSetOid = parameters.ValueSetOid,
                    valueSetCode = parameters.ValueSetCode,
                    valueSetVersionId = parameters.ValueSetVersionId,
                    valueSetVersionNumber = parameters.ValueSetVersionNumber,
                    conceptCode = parameters.ConceptCode,
                    domain = domainParameters.Domain,
                    pageNumber = parameters.PageNumber + 1,
                    pageSize = parameters.PageSize
                }));

            default:
                return(Url.Link(nameof(GetValueSetConcepts),
                                new
                {
                    searchQuery = parameters.SearchQuery,
                    valueSetOid = parameters.ValueSetOid,
                    valueSetCode = parameters.ValueSetCode,
                    valueSetVersionId = parameters.ValueSetVersionId,
                    valueSetVersionNumber = parameters.ValueSetVersionNumber,
                    conceptCode = parameters.ConceptCode,
                    domain = domainParameters.Domain,
                    pageNumber = parameters.PageNumber,
                    pageSize = parameters.PageSize
                }));
            }
        }