Search in sources :

Example 1 with ConceptCriteria

use of org.snomed.snowstorm.core.data.services.pojo.ConceptCriteria in project snowstorm by IHTSDO.

the class MultiSearchController method findConcepts.

@ApiOperation("Search concepts across multiple Code Systems.")
@RequestMapping(value = "multisearch/concepts", method = RequestMethod.GET)
@JsonView(value = View.Component.class)
public ItemsPage<ConceptMini> findConcepts(@RequestParam(required = false) Set<String> conceptIds, @RequestParam(required = false) Boolean active, @RequestParam(defaultValue = "0") int offset, @RequestParam(defaultValue = "50") int limit, @RequestHeader(value = "Accept-Language", defaultValue = Config.DEFAULT_ACCEPT_LANG_HEADER) String acceptLanguageHeader) throws TooCostlyException {
    TimerUtil timer = new TimerUtil("MultiSearch - Concepts");
    ConceptCriteria conceptCriteria = new ConceptCriteria().conceptIds(conceptIds).active(active);
    PageRequest pageRequest = ControllerHelper.getPageRequest(offset, limit);
    Page<Concept> concepts = multiSearchService.findConcepts(conceptCriteria, pageRequest);
    List<ConceptMini> minis = concepts.getContent().stream().map(concept -> {
        ConceptMini mini = new ConceptMini(concept, null);
        mini.addExtraField("branch", concept.getPath());
        return mini;
    }).collect(Collectors.toList());
    timer.finish();
    return new ItemsPage<>(new PageImpl<>(minis, pageRequest, concepts.getTotalElements()));
}
Also used : Concept(org.snomed.snowstorm.core.data.domain.Concept) java.util(java.util) JsonView(com.fasterxml.jackson.annotation.JsonView) ApiParam(io.swagger.annotations.ApiParam) PageWithBucketAggregations(org.snomed.snowstorm.core.data.services.pojo.PageWithBucketAggregations) Autowired(org.springframework.beans.factory.annotation.Autowired) MultiSearchService(org.snomed.snowstorm.core.data.services.MultiSearchService) Concept(org.snomed.snowstorm.core.data.domain.Concept) ApiOperation(io.swagger.annotations.ApiOperation) BrowserDescriptionSearchResult(org.snomed.snowstorm.rest.pojo.BrowserDescriptionSearchResult) Description(org.snomed.snowstorm.core.data.domain.Description) Api(io.swagger.annotations.Api) LanguageDialect(org.snomed.snowstorm.core.pojo.LanguageDialect) Config(org.snomed.snowstorm.config.Config) ConceptMini(org.snomed.snowstorm.core.data.domain.ConceptMini) ConceptCriteria(org.snomed.snowstorm.core.data.services.pojo.ConceptCriteria) ItemsPage(org.snomed.snowstorm.rest.pojo.ItemsPage) PageRequest(org.springframework.data.domain.PageRequest) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) ConceptService(org.snomed.snowstorm.core.data.services.ConceptService) DescriptionCriteria(org.snomed.snowstorm.core.data.services.pojo.DescriptionCriteria) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) TooCostlyException(org.snomed.snowstorm.core.data.services.TooCostlyException) TimerUtil(org.snomed.snowstorm.core.util.TimerUtil) PageImpl(org.springframework.data.domain.PageImpl) PageRequest(org.springframework.data.domain.PageRequest) ItemsPage(org.snomed.snowstorm.rest.pojo.ItemsPage) ConceptMini(org.snomed.snowstorm.core.data.domain.ConceptMini) TimerUtil(org.snomed.snowstorm.core.util.TimerUtil) ConceptCriteria(org.snomed.snowstorm.core.data.services.pojo.ConceptCriteria) ApiOperation(io.swagger.annotations.ApiOperation) JsonView(com.fasterxml.jackson.annotation.JsonView)

Example 2 with ConceptCriteria

use of org.snomed.snowstorm.core.data.services.pojo.ConceptCriteria in project snowstorm by IHTSDO.

the class WebRoutingService method findConcept.

private Concept findConcept(UriParts uriParts, CodeSystemVersion version) {
    // Multisearch is expensive, so we'll try on default branch for the specified module/version first
    Concept concept = null;
    if (version != null) {
        concept = conceptService.find(uriParts.sctId, null, version.getBranchPath());
        if (concept != null) {
            // Ensure we're redirecting to a published version
            concept.setPath(multiSearchService.getPublishedVersionOfBranch(concept.getPath()));
        }
    }
    if (concept == null) {
        ConceptCriteria criteria = new ConceptCriteria().conceptIds(Collections.singleton(uriParts.sctId));
        Page<Concept> concepts = multiSearchService.findConcepts(criteria, PageRequest.of(0, 1));
        List<Concept> content = concepts.getContent();
        if (!content.isEmpty()) {
            concept = content.get(0);
        }
    }
    return concept;
}
Also used : ConceptCriteria(org.snomed.snowstorm.core.data.services.pojo.ConceptCriteria)

Example 3 with ConceptCriteria

use of org.snomed.snowstorm.core.data.services.pojo.ConceptCriteria in project snowstorm by IHTSDO.

the class MultiSearchService method findConcepts.

public Page<Concept> findConcepts(ConceptCriteria criteria, PageRequest pageRequest) {
    final BoolQueryBuilder conceptQuery = boolQuery().must(getBranchesQuery());
    conceptService.addClauses(criteria.getConceptIds(), criteria.getActive(), conceptQuery);
    NativeSearchQuery query = new NativeSearchQueryBuilder().withQuery(conceptQuery).withPageable(pageRequest).build();
    SearchHits<Concept> searchHits = elasticsearchTemplate.search(query, Concept.class);
    // Populate the published version path back in
    List<Concept> concepts = searchHits.get().map(SearchHit::getContent).map(c -> {
        c.setPath(getPublishedVersionOfBranch(c.getPath()));
        return c;
    }).collect(Collectors.toList());
    return new PageImpl<>(concepts, pageRequest, searchHits.getTotalHits());
}
Also used : Concept(org.snomed.snowstorm.core.data.domain.Concept) CodeSystem(org.snomed.snowstorm.core.data.domain.CodeSystem) LoggerFactory(org.slf4j.LoggerFactory) PageWithBucketAggregations(org.snomed.snowstorm.core.data.services.pojo.PageWithBucketAggregations) Autowired(org.springframework.beans.factory.annotation.Autowired) CommitType(io.kaicode.elasticvc.domain.Commit.CommitType) AGGREGATION_SEARCH_SIZE(org.snomed.snowstorm.config.Config.AGGREGATION_SEARCH_SIZE) HashMap(java.util.HashMap) Concept(org.snomed.snowstorm.core.data.domain.Concept) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ElasticsearchRestTemplate(org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate) Description(org.snomed.snowstorm.core.data.domain.Description) Service(org.springframework.stereotype.Service) Map(java.util.Map) Aggregation(org.elasticsearch.search.aggregations.Aggregation) CodeSystemVersion(org.snomed.snowstorm.core.data.domain.CodeSystemVersion) QueryBuilders.termsQuery(org.elasticsearch.index.query.QueryBuilders.termsQuery) SearchHit(org.springframework.data.elasticsearch.core.SearchHit) Commit(io.kaicode.elasticvc.domain.Commit) PageWithBucketAggregationsFactory(org.snomed.snowstorm.core.data.services.pojo.PageWithBucketAggregationsFactory) ReferenceSetMember(org.snomed.snowstorm.core.data.domain.ReferenceSetMember) Logger(org.slf4j.Logger) VersionControlHelper(io.kaicode.elasticvc.api.VersionControlHelper) QueryBuilders.boolQuery(org.elasticsearch.index.query.QueryBuilders.boolQuery) Aggregations(org.elasticsearch.search.aggregations.Aggregations) SearchHits(org.springframework.data.elasticsearch.core.SearchHits) Collection(java.util.Collection) ConceptCriteria(org.snomed.snowstorm.core.data.services.pojo.ConceptCriteria) Set(java.util.Set) PageRequest(org.springframework.data.domain.PageRequest) AggregationBuilders(org.elasticsearch.search.aggregations.AggregationBuilders) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) QueryBuilders.termQuery(org.elasticsearch.index.query.QueryBuilders.termQuery) List(java.util.List) LongOpenHashSet(it.unimi.dsi.fastutil.longs.LongOpenHashSet) CommitListener(io.kaicode.elasticvc.api.CommitListener) CollectionUtils(org.springframework.util.CollectionUtils) LocalDate(java.time.LocalDate) DescriptionCriteria(org.snomed.snowstorm.core.data.services.pojo.DescriptionCriteria) SearchHitsIterator(org.springframework.data.elasticsearch.core.SearchHitsIterator) NativeSearchQueryBuilder(org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder) Branch(io.kaicode.elasticvc.domain.Branch) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) NativeSearchQuery(org.springframework.data.elasticsearch.core.query.NativeSearchQuery) PageImpl(org.springframework.data.domain.PageImpl) PathUtil(io.kaicode.elasticvc.api.PathUtil) PageImpl(org.springframework.data.domain.PageImpl) SearchHit(org.springframework.data.elasticsearch.core.SearchHit) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) NativeSearchQueryBuilder(org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder) NativeSearchQuery(org.springframework.data.elasticsearch.core.query.NativeSearchQuery)

Example 4 with ConceptCriteria

use of org.snomed.snowstorm.core.data.services.pojo.ConceptCriteria in project snowstorm by IHTSDO.

the class FHIRCodeSystemProvider method lookup.

// Method common to both implicit and instance lookups
private Parameters lookup(HttpServletRequest request, StringType system, CodeType code, Coding coding, String displayLanguage, List<CodeType> propertiesType) throws FHIROperationException {
    String conceptId = fhirHelper.recoverConceptId(code, coding);
    List<LanguageDialect> designations = new ArrayList<>();
    // Also if displayLanguage has been used, ensure that's part of our requested Language Codes
    // And make it the first in the list so we pick it up for the display element
    fhirHelper.setLanguageOptions(designations, displayLanguage, request);
    Concept fullConcept;
    BranchPath branchPath;
    if (system == null || system.toString().equals(SNOMED_URI)) {
        // Multisearch is expensive, so we'll try on default branch first
        branchPath = fhirHelper.getBranchPathFromURI(system);
        fullConcept = conceptService.find(conceptId, designations, branchPath.toString());
        if (fullConcept == null) {
            ConceptCriteria criteria = new ConceptCriteria().conceptIds(Collections.singleton(conceptId));
            Page<Concept> concepts = multiSearchService.findConcepts(criteria, PageRequest.of(0, 1));
            List<Concept> content = concepts.getContent();
            if (!content.isEmpty()) {
                Concept concept = content.get(0);
                branchPath = new BranchPath(concept.getPath());
                fullConcept = conceptService.find(conceptId, designations, concept.getPath());
            } else {
                throw new NotFoundException(conceptId + " not found on any code system version");
            }
        }
    } else {
        branchPath = fhirHelper.getBranchPathFromURI(system);
        fullConcept = conceptService.find(conceptId, designations, branchPath.toString());
        if (fullConcept == null) {
            throw new NotFoundException("Concept " + conceptId + " was not found on branch " + branchPath);
        }
    }
    Page<Long> childIds = queryService.searchForIds(queryService.createQueryBuilder(false).ecl("<!" + conceptId), branchPath.toString(), LARGE_PAGE);
    Set<FhirSctProperty> properties = FhirSctProperty.parse(propertiesType);
    return pMapper.mapToFHIR(system, fullConcept, childIds.getContent(), properties, designations);
}
Also used : Concept(org.snomed.snowstorm.core.data.domain.Concept) LanguageDialect(org.snomed.snowstorm.core.pojo.LanguageDialect) NotFoundException(org.snomed.snowstorm.core.data.services.NotFoundException) ConceptCriteria(org.snomed.snowstorm.core.data.services.pojo.ConceptCriteria) BranchPath(org.snomed.snowstorm.fhir.domain.BranchPath)

Example 5 with ConceptCriteria

use of org.snomed.snowstorm.core.data.services.pojo.ConceptCriteria in project snowstorm by IHTSDO.

the class FHIRCodeSystemProvider method validateCode.

private Parameters validateCode(HttpServletRequest request, HttpServletResponse response, UriType url, StringType codeSystem, CodeType code, String display, StringType version, DateTimeType date, Coding coding, String displayLanguage) throws FHIROperationException {
    List<LanguageDialect> languageDialects = fhirHelper.getLanguageDialects(null, request.getHeader(ACCEPT_LANGUAGE_HEADER));
    String conceptId = fhirHelper.recoverConceptId(code, coding);
    ConceptCriteria criteria = new ConceptCriteria().conceptIds(Collections.singleton(conceptId));
    Concept fullConcept = null;
    if (codeSystem == null || codeSystem.toString().equals(SNOMED_URI)) {
        Page<Concept> concepts = multiSearchService.findConcepts(criteria, PageRequest.of(0, 1));
        List<Concept> content = concepts.getContent();
        if (!content.isEmpty()) {
            Concept concept = content.get(0);
            fullConcept = conceptService.find(conceptId, languageDialects, concept.getPath());
        }
    } else {
        BranchPath branchPath = fhirHelper.getBranchPathFromURI(codeSystem);
        fullConcept = conceptService.find(conceptId, languageDialects, branchPath.toString());
    }
    if (fullConcept == null) {
        return pMapper.conceptNotFound();
    } else {
        return pMapper.mapToFHIR(fullConcept, display);
    }
}
Also used : Concept(org.snomed.snowstorm.core.data.domain.Concept) BranchPath(org.snomed.snowstorm.fhir.domain.BranchPath) LanguageDialect(org.snomed.snowstorm.core.pojo.LanguageDialect) ConceptCriteria(org.snomed.snowstorm.core.data.services.pojo.ConceptCriteria)

Aggregations

ConceptCriteria (org.snomed.snowstorm.core.data.services.pojo.ConceptCriteria)5 Concept (org.snomed.snowstorm.core.data.domain.Concept)4 Collectors (java.util.stream.Collectors)2 Description (org.snomed.snowstorm.core.data.domain.Description)2 DescriptionCriteria (org.snomed.snowstorm.core.data.services.pojo.DescriptionCriteria)2 PageWithBucketAggregations (org.snomed.snowstorm.core.data.services.pojo.PageWithBucketAggregations)2 LanguageDialect (org.snomed.snowstorm.core.pojo.LanguageDialect)2 BranchPath (org.snomed.snowstorm.fhir.domain.BranchPath)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Page (org.springframework.data.domain.Page)2 PageImpl (org.springframework.data.domain.PageImpl)2 PageRequest (org.springframework.data.domain.PageRequest)2 JsonView (com.fasterxml.jackson.annotation.JsonView)1 CommitListener (io.kaicode.elasticvc.api.CommitListener)1 PathUtil (io.kaicode.elasticvc.api.PathUtil)1 VersionControlHelper (io.kaicode.elasticvc.api.VersionControlHelper)1 Branch (io.kaicode.elasticvc.domain.Branch)1 Commit (io.kaicode.elasticvc.domain.Commit)1 CommitType (io.kaicode.elasticvc.domain.Commit.CommitType)1 Api (io.swagger.annotations.Api)1