Search in sources :

Example 1 with SnomedRelationship

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

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

the class SnomedExtensionUpgradeTest method upgrade07DonatedRelationship.

@Test
public void upgrade07DonatedRelationship() throws Exception {
    // create extension on the latest SI VERSION
    CodeSystem extension = createExtension(latestInternationalVersion, branchPath.lastSegment());
    String extensionModuleId = createModule(extension);
    Json extensionRelationshipRequest = Json.object("namespaceId", Concepts.B2I_NAMESPACE, "moduleId", extensionModuleId, "sourceId", Concepts.ROOT_CONCEPT, "typeId", Concepts.PART_OF, "destinationId", Concepts.NAMESPACE_ROOT, "characteristicTypeId", Concepts.ADDITIONAL_RELATIONSHIP, "relationshipGroup", 0, "commitComment", "Created new extension relationship");
    String extensionRelationshipId = createRelationship(extension.getResourceURI(), extensionRelationshipRequest);
    // create new extension version
    createVersion(extension.getId(), "v1", LocalDate.now()).statusCode(201);
    // simulate donation of relationship to INT with slightly different props but same ID
    Json donatedRelationshipRequest = Json.assign(extensionRelationshipRequest, Json.object("id", extensionRelationshipId, "moduleId", Concepts.MODULE_SCT_CORE, "characteristicTypeId", Concepts.INFERRED_RELATIONSHIP, "relationshipGroup", 1, "commitComment", "Created new donated INT relationship"));
    String donatedRelationshipId = createRelationship(SnomedContentRule.SNOMEDCT, donatedRelationshipRequest);
    LocalDate effectiveTime = getNextAvailableEffectiveDate(SNOMEDCT);
    createVersion(SNOMEDCT, effectiveTime).statusCode(201);
    assertEquals(extensionRelationshipId, donatedRelationshipId);
    // start upgrade to the new available upgrade version
    CodeSystem upgradeCodeSystem = createExtensionUpgrade(extension.getResourceURI(), CodeSystem.uri(SNOMEDCT, effectiveTime.toString()));
    SnomedRelationship donatedRelationshipOnUpgrade = getRelationship(upgradeCodeSystem.getResourceURI(), donatedRelationshipId);
    assertEquals(Concepts.MODULE_SCT_CORE, donatedRelationshipOnUpgrade.getModuleId());
    assertEquals(Concepts.INFERRED_RELATIONSHIP, donatedRelationshipOnUpgrade.getCharacteristicTypeId());
    assertEquals(1, donatedRelationshipOnUpgrade.getRelationshipGroup().intValue());
}
Also used : SnomedRelationship(com.b2international.snowowl.snomed.core.domain.SnomedRelationship) Json(com.b2international.commons.json.Json) CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 3 with SnomedRelationship

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

the class BranchCompareRequestTest method prepareBranchWithNewChanges.

private Set<ComponentIdentifier> prepareBranchWithNewChanges(String branchPath) {
    final IBranchPath branch = BranchPathUtils.createPath(branchPath);
    final String newConceptId = createNewConcept(branch);
    final SnomedConcept concept = getComponent(branch, SnomedComponentType.CONCEPT, newConceptId, "descriptions(expand(members())),relationships()").extract().as(SnomedConcept.class);
    final Set<ComponentIdentifier> newIds = newHashSet();
    newIds.add(ComponentIdentifier.of(SnomedConcept.TYPE, concept.getId()));
    for (SnomedDescription description : concept.getDescriptions()) {
        newIds.add(ComponentIdentifier.of(SnomedDescription.TYPE, description.getId()));
        for (SnomedReferenceSetMember member : description.getMembers()) {
            newIds.add(ComponentIdentifier.of(SnomedReferenceSetMember.TYPE, member.getId()));
        }
    }
    for (SnomedRelationship relationship : concept.getRelationships()) {
        newIds.add(ComponentIdentifier.of(SnomedRelationship.TYPE, relationship.getId()));
    }
    return newIds;
}
Also used : SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) SnomedRelationship(com.b2international.snowowl.snomed.core.domain.SnomedRelationship) ComponentIdentifier(com.b2international.snowowl.core.ComponentIdentifier) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) IBranchPath(com.b2international.snowowl.core.api.IBranchPath)

Example 4 with SnomedRelationship

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

the class SnomedCompareRestRequestTest method prepareNewChanges.

private Set<ComponentIdentifier> prepareNewChanges(String conceptId, IBranchPath branchPath) {
    final SnomedConcept concept = getComponent(branchPath, SnomedComponentType.CONCEPT, conceptId, "descriptions(expand(members())),relationships()").extract().as(SnomedConcept.class);
    final Set<ComponentIdentifier> newIds = newHashSet();
    newIds.add(ComponentIdentifier.of(SnomedConcept.TYPE, concept.getId()));
    for (SnomedDescription description : concept.getDescriptions()) {
        newIds.add(ComponentIdentifier.of(SnomedDescription.TYPE, description.getId()));
        for (SnomedReferenceSetMember member : description.getMembers()) {
            newIds.add(ComponentIdentifier.of(SnomedReferenceSetMember.TYPE, member.getId()));
        }
    }
    for (SnomedRelationship relationship : concept.getRelationships()) {
        newIds.add(ComponentIdentifier.of(SnomedRelationship.TYPE, relationship.getId()));
    }
    return newIds;
}
Also used : SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) SnomedRelationship(com.b2international.snowowl.snomed.core.domain.SnomedRelationship) ComponentIdentifier(com.b2international.snowowl.core.ComponentIdentifier) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept)

Example 5 with SnomedRelationship

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

the class EclExpression method resolveToGroupedOnly.

private Promise<Multimap<String, Integer>> resolveToGroupedOnly(BranchContext context, Set<String> sourceIds) {
    final Set<String> characteristicTypes = isInferred() ? SnomedEclRefinementEvaluator.INFERRED_CHARACTERISTIC_TYPES : SnomedEclRefinementEvaluator.STATED_CHARACTERISTIC_TYPES;
    List<Promise<Multimap<String, Integer>>> promises = newArrayListWithCapacity(3);
    // search relationships
    promises.add(SnomedRequests.prepareSearchRelationship().all().filterByActive(true).filterByCharacteristicTypes(characteristicTypes).filterBySources(sourceIds).filterByGroup(1, Integer.MAX_VALUE).setEclExpressionForm(expressionForm).setFields(SnomedRelationshipIndexEntry.Fields.ID, SnomedRelationshipIndexEntry.Fields.SOURCE_ID, SnomedRelationshipIndexEntry.Fields.RELATIONSHIP_GROUP).build(context.service(ResourceURI.class)).execute(context.service(IEventBus.class)).then(new Function<SnomedRelationships, Multimap<String, Integer>>() {

        @Override
        public Multimap<String, Integer> apply(SnomedRelationships input) {
            final Multimap<String, SnomedRelationship> relationshipsBySource = Multimaps.index(input, SnomedRelationship::getSourceId);
            final Multimap<String, Integer> groupsByRelationshipId = Multimaps.transformValues(relationshipsBySource, SnomedRelationship::getRelationshipGroup);
            return ImmutableSetMultimap.copyOf(groupsByRelationshipId);
        }
    }));
    // search concrete domain members
    if (context.service(SnomedCoreConfiguration.class).isConcreteDomainSupported()) {
        final Options propFilter = Options.builder().put(SnomedRf2Headers.FIELD_CHARACTERISTIC_TYPE_ID, characteristicTypes).put(SearchResourceRequest.operator(SnomedRf2Headers.FIELD_RELATIONSHIP_GROUP), SearchResourceRequest.Operator.NOT_EQUALS).put(SnomedRf2Headers.FIELD_RELATIONSHIP_GROUP, 0).build();
        promises.add(SnomedRequests.prepareSearchMember().all().filterByActive(true).filterByReferencedComponent(sourceIds).filterByRefSetType(SnomedRefSetType.CONCRETE_DATA_TYPE).filterByProps(propFilter).setEclExpressionForm(expressionForm).build(context.service(ResourceURI.class)).execute(context.service(IEventBus.class)).then(members -> {
            final Multimap<String, SnomedReferenceSetMember> relationshipsBySource = Multimaps.index(members, m -> m.getReferencedComponent().getId());
            return Multimaps.transformValues(relationshipsBySource, m -> (Integer) m.getProperties().get(SnomedRf2Headers.FIELD_RELATIONSHIP_GROUP));
        }));
    } else {
        promises.add(Promise.immediate(ImmutableSetMultimap.of()));
    }
    // search owl axiom members
    if (isStated()) {
        ImmutableSetMultimap.Builder<String, Integer> groupedAxioms = ImmutableSetMultimap.builder();
        SnomedEclRefinementEvaluator.evalAxiomStatements(context, true, sourceIds, null, null).forEach(property -> groupedAxioms.put(property.getObjectId(), property.getGroup()));
        promises.add(Promise.immediate(groupedAxioms.build()));
    } else {
        promises.add(Promise.immediate(ImmutableSetMultimap.of()));
    }
    return Promise.all(promises).then(statements -> {
        Multimap<String, Integer> relationshipStatements = (Multimap<String, Integer>) statements.get(0);
        Multimap<String, Integer> concreteDomainStatements = (Multimap<String, Integer>) statements.get(1);
        Multimap<String, Integer> axiomStatements = (Multimap<String, Integer>) statements.get(2);
        return ImmutableSetMultimap.<String, Integer>builder().putAll(relationshipStatements).putAll(concreteDomainStatements).putAll(axiomStatements).build();
    });
}
Also used : Query(com.b2international.index.query.Query) SnomedRelationshipIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry) Promise(com.b2international.snowowl.core.events.util.Promise) Multimap(com.google.common.collect.Multimap) Multimaps(com.google.common.collect.Multimaps) SnomedRequests(com.b2international.snowowl.snomed.datastore.request.SnomedRequests) Options(com.b2international.commons.options.Options) NestedExpression(com.b2international.snomed.ecl.ecl.NestedExpression) RevisionSearcher(com.b2international.index.revision.RevisionSearcher) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) SnomedConceptDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument) Nullable(javax.annotation.Nullable) ResourceURI(com.b2international.snowowl.core.ResourceURI) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) Lists.newArrayListWithCapacity(com.google.common.collect.Lists.newArrayListWithCapacity) Function(com.google.common.base.Function) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException) RevisionDocument(com.b2international.snowowl.core.repository.RevisionDocument) SnomedConcepts(com.b2international.snowowl.snomed.core.domain.SnomedConcepts) Set(java.util.Set) IOException(java.io.IOException) IEventBus(com.b2international.snowowl.eventbus.IEventBus) NotNull(javax.validation.constraints.NotNull) PathWithVersion(com.b2international.snowowl.core.uri.ResourceURIPathResolver.PathWithVersion) SnomedRelationships(com.b2international.snowowl.snomed.core.domain.SnomedRelationships) Any(com.b2international.snomed.ecl.ecl.Any) Trees(com.b2international.snowowl.snomed.core.tree.Trees) SearchResourceRequest(com.b2international.snowowl.core.request.SearchResourceRequest) SnomedRelationship(com.b2international.snowowl.snomed.core.domain.SnomedRelationship) List(java.util.List) Expressions(com.b2international.index.query.Expressions) SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) Expression(com.b2international.index.query.Expression) Preconditions(com.google.common.base.Preconditions) Ecl(com.b2international.snomed.ecl.Ecl) SnomedRf2Headers(com.b2international.snowowl.snomed.common.SnomedRf2Headers) EclConceptReference(com.b2international.snomed.ecl.ecl.EclConceptReference) ExpressionConstraint(com.b2international.snomed.ecl.ecl.ExpressionConstraint) BranchContext(com.b2international.snowowl.core.domain.BranchContext) SnomedRefSetType(com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType) SnomedCoreConfiguration(com.b2international.snowowl.snomed.datastore.config.SnomedCoreConfiguration) Options(com.b2international.commons.options.Options) SnomedRelationship(com.b2international.snowowl.snomed.core.domain.SnomedRelationship) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) SnomedCoreConfiguration(com.b2international.snowowl.snomed.datastore.config.SnomedCoreConfiguration) SnomedRelationships(com.b2international.snowowl.snomed.core.domain.SnomedRelationships) Promise(com.b2international.snowowl.core.events.util.Promise) Function(com.google.common.base.Function) Multimap(com.google.common.collect.Multimap) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) IEventBus(com.b2international.snowowl.eventbus.IEventBus)

Aggregations

SnomedRelationship (com.b2international.snowowl.snomed.core.domain.SnomedRelationship)16 SnomedConcept (com.b2international.snowowl.snomed.core.domain.SnomedConcept)8 Options (com.b2international.commons.options.Options)6 SnomedDescription (com.b2international.snowowl.snomed.core.domain.SnomedDescription)5 SnomedConceptRequestCache (com.b2international.snowowl.snomed.datastore.request.SnomedConceptRequestCache)5 SnomedReferenceSetMember (com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember)4 BranchContext (com.b2international.snowowl.core.domain.BranchContext)3 SnomedConcepts (com.b2international.snowowl.snomed.core.domain.SnomedConcepts)3 AbstractSnomedApiTest (com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)3 Test (org.junit.Test)3 ExtendedLocale (com.b2international.commons.http.ExtendedLocale)2 Json (com.b2international.commons.json.Json)2 ComponentIdentifier (com.b2international.snowowl.core.ComponentIdentifier)2 Concepts (com.b2international.snowowl.snomed.common.SnomedConstants.Concepts)2 SnomedRf2Headers (com.b2international.snowowl.snomed.common.SnomedRf2Headers)2 SnomedCoreComponent (com.b2international.snowowl.snomed.core.domain.SnomedCoreComponent)2 SnomedRelationships (com.b2international.snowowl.snomed.core.domain.SnomedRelationships)2 SnomedRefSetType (com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType)2 SnomedRelationshipIndexEntry (com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry)2 List (java.util.List)2