use of com.b2international.commons.options.Options in project snow-owl by b2ihealthcare.
the class SnomedDescriptionConverter method expandType.
private void expandType(List<SnomedDescription> results, final Set<String> descriptionIds) {
if (expand().containsKey("type")) {
final Options expandOptions = expand().get("type", Options.class);
final Iterable<String> typeIds = FluentIterable.from(results).transform(SnomedDescription::getTypeId);
context().service(SnomedConceptRequestCache.class).request(typeIds, expandOptions.getOptions("expand"), locales(), typesById -> {
for (SnomedDescription description : results) {
((SnomedDescription) description).setType(typesById.get(description.getTypeId()));
}
});
}
}
use of com.b2international.commons.options.Options in project snow-owl by b2ihealthcare.
the class SnomedDescriptionConverter method expandConcept.
private void expandConcept(List<SnomedDescription> results, final Set<String> descriptionIds) {
if (expand().containsKey("concept")) {
final Options expandOptions = expand().get("concept", Options.class);
final Iterable<String> conceptIds = FluentIterable.from(results).transform(SnomedDescription::getConceptId);
context().service(SnomedConceptRequestCache.class).request(conceptIds, expandOptions.getOptions("expand"), locales(), conceptsById -> {
for (SnomedDescription description : results) {
((SnomedDescription) description).setConcept(conceptsById.get(description.getConceptId()));
}
});
}
}
use of com.b2international.commons.options.Options in project snow-owl by b2ihealthcare.
the class SnomedDescriptionConverter method expandCaseSignificance.
private void expandCaseSignificance(List<SnomedDescription> results) {
if (!expand().containsKey("caseSignificance")) {
return;
}
final Iterable<String> caseSignificanceIds = results.stream().map(SnomedDescription::getCaseSignificanceId)::iterator;
final Options caseSignificanceExpand = expand().get("caseSignificance", Options.class);
context().service(SnomedConceptRequestCache.class).request(caseSignificanceIds, caseSignificanceExpand.getOptions("expand"), locales(), caseSignificancesById -> {
for (SnomedDescription result : results) {
result.setCaseSignificance(caseSignificancesById.get(result.getCaseSignificanceId()));
}
});
}
use of com.b2international.commons.options.Options in project snow-owl by b2ihealthcare.
the class SnomedReferenceSetMemberConverter method expandComponentCategory.
private void expandComponentCategory(Options expandOptions, Multimap<String, SnomedReferenceSetMember> referencedComponentIdToMemberMap, Multimap<ComponentCategory, String> componentCategoryToIdMap, ComponentCategory category) {
final Collection<String> componentIds = componentCategoryToIdMap.get(category);
final SearchResourceRequestBuilder<?, BranchContext, ? extends CollectionResource<? extends SnomedCoreComponent>> search;
switch(category) {
case CONCEPT:
search = SnomedRequests.prepareSearchConcept();
break;
case DESCRIPTION:
search = SnomedRequests.prepareSearchDescription();
break;
case RELATIONSHIP:
search = SnomedRequests.prepareSearchRelationship();
break;
default:
throw new UnsupportedOperationException("Category is not supported in referenced component expansion");
}
search.filterByIds(componentIds).setLimit(componentIds.size()).setLocales(locales()).setExpand(expandOptions.get("expand", Options.class));
CollectionResource<? extends SnomedCoreComponent> components = search.build().execute(context());
for (SnomedCoreComponent component : components) {
for (SnomedReferenceSetMember member : referencedComponentIdToMemberMap.get(component.getId())) {
((SnomedReferenceSetMember) member).setReferencedComponent(component);
}
}
}
use of com.b2international.commons.options.Options in project snow-owl by b2ihealthcare.
the class SnomedReferenceSetMemberConverter method expandTargetComponent.
private void expandTargetComponent(List<SnomedReferenceSetMember> results) {
if (expand().containsKey(SnomedReferenceSetMember.Expand.TARGET_COMPONENT)) {
final Options expandOptions = expand().get(SnomedReferenceSetMember.Expand.TARGET_COMPONENT, Options.class);
final Multimap<String, SnomedReferenceSetMember> membersByTargetComponent = HashMultimap.create();
for (SnomedReferenceSetMember member : results) {
final Map<String, Object> props = member.getProperties();
if (props.containsKey(SnomedRf2Headers.FIELD_TARGET_COMPONENT_ID)) {
membersByTargetComponent.put(((String) props.get(SnomedRf2Headers.FIELD_TARGET_COMPONENT_ID)), member);
}
}
final Multimap<ComponentCategory, String> targetComponentIdsByCategory = Multimaps.index(membersByTargetComponent.keySet(), new Function<String, ComponentCategory>() {
@Override
public ComponentCategory apply(String id) {
return SnomedIdentifiers.getComponentCategory(id);
}
});
for (ComponentCategory category : targetComponentIdsByCategory.keySet()) {
final Collection<String> targetComponentIds = targetComponentIdsByCategory.get(category);
final Map<String, ? extends SnomedCoreComponent> componentsById = Maps.uniqueIndex(getComponents(category, targetComponentIds, expandOptions.get("expand", Options.class)), IComponent::getId);
for (String targetComponentId : targetComponentIds) {
final SnomedCoreComponent targetComponent = componentsById.get(targetComponentId);
if (targetComponent != null) {
for (SnomedReferenceSetMember member : membersByTargetComponent.get(targetComponentId)) {
final Map<String, Object> newProps = newHashMap(member.getProperties());
newProps.put(SnomedReferenceSetMember.Expand.TARGET_COMPONENT, targetComponent);
((SnomedReferenceSetMember) member).setProperties(newProps);
}
}
}
}
}
}
Aggregations