Search in sources :

Example 46 with Options

use of com.b2international.commons.options.Options in project snow-owl by b2ihealthcare.

the class SnomedRelationshipConverter method expandSource.

private void expandSource(List<SnomedRelationship> results) {
    if (expand().containsKey(SnomedRelationship.Expand.SOURCE)) {
        final Options sourceOptions = expand().get(SnomedRelationship.Expand.SOURCE, Options.class);
        final Iterable<String> sourceConceptIds = FluentIterable.from(results).transform(SnomedRelationship::getSourceId);
        context().service(SnomedConceptRequestCache.class).request(sourceConceptIds, sourceOptions.getOptions("expand"), locales(), sourceConceptsById -> {
            for (SnomedRelationship relationship : results) {
                final String sourceId = relationship.getSourceId();
                if (sourceConceptsById.containsKey(sourceId)) {
                    final SnomedConcept sourceConcept = sourceConceptsById.get(sourceId);
                    ((SnomedRelationship) relationship).setSource(sourceConcept);
                }
            }
        });
    }
}
Also used : Options(com.b2international.commons.options.Options) SnomedRelationship(com.b2international.snowowl.snomed.core.domain.SnomedRelationship) SnomedConceptRequestCache(com.b2international.snowowl.snomed.datastore.request.SnomedConceptRequestCache) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept)

Example 47 with Options

use of com.b2international.commons.options.Options in project snow-owl by b2ihealthcare.

the class MembersExpander method expand.

void expand(List<? extends SnomedCoreComponent> results, Set<String> componentIds) {
    if (expand.containsKey("members")) {
        final Options membersOptions = expand.get("members", Options.class);
        // TODO better support for limit, offset, filtering, selection
        final SnomedRefSetMemberSearchRequestBuilder requestBuilder = SnomedRequests.prepareSearchMember().all().filterByReferencedComponent(componentIds);
        addActiveFilter(requestBuilder, membersOptions);
        addRefSetTypesFilter(requestBuilder, membersOptions);
        final OptionsBuilder propertyOptionsBuilder = OptionsBuilder.newBuilder();
        addCharacteristicTypeFilter(propertyOptionsBuilder, membersOptions);
        final Options propertyOptions = propertyOptionsBuilder.build();
        if (!propertyOptions.isEmpty()) {
            requestBuilder.filterByProps(propertyOptions);
        }
        final SnomedReferenceSetMembers matchingMembers = requestBuilder.setLocales(locales).setExpand(membersOptions.get("expand", Options.class)).build().execute(context);
        final Multimap<String, SnomedReferenceSetMember> membersByReferencedComponentId = Multimaps.index(matchingMembers, input -> input.getReferencedComponent().getId());
        for (SnomedCoreComponent component : results) {
            final Collection<SnomedReferenceSetMember> members = membersByReferencedComponentId.get(component.getId());
            ((SnomedCoreComponent) component).setMembers(new SnomedReferenceSetMembers(ImmutableList.copyOf(members), null, members.size(), members.size()));
        }
    }
}
Also used : SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) Options(com.b2international.commons.options.Options) SnomedCoreComponent(com.b2international.snowowl.snomed.core.domain.SnomedCoreComponent) SnomedReferenceSetMembers(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers) SnomedRefSetMemberSearchRequestBuilder(com.b2international.snowowl.snomed.datastore.request.SnomedRefSetMemberSearchRequestBuilder) OptionsBuilder(com.b2international.commons.options.OptionsBuilder)

Example 48 with Options

use of com.b2international.commons.options.Options in project snow-owl by b2ihealthcare.

the class SnomedConceptConverter method expandDefinitionStatus.

private void expandDefinitionStatus(List<SnomedConcept> results) {
    if (!expand().containsKey(SnomedConcept.Expand.DEFINITION_STATUS)) {
        return;
    }
    final Options definitionStatusExpand = expand().getOptions(SnomedConcept.Expand.DEFINITION_STATUS).getOptions("expand");
    final Iterable<String> definitionStatusIds = results.stream().map(SnomedConcept::getDefinitionStatusId)::iterator;
    context().service(SnomedConceptRequestCache.class).request(definitionStatusIds, definitionStatusExpand, locales(), definitionStatusesById -> {
        for (SnomedConcept result : results) {
            result.setDefinitionStatus(definitionStatusesById.get(result.getDefinitionStatusId()));
        }
    });
}
Also used : Options(com.b2international.commons.options.Options) SnomedConceptRequestCache(com.b2international.snowowl.snomed.datastore.request.SnomedConceptRequestCache)

Example 49 with Options

use of com.b2international.commons.options.Options in project snow-owl by b2ihealthcare.

the class SnomedConceptConverter method expandAncestors.

private void expandAncestors(List<SnomedConcept> results, Set<String> conceptIds, String ancestorsExpandKey, boolean stated) {
    if (!expand().containsKey(ancestorsExpandKey)) {
        return;
    }
    final Options expandOptions = expand().get(ancestorsExpandKey, Options.class);
    final boolean direct = DescendantsExpander.checkDirect(expandOptions, ancestorsExpandKey);
    final Multimap<String, String> ancestorsByDescendant = TreeMultimap.create();
    for (SnomedConcept concept : results) {
        final long[] parentIds = stated ? concept.getStatedParentIds() : concept.getParentIds();
        if (parentIds != null) {
            for (long parent : parentIds) {
                if (IComponent.ROOT_IDL != parent) {
                    ancestorsByDescendant.put(concept.getId(), Long.toString(parent));
                }
            }
        }
        if (!direct) {
            final long[] ancestorIds = stated ? concept.getStatedAncestorIds() : concept.getAncestorIds();
            if (ancestorIds != null) {
                for (long ancestor : ancestorIds) {
                    if (IComponent.ROOT_IDL != ancestor) {
                        ancestorsByDescendant.put(concept.getId(), Long.toString(ancestor));
                    }
                }
            }
        }
    }
    final int limit = getLimit(expandOptions);
    final Collection<String> componentIds = newHashSet(ancestorsByDescendant.values());
    if (limit > 0 && !componentIds.isEmpty()) {
        final SnomedConcepts ancestors = SnomedRequests.prepareSearchConcept().all().filterByIds(componentIds).setLocales(locales()).setExpand(expandOptions.get("expand", Options.class)).build().execute(context());
        final Map<String, SnomedConcept> ancestorsById = newHashMap();
        ancestorsById.putAll(Maps.uniqueIndex(ancestors, SnomedConcept::getId));
        for (SnomedConcept concept : results) {
            final Collection<String> ancestorIds = ancestorsByDescendant.get(concept.getId());
            final List<SnomedConcept> conceptAncestors = FluentIterable.from(ancestorIds).limit(limit).transform(Functions.forMap(ancestorsById)).toList();
            final SnomedConcepts ancestorConcepts = new SnomedConcepts(conceptAncestors, null, limit, ancestorIds.size());
            if (stated) {
                concept.setStatedAncestors(ancestorConcepts);
            } else {
                concept.setAncestors(ancestorConcepts);
            }
        }
    } else {
        for (SnomedConcept concept : results) {
            final Collection<String> ancestorIds = ancestorsByDescendant.get(concept.getId());
            final SnomedConcepts ancestors = new SnomedConcepts(limit, ancestorIds.size());
            if (stated) {
                concept.setStatedAncestors(ancestors);
            } else {
                concept.setAncestors(ancestors);
            }
        }
    }
}
Also used : Options(com.b2international.commons.options.Options)

Example 50 with Options

use of com.b2international.commons.options.Options in project snow-owl by b2ihealthcare.

the class SnomedDescriptionConverter method expandAcceptabilities.

private void expandAcceptabilities(List<SnomedDescription> results) {
    if (!expand().containsKey("acceptabilities")) {
        return;
    }
    // expand the acceptability objects first
    for (SnomedDescription result : results) {
        if (!CompareUtils.isEmpty(result.getAcceptabilityMap())) {
            List<AcceptabilityMembership> acceptabilities = result.getAcceptabilityMap().entrySet().stream().map(entry -> new AcceptabilityMembership(entry.getKey(), entry.getValue().getConceptId())).sorted().collect(Collectors.toList());
            result.setAcceptabilities(acceptabilities);
        } else {
            result.setAcceptabilities(Collections.emptyList());
        }
    }
    // additional expansions supported inside the acceptabilities() expand
    final Options expandOptions = expand().get("acceptabilities", Options.class).getOptions("expand");
    if (expandOptions.containsKey("acceptability")) {
        final Options acceptabilityExpand = expandOptions.get("acceptability", Options.class);
        final Iterable<String> acceptabilityIds = results.stream().flatMap(d -> d.getAcceptabilities().stream().map(AcceptabilityMembership::getAcceptabilityId))::iterator;
        context().service(SnomedConceptRequestCache.class).request(acceptabilityIds, acceptabilityExpand.getOptions("expand"), locales(), acceptabilitiesById -> {
            for (SnomedDescription result : results) {
                result.getAcceptabilities().forEach(acceptabilityMembership -> {
                    acceptabilityMembership.setAcceptability(acceptabilitiesById.get(acceptabilityMembership.getAcceptabilityId()));
                });
            }
        });
    }
    if (expandOptions.containsKey("languageRefSet")) {
        final Options languageRefSetExpand = expandOptions.get("languageRefSet", Options.class);
        final Iterable<String> languageRefSetIds = results.stream().flatMap(d -> d.getAcceptabilities().stream().map(AcceptabilityMembership::getLanguageRefSetId))::iterator;
        context().service(SnomedConceptRequestCache.class).request(languageRefSetIds, languageRefSetExpand.getOptions("expand"), locales(), languageRefSetsById -> {
            for (SnomedDescription result : results) {
                result.getAcceptabilities().forEach(acceptabilityMembership -> {
                    acceptabilityMembership.setLanguageRefSet(languageRefSetsById.get(acceptabilityMembership.getLanguageRefSetId()));
                });
            }
        });
    }
}
Also used : SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) AcceptabilityMembership(com.b2international.snowowl.snomed.core.domain.AcceptabilityMembership) Set(java.util.Set) Collectors(java.util.stream.Collectors) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) BaseRevisionResourceConverter(com.b2international.snowowl.core.request.BaseRevisionResourceConverter) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) List(java.util.List) ExtendedLocale(com.b2international.commons.http.ExtendedLocale) Options(com.b2international.commons.options.Options) FluentIterable(com.google.common.collect.FluentIterable) SnomedDescriptions(com.b2international.snowowl.snomed.core.domain.SnomedDescriptions) SnomedDescriptionIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionIndexEntry) CompareUtils(com.b2international.commons.CompareUtils) BranchContext(com.b2international.snowowl.core.domain.BranchContext) Collections(java.util.Collections) SnomedConceptRequestCache(com.b2international.snowowl.snomed.datastore.request.SnomedConceptRequestCache) Options(com.b2international.commons.options.Options) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) AcceptabilityMembership(com.b2international.snowowl.snomed.core.domain.AcceptabilityMembership) SnomedConceptRequestCache(com.b2international.snowowl.snomed.datastore.request.SnomedConceptRequestCache)

Aggregations

Options (com.b2international.commons.options.Options)57 List (java.util.List)15 Collectors (java.util.stream.Collectors)14 Set (java.util.Set)13 ExtendedLocale (com.b2international.commons.http.ExtendedLocale)11 BranchContext (com.b2international.snowowl.core.domain.BranchContext)11 SnomedConcept (com.b2international.snowowl.snomed.core.domain.SnomedConcept)11 SnomedConceptRequestCache (com.b2international.snowowl.snomed.datastore.request.SnomedConceptRequestCache)11 Test (org.junit.Test)9 SnomedReferenceSetMember (com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember)8 Map (java.util.Map)8 Concepts (com.b2international.snowowl.snomed.common.SnomedConstants.Concepts)7 SnomedConcepts (com.b2international.snowowl.snomed.core.domain.SnomedConcepts)7 BadRequestException (com.b2international.commons.exceptions.BadRequestException)6 ResourceURI (com.b2international.snowowl.core.ResourceURI)6 RepositoryContext (com.b2international.snowowl.core.domain.RepositoryContext)6 SnomedRelationship (com.b2international.snowowl.snomed.core.domain.SnomedRelationship)6 SnomedRequests (com.b2international.snowowl.snomed.datastore.request.SnomedRequests)6 Multimaps (com.google.common.collect.Multimaps)6 Collection (java.util.Collection)6