Search in sources :

Example 1 with AcceptabilityMembership

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

the class SnomedDescriptionConverter method expandAcceptabilities.

private void expandAcceptabilities(List<SnomedDescription> results) {
    if (!expand().containsKey("acceptabilities")) {
        return;
    }
    // expand the acceptability objects first
    for (SnomedDescription result : results) {
        if (!CompareUtils.isEmpty(result.getAcceptabilityMap())) {
            List<AcceptabilityMembership> acceptabilities = result.getAcceptabilityMap().entrySet().stream().map(entry -> new AcceptabilityMembership(entry.getKey(), entry.getValue().getConceptId())).sorted().collect(Collectors.toList());
            result.setAcceptabilities(acceptabilities);
        } else {
            result.setAcceptabilities(Collections.emptyList());
        }
    }
    // additional expansions supported inside the acceptabilities() expand
    final Options expandOptions = expand().get("acceptabilities", Options.class).getOptions("expand");
    if (expandOptions.containsKey("acceptability")) {
        final Options acceptabilityExpand = expandOptions.get("acceptability", Options.class);
        final Iterable<String> acceptabilityIds = results.stream().flatMap(d -> d.getAcceptabilities().stream().map(AcceptabilityMembership::getAcceptabilityId))::iterator;
        context().service(SnomedConceptRequestCache.class).request(acceptabilityIds, acceptabilityExpand.getOptions("expand"), locales(), acceptabilitiesById -> {
            for (SnomedDescription result : results) {
                result.getAcceptabilities().forEach(acceptabilityMembership -> {
                    acceptabilityMembership.setAcceptability(acceptabilitiesById.get(acceptabilityMembership.getAcceptabilityId()));
                });
            }
        });
    }
    if (expandOptions.containsKey("languageRefSet")) {
        final Options languageRefSetExpand = expandOptions.get("languageRefSet", Options.class);
        final Iterable<String> languageRefSetIds = results.stream().flatMap(d -> d.getAcceptabilities().stream().map(AcceptabilityMembership::getLanguageRefSetId))::iterator;
        context().service(SnomedConceptRequestCache.class).request(languageRefSetIds, languageRefSetExpand.getOptions("expand"), locales(), languageRefSetsById -> {
            for (SnomedDescription result : results) {
                result.getAcceptabilities().forEach(acceptabilityMembership -> {
                    acceptabilityMembership.setLanguageRefSet(languageRefSetsById.get(acceptabilityMembership.getLanguageRefSetId()));
                });
            }
        });
    }
}
Also used : SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) AcceptabilityMembership(com.b2international.snowowl.snomed.core.domain.AcceptabilityMembership) Set(java.util.Set) Collectors(java.util.stream.Collectors) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) BaseRevisionResourceConverter(com.b2international.snowowl.core.request.BaseRevisionResourceConverter) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) List(java.util.List) ExtendedLocale(com.b2international.commons.http.ExtendedLocale) Options(com.b2international.commons.options.Options) FluentIterable(com.google.common.collect.FluentIterable) SnomedDescriptions(com.b2international.snowowl.snomed.core.domain.SnomedDescriptions) SnomedDescriptionIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionIndexEntry) CompareUtils(com.b2international.commons.CompareUtils) BranchContext(com.b2international.snowowl.core.domain.BranchContext) Collections(java.util.Collections) SnomedConceptRequestCache(com.b2international.snowowl.snomed.datastore.request.SnomedConceptRequestCache) Options(com.b2international.commons.options.Options) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) AcceptabilityMembership(com.b2international.snowowl.snomed.core.domain.AcceptabilityMembership) SnomedConceptRequestCache(com.b2international.snowowl.snomed.datastore.request.SnomedConceptRequestCache)

Aggregations

CompareUtils (com.b2international.commons.CompareUtils)1 ExtendedLocale (com.b2international.commons.http.ExtendedLocale)1 Options (com.b2international.commons.options.Options)1 BranchContext (com.b2international.snowowl.core.domain.BranchContext)1 BaseRevisionResourceConverter (com.b2international.snowowl.core.request.BaseRevisionResourceConverter)1 Concepts (com.b2international.snowowl.snomed.common.SnomedConstants.Concepts)1 AcceptabilityMembership (com.b2international.snowowl.snomed.core.domain.AcceptabilityMembership)1 SnomedConcept (com.b2international.snowowl.snomed.core.domain.SnomedConcept)1 SnomedDescription (com.b2international.snowowl.snomed.core.domain.SnomedDescription)1 SnomedDescriptions (com.b2international.snowowl.snomed.core.domain.SnomedDescriptions)1 SnomedDescriptionIndexEntry (com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionIndexEntry)1 SnomedConceptRequestCache (com.b2international.snowowl.snomed.datastore.request.SnomedConceptRequestCache)1 FluentIterable (com.google.common.collect.FluentIterable)1 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)1 Collections (java.util.Collections)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1