org.molgenis.data.icd10.CollectionsQueryTransformerImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of molgenis-data-icd10 Show documentation
Show all versions of molgenis-data-icd10 Show documentation
ICD-10 related functionality
package org.molgenis.data.icd10;
import static com.google.common.graph.Traverser.forTree;
import static java.util.Collections.singletonList;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toList;
import com.google.common.collect.Streams;
import com.google.common.graph.Traverser;
import java.util.Collection;
import java.util.List;
import org.molgenis.data.DataService;
import org.molgenis.data.Entity;
import org.molgenis.data.Query;
import org.molgenis.data.QueryRule;
import org.springframework.stereotype.Component;
@Component
public class CollectionsQueryTransformerImpl implements CollectionsQueryTransformer {
private static final Traverser RULE_TRAVERSER = forTree(QueryRule::getNestedRules);
private final Icd10ClassExpander icd10ClassExpander;
private final DataService dataService;
CollectionsQueryTransformerImpl(Icd10ClassExpander icd10ClassExpander, DataService dataService) {
this.icd10ClassExpander = requireNonNull(icd10ClassExpander);
this.dataService = requireNonNull(dataService);
}
@Override
public Query transformQuery(
Query query, String icd10EntityTypeId, String expandAttribute) {
if (query != null && query.getRules() != null && !query.getRules().isEmpty()) {
query
.getRules()
.forEach(
rule ->
Streams.stream(RULE_TRAVERSER.depthFirstPreOrder(rule))
.filter(nestedRule -> isTransformableRule(nestedRule, expandAttribute))
.forEach(nestedRule -> transformQueryRule(nestedRule, icd10EntityTypeId)));
}
return query;
}
private void transformQueryRule(QueryRule rule, String icd10EntityTypeId) {
List