use of com.b2international.commons.options.Options in project snow-owl by b2ihealthcare.
the class DescendantsExpander method expand.
public final void expand(List<R> results, Set<String> ids) {
if (!expand().containsKey(descendantsExpandKey)) {
return;
}
final Options descendantExpandOptions = expand().get(descendantsExpandKey, Options.class);
final boolean direct = checkDirect(descendantExpandOptions);
expand(results, ids, descendantExpandOptions, direct);
}
use of com.b2international.commons.options.Options in project snow-owl by b2ihealthcare.
the class ResourceConverter method expandVersions.
private void expandVersions(List<Resource> results) {
if (expand().containsKey(TerminologyResource.Expand.VERSIONS)) {
Options expandOptions = expand().getOptions(TerminologyResource.Expand.VERSIONS);
// version searches must be performed on individual terminology resources to provide correct results
results.stream().filter(TerminologyResource.class::isInstance).map(TerminologyResource.class::cast).forEach(res -> {
Versions versions = ResourceRequests.prepareSearchVersion().filterByResource(res.getResourceURI()).setLimit(getLimit(expandOptions)).setFields(expandOptions.containsKey("fields") ? expandOptions.getList("fields", String.class) : null).sortBy(expandOptions.containsKey("sort") ? expandOptions.getString("sort") : null).setLocales(locales()).build().execute(context());
res.setVersions(versions);
});
}
}
use of com.b2international.commons.options.Options in project snow-owl by b2ihealthcare.
the class InactivationPropertiesExpander method expand.
void expand(List<? extends SnomedCoreComponent> results, Set<String> referencedComponentIds) {
if (!expand.containsKey(SnomedCoreComponent.Expand.INACTIVATION_PROPERTIES)) {
return;
}
final Multimap<String, SnomedReferenceSetMember> membersByReferencedComponentId = ArrayListMultimap.create();
SnomedRequests.prepareSearchMember().setLimit(10_000).filterByActive(true).filterByRefSet(String.format("<%s OR %s", Concepts.REFSET_ASSOCIATION_TYPE, inactivationIndicatorRefSetId)).filterByReferencedComponent(referencedComponentIds).stream(context).flatMap(SnomedReferenceSetMembers::stream).forEachOrdered(member -> {
membersByReferencedComponentId.put(member.getReferencedComponentId(), member);
});
final Options inactivationPropertiesExpand = expand.getOptions(SnomedCoreComponent.Expand.INACTIVATION_PROPERTIES);
Map<String, SnomedConcept> associationTargetComponentsById = Collections.emptyMap();
Map<String, SnomedConcept> inactivationIndicatorsById = Collections.emptyMap();
final Options nestedExpands = inactivationPropertiesExpand.getOptions("expand");
if (nestedExpands != null && nestedExpands.containsKey(InactivationProperties.Expand.ASSOCIATION_TARGETS)) {
final Options associationTargetsExpand = nestedExpands.getOptions(InactivationProperties.Expand.ASSOCIATION_TARGETS).getOptions("expand");
final Set<String> componentsToExpand = membersByReferencedComponentId.values().stream().filter(member -> SnomedRefSetType.ASSOCIATION.equals(member.type())).map(member -> (String) member.getProperties().get(SnomedRf2Headers.FIELD_TARGET_COMPONENT_ID)).filter(id -> !Strings.isNullOrEmpty(id)).collect(Collectors.toSet());
if (associationTargetsExpand != null && associationTargetsExpand.containsKey(AssociationTarget.Expand.TARGET_COMPONENT)) {
associationTargetComponentsById = expandConceptByIdMap(associationTargetsExpand.getOptions(AssociationTarget.Expand.TARGET_COMPONENT).getOptions("expand"), componentsToExpand, context);
}
}
if (nestedExpands != null && nestedExpands.containsKey(InactivationProperties.Expand.INACTIVATION_INDICATOR)) {
final Options inactivationIndicatorExpand = nestedExpands.getOptions(InactivationProperties.Expand.INACTIVATION_INDICATOR);
final Set<String> componentsToExpand = membersByReferencedComponentId.values().stream().filter(member -> SnomedRefSetType.ATTRIBUTE_VALUE.equals(member.type())).map(member -> (String) member.getProperties().get(SnomedRf2Headers.FIELD_VALUE_ID)).filter(id -> !Strings.isNullOrEmpty(id)).collect(Collectors.toSet());
inactivationIndicatorsById = expandConceptByIdMap(inactivationIndicatorExpand.getOptions("expand"), componentsToExpand, context);
}
for (SnomedCoreComponent result : results) {
final Collection<SnomedReferenceSetMember> referringMembers = membersByReferencedComponentId.get(result.getId());
final ImmutableList.Builder<AssociationTarget> associationTargets = ImmutableList.builder();
final Set<String> inactivationIndicatorIds = Sets.newHashSet();
for (SnomedReferenceSetMember referringMember : referringMembers) {
if (SnomedRefSetType.ASSOCIATION.equals(referringMember.type())) {
final AssociationTarget associationTarget = new AssociationTarget();
final String targetComponentId = (String) referringMember.getProperties().get(SnomedRf2Headers.FIELD_TARGET_COMPONENT_ID);
associationTarget.setReferenceSetId(referringMember.getRefsetId());
associationTarget.setTargetComponentId(targetComponentId);
if (associationTargetComponentsById.containsKey(targetComponentId)) {
associationTarget.setTargetComponent(associationTargetComponentsById.get(targetComponentId));
}
associationTargets.add(associationTarget);
} else if (SnomedRefSetType.ATTRIBUTE_VALUE.equals(referringMember.type())) {
inactivationIndicatorIds.add((String) referringMember.getProperties().get(SnomedRf2Headers.FIELD_VALUE_ID));
}
}
final String inactivationIndicatorId = Iterables.getFirst(inactivationIndicatorIds, null);
InactivationProperties inactivationProperties = new InactivationProperties();
inactivationProperties.setInactivationIndicatorId(inactivationIndicatorId);
inactivationProperties.setAssociationTargets(associationTargets.build());
if (!Strings.isNullOrEmpty(inactivationIndicatorId) && inactivationIndicatorsById.containsKey(inactivationIndicatorId)) {
inactivationProperties.setInactivationIndicator(inactivationIndicatorsById.get(inactivationIndicatorId));
}
result.setInactivationProperties(inactivationProperties);
}
}
use of com.b2international.commons.options.Options in project snow-owl by b2ihealthcare.
the class ModuleExpander method expand.
void expand(List<? extends SnomedComponent> results) {
if (expand.containsKey(SnomedComponent.Expand.MODULE)) {
final Options moduleOptions = expand.get(SnomedComponent.Expand.MODULE, Options.class);
final Iterable<String> moduleIds = results.stream().map(SnomedComponent::getModuleId)::iterator;
context.service(SnomedConceptRequestCache.class).request(moduleIds, moduleOptions.getOptions("expand"), locales, modulesById -> {
for (SnomedComponent component : results) {
component.setModule(modulesById.get(component.getModuleId()));
}
});
}
}
use of com.b2international.commons.options.Options 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);
}
}
});
}
}
Aggregations