Search in sources :

Example 11 with SnomedRelationship

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

the class SnomedRelationshipApiTest method createRelationshipInferred.

@Test
public void createRelationshipInferred() {
    Json requestBody = createRelationshipRequestBody(Concepts.ROOT_CONCEPT, Concepts.PART_OF, Concepts.NAMESPACE_ROOT, Concepts.INFERRED_RELATIONSHIP).with("commitComment", "Created new relationship with inferred characteristic type");
    String relationshipId = assertCreated(createComponent(branchPath, SnomedComponentType.RELATIONSHIP, requestBody));
    SnomedRelationship relationship = getComponent(branchPath, SnomedComponentType.RELATIONSHIP, relationshipId, "source()", "type()", "destination()", "characteristicType()", "modifier()").statusCode(200).extract().as(SnomedRelationship.class);
    assertEquals(Concepts.INFERRED_RELATIONSHIP, relationship.getCharacteristicType().getId());
    assertEquals(Concepts.ROOT_CONCEPT, relationship.getSource().getId());
    assertEquals(Concepts.PART_OF, relationship.getType().getId());
    assertEquals(Concepts.NAMESPACE_ROOT, relationship.getDestination().getId());
    assertEquals(Concepts.EXISTENTIAL_RESTRICTION_MODIFIER, relationship.getModifier().getId());
}
Also used : SnomedRelationship(com.b2international.snowowl.snomed.core.domain.SnomedRelationship) Json(com.b2international.commons.json.Json) Test(org.junit.Test) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)

Example 12 with SnomedRelationship

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

the class SnomedSimpleTypeRefSetDSVExporter method computeHeader.

private void computeHeader(SnomedConcepts chunk) {
    for (SnomedConcept concept : chunk) {
        for (AbstractSnomedDsvExportItem exportItem : exportItems) {
            switch(exportItem.getType()) {
                case DESCRIPTION:
                    ComponentIdSnomedDsvExportItem descriptionItem = (ComponentIdSnomedDsvExportItem) exportItem;
                    String descriptionTypeId = descriptionItem.getComponentId();
                    Integer matchingDescriptions = concept.getDescriptions().stream().filter(d -> descriptionTypeId.equals(d.getTypeId())).collect(Collectors.reducing(0, description -> 1, Integer::sum));
                    descriptionCount.merge(descriptionTypeId, matchingDescriptions, Math::max);
                    break;
                case RELATIONSHIP:
                    ComponentIdSnomedDsvExportItem relationshipItem = (ComponentIdSnomedDsvExportItem) exportItem;
                    String relationshipTypeId = relationshipItem.getComponentId();
                    Map<Integer, Integer> matchingRelationships = concept.getRelationships().stream().filter(r -> relationshipTypeId.equals(r.getTypeId()) && (Concepts.INFERRED_RELATIONSHIP.equals(r.getCharacteristicTypeId()) || Concepts.ADDITIONAL_RELATIONSHIP.equals(r.getCharacteristicTypeId()))).collect(Collectors.groupingBy(SnomedRelationship::getRelationshipGroup, Collectors.reducing(0, relationship -> 1, Integer::sum)));
                    matchingRelationships.entrySet().stream().forEach(entry -> {
                        propertyCountByGroup.compute(entry.getKey(), (key, oldValue) -> {
                            Map<String, Integer> propertyCountForGroup = ofNullable(oldValue).orElseGet(HashMap::new);
                            propertyCountForGroup.merge(relationshipTypeId, entry.getValue(), Math::max);
                            return propertyCountForGroup;
                        });
                    });
                    break;
                case DATAYPE:
                    ComponentIdSnomedDsvExportItem dataTypeItem = (ComponentIdSnomedDsvExportItem) exportItem;
                    String dataTypeId = dataTypeItem.getComponentId();
                    Map<Integer, Integer> matchingMembers = concept.getMembers().stream().filter(m -> SnomedRefSetType.CONCRETE_DATA_TYPE.equals(m.type()) && m.isActive() && dataTypeId.equals(m.getProperties().get(SnomedRf2Headers.FIELD_TYPE_ID)) && (Concepts.INFERRED_RELATIONSHIP.equals(m.getProperties().get(SnomedRf2Headers.FIELD_CHARACTERISTIC_TYPE_ID)) || Concepts.ADDITIONAL_RELATIONSHIP.equals(m.getProperties().get(SnomedRf2Headers.FIELD_CHARACTERISTIC_TYPE_ID)))).collect(Collectors.groupingBy(m -> (Integer) m.getProperties().get(SnomedRf2Headers.FIELD_RELATIONSHIP_GROUP), Collectors.reducing(0, relationship -> 1, Integer::sum)));
                    matchingMembers.entrySet().stream().forEach(entry -> {
                        propertyCountByGroup.compute(entry.getKey(), (key, oldValue) -> {
                            Map<String, Integer> propertyCountForGroup = ofNullable(oldValue).orElseGet(HashMap::new);
                            propertyCountForGroup.merge(dataTypeId, entry.getValue(), Math::max);
                            return propertyCountForGroup;
                        });
                    });
                    break;
                default:
                    // Single-use fields don't need to be counted in advance
                    break;
            }
        }
    }
}
Also used : EffectiveTimes(com.b2international.snowowl.core.date.EffectiveTimes) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) java.util(java.util) SnomedConceptSearchRequestBuilder(com.b2international.snowowl.snomed.datastore.request.SnomedConceptSearchRequestBuilder) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) ExtendedLocale(com.b2international.commons.http.ExtendedLocale) SnomedRequests(com.b2international.snowowl.snomed.datastore.request.SnomedRequests) ComponentIdSnomedDsvExportItem(com.b2international.snowowl.snomed.datastore.internal.rf2.ComponentIdSnomedDsvExportItem) SnomedConceptDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument) Path(java.nio.file.Path) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Charsets(com.google.common.base.Charsets) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Files(java.nio.file.Files) ImmutableMap(com.google.common.collect.ImmutableMap) Optional.ofNullable(java.util.Optional.ofNullable) BufferedWriter(java.io.BufferedWriter) Dates(com.b2international.snowowl.core.date.Dates) SnomedConcepts(com.b2international.snowowl.snomed.core.domain.SnomedConcepts) AbstractSnomedDsvExportItem(com.b2international.snowowl.snomed.datastore.internal.rf2.AbstractSnomedDsvExportItem) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SnomedRelationship(com.b2international.snowowl.snomed.core.domain.SnomedRelationship) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) SnomedRefSetDSVExportModel(com.b2international.snowowl.snomed.datastore.internal.rf2.SnomedRefSetDSVExportModel) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) DatatypeSnomedDsvExportItem(com.b2international.snowowl.snomed.datastore.internal.rf2.DatatypeSnomedDsvExportItem) Ordering(com.google.common.collect.Ordering) Sort(com.b2international.snowowl.core.request.SearchResourceRequest.Sort) SearchResourceRequestIterator(com.b2international.snowowl.core.request.SearchResourceRequestIterator) SnomedRf2Headers(com.b2international.snowowl.snomed.common.SnomedRf2Headers) BranchContext(com.b2international.snowowl.core.domain.BranchContext) SnomedRefSetType(com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType) Joiner(com.google.common.base.Joiner) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) AbstractSnomedDsvExportItem(com.b2international.snowowl.snomed.datastore.internal.rf2.AbstractSnomedDsvExportItem) ComponentIdSnomedDsvExportItem(com.b2international.snowowl.snomed.datastore.internal.rf2.ComponentIdSnomedDsvExportItem)

Example 13 with SnomedRelationship

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

the class SnomedConcreteValueApiTest method updateConcreteValueWithSamePropertiesShouldNotCauseAnyChange.

@Test
public void updateConcreteValueWithSamePropertiesShouldNotCauseAnyChange() throws Exception {
    final String relationshipId = createNewConcreteValue(branchPath);
    final SnomedRelationship concreteValue = getRelationship(relationshipId);
    // explicitly create a new Boolean object with same value to simulate deserialization "bug"
    concreteValue.setActive(new Boolean(true));
    // same value as set in createNewConcreteValue(String)
    concreteValue.setValueAsObject(new RelationshipValue("Hello World!"));
    Boolean updated = SnomedRequests.prepareCommit().setCommitComment("Update concrete value").setBody(concreteValue.toUpdateRequest()).build(branchPath.getPath()).execute(getBus()).getSync(1, TimeUnit.MINUTES).getResultAs(Boolean.class);
    assertFalse(updated);
}
Also used : SnomedRelationship(com.b2international.snowowl.snomed.core.domain.SnomedRelationship) RelationshipValue(com.b2international.snowowl.snomed.core.domain.RelationshipValue) Test(org.junit.Test) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)

Example 14 with SnomedRelationship

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

the class SnomedRelationshipConverter method expandType.

private void expandType(List<SnomedRelationship> results) {
    if (expand().containsKey(SnomedRelationship.Expand.TYPE)) {
        final Options typeOptions = expand().get(SnomedRelationship.Expand.TYPE, Options.class);
        final Iterable<String> typeConceptIds = FluentIterable.from(results).transform(SnomedRelationship::getTypeId);
        context().service(SnomedConceptRequestCache.class).request(typeConceptIds, typeOptions.getOptions("expand"), locales(), typeConceptsById -> {
            for (SnomedRelationship relationship : results) {
                final String typeId = relationship.getTypeId();
                if (typeConceptsById.containsKey(typeId)) {
                    final SnomedConcept typeConcept = typeConceptsById.get(typeId);
                    ((SnomedRelationship) relationship).setType(typeConcept);
                }
            }
        });
    }
}
Also used : Options(com.b2international.commons.options.Options) SnomedRelationship(com.b2international.snowowl.snomed.core.domain.SnomedRelationship) SnomedConceptRequestCache(com.b2international.snowowl.snomed.datastore.request.SnomedConceptRequestCache) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept)

Example 15 with SnomedRelationship

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

the class SnomedRelationshipConverter method expandSource.

private void expandSource(List<SnomedRelationship> results) {
    if (expand().containsKey(SnomedRelationship.Expand.SOURCE)) {
        final Options sourceOptions = expand().get(SnomedRelationship.Expand.SOURCE, Options.class);
        final Iterable<String> sourceConceptIds = FluentIterable.from(results).transform(SnomedRelationship::getSourceId);
        context().service(SnomedConceptRequestCache.class).request(sourceConceptIds, sourceOptions.getOptions("expand"), locales(), sourceConceptsById -> {
            for (SnomedRelationship relationship : results) {
                final String sourceId = relationship.getSourceId();
                if (sourceConceptsById.containsKey(sourceId)) {
                    final SnomedConcept sourceConcept = sourceConceptsById.get(sourceId);
                    ((SnomedRelationship) relationship).setSource(sourceConcept);
                }
            }
        });
    }
}
Also used : Options(com.b2international.commons.options.Options) SnomedRelationship(com.b2international.snowowl.snomed.core.domain.SnomedRelationship) SnomedConceptRequestCache(com.b2international.snowowl.snomed.datastore.request.SnomedConceptRequestCache) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept)

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