Search in sources :

Example 1 with ValueSetMembers

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

the class ValueSetMemberSearchSnomedReferenceSetTest method filterByRefsetUri.

@Test
public void filterByRefsetUri() throws Exception {
    SnomedReferenceSetMembers members = SnomedRequests.prepareSearchMember().all().filterByRefSet(Concepts.REFSET_DESCRIPTION_TYPE).build(CODESYSTEM).execute(Services.bus()).getSync(1, TimeUnit.MINUTES);
    ValueSetMembers setMembers = CodeSystemRequests.prepareSearchMembers().all().filterByValueSet(ComponentURI.of(CODESYSTEM, SnomedConcept.REFSET_TYPE, Concepts.REFSET_DESCRIPTION_TYPE).toString()).buildAsync().execute(Services.bus()).getSync(1, TimeUnit.MINUTES);
    assertThat(setMembers.getTotal()).isEqualTo(members.getTotal());
    assertThat(setMembers.stream().allMatch(m -> SnomedContentRule.SNOMEDCT.equals(m.getReferencedComponentURI().resourceUri())));
    Set<String> setMemberSourceCodes = FluentIterable.from(setMembers).transform(m -> m.getReferencedComponentURI().identifier()).toSet();
    Set<String> setMemberSourceTerms = FluentIterable.from(setMembers).transform(m -> m.getReferencedComponentURI().identifier()).toSet();
    assertThat(setMemberSourceCodes.contains(Concepts.TEXT_DEFINITION));
    assertThat(setMemberSourceCodes.contains(Concepts.FULLY_SPECIFIED_NAME));
    assertThat(setMemberSourceCodes.contains(Concepts.SYNONYM));
    assertThat(setMemberSourceTerms.contains(DEFINITION));
    assertThat(setMemberSourceTerms.contains(FSN));
    assertThat(setMemberSourceTerms.contains(SYNONYM));
}
Also used : SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) Acceptability(com.b2international.snowowl.snomed.core.domain.Acceptability) RestExtensions(com.b2international.snowowl.test.commons.rest.RestExtensions) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SnomedRefSetUtil(com.b2international.snowowl.snomed.datastore.SnomedRefSetUtil) ValueSetMembers(com.b2international.snowowl.core.domain.ValueSetMembers) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) SnomedContentRule(com.b2international.snowowl.test.commons.SnomedContentRule) SnomedRelationshipCreateRequestBuilder(com.b2international.snowowl.snomed.datastore.request.SnomedRelationshipCreateRequestBuilder) SnomedRequests(com.b2international.snowowl.snomed.datastore.request.SnomedRequests) FluentIterable(com.google.common.collect.FluentIterable) Map(java.util.Map) SnomedDescriptionCreateRequestBuilder(com.b2international.snowowl.snomed.datastore.request.SnomedDescriptionCreateRequestBuilder) ResourceURI(com.b2international.snowowl.core.ResourceURI) SnomedReferenceSetMembers(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) ComponentURI(com.b2international.snowowl.core.uri.ComponentURI) Test(org.junit.Test) UUID(java.util.UUID) TimeUnit(java.util.concurrent.TimeUnit) Services(com.b2international.snowowl.test.commons.Services) CodeSystemRequests(com.b2international.snowowl.core.codesystem.CodeSystemRequests) SnomedRf2Headers(com.b2international.snowowl.snomed.common.SnomedRf2Headers) SnomedConstants(com.b2international.snowowl.snomed.common.SnomedConstants) Assert.assertEquals(org.junit.Assert.assertEquals) SnomedRefSetType(com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType) SnomedReferenceSetMembers(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers) ValueSetMembers(com.b2international.snowowl.core.domain.ValueSetMembers) Test(org.junit.Test)

Example 2 with ValueSetMembers

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

the class ValueSetMemberSearchRequest method doExecute.

@Override
protected ValueSetMembers doExecute(ServiceProvider context) throws IOException {
    final int limit = limit();
    Options options = Options.builder().putAll(options()).put(MemberSearchRequestEvaluator.OptionKey.AFTER, searchAfter()).put(MemberSearchRequestEvaluator.OptionKey.LIMIT, limit).put(MemberSearchRequestEvaluator.OptionKey.LOCALES, locales()).put(SearchResourceRequest.OptionKey.SORT_BY, sortBy()).build();
    // extract all ValueSetMemberSearchRequestEvaluator from all connected toolings and determine which ones can handle this request
    List<ValueSetMembers> evaluatedMembers = context.service(RepositoryManager.class).repositories().stream().flatMap(repository -> {
        ValueSetMemberSearchRequestEvaluator evaluator = repository.service(ValueSetMemberSearchRequestEvaluator.class);
        Set<ResourceURI> targets = evaluator.evaluateSearchTargetResources(context, options);
        return targets.stream().map(uri -> {
            return evaluator.evaluate(uri, context, options);
        });
    }).collect(Collectors.toList());
    // calculate grand total
    int total = 0;
    for (ValueSetMembers evaluatedMember : evaluatedMembers) {
        total += evaluatedMember.getTotal();
    }
    return new ValueSetMembers(// TODO add manual sorting here if multiple resources have been fetched
    evaluatedMembers.stream().flatMap(ValueSetMembers::stream).limit(limit).collect(Collectors.toList()), null, /* not supported across resources, TODO support it when a single ValueSet is being fetched */
    limit, total);
}
Also used : List(java.util.List) Options(com.b2international.commons.options.Options) RepositoryManager(com.b2international.snowowl.core.RepositoryManager) ServiceProvider(com.b2international.snowowl.core.ServiceProvider) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ValueSetMembers(com.b2international.snowowl.core.domain.ValueSetMembers) ResourceURI(com.b2international.snowowl.core.ResourceURI) Options(com.b2international.commons.options.Options) Set(java.util.Set) ValueSetMembers(com.b2international.snowowl.core.domain.ValueSetMembers)

Aggregations

ResourceURI (com.b2international.snowowl.core.ResourceURI)2 ValueSetMembers (com.b2international.snowowl.core.domain.ValueSetMembers)2 Set (java.util.Set)2 Options (com.b2international.commons.options.Options)1 RepositoryManager (com.b2international.snowowl.core.RepositoryManager)1 ServiceProvider (com.b2international.snowowl.core.ServiceProvider)1 CodeSystemRequests (com.b2international.snowowl.core.codesystem.CodeSystemRequests)1 ComponentURI (com.b2international.snowowl.core.uri.ComponentURI)1 SnomedConstants (com.b2international.snowowl.snomed.common.SnomedConstants)1 Concepts (com.b2international.snowowl.snomed.common.SnomedConstants.Concepts)1 SnomedRf2Headers (com.b2international.snowowl.snomed.common.SnomedRf2Headers)1 Acceptability (com.b2international.snowowl.snomed.core.domain.Acceptability)1 SnomedConcept (com.b2international.snowowl.snomed.core.domain.SnomedConcept)1 SnomedRefSetType (com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType)1 SnomedReferenceSetMembers (com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers)1 SnomedRefSetUtil (com.b2international.snowowl.snomed.datastore.SnomedRefSetUtil)1 SnomedDescriptionCreateRequestBuilder (com.b2international.snowowl.snomed.datastore.request.SnomedDescriptionCreateRequestBuilder)1 SnomedRelationshipCreateRequestBuilder (com.b2international.snowowl.snomed.datastore.request.SnomedRelationshipCreateRequestBuilder)1 SnomedRequests (com.b2international.snowowl.snomed.datastore.request.SnomedRequests)1 Services (com.b2international.snowowl.test.commons.Services)1