Search in sources :

Example 26 with Options

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

the class SnomedDescriptionConverter method expandType.

private void expandType(List<SnomedDescription> results, final Set<String> descriptionIds) {
    if (expand().containsKey("type")) {
        final Options expandOptions = expand().get("type", Options.class);
        final Iterable<String> typeIds = FluentIterable.from(results).transform(SnomedDescription::getTypeId);
        context().service(SnomedConceptRequestCache.class).request(typeIds, expandOptions.getOptions("expand"), locales(), typesById -> {
            for (SnomedDescription description : results) {
                ((SnomedDescription) description).setType(typesById.get(description.getTypeId()));
            }
        });
    }
}
Also used : Options(com.b2international.commons.options.Options) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) SnomedConceptRequestCache(com.b2international.snowowl.snomed.datastore.request.SnomedConceptRequestCache)

Example 27 with Options

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

the class SnomedDescriptionConverter method expandConcept.

private void expandConcept(List<SnomedDescription> results, final Set<String> descriptionIds) {
    if (expand().containsKey("concept")) {
        final Options expandOptions = expand().get("concept", Options.class);
        final Iterable<String> conceptIds = FluentIterable.from(results).transform(SnomedDescription::getConceptId);
        context().service(SnomedConceptRequestCache.class).request(conceptIds, expandOptions.getOptions("expand"), locales(), conceptsById -> {
            for (SnomedDescription description : results) {
                ((SnomedDescription) description).setConcept(conceptsById.get(description.getConceptId()));
            }
        });
    }
}
Also used : Options(com.b2international.commons.options.Options) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) SnomedConceptRequestCache(com.b2international.snowowl.snomed.datastore.request.SnomedConceptRequestCache)

Example 28 with Options

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

the class SnomedDescriptionConverter method expandCaseSignificance.

private void expandCaseSignificance(List<SnomedDescription> results) {
    if (!expand().containsKey("caseSignificance")) {
        return;
    }
    final Iterable<String> caseSignificanceIds = results.stream().map(SnomedDescription::getCaseSignificanceId)::iterator;
    final Options caseSignificanceExpand = expand().get("caseSignificance", Options.class);
    context().service(SnomedConceptRequestCache.class).request(caseSignificanceIds, caseSignificanceExpand.getOptions("expand"), locales(), caseSignificancesById -> {
        for (SnomedDescription result : results) {
            result.setCaseSignificance(caseSignificancesById.get(result.getCaseSignificanceId()));
        }
    });
}
Also used : Options(com.b2international.commons.options.Options) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) SnomedConceptRequestCache(com.b2international.snowowl.snomed.datastore.request.SnomedConceptRequestCache)

Example 29 with Options

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

the class SnomedReferenceSetMemberConverter method expandComponentCategory.

private void expandComponentCategory(Options expandOptions, Multimap<String, SnomedReferenceSetMember> referencedComponentIdToMemberMap, Multimap<ComponentCategory, String> componentCategoryToIdMap, ComponentCategory category) {
    final Collection<String> componentIds = componentCategoryToIdMap.get(category);
    final SearchResourceRequestBuilder<?, BranchContext, ? extends CollectionResource<? extends SnomedCoreComponent>> search;
    switch(category) {
        case CONCEPT:
            search = SnomedRequests.prepareSearchConcept();
            break;
        case DESCRIPTION:
            search = SnomedRequests.prepareSearchDescription();
            break;
        case RELATIONSHIP:
            search = SnomedRequests.prepareSearchRelationship();
            break;
        default:
            throw new UnsupportedOperationException("Category is not supported in referenced component expansion");
    }
    search.filterByIds(componentIds).setLimit(componentIds.size()).setLocales(locales()).setExpand(expandOptions.get("expand", Options.class));
    CollectionResource<? extends SnomedCoreComponent> components = search.build().execute(context());
    for (SnomedCoreComponent component : components) {
        for (SnomedReferenceSetMember member : referencedComponentIdToMemberMap.get(component.getId())) {
            ((SnomedReferenceSetMember) member).setReferencedComponent(component);
        }
    }
}
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) BranchContext(com.b2international.snowowl.core.domain.BranchContext)

Example 30 with Options

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

the class SnomedReferenceSetMemberConverter method expandTargetComponent.

private void expandTargetComponent(List<SnomedReferenceSetMember> results) {
    if (expand().containsKey(SnomedReferenceSetMember.Expand.TARGET_COMPONENT)) {
        final Options expandOptions = expand().get(SnomedReferenceSetMember.Expand.TARGET_COMPONENT, Options.class);
        final Multimap<String, SnomedReferenceSetMember> membersByTargetComponent = HashMultimap.create();
        for (SnomedReferenceSetMember member : results) {
            final Map<String, Object> props = member.getProperties();
            if (props.containsKey(SnomedRf2Headers.FIELD_TARGET_COMPONENT_ID)) {
                membersByTargetComponent.put(((String) props.get(SnomedRf2Headers.FIELD_TARGET_COMPONENT_ID)), member);
            }
        }
        final Multimap<ComponentCategory, String> targetComponentIdsByCategory = Multimaps.index(membersByTargetComponent.keySet(), new Function<String, ComponentCategory>() {

            @Override
            public ComponentCategory apply(String id) {
                return SnomedIdentifiers.getComponentCategory(id);
            }
        });
        for (ComponentCategory category : targetComponentIdsByCategory.keySet()) {
            final Collection<String> targetComponentIds = targetComponentIdsByCategory.get(category);
            final Map<String, ? extends SnomedCoreComponent> componentsById = Maps.uniqueIndex(getComponents(category, targetComponentIds, expandOptions.get("expand", Options.class)), IComponent::getId);
            for (String targetComponentId : targetComponentIds) {
                final SnomedCoreComponent targetComponent = componentsById.get(targetComponentId);
                if (targetComponent != null) {
                    for (SnomedReferenceSetMember member : membersByTargetComponent.get(targetComponentId)) {
                        final Map<String, Object> newProps = newHashMap(member.getProperties());
                        newProps.put(SnomedReferenceSetMember.Expand.TARGET_COMPONENT, targetComponent);
                        ((SnomedReferenceSetMember) member).setProperties(newProps);
                    }
                }
            }
        }
    }
}
Also used : Options(com.b2international.commons.options.Options) SnomedCoreComponent(com.b2international.snowowl.snomed.core.domain.SnomedCoreComponent) IComponent(com.b2international.snowowl.core.domain.IComponent) ComponentCategory(com.b2international.snowowl.core.terminology.ComponentCategory) SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember)

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