use of com.b2international.snowowl.snomed.core.domain.AcceptabilityMembership 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