Search in sources :

Example 1 with SnomedDisplayTermType

use of com.b2international.snowowl.snomed.core.SnomedDisplayTermType in project snow-owl by b2ihealthcare.

the class SnomedConceptSearchRequestEvaluator method evaluate.

@Override
public Concepts evaluate(ResourceURI uri, ServiceProvider context, Options search) {
    final String preferredDisplay = search.getString(OptionKey.DISPLAY);
    SnomedDisplayTermType displayTermType;
    if (preferredDisplay != null) {
        displayTermType = SnomedDisplayTermType.getEnum(preferredDisplay);
    } else {
        displayTermType = SnomedDisplayTermType.PT;
    }
    final SnomedConceptSearchRequestBuilder req = SnomedRequests.prepareSearchConcept();
    evaluateTermFilterOptions(req, search);
    if (search.containsKey(OptionKey.ID)) {
        req.filterByIds(search.getCollection(OptionKey.ID, String.class));
    }
    if (search.containsKey(OptionKey.ACTIVE)) {
        req.filterByActive(search.getBoolean(OptionKey.ACTIVE));
    }
    if (search.containsKey(OptionKey.PARENT)) {
        req.filterByParents(search.getCollection(OptionKey.PARENT, String.class));
    }
    if (search.containsKey(OptionKey.ANCESTOR)) {
        req.filterByAncestors(search.getCollection(OptionKey.ANCESTOR, String.class));
    }
    if (search.containsKey(OptionKey.TERM_TYPE)) {
        req.filterByDescriptionType(search.getString(OptionKey.TERM_TYPE));
    }
    if (search.containsKey(OptionKey.QUERY) || search.containsKey(OptionKey.MUST_NOT_QUERY)) {
        StringBuilder query = new StringBuilder();
        if (search.containsKey(OptionKey.QUERY)) {
            query.append("(").append(Ecl.or(search.getCollection(OptionKey.QUERY, String.class))).append(")");
        } else {
            query.append(Ecl.ANY);
        }
        if (search.containsKey(OptionKey.MUST_NOT_QUERY)) {
            query.append(" MINUS (").append(Ecl.or(search.getCollection(OptionKey.MUST_NOT_QUERY, String.class))).append(")");
        }
        req.filterByEcl(query.toString());
    }
    boolean requestedExpand = search.containsKey(OptionKey.EXPAND);
    // make sure preferredDescriptions() and displayTermType expansion data are always loaded
    Options expand = ExpandParser.parse("preferredDescriptions()").merge(requestedExpand ? search.getOptions(OptionKey.EXPAND) : Options.empty());
    if (!Strings.isNullOrEmpty(displayTermType.getExpand())) {
        expand = ExpandParser.parse(displayTermType.getExpand()).merge(expand);
    }
    SnomedConcepts matches = req.setLocales(search.getList(OptionKey.LOCALES, ExtendedLocale.class)).setSearchAfter(search.getString(OptionKey.AFTER)).setLimit(search.get(OptionKey.LIMIT, Integer.class)).setFields(search.getList(OptionKey.FIELDS, String.class)).setExpand(expand).sortBy(search.containsKey(SearchResourceRequest.OptionKey.SORT_BY) ? search.getList(SearchResourceRequest.OptionKey.SORT_BY, SearchResourceRequest.Sort.class) : null).build(uri).execute(context);
    return new Concepts(matches.stream().map(concept -> toConcept(uri, concept, displayTermType.getLabel(concept), requestedExpand)).collect(Collectors.toList()), matches.getSearchAfter(), matches.getLimit(), matches.getTotal());
}
Also used : Options(com.b2international.commons.options.Options) SnomedConcepts(com.b2international.snowowl.snomed.core.domain.SnomedConcepts) Concepts(com.b2international.snowowl.core.domain.Concepts) SnomedDisplayTermType(com.b2international.snowowl.snomed.core.SnomedDisplayTermType) SnomedConcepts(com.b2international.snowowl.snomed.core.domain.SnomedConcepts) SnomedConceptSearchRequestBuilder(com.b2international.snowowl.snomed.datastore.request.SnomedConceptSearchRequestBuilder) SearchResourceRequest(com.b2international.snowowl.core.request.SearchResourceRequest)

Example 2 with SnomedDisplayTermType

use of com.b2international.snowowl.snomed.core.SnomedDisplayTermType in project snow-owl by b2ihealthcare.

the class SnomedConceptMapSearchRequestEvaluator method toCollectionResource.

private ConceptMapMappings toCollectionResource(SnomedReferenceSetMembers referenceSetMembers, ResourceURI uri, ServiceProvider context, Options search, SnomedDisplayTermType snomedDisplayTermType) {
    final Set<String> refSetsToFetch = referenceSetMembers.stream().map(SnomedReferenceSetMember::getRefsetId).collect(Collectors.toSet());
    final Map<String, SnomedConcept> refSetsById = SnomedRequests.prepareSearchConcept().all().filterByIds(refSetsToFetch).setLocales(search.getList(OptionKey.LOCALES, ExtendedLocale.class)).setExpand("pt(),referenceSet()").build(uri).execute(context.service(IEventBus.class)).getSync(1, TimeUnit.MINUTES).stream().collect(Collectors.toMap(SnomedConcept::getId, concept -> concept));
    final Map<String, ComponentURI> targetComponentsByRefSetId = getTargetComponentsByRefSetId(context, refSetsById);
    List<ConceptMapMapping> mappings = referenceSetMembers.stream().filter(m -> SnomedConcept.TYPE.equals(m.getReferencedComponent().getComponentType())).map(m -> {
        return toMapping(m, uri, targetComponentsByRefSetId.get(m.getRefsetId()), snomedDisplayTermType, refSetsById);
    }).collect(Collectors.toList());
    if (!mappings.isEmpty()) {
        final Map<String, Concept> conceptsById = Multimaps.index(mappings, mapping -> mapping.getTargetComponentURI().resourceUri()).asMap().entrySet().stream().filter(entry -> !TerminologyRegistry.UNSPECIFIED.equals(entry.getKey().getResourceId())).map(entry -> {
            final Set<String> idsToFetch = entry.getValue().stream().map(map -> map.getTargetComponentURI().identifier()).collect(Collectors.toSet());
            return CodeSystemRequests.prepareSearchConcepts().all().filterByCodeSystemUri(entry.getKey()).filterByIds(idsToFetch).buildAsync().execute(context.service(IEventBus.class)).getSync(5, TimeUnit.MINUTES).stream().collect(Collectors.toMap(Concept::getId, c -> c));
        }).flatMap(map -> map.entrySet().stream()).collect(Collectors.toMap(entry -> entry.getKey(), entry -> entry.getValue(), (concept1, concept2) -> concept1));
        mappings = mappings.stream().map(mapping -> {
            final String mapTargetId = mapping.getTargetComponentURI().identifier();
            if (conceptsById.containsKey(mapTargetId) && !mapping.getTargetComponentURI().isUnspecified()) {
                final Concept concept = conceptsById.get(mapTargetId);
                return mapping.toBuilder().targetTerm(concept.getTerm()).targetIconId(concept.getIconId()).build();
            } else {
                return mapping;
            }
        }).collect(Collectors.toList());
    }
    return new ConceptMapMappings(mappings, referenceSetMembers.getSearchAfter(), referenceSetMembers.getLimit(), referenceSetMembers.getTotal());
}
Also used : CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) SnomedRefSetUtil(com.b2international.snowowl.snomed.datastore.SnomedRefSetUtil) ConceptMapMappingSearchRequestEvaluator(com.b2international.snowowl.core.request.ConceptMapMappingSearchRequestEvaluator) SnomedDisplayTermType(com.b2international.snowowl.snomed.core.SnomedDisplayTermType) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) Multimaps(com.google.common.collect.Multimaps) Strings(com.google.common.base.Strings) ExtendedLocale(com.b2international.commons.http.ExtendedLocale) Options(com.b2international.commons.options.Options) ConceptMapMappings(com.b2international.snowowl.core.domain.ConceptMapMappings) Map(java.util.Map) ResourceURI(com.b2international.snowowl.core.ResourceURI) SnomedReferenceSetMembers(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers) ConceptMapMapping(com.b2international.snowowl.core.domain.ConceptMapMapping) Collection(java.util.Collection) MappingCorrelation(com.b2international.snowowl.core.request.MappingCorrelation) Set(java.util.Set) ComponentURI(com.b2international.snowowl.core.uri.ComponentURI) Builder(com.b2international.snowowl.core.domain.ConceptMapMapping.Builder) IEventBus(com.b2international.snowowl.eventbus.IEventBus) Collectors(java.util.stream.Collectors) TerminologyRegistry(com.b2international.snowowl.core.terminology.TerminologyRegistry) TimeUnit(java.util.concurrent.TimeUnit) ResourceDocument(com.b2international.snowowl.core.internal.ResourceDocument) List(java.util.List) Concept(com.b2international.snowowl.core.domain.Concept) SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) ServiceProvider(com.b2international.snowowl.core.ServiceProvider) CodeSystemRequests(com.b2international.snowowl.core.codesystem.CodeSystemRequests) SnomedRf2Headers(com.b2international.snowowl.snomed.common.SnomedRf2Headers) SnomedReferenceSet(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSet) OptionsBuilder(com.b2international.commons.options.OptionsBuilder) SnomedRefSetType(com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) Concept(com.b2international.snowowl.core.domain.Concept) ConceptMapMapping(com.b2international.snowowl.core.domain.ConceptMapMapping) ComponentURI(com.b2international.snowowl.core.uri.ComponentURI) ExtendedLocale(com.b2international.commons.http.ExtendedLocale) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) ConceptMapMappings(com.b2international.snowowl.core.domain.ConceptMapMappings)

Example 3 with SnomedDisplayTermType

use of com.b2international.snowowl.snomed.core.SnomedDisplayTermType in project snow-owl by b2ihealthcare.

the class SnomedConceptMapSearchRequestEvaluator method evaluate.

@Override
public ConceptMapMappings evaluate(ResourceURI uri, ServiceProvider context, Options search) {
    final String preferredDisplay = search.get(OptionKey.DISPLAY, String.class);
    final SnomedDisplayTermType snomedDisplayTermType = SnomedDisplayTermType.getEnum(preferredDisplay);
    SnomedReferenceSetMembers referenceSetMembers = fetchRefsetMembers(uri, context, search, snomedDisplayTermType);
    return toCollectionResource(referenceSetMembers, uri, context, search, snomedDisplayTermType);
}
Also used : SnomedDisplayTermType(com.b2international.snowowl.snomed.core.SnomedDisplayTermType) SnomedReferenceSetMembers(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers)

Aggregations

SnomedDisplayTermType (com.b2international.snowowl.snomed.core.SnomedDisplayTermType)3 Options (com.b2international.commons.options.Options)2 SnomedReferenceSetMembers (com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers)2 ExtendedLocale (com.b2international.commons.http.ExtendedLocale)1 OptionsBuilder (com.b2international.commons.options.OptionsBuilder)1 ResourceURI (com.b2international.snowowl.core.ResourceURI)1 ServiceProvider (com.b2international.snowowl.core.ServiceProvider)1 CodeSystem (com.b2international.snowowl.core.codesystem.CodeSystem)1 CodeSystemRequests (com.b2international.snowowl.core.codesystem.CodeSystemRequests)1 Concept (com.b2international.snowowl.core.domain.Concept)1 ConceptMapMapping (com.b2international.snowowl.core.domain.ConceptMapMapping)1 Builder (com.b2international.snowowl.core.domain.ConceptMapMapping.Builder)1 ConceptMapMappings (com.b2international.snowowl.core.domain.ConceptMapMappings)1 Concepts (com.b2international.snowowl.core.domain.Concepts)1 ResourceDocument (com.b2international.snowowl.core.internal.ResourceDocument)1 ConceptMapMappingSearchRequestEvaluator (com.b2international.snowowl.core.request.ConceptMapMappingSearchRequestEvaluator)1 MappingCorrelation (com.b2international.snowowl.core.request.MappingCorrelation)1 SearchResourceRequest (com.b2international.snowowl.core.request.SearchResourceRequest)1 TerminologyRegistry (com.b2international.snowowl.core.terminology.TerminologyRegistry)1 ComponentURI (com.b2international.snowowl.core.uri.ComponentURI)1