Search in sources :

Example 36 with SnomedReferenceSetMember

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

the class SnomedRefSetMemberApiTest method createAndUpdateModuleDependencyMemberWithEffectiveTime.

@Test
public void createAndUpdateModuleDependencyMemberWithEffectiveTime() {
    Json requestBody = createRefSetMemberRequestBody(Concepts.REFSET_MODULE_DEPENDENCY_TYPE, Concepts.MODULE_SCT_MODEL_COMPONENT).with(SnomedRf2Headers.FIELD_SOURCE_EFFECTIVE_TIME, "20181001").with(SnomedRf2Headers.FIELD_TARGET_EFFECTIVE_TIME, "20181001").with("commitComment", "Created new module dependency reference set member");
    String memberId = assertCreated(createComponent(branchPath, SnomedComponentType.MEMBER, requestBody));
    SnomedReferenceSetMember member = getComponent(branchPath, SnomedComponentType.MEMBER, memberId).statusCode(200).extract().as(SnomedReferenceSetMember.class);
    assertEquals(EffectiveTimes.parse("20181001", DateFormats.SHORT), member.getProperties().get(SnomedRf2Headers.FIELD_SOURCE_EFFECTIVE_TIME));
    assertEquals(EffectiveTimes.parse("20181001", DateFormats.SHORT), member.getProperties().get(SnomedRf2Headers.FIELD_TARGET_EFFECTIVE_TIME));
    Json updateRequest = Json.object(SnomedRf2Headers.FIELD_SOURCE_EFFECTIVE_TIME, "", SnomedRf2Headers.FIELD_TARGET_EFFECTIVE_TIME, "", "commitComment", "Updated reference set member");
    updateRefSetComponent(branchPath, SnomedComponentType.MEMBER, memberId, updateRequest, false).statusCode(204);
    SnomedReferenceSetMember updatedMember = getComponent(branchPath, SnomedComponentType.MEMBER, memberId).statusCode(200).extract().as(SnomedReferenceSetMember.class);
    assertNull(updatedMember.getProperties().get(SnomedRf2Headers.FIELD_SOURCE_EFFECTIVE_TIME));
    assertNull(updatedMember.getProperties().get(SnomedRf2Headers.FIELD_TARGET_EFFECTIVE_TIME));
}
Also used : SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) Json(com.b2international.commons.json.Json) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)

Example 37 with SnomedReferenceSetMember

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

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

the class SnomedRefSetMemberApiTest method updateOwlAxiomRefsetMembers.

@Test
public void updateOwlAxiomRefsetMembers() {
    String conceptId = createNewConcept(branchPath);
    Json createRequestBody = createRefSetMemberRequestBody(Concepts.REFSET_OWL_AXIOM, conceptId).with(SnomedRf2Headers.FIELD_OWL_EXPRESSION, SnomedApiTestConstants.owlAxiom3(conceptId)).with("commitComment", "Created new OWL Axiom reference set member");
    String memberId = assertCreated(createComponent(branchPath, SnomedComponentType.MEMBER, createRequestBody));
    final SnomedReferenceSetMember member = SnomedRequests.prepareGetMember(memberId).setExpand("owlRelationships()").build(branchPath.getPath()).execute(getBus()).getSync();
    assertThat(member.getClassOWLRelationships()).containsOnly(SnomedOWLRelationshipDocument.create(Concepts.IS_A, "410680006", 0), SnomedOWLRelationshipDocument.create("734136001", "900000000000470007", 1));
    final Json updateRequestBody = Json.object(SnomedRf2Headers.FIELD_OWL_EXPRESSION, SnomedApiTestConstants.owlAxiom4(conceptId), "commitComment", "Update OWL Axiom reference set member");
    updateRefSetComponent(branchPath, SnomedComponentType.MEMBER, memberId, updateRequestBody, true).statusCode(204);
    final SnomedReferenceSetMember updatedMember = SnomedRequests.prepareGetMember(memberId).setExpand("owlRelationships()").build(branchPath.getPath()).execute(getBus()).getSync();
    assertThat(updatedMember.getClassOWLRelationships()).containsOnly(SnomedOWLRelationshipDocument.create(Concepts.IS_A, "410680006", 0), SnomedOWLRelationshipDocument.create("734136001", "900000000000470007", 1), SnomedOWLRelationshipDocument.create("371881003", "900000000000450001", 1));
}
Also used : SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Json(com.b2international.commons.json.Json) Test(org.junit.Test) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)

Example 39 with SnomedReferenceSetMember

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

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

SnomedReferenceSetMember (com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember)41 Test (org.junit.Test)17 AbstractSnomedApiTest (com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)13 Json (com.b2international.commons.json.Json)12 SnomedRf2Headers (com.b2international.snowowl.snomed.common.SnomedRf2Headers)11 SnomedReferenceSetMembers (com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers)11 Options (com.b2international.commons.options.Options)8 SnomedConcept (com.b2international.snowowl.snomed.core.domain.SnomedConcept)8 SnomedDescription (com.b2international.snowowl.snomed.core.domain.SnomedDescription)8 List (java.util.List)8 Concepts (com.b2international.snowowl.snomed.common.SnomedConstants.Concepts)7 Map (java.util.Map)7 SnomedRefSetType (com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType)6 IBranchPath (com.b2international.snowowl.core.api.IBranchPath)5 BranchContext (com.b2international.snowowl.core.domain.BranchContext)5 TransactionContext (com.b2international.snowowl.core.domain.TransactionContext)5 ComponentCategory (com.b2international.snowowl.core.terminology.ComponentCategory)5 Collectors (java.util.stream.Collectors)5 BranchPathUtils (com.b2international.snowowl.core.branch.BranchPathUtils)4 EffectiveTimes (com.b2international.snowowl.core.date.EffectiveTimes)4