Search in sources :

Example 16 with SnomedReferenceSetMembers

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

the class SnomedDescriptionApiTest method updateAcceptability.

@Test
public void updateAcceptability() {
    String descriptionId = createNewDescription(branchPath);
    SnomedReferenceSetMembers beforeMembers = getComponent(branchPath, SnomedComponentType.DESCRIPTION, descriptionId, "members()").statusCode(200).extract().as(SnomedDescription.class).getMembers();
    assertEquals(1, beforeMembers.getTotal());
    SnomedReferenceSetMember beforeMember = Iterables.getOnlyElement(beforeMembers);
    Json requestBody = Json.object("acceptability", SnomedApiTestConstants.UK_PREFERRED_MAP, "commitComment", "Updated description acceptability");
    updateComponent(branchPath, SnomedComponentType.DESCRIPTION, descriptionId, requestBody).statusCode(204);
    SnomedReferenceSetMembers afterMembers = getComponent(branchPath, SnomedComponentType.DESCRIPTION, descriptionId, "members()").statusCode(200).extract().as(SnomedDescription.class).getMembers();
    assertEquals(1, afterMembers.getTotal());
    SnomedReferenceSetMember afterMember = Iterables.getOnlyElement(afterMembers);
    assertEquals(beforeMember.getId(), afterMember.getId());
    assertEquals(Concepts.REFSET_DESCRIPTION_ACCEPTABILITY_PREFERRED, afterMember.getProperties().get(SnomedRf2Headers.FIELD_ACCEPTABILITY_ID));
    assertEquals(Concepts.REFSET_LANGUAGE_TYPE_UK, afterMember.getRefsetId());
}
Also used : SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) SnomedReferenceSetMembers(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers) Json(com.b2international.commons.json.Json) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest) Test(org.junit.Test)

Example 17 with SnomedReferenceSetMembers

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

the class SnomedDescriptionApiTest method updateAcceptabilityWithAddition.

@Test
public void updateAcceptabilityWithAddition() throws Exception {
    changeToAcceptable(branchPath, Concepts.ROOT_CONCEPT, Concepts.REFSET_LANGUAGE_TYPE_UK);
    String descriptionId = createNewDescription(branchPath, Concepts.ROOT_CONCEPT, Concepts.SYNONYM, SnomedApiTestConstants.UK_PREFERRED_MAP);
    changeToAcceptable(branchPath, Concepts.ROOT_CONCEPT, Concepts.REFSET_LANGUAGE_TYPE_US);
    Json requestBody = Json.object("acceptability", Json.object(Concepts.REFSET_LANGUAGE_TYPE_UK, Acceptability.ACCEPTABLE, Concepts.REFSET_LANGUAGE_TYPE_US, Acceptability.PREFERRED), "commitComment", "Changed UK, added US acceptability to description");
    updateComponent(branchPath, SnomedComponentType.DESCRIPTION, descriptionId, requestBody).statusCode(204);
    SnomedReferenceSetMembers members = getComponent(branchPath, SnomedComponentType.DESCRIPTION, descriptionId, "members()").statusCode(200).body("members.items.refsetId", hasItems(Concepts.REFSET_LANGUAGE_TYPE_UK, Concepts.REFSET_LANGUAGE_TYPE_US)).extract().as(SnomedDescription.class).getMembers();
    assertEquals(2, members.getTotal());
    getComponent(branchPath, SnomedComponentType.CONCEPT, Concepts.ROOT_CONCEPT, "pt()").statusCode(200).body("pt.id", equalTo(descriptionId));
}
Also used : SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) SnomedReferenceSetMembers(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers) Json(com.b2international.commons.json.Json) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest) Test(org.junit.Test)

Example 18 with SnomedReferenceSetMembers

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

the class InactivationPropertiesExpander method expand.

void expand(List<? extends SnomedCoreComponent> results, Set<String> referencedComponentIds) {
    if (!expand.containsKey(SnomedCoreComponent.Expand.INACTIVATION_PROPERTIES)) {
        return;
    }
    final Multimap<String, SnomedReferenceSetMember> membersByReferencedComponentId = ArrayListMultimap.create();
    SnomedRequests.prepareSearchMember().setLimit(10_000).filterByActive(true).filterByRefSet(String.format("<%s OR %s", Concepts.REFSET_ASSOCIATION_TYPE, inactivationIndicatorRefSetId)).filterByReferencedComponent(referencedComponentIds).stream(context).flatMap(SnomedReferenceSetMembers::stream).forEachOrdered(member -> {
        membersByReferencedComponentId.put(member.getReferencedComponentId(), member);
    });
    final Options inactivationPropertiesExpand = expand.getOptions(SnomedCoreComponent.Expand.INACTIVATION_PROPERTIES);
    Map<String, SnomedConcept> associationTargetComponentsById = Collections.emptyMap();
    Map<String, SnomedConcept> inactivationIndicatorsById = Collections.emptyMap();
    final Options nestedExpands = inactivationPropertiesExpand.getOptions("expand");
    if (nestedExpands != null && nestedExpands.containsKey(InactivationProperties.Expand.ASSOCIATION_TARGETS)) {
        final Options associationTargetsExpand = nestedExpands.getOptions(InactivationProperties.Expand.ASSOCIATION_TARGETS).getOptions("expand");
        final Set<String> componentsToExpand = membersByReferencedComponentId.values().stream().filter(member -> SnomedRefSetType.ASSOCIATION.equals(member.type())).map(member -> (String) member.getProperties().get(SnomedRf2Headers.FIELD_TARGET_COMPONENT_ID)).filter(id -> !Strings.isNullOrEmpty(id)).collect(Collectors.toSet());
        if (associationTargetsExpand != null && associationTargetsExpand.containsKey(AssociationTarget.Expand.TARGET_COMPONENT)) {
            associationTargetComponentsById = expandConceptByIdMap(associationTargetsExpand.getOptions(AssociationTarget.Expand.TARGET_COMPONENT).getOptions("expand"), componentsToExpand, context);
        }
    }
    if (nestedExpands != null && nestedExpands.containsKey(InactivationProperties.Expand.INACTIVATION_INDICATOR)) {
        final Options inactivationIndicatorExpand = nestedExpands.getOptions(InactivationProperties.Expand.INACTIVATION_INDICATOR);
        final Set<String> componentsToExpand = membersByReferencedComponentId.values().stream().filter(member -> SnomedRefSetType.ATTRIBUTE_VALUE.equals(member.type())).map(member -> (String) member.getProperties().get(SnomedRf2Headers.FIELD_VALUE_ID)).filter(id -> !Strings.isNullOrEmpty(id)).collect(Collectors.toSet());
        inactivationIndicatorsById = expandConceptByIdMap(inactivationIndicatorExpand.getOptions("expand"), componentsToExpand, context);
    }
    for (SnomedCoreComponent result : results) {
        final Collection<SnomedReferenceSetMember> referringMembers = membersByReferencedComponentId.get(result.getId());
        final ImmutableList.Builder<AssociationTarget> associationTargets = ImmutableList.builder();
        final Set<String> inactivationIndicatorIds = Sets.newHashSet();
        for (SnomedReferenceSetMember referringMember : referringMembers) {
            if (SnomedRefSetType.ASSOCIATION.equals(referringMember.type())) {
                final AssociationTarget associationTarget = new AssociationTarget();
                final String targetComponentId = (String) referringMember.getProperties().get(SnomedRf2Headers.FIELD_TARGET_COMPONENT_ID);
                associationTarget.setReferenceSetId(referringMember.getRefsetId());
                associationTarget.setTargetComponentId(targetComponentId);
                if (associationTargetComponentsById.containsKey(targetComponentId)) {
                    associationTarget.setTargetComponent(associationTargetComponentsById.get(targetComponentId));
                }
                associationTargets.add(associationTarget);
            } else if (SnomedRefSetType.ATTRIBUTE_VALUE.equals(referringMember.type())) {
                inactivationIndicatorIds.add((String) referringMember.getProperties().get(SnomedRf2Headers.FIELD_VALUE_ID));
            }
        }
        final String inactivationIndicatorId = Iterables.getFirst(inactivationIndicatorIds, null);
        InactivationProperties inactivationProperties = new InactivationProperties();
        inactivationProperties.setInactivationIndicatorId(inactivationIndicatorId);
        inactivationProperties.setAssociationTargets(associationTargets.build());
        if (!Strings.isNullOrEmpty(inactivationIndicatorId) && inactivationIndicatorsById.containsKey(inactivationIndicatorId)) {
            inactivationProperties.setInactivationIndicator(inactivationIndicatorsById.get(inactivationIndicatorId));
        }
        result.setInactivationProperties(inactivationProperties);
    }
}
Also used : java.util(java.util) com.b2international.snowowl.snomed.core.domain(com.b2international.snowowl.snomed.core.domain) Collectors(java.util.stream.Collectors) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) Strings(com.google.common.base.Strings) ExtendedLocale(com.b2international.commons.http.ExtendedLocale) SnomedRequests(com.b2international.snowowl.snomed.datastore.request.SnomedRequests) Options(com.b2international.commons.options.Options) SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) SnomedRf2Headers(com.b2international.snowowl.snomed.common.SnomedRf2Headers) BranchContext(com.b2international.snowowl.core.domain.BranchContext) com.google.common.collect(com.google.common.collect) SnomedRefSetType(com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType) SnomedReferenceSetMembers(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers) Options(com.b2international.commons.options.Options) SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember)

Example 19 with SnomedReferenceSetMembers

use of com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers 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 20 with SnomedReferenceSetMembers

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

SnomedReferenceSetMembers (com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers)20 Test (org.junit.Test)14 AbstractSnomedApiTest (com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)10 Json (com.b2international.commons.json.Json)9 SnomedReferenceSetMember (com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember)9 SnomedConcept (com.b2international.snowowl.snomed.core.domain.SnomedConcept)5 SnomedDescription (com.b2international.snowowl.snomed.core.domain.SnomedDescription)5 Options (com.b2international.commons.options.Options)4 SnomedRf2Headers (com.b2international.snowowl.snomed.common.SnomedRf2Headers)4 ExtendedLocale (com.b2international.commons.http.ExtendedLocale)3 ComponentURI (com.b2international.snowowl.core.uri.ComponentURI)3 Concepts (com.b2international.snowowl.snomed.common.SnomedConstants.Concepts)3 SnomedRefSetType (com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType)3 OptionsBuilder (com.b2international.commons.options.OptionsBuilder)2 ResourceURI (com.b2international.snowowl.core.ResourceURI)2 CodeSystemRequests (com.b2international.snowowl.core.codesystem.CodeSystemRequests)2 BranchContext (com.b2international.snowowl.core.domain.BranchContext)2 SnomedDisplayTermType (com.b2international.snowowl.snomed.core.SnomedDisplayTermType)2 SnomedCoreComponent (com.b2international.snowowl.snomed.core.domain.SnomedCoreComponent)2 SnomedRefSetUtil (com.b2international.snowowl.snomed.datastore.SnomedRefSetUtil)2