Search in sources :

Example 6 with RevisionIndexReadRequest

use of com.b2international.snowowl.core.request.RevisionIndexReadRequest in project snow-owl by b2ihealthcare.

the class ConceptChangeConverter method expand.

@Override
public void expand(final List<ConceptChange> results) {
    if (!expand().containsKey(ConceptChange.Expand.CONCEPT)) {
        return;
    }
    /*
		 * Depending on the concept change search request, we might need to issue
		 * SNOMED CT searches against multiple branches; find out which ones we have.
		 */
    final Multimap<String, ConceptChange> itemsByBranch = getItemsByBranch(results);
    // Check if we only need to load inferred concepts in their entirety
    final Options expandOptions = expand().getOptions(ConceptChange.Expand.CONCEPT);
    // pt() and fsn() are the only useful options here
    final Options conceptExpandOptions = expandOptions.getOptions("expand");
    conceptExpandOptions.keySet().retainAll(CONCEPT_EXPAND_OPTIONS);
    for (final String branch : itemsByBranch.keySet()) {
        final Collection<ConceptChange> itemsForCurrentBranch = itemsByBranch.get(branch);
        final Set<String> conceptIds = itemsForCurrentBranch.stream().map(c -> c.getConcept().getOriginConceptId()).collect(Collectors.toSet());
        final Request<BranchContext, SnomedConcepts> conceptSearchRequest = SnomedRequests.prepareSearchConcept().filterByIds(conceptIds).setLimit(conceptIds.size()).setExpand(conceptExpandOptions).setLocales(locales()).build();
        final SnomedConcepts concepts = new BranchRequest<>(branch, new RevisionIndexReadRequest<>(conceptSearchRequest)).execute(context());
        final Map<String, SnomedConcept> conceptsById = Maps.uniqueIndex(concepts, SnomedConcept::getId);
        for (final ConceptChange item : itemsForCurrentBranch) {
            final ReasonerConcept reasonerConcept = item.getConcept();
            final String conceptId = reasonerConcept.getOriginConceptId();
            final SnomedConcept expandedConcept = conceptsById.get(conceptId);
            reasonerConcept.setDefinitionStatusId(expandedConcept.getDefinitionStatusId());
            reasonerConcept.setPt(expandedConcept.getPt());
            reasonerConcept.setFsn(expandedConcept.getFsn());
        // reasonerConcept.setReleased(...) is already set
        }
    }
}
Also used : SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) BranchRequest(com.b2international.snowowl.core.request.BranchRequest) RepositoryContext(com.b2international.snowowl.core.domain.RepositoryContext) ImmutableSet(com.google.common.collect.ImmutableSet) ClassificationRequests(com.b2international.snowowl.snomed.reasoner.request.ClassificationRequests) Collection(java.util.Collection) Request(com.b2international.snowowl.core.events.Request) SnomedConcepts(com.b2international.snowowl.snomed.core.domain.SnomedConcepts) com.b2international.snowowl.snomed.reasoner.domain(com.b2international.snowowl.snomed.reasoner.domain) Set(java.util.Set) Multimap(com.google.common.collect.Multimap) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) RevisionIndexReadRequest(com.b2international.snowowl.core.request.RevisionIndexReadRequest) Multimaps(com.google.common.collect.Multimaps) List(java.util.List) ExtendedLocale(com.b2international.commons.http.ExtendedLocale) SnomedRequests(com.b2international.snowowl.snomed.datastore.request.SnomedRequests) Options(com.b2international.commons.options.Options) Map(java.util.Map) ConceptChangeDocument(com.b2international.snowowl.snomed.reasoner.index.ConceptChangeDocument) BranchContext(com.b2international.snowowl.core.domain.BranchContext) BaseResourceConverter(com.b2international.snowowl.core.request.BaseResourceConverter) Options(com.b2international.commons.options.Options) RevisionIndexReadRequest(com.b2international.snowowl.core.request.RevisionIndexReadRequest) SnomedConcepts(com.b2international.snowowl.snomed.core.domain.SnomedConcepts) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) BranchContext(com.b2international.snowowl.core.domain.BranchContext)

Aggregations

RevisionIndexReadRequest (com.b2international.snowowl.core.request.RevisionIndexReadRequest)6 Options (com.b2international.commons.options.Options)5 BranchContext (com.b2international.snowowl.core.domain.BranchContext)5 RepositoryContext (com.b2international.snowowl.core.domain.RepositoryContext)5 BranchRequest (com.b2international.snowowl.core.request.BranchRequest)5 Collection (java.util.Collection)5 List (java.util.List)5 Set (java.util.Set)5 ExtendedLocale (com.b2international.commons.http.ExtendedLocale)4 Request (com.b2international.snowowl.core.events.Request)4 BaseResourceConverter (com.b2international.snowowl.core.request.BaseResourceConverter)4 SnomedRequests (com.b2international.snowowl.snomed.datastore.request.SnomedRequests)4 com.b2international.snowowl.snomed.reasoner.domain (com.b2international.snowowl.snomed.reasoner.domain)4 ClassificationRequests (com.b2international.snowowl.snomed.reasoner.request.ClassificationRequests)4 Maps (com.google.common.collect.Maps)4 Multimap (com.google.common.collect.Multimap)4 Multimaps (com.google.common.collect.Multimaps)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 SnomedConcept (com.b2international.snowowl.snomed.core.domain.SnomedConcept)2