Search in sources :

Example 21 with Options

use of com.b2international.commons.options.Options in project snow-owl by b2ihealthcare.

the class SnomedRelationshipConverter method expandCharacteristicType.

private void expandCharacteristicType(List<SnomedRelationship> results) {
    if (expand().containsKey(SnomedRelationship.Expand.CHARACTERISTIC_TYPE)) {
        final Options characteristicTypeOptions = expand().get(SnomedRelationship.Expand.CHARACTERISTIC_TYPE, Options.class);
        final Iterable<String> characteristicTypeConceptIds = FluentIterable.from(results).transform(SnomedRelationship::getCharacteristicTypeId);
        context().service(SnomedConceptRequestCache.class).request(characteristicTypeConceptIds, characteristicTypeOptions.getOptions("expand"), locales(), characteristicTypesById -> {
            for (SnomedRelationship relationship : results) {
                ((SnomedRelationship) relationship).setCharacteristicType(characteristicTypesById.get(relationship.getCharacteristicTypeId()));
            }
        });
    }
}
Also used : Options(com.b2international.commons.options.Options) SnomedRelationship(com.b2international.snowowl.snomed.core.domain.SnomedRelationship) SnomedConceptRequestCache(com.b2international.snowowl.snomed.datastore.request.SnomedConceptRequestCache)

Example 22 with Options

use of com.b2international.commons.options.Options in project snow-owl by b2ihealthcare.

the class SnomedConceptConverter method expandRelationships.

private void expandRelationships(List<SnomedConcept> results, final Set<String> conceptIds) {
    if (!expand().containsKey(SnomedConcept.Expand.RELATIONSHIPS)) {
        return;
    }
    final Options expandOptions = expand().get(SnomedConcept.Expand.RELATIONSHIPS, Options.class);
    final SnomedRelationships relationships = SnomedRequests.prepareSearchRelationship().all().filterByActive(expandOptions.get("active", Boolean.class)).filterByCharacteristicType(expandOptions.get("characteristicTypeId", String.class)).filterByTypes(expandOptions.containsKey("typeId") ? expandOptions.getCollection("typeId", String.class) : null).filterByDestinations(expandOptions.containsKey("destinationId") ? expandOptions.getCollection("destinationId", String.class) : null).filterBySources(conceptIds).setExpand(expandOptions.get("expand", Options.class)).setLocales(locales()).sortBy(expandOptions.get("sort", String.class)).build().execute(context());
    final ListMultimap<String, SnomedRelationship> relationshipsByConceptId = Multimaps.index(relationships, relationship -> relationship.getSourceId());
    for (SnomedConcept concept : results) {
        final List<SnomedRelationship> conceptRelationships = relationshipsByConceptId.get(concept.getId());
        concept.setRelationships(new SnomedRelationships(conceptRelationships, null, conceptRelationships.size(), conceptRelationships.size()));
    }
}
Also used : Options(com.b2international.commons.options.Options)

Example 23 with Options

use of com.b2international.commons.options.Options in project snow-owl by b2ihealthcare.

the class SnomedConceptConverter method expandDescriptions.

private void expandDescriptions(List<SnomedConcept> results, final Set<String> conceptIds) {
    if (!expand().containsKey(SnomedConcept.Expand.DESCRIPTIONS)) {
        return;
    }
    final Options expandOptions = expand().get(SnomedConcept.Expand.DESCRIPTIONS, Options.class);
    final SnomedDescriptions descriptions = SnomedRequests.prepareSearchDescription().all().setExpand(expandOptions.get("expand", Options.class)).filterByActive(expandOptions.get("active", Boolean.class)).filterByType(expandOptions.get("typeId", String.class)).filterByConcepts(conceptIds).setLocales(locales()).sortBy(expandOptions.get("sort", String.class)).build().execute(context());
    final ListMultimap<String, SnomedDescription> descriptionsByConceptId = Multimaps.index(descriptions, description -> description.getConceptId());
    for (SnomedConcept concept : results) {
        final List<SnomedDescription> conceptDescriptions = descriptionsByConceptId.get(concept.getId());
        concept.setDescriptions(new SnomedDescriptions(conceptDescriptions, null, conceptDescriptions.size(), conceptDescriptions.size()));
    }
}
Also used : Options(com.b2international.commons.options.Options)

Example 24 with Options

use of com.b2international.commons.options.Options in project snow-owl by b2ihealthcare.

the class SnomedConceptConverter method expandInboundRelationships.

private void expandInboundRelationships(List<SnomedConcept> results, final Set<String> conceptIds) {
    if (!expand().containsKey(SnomedConcept.Expand.INBOUND_RELATIONSHIPS)) {
        return;
    }
    final Options expandOptions = expand().get(SnomedConcept.Expand.INBOUND_RELATIONSHIPS, Options.class);
    final int relationshipSearchLimit = getLimit(expandOptions);
    final SnomedRelationships inboundRelationships = SnomedRequests.prepareSearchRelationship().setLimit(relationshipSearchLimit).filterByTypes(expandOptions.containsKey("typeId") ? expandOptions.getCollection("typeId", String.class) : null).filterBySources(expandOptions.containsKey("sourceId") ? expandOptions.getCollection("sourceId", String.class) : null).filterByActive(expandOptions.get("active", Boolean.class)).filterByCharacteristicType(expandOptions.get("characteristicTypeId", String.class)).filterByDestinations(conceptIds).setExpand(expandOptions.get("expand", Options.class)).setLocales(locales()).sortBy(expandOptions.get("sort", String.class)).build().execute(context());
    // filterByDestination above ensures that all relationships have a destinationId
    final ListMultimap<String, SnomedRelationship> inboundRelationshipsByConceptId = Multimaps.index(inboundRelationships, inboundRelationship -> inboundRelationship.getDestinationId());
    for (SnomedConcept concept : results) {
        final List<SnomedRelationship> conceptInboundRelationships = inboundRelationshipsByConceptId.get(concept.getId());
        concept.setInboundRelationships(new SnomedRelationships(conceptInboundRelationships, null, conceptInboundRelationships.size(), conceptInboundRelationships.size()));
    }
}
Also used : Options(com.b2international.commons.options.Options)

Example 25 with Options

use of com.b2international.commons.options.Options in project snow-owl by b2ihealthcare.

the class SnomedConceptConverter method getReferenceSetConverter.

private SnomedReferenceSetConverter getReferenceSetConverter() {
    if (referenceSetConverter == null) {
        // Not null, even if the expand parameter is missing
        Options expandOptions = expand().getOptions(SnomedConcept.Expand.REFERENCE_SET);
        referenceSetConverter = new SnomedReferenceSetConverter(context(), expandOptions.getOptions("expand"), locales());
    }
    return referenceSetConverter;
}
Also used : Options(com.b2international.commons.options.Options)

Aggregations

Options (com.b2international.commons.options.Options)57 List (java.util.List)15 Collectors (java.util.stream.Collectors)14 Set (java.util.Set)13 ExtendedLocale (com.b2international.commons.http.ExtendedLocale)11 BranchContext (com.b2international.snowowl.core.domain.BranchContext)11 SnomedConcept (com.b2international.snowowl.snomed.core.domain.SnomedConcept)11 SnomedConceptRequestCache (com.b2international.snowowl.snomed.datastore.request.SnomedConceptRequestCache)11 Test (org.junit.Test)9 SnomedReferenceSetMember (com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember)8 Map (java.util.Map)8 Concepts (com.b2international.snowowl.snomed.common.SnomedConstants.Concepts)7 SnomedConcepts (com.b2international.snowowl.snomed.core.domain.SnomedConcepts)7 BadRequestException (com.b2international.commons.exceptions.BadRequestException)6 ResourceURI (com.b2international.snowowl.core.ResourceURI)6 RepositoryContext (com.b2international.snowowl.core.domain.RepositoryContext)6 SnomedRelationship (com.b2international.snowowl.snomed.core.domain.SnomedRelationship)6 SnomedRequests (com.b2international.snowowl.snomed.datastore.request.SnomedRequests)6 Multimaps (com.google.common.collect.Multimaps)6 Collection (java.util.Collection)6