Search in sources :

Example 1 with SnomedCoreComponent

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

the class MapTypeRefSetDSVExporter method prepareLabelCache.

private Map<String, String> prepareLabelCache(SnomedReferenceSetMembers membersToExport) {
    final SnomedConcepts modelComponents = SnomedRequests.prepareSearchConcept().all().filterByActive(true).filterByEcl(String.format("< (%s OR %s) ", Concepts.MODULE_ROOT, Concepts.REFSET_ATTRIBUTE)).setExpand("fsn()").setLocales(exportSetting.getLocales()).build().execute(context);
    final Map<String, String> labels = newHashMapWithExpectedSize(membersToExport.getTotal() + modelComponents.getTotal());
    modelComponents.forEach(modelComponent -> {
        labels.put(modelComponent.getId(), getFsnOrId(modelComponent));
    });
    for (SnomedReferenceSetMember snomedReferenceSetMember : membersToExport) {
        SnomedCoreComponent referencedComponent = snomedReferenceSetMember.getReferencedComponent();
        String id = referencedComponent.getId();
        if (referencedComponent instanceof SnomedConcept) {
            labels.put(id, getFsnOrId((SnomedConcept) referencedComponent));
        } else if (referencedComponent instanceof SnomedDescription) {
            labels.put(id, ((SnomedDescription) referencedComponent).getTerm());
        } else if (referencedComponent instanceof SnomedRelationship) {
            SnomedRelationship relationship = (SnomedRelationship) referencedComponent;
            if (relationship.hasValue()) {
                labels.put(id, String.format("%s - %s - %s", relationship.getSourceId(), relationship.getTypeId(), relationship.getValue()));
            } else {
                labels.put(id, String.format("%s - %s - %s", relationship.getSourceId(), relationship.getTypeId(), relationship.getDestinationId()));
            }
        }
    }
    return labels;
}
Also used : SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) SnomedCoreComponent(com.b2international.snowowl.snomed.core.domain.SnomedCoreComponent) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) SnomedRelationship(com.b2international.snowowl.snomed.core.domain.SnomedRelationship) SnomedConcepts(com.b2international.snowowl.snomed.core.domain.SnomedConcepts) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept)

Example 2 with SnomedCoreComponent

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

the class SnomedReferenceSetMemberConverter method setReferencedComponent.

private void setReferencedComponent(SnomedReferenceSetMember member, String referencedComponentId, String referencedComponentType) {
    // XXX: partial field loading support
    if (referencedComponentType == null || referencedComponentId == null)
        return;
    final SnomedCoreComponent component;
    switch(referencedComponentType) {
        // TODO support query type refset refcomp expansion, currently it's a concept
        case SnomedConcept.REFSET_TYPE:
        case SnomedConcept.TYPE:
            component = new SnomedConcept();
            ((SnomedConcept) component).setId(referencedComponentId);
            break;
        case SnomedDescription.TYPE:
            component = new SnomedDescription();
            ((SnomedDescription) component).setId(referencedComponentId);
            break;
        case SnomedRelationship.TYPE:
            component = new SnomedRelationship();
            ((SnomedRelationship) component).setId(referencedComponentId);
            break;
        default:
            throw new UnsupportedOperationException("UnsupportedReferencedComponentType: " + referencedComponentType);
    }
    member.setReferencedComponent(component);
}
Also used : SnomedCoreComponent(com.b2international.snowowl.snomed.core.domain.SnomedCoreComponent) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) SnomedRelationship(com.b2international.snowowl.snomed.core.domain.SnomedRelationship) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept)

Example 3 with SnomedCoreComponent

use of com.b2international.snowowl.snomed.core.domain.SnomedCoreComponent 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 4 with SnomedCoreComponent

use of com.b2international.snowowl.snomed.core.domain.SnomedCoreComponent 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)

Example 5 with SnomedCoreComponent

use of com.b2international.snowowl.snomed.core.domain.SnomedCoreComponent 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)

Aggregations

SnomedCoreComponent (com.b2international.snowowl.snomed.core.domain.SnomedCoreComponent)6 Options (com.b2international.commons.options.Options)4 SnomedReferenceSetMember (com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember)4 BranchContext (com.b2international.snowowl.core.domain.BranchContext)2 SnomedConcept (com.b2international.snowowl.snomed.core.domain.SnomedConcept)2 SnomedDescription (com.b2international.snowowl.snomed.core.domain.SnomedDescription)2 SnomedRelationship (com.b2international.snowowl.snomed.core.domain.SnomedRelationship)2 OptionsBuilder (com.b2international.commons.options.OptionsBuilder)1 IComponent (com.b2international.snowowl.core.domain.IComponent)1 RevisionIndexReadRequest (com.b2international.snowowl.core.request.RevisionIndexReadRequest)1 ComponentCategory (com.b2international.snowowl.core.terminology.ComponentCategory)1 SnomedConcepts (com.b2international.snowowl.snomed.core.domain.SnomedConcepts)1 SnomedReferenceSetMembers (com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers)1 SnomedRefSetMemberSearchRequestBuilder (com.b2international.snowowl.snomed.datastore.request.SnomedRefSetMemberSearchRequestBuilder)1