use of com.b2international.snowowl.snomed.core.domain.SnomedCoreComponent in project snow-owl by b2ihealthcare.
the class MapTypeRefSetDSVExporter method prepareLabelCache.
private Map<String, String> prepareLabelCache(SnomedReferenceSetMembers membersToExport) {
final SnomedConcepts modelComponents = SnomedRequests.prepareSearchConcept().all().filterByActive(true).filterByEcl(String.format("< (%s OR %s) ", Concepts.MODULE_ROOT, Concepts.REFSET_ATTRIBUTE)).setExpand("fsn()").setLocales(exportSetting.getLocales()).build().execute(context);
final Map<String, String> labels = newHashMapWithExpectedSize(membersToExport.getTotal() + modelComponents.getTotal());
modelComponents.forEach(modelComponent -> {
labels.put(modelComponent.getId(), getFsnOrId(modelComponent));
});
for (SnomedReferenceSetMember snomedReferenceSetMember : membersToExport) {
SnomedCoreComponent referencedComponent = snomedReferenceSetMember.getReferencedComponent();
String id = referencedComponent.getId();
if (referencedComponent instanceof SnomedConcept) {
labels.put(id, getFsnOrId((SnomedConcept) referencedComponent));
} else if (referencedComponent instanceof SnomedDescription) {
labels.put(id, ((SnomedDescription) referencedComponent).getTerm());
} else if (referencedComponent instanceof SnomedRelationship) {
SnomedRelationship relationship = (SnomedRelationship) referencedComponent;
if (relationship.hasValue()) {
labels.put(id, String.format("%s - %s - %s", relationship.getSourceId(), relationship.getTypeId(), relationship.getValue()));
} else {
labels.put(id, String.format("%s - %s - %s", relationship.getSourceId(), relationship.getTypeId(), relationship.getDestinationId()));
}
}
}
return labels;
}
use of com.b2international.snowowl.snomed.core.domain.SnomedCoreComponent in project snow-owl by b2ihealthcare.
the class SnomedReferenceSetMemberConverter method setReferencedComponent.
private void setReferencedComponent(SnomedReferenceSetMember member, String referencedComponentId, String referencedComponentType) {
// XXX: partial field loading support
if (referencedComponentType == null || referencedComponentId == null)
return;
final SnomedCoreComponent component;
switch(referencedComponentType) {
// TODO support query type refset refcomp expansion, currently it's a concept
case SnomedConcept.REFSET_TYPE:
case SnomedConcept.TYPE:
component = new SnomedConcept();
((SnomedConcept) component).setId(referencedComponentId);
break;
case SnomedDescription.TYPE:
component = new SnomedDescription();
((SnomedDescription) component).setId(referencedComponentId);
break;
case SnomedRelationship.TYPE:
component = new SnomedRelationship();
((SnomedRelationship) component).setId(referencedComponentId);
break;
default:
throw new UnsupportedOperationException("UnsupportedReferencedComponentType: " + referencedComponentType);
}
member.setReferencedComponent(component);
}
use of com.b2international.snowowl.snomed.core.domain.SnomedCoreComponent 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.snowowl.snomed.core.domain.SnomedCoreComponent 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);
}
}
}
}
}
}
use of com.b2international.snowowl.snomed.core.domain.SnomedCoreComponent 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()));
}
}
}
Aggregations