use of com.b2international.commons.options.Options 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);
}
}
});
}
}
use of com.b2international.commons.options.Options in project snow-owl by b2ihealthcare.
the class MembersExpander method expand.
void expand(List<? extends SnomedCoreComponent> results, Set<String> componentIds) {
if (expand.containsKey("members")) {
final Options membersOptions = expand.get("members", Options.class);
// TODO better support for limit, offset, filtering, selection
final SnomedRefSetMemberSearchRequestBuilder requestBuilder = SnomedRequests.prepareSearchMember().all().filterByReferencedComponent(componentIds);
addActiveFilter(requestBuilder, membersOptions);
addRefSetTypesFilter(requestBuilder, membersOptions);
final OptionsBuilder propertyOptionsBuilder = OptionsBuilder.newBuilder();
addCharacteristicTypeFilter(propertyOptionsBuilder, membersOptions);
final Options propertyOptions = propertyOptionsBuilder.build();
if (!propertyOptions.isEmpty()) {
requestBuilder.filterByProps(propertyOptions);
}
final SnomedReferenceSetMembers matchingMembers = requestBuilder.setLocales(locales).setExpand(membersOptions.get("expand", Options.class)).build().execute(context);
final Multimap<String, SnomedReferenceSetMember> membersByReferencedComponentId = Multimaps.index(matchingMembers, input -> input.getReferencedComponent().getId());
for (SnomedCoreComponent component : results) {
final Collection<SnomedReferenceSetMember> members = membersByReferencedComponentId.get(component.getId());
((SnomedCoreComponent) component).setMembers(new SnomedReferenceSetMembers(ImmutableList.copyOf(members), null, members.size(), members.size()));
}
}
}
use of com.b2international.commons.options.Options in project snow-owl by b2ihealthcare.
the class SnomedConceptConverter method expandDefinitionStatus.
private void expandDefinitionStatus(List<SnomedConcept> results) {
if (!expand().containsKey(SnomedConcept.Expand.DEFINITION_STATUS)) {
return;
}
final Options definitionStatusExpand = expand().getOptions(SnomedConcept.Expand.DEFINITION_STATUS).getOptions("expand");
final Iterable<String> definitionStatusIds = results.stream().map(SnomedConcept::getDefinitionStatusId)::iterator;
context().service(SnomedConceptRequestCache.class).request(definitionStatusIds, definitionStatusExpand, locales(), definitionStatusesById -> {
for (SnomedConcept result : results) {
result.setDefinitionStatus(definitionStatusesById.get(result.getDefinitionStatusId()));
}
});
}
use of com.b2international.commons.options.Options in project snow-owl by b2ihealthcare.
the class SnomedConceptConverter method expandAncestors.
private void expandAncestors(List<SnomedConcept> results, Set<String> conceptIds, String ancestorsExpandKey, boolean stated) {
if (!expand().containsKey(ancestorsExpandKey)) {
return;
}
final Options expandOptions = expand().get(ancestorsExpandKey, Options.class);
final boolean direct = DescendantsExpander.checkDirect(expandOptions, ancestorsExpandKey);
final Multimap<String, String> ancestorsByDescendant = TreeMultimap.create();
for (SnomedConcept concept : results) {
final long[] parentIds = stated ? concept.getStatedParentIds() : concept.getParentIds();
if (parentIds != null) {
for (long parent : parentIds) {
if (IComponent.ROOT_IDL != parent) {
ancestorsByDescendant.put(concept.getId(), Long.toString(parent));
}
}
}
if (!direct) {
final long[] ancestorIds = stated ? concept.getStatedAncestorIds() : concept.getAncestorIds();
if (ancestorIds != null) {
for (long ancestor : ancestorIds) {
if (IComponent.ROOT_IDL != ancestor) {
ancestorsByDescendant.put(concept.getId(), Long.toString(ancestor));
}
}
}
}
}
final int limit = getLimit(expandOptions);
final Collection<String> componentIds = newHashSet(ancestorsByDescendant.values());
if (limit > 0 && !componentIds.isEmpty()) {
final SnomedConcepts ancestors = SnomedRequests.prepareSearchConcept().all().filterByIds(componentIds).setLocales(locales()).setExpand(expandOptions.get("expand", Options.class)).build().execute(context());
final Map<String, SnomedConcept> ancestorsById = newHashMap();
ancestorsById.putAll(Maps.uniqueIndex(ancestors, SnomedConcept::getId));
for (SnomedConcept concept : results) {
final Collection<String> ancestorIds = ancestorsByDescendant.get(concept.getId());
final List<SnomedConcept> conceptAncestors = FluentIterable.from(ancestorIds).limit(limit).transform(Functions.forMap(ancestorsById)).toList();
final SnomedConcepts ancestorConcepts = new SnomedConcepts(conceptAncestors, null, limit, ancestorIds.size());
if (stated) {
concept.setStatedAncestors(ancestorConcepts);
} else {
concept.setAncestors(ancestorConcepts);
}
}
} else {
for (SnomedConcept concept : results) {
final Collection<String> ancestorIds = ancestorsByDescendant.get(concept.getId());
final SnomedConcepts ancestors = new SnomedConcepts(limit, ancestorIds.size());
if (stated) {
concept.setStatedAncestors(ancestors);
} else {
concept.setAncestors(ancestors);
}
}
}
}
use of com.b2international.commons.options.Options 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()));
});
}
});
}
}
Aggregations