Search in sources :

Example 51 with Options

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

the class ClassificationTaskConverter method expandRelationshipChanges.

private void expandRelationshipChanges(final List<ClassificationTask> results, final Set<String> classificationTaskIds) {
    if (!expand().containsKey(ClassificationTask.Expand.RELATIONSHIP_CHANGES)) {
        return;
    }
    final Options expandOptions = expand().get(ClassificationTask.Expand.RELATIONSHIP_CHANGES, Options.class);
    final RelationshipChangeSearchRequestBuilder builder = ClassificationRequests.prepareSearchRelationshipChange().all().filterByClassificationId(classificationTaskIds);
    if (expandOptions.containsKey("sourceId")) {
        builder.filterBySourceId(expandOptions.getCollection("sourceId", String.class));
    }
    final RelationshipChanges relationshipChanges = builder.setExpand(expandOptions.get("expand", Options.class)).setLocales(locales()).build().execute(context());
    final ListMultimap<String, RelationshipChange> relationshipChangesByTaskId = Multimaps.index(relationshipChanges, RelationshipChange::getClassificationId);
    for (final ClassificationTask classificationTask : results) {
        final List<RelationshipChange> taskChanges = relationshipChangesByTaskId.get(classificationTask.getId());
        classificationTask.setRelationshipChanges(new RelationshipChanges(taskChanges, null, taskChanges.size(), taskChanges.size()));
    }
}
Also used : Options(com.b2international.commons.options.Options) ClassificationTask(com.b2international.snowowl.snomed.reasoner.domain.ClassificationTask) RelationshipChange(com.b2international.snowowl.snomed.reasoner.domain.RelationshipChange) RelationshipChangeSearchRequestBuilder(com.b2international.snowowl.snomed.reasoner.request.RelationshipChangeSearchRequestBuilder) RelationshipChanges(com.b2international.snowowl.snomed.reasoner.domain.RelationshipChanges)

Example 52 with Options

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

the class ClassificationTaskConverter method expandEquivalentConceptSets.

private void expandEquivalentConceptSets(final List<ClassificationTask> results, final Set<String> classificationTaskIds) {
    if (!expand().containsKey(ClassificationTask.Expand.EQUIVALENT_CONCEPT_SETS)) {
        return;
    }
    final Options expandOptions = expand().get(ClassificationTask.Expand.EQUIVALENT_CONCEPT_SETS, Options.class);
    final EquivalentConceptSets equivalentConceptSets = ClassificationRequests.prepareSearchEquivalentConceptSet().filterByClassificationId(classificationTaskIds).all().setExpand(expandOptions.get("expand", Options.class)).setLocales(locales()).build().execute(context());
    final ListMultimap<String, EquivalentConceptSet> setsByTaskId = Multimaps.index(equivalentConceptSets, EquivalentConceptSet::getClassificationId);
    for (final ClassificationTask classificationTask : results) {
        final List<EquivalentConceptSet> taskSets = setsByTaskId.get(classificationTask.getId());
        classificationTask.setEquivalentConceptSets(new EquivalentConceptSets(taskSets, null, taskSets.size(), taskSets.size()));
    }
}
Also used : Options(com.b2international.commons.options.Options) EquivalentConceptSets(com.b2international.snowowl.snomed.reasoner.domain.EquivalentConceptSets) ClassificationTask(com.b2international.snowowl.snomed.reasoner.domain.ClassificationTask) EquivalentConceptSet(com.b2international.snowowl.snomed.reasoner.domain.EquivalentConceptSet)

Example 53 with Options

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

the class ClassificationTaskConverter method expandConcreteDomainChanges.

private void expandConcreteDomainChanges(final List<ClassificationTask> results, final Set<String> classificationTaskIds) {
    if (!expand().containsKey(ClassificationTask.Expand.CONCRETE_DOMAIN_CHANGES)) {
        return;
    }
    final Options expandOptions = expand().get(ClassificationTask.Expand.CONCRETE_DOMAIN_CHANGES, Options.class);
    final ConcreteDomainChanges concreteDomainChanges = ClassificationRequests.prepareSearchConcreteDomainChange().filterByClassificationId(classificationTaskIds).all().setExpand(expandOptions.get("expand", Options.class)).setLocales(locales()).build().execute(context());
    final ListMultimap<String, ConcreteDomainChange> concreteDomainChangesByTaskId = Multimaps.index(concreteDomainChanges, ConcreteDomainChange::getClassificationId);
    for (final ClassificationTask classificationTask : results) {
        final List<ConcreteDomainChange> taskChanges = concreteDomainChangesByTaskId.get(classificationTask.getId());
        classificationTask.setConcreteDomainChanges(new ConcreteDomainChanges(taskChanges, null, taskChanges.size(), taskChanges.size()));
    }
}
Also used : Options(com.b2international.commons.options.Options) ClassificationTask(com.b2international.snowowl.snomed.reasoner.domain.ClassificationTask) ConcreteDomainChange(com.b2international.snowowl.snomed.reasoner.domain.ConcreteDomainChange) ConcreteDomainChanges(com.b2international.snowowl.snomed.reasoner.domain.ConcreteDomainChanges)

Example 54 with Options

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

the class ConcreteDomainChangeConverter method expandComponentCategory.

// Copied from SnomedReferenceSetMemberConverter
private void expandComponentCategory(final String branch, final ComponentCategory category, final Collection<String> componentIds, final Options componentOptions, final Multimap<String, ReasonerConcreteDomainMember> membersByReferencedComponent) {
    final SearchResourceRequestBuilder<?, BranchContext, ? extends CollectionResource<? extends SnomedCoreComponent>> searchRequestBuilder = createSearchRequestBuilder(category);
    searchRequestBuilder.filterByIds(componentIds).setLimit(componentIds.size()).setLocales(locales()).setExpand(componentOptions.get("expand", Options.class));
    final CollectionResource<? extends SnomedCoreComponent> referencedComponents = new BranchRequest<>(branch, new RevisionIndexReadRequest<>(searchRequestBuilder.build())).execute(context());
    for (final SnomedCoreComponent referencedComponent : referencedComponents) {
        for (final ReasonerConcreteDomainMember member : membersByReferencedComponent.get(referencedComponent.getId())) {
            member.setReferencedComponent(referencedComponent);
        }
    }
}
Also used : Options(com.b2international.commons.options.Options) SnomedCoreComponent(com.b2international.snowowl.snomed.core.domain.SnomedCoreComponent) BranchContext(com.b2international.snowowl.core.domain.BranchContext) RevisionIndexReadRequest(com.b2international.snowowl.core.request.RevisionIndexReadRequest)

Example 55 with Options

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

the class ConcreteDomainChangeConverter method expand.

@Override
public void expand(final List<ConcreteDomainChange> results) {
    if (!expand().containsKey(ConcreteDomainChange.Expand.CONCRETE_DOMAIN_MEMBER)) {
        return;
    }
    /*
		 * Depending on the CD member change search request, we might need to issue
		 * SNOMED CT searches against multiple branches; find out which ones we have.
		 */
    final Multimap<String, ConcreteDomainChange> itemsByBranch = getItemsByBranch(results);
    // Check if we only need to load inferred CD members in their entirety
    final Options expandOptions = expand().getOptions(ConcreteDomainChange.Expand.CONCRETE_DOMAIN_MEMBER);
    final boolean inferredOnly = expandOptions.getBoolean("inferredOnly");
    final Options cdMemberExpandOptions = expandOptions.getOptions("expand");
    final Options referencedComponentOptions = cdMemberExpandOptions.getOptions(SnomedReferenceSetMember.Expand.REFERENCED_COMPONENT);
    /*
		 * Remove this option from the member expand options map, so that member search
		 * does not expand the referenced component again
		 */
    final boolean needsReferencedComponent = cdMemberExpandOptions.keySet().remove(SnomedReferenceSetMember.Expand.REFERENCED_COMPONENT);
    for (final String branch : itemsByBranch.keySet()) {
        final Collection<ConcreteDomainChange> itemsForCurrentBranch = itemsByBranch.get(branch);
        /*
			 * Expand referenced component on members via a separate search request, as they
			 * can be different from the referenced component on the "origin" member
			 */
        if (needsReferencedComponent) {
            final List<ReasonerConcreteDomainMember> blankMembers = itemsForCurrentBranch.stream().filter(c -> !inferredOnly || ChangeNature.NEW.equals(c.getChangeNature())).map(ConcreteDomainChange::getConcreteDomainMember).collect(Collectors.toList());
            final Multimap<String, ReasonerConcreteDomainMember> membersByReferencedComponent = Multimaps.index(blankMembers, ReasonerConcreteDomainMember::getReferencedComponentId);
            final Multimap<ComponentCategory, String> referencedComponentsByCategory = Multimaps.index(membersByReferencedComponent.keySet(), SnomedIdentifiers::getComponentCategory);
            for (final Entry<ComponentCategory, Collection<String>> categoryEntry : referencedComponentsByCategory.asMap().entrySet()) {
                expandComponentCategory(branch, categoryEntry.getKey(), categoryEntry.getValue(), referencedComponentOptions, membersByReferencedComponent);
            }
        }
        /*
			 * Then fetch all the required members (these will have a referenced component
			 * ID that should no longer be copied on inferred members). Note that the same "origin"
			 * member might be used for multiple eg. "new" counterparts.
			 */
        final Set<String> cdMemberUuids = itemsForCurrentBranch.stream().filter(c -> !inferredOnly || ChangeNature.NEW.equals(c.getChangeNature())).map(c -> c.getConcreteDomainMember().getOriginMemberId()).collect(Collectors.toSet());
        final Request<BranchContext, SnomedReferenceSetMembers> cdMemberSearchRequest = SnomedRequests.prepareSearchMember().filterByIds(cdMemberUuids).setLimit(cdMemberUuids.size()).setExpand(cdMemberExpandOptions).setLocales(locales()).build();
        final SnomedReferenceSetMembers cdMembers = new BranchRequest<>(branch, new RevisionIndexReadRequest<>(cdMemberSearchRequest)).execute(context());
        final Map<String, SnomedReferenceSetMember> cdMembersByUuid = Maps.uniqueIndex(cdMembers, SnomedReferenceSetMember::getId);
        /*
			 * Finally, set the member on the change item, but preserve the properties that
			 * were already set in "toResource"
			 */
        for (final ConcreteDomainChange item : itemsForCurrentBranch) {
            final ReasonerConcreteDomainMember reasonerMember = item.getConcreteDomainMember();
            final String memberUuid = reasonerMember.getOriginMemberId();
            switch(item.getChangeNature()) {
                case NEW:
                    {
                        final SnomedReferenceSetMember expandedMember = cdMembersByUuid.get(memberUuid);
                        final Map<String, Object> expandedProperties = expandedMember.getProperties();
                        // reasonerMember.setCharacteristicTypeId(...) is already set
                        // reasonerMember.setGroup(...) is already set
                        // reasonerMember.setReferencedComponent(...) is already set (or expanded)
                        reasonerMember.setReferenceSetId(expandedMember.getRefsetId());
                        // reasonerMember.setReleased(...) is already set
                        reasonerMember.setSerializedValue((String) expandedProperties.get(SnomedRf2Headers.FIELD_VALUE));
                        reasonerMember.setTypeId((String) expandedProperties.get(SnomedRf2Headers.FIELD_TYPE_ID));
                    }
                    break;
                case UPDATED:
                    if (!inferredOnly) {
                        final SnomedReferenceSetMember expandedMember = cdMembersByUuid.get(memberUuid);
                        final Map<String, Object> expandedProperties = expandedMember.getProperties();
                        reasonerMember.setCharacteristicTypeId((String) expandedProperties.get(SnomedRf2Headers.FIELD_CHARACTERISTIC_TYPE_ID));
                        reasonerMember.setGroup((Integer) expandedProperties.get(SnomedRf2Headers.FIELD_RELATIONSHIP_GROUP));
                        // reasonerMember.setReferencedComponent(...) is already set (or expanded)
                        reasonerMember.setReferenceSetId(expandedMember.getRefsetId());
                        // reasonerMember.setReleased(...) is already set
                        // reasonerMember.setSerializedValue(...) is already set
                        reasonerMember.setTypeId((String) expandedProperties.get(SnomedRf2Headers.FIELD_TYPE_ID));
                    }
                    break;
                case REDUNDANT:
                    if (!inferredOnly) {
                        final SnomedReferenceSetMember expandedMember = cdMembersByUuid.get(memberUuid);
                        final Map<String, Object> expandedProperties = expandedMember.getProperties();
                        reasonerMember.setCharacteristicTypeId((String) expandedProperties.get(SnomedRf2Headers.FIELD_CHARACTERISTIC_TYPE_ID));
                        reasonerMember.setGroup((Integer) expandedProperties.get(SnomedRf2Headers.FIELD_RELATIONSHIP_GROUP));
                        // reasonerMember.setReferencedComponent(...) is already set (or expanded)
                        reasonerMember.setReferenceSetId(expandedMember.getRefsetId());
                        // reasonerMember.setReleased(...) is already set
                        reasonerMember.setSerializedValue((String) expandedProperties.get(SnomedRf2Headers.FIELD_VALUE));
                        reasonerMember.setTypeId((String) expandedProperties.get(SnomedRf2Headers.FIELD_TYPE_ID));
                    }
                    break;
                default:
                    throw new IllegalStateException(String.format("Unexpected CD member change '%s' found with UUID '%s'.", item.getChangeNature(), item.getConcreteDomainMember().getOriginMemberId()));
            }
        }
    }
}
Also used : BranchRequest(com.b2international.snowowl.core.request.BranchRequest) com.b2international.snowowl.snomed.reasoner.domain(com.b2international.snowowl.snomed.reasoner.domain) Multimap(com.google.common.collect.Multimap) Multimaps(com.google.common.collect.Multimaps) ExtendedLocale(com.b2international.commons.http.ExtendedLocale) SnomedRequests(com.b2international.snowowl.snomed.datastore.request.SnomedRequests) Options(com.b2international.commons.options.Options) Map(java.util.Map) CollectionResource(com.b2international.snowowl.core.domain.CollectionResource) SnomedReferenceSetMembers(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers) RepositoryContext(com.b2international.snowowl.core.domain.RepositoryContext) ClassificationRequests(com.b2international.snowowl.snomed.reasoner.request.ClassificationRequests) Collection(java.util.Collection) Request(com.b2international.snowowl.core.events.Request) Set(java.util.Set) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) RevisionIndexReadRequest(com.b2international.snowowl.core.request.RevisionIndexReadRequest) ConcreteDomainChangeDocument(com.b2international.snowowl.snomed.reasoner.index.ConcreteDomainChangeDocument) List(java.util.List) SnomedCoreComponent(com.b2international.snowowl.snomed.core.domain.SnomedCoreComponent) SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) Entry(java.util.Map.Entry) SearchResourceRequestBuilder(com.b2international.snowowl.core.request.SearchResourceRequestBuilder) SnomedIdentifiers(com.b2international.snowowl.snomed.cis.SnomedIdentifiers) SnomedRf2Headers(com.b2international.snowowl.snomed.common.SnomedRf2Headers) BranchContext(com.b2international.snowowl.core.domain.BranchContext) ComponentCategory(com.b2international.snowowl.core.terminology.ComponentCategory) BaseResourceConverter(com.b2international.snowowl.core.request.BaseResourceConverter) Options(com.b2international.commons.options.Options) SnomedIdentifiers(com.b2international.snowowl.snomed.cis.SnomedIdentifiers) ComponentCategory(com.b2international.snowowl.core.terminology.ComponentCategory) SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) RevisionIndexReadRequest(com.b2international.snowowl.core.request.RevisionIndexReadRequest) SnomedReferenceSetMembers(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers) BranchContext(com.b2international.snowowl.core.domain.BranchContext) Collection(java.util.Collection) Map(java.util.Map)

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