use of com.b2international.snowowl.snomed.core.domain.SnomedConcept in project snow-owl by b2ihealthcare.
the class DescriptionChangeConverter method expand.
@Override
public void expand(final List<DescriptionChange> results) {
if (!expand().containsKey(DescriptionChange.Expand.DESCRIPTION)) {
return;
}
/*
* Depending on the CD member change search request, we might need to issue
* SNOMED CT searches against multiple branches; find out which ones we have.
*/
final Multimap<String, DescriptionChange> itemsByBranch = getItemsByBranch(results);
// Check if we only need to load inferred CD members in their entirety
final Options expandOptions = expand().getOptions(DescriptionChange.Expand.DESCRIPTION);
final boolean inferredOnly = expandOptions.getBoolean("inferredOnly");
final Options descriptionExpandOptions = expandOptions.getOptions("expand");
final Options conceptOptions = descriptionExpandOptions.getOptions("concept");
final boolean needsConcept = descriptionExpandOptions.keySet().contains("concept");
for (final String branch : itemsByBranch.keySet()) {
final Collection<DescriptionChange> itemsForCurrentBranch = itemsByBranch.get(branch);
/*
* Expand concept on "new" descriptions via a separate search request, they will
* be different from the concept on the "origin" description.
*/
if (needsConcept) {
final List<ReasonerDescription> blankDescriptions = itemsForCurrentBranch.stream().filter(c -> ChangeNature.NEW.equals(c.getChangeNature())).map(DescriptionChange::getDescription).collect(Collectors.toList());
final Multimap<String, ReasonerDescription> descriptionsByConceptId = FluentIterable.from(blankDescriptions).index(ReasonerDescription::getConceptId);
final Set<String> conceptIds = descriptionsByConceptId.keySet();
final Request<BranchContext, SnomedConcepts> conceptSearchRequest = SnomedRequests.prepareSearchConcept().filterByIds(conceptIds).setLimit(conceptIds.size()).setExpand(conceptOptions.get("expand", Options.class)).setLocales(locales()).build();
final SnomedConcepts concepts = new BranchRequest<>(branch, new RevisionIndexReadRequest<>(conceptSearchRequest)).execute(context());
for (final SnomedConcept concept : concepts) {
final String conceptId = concept.getId();
final Collection<ReasonerDescription> descriptionsForConcept = descriptionsByConceptId.get(conceptId);
for (final ReasonerDescription description : descriptionsForConcept) {
description.setConcept(concept);
}
}
}
/*
* Then fetch all the required descriptions. Note that the same "origin"
* description might be used for multiple eg. "new" counterparts.
*/
final Set<String> descriptionIds = itemsForCurrentBranch.stream().filter(c -> !inferredOnly || ChangeNature.NEW.equals(c.getChangeNature())).map(c -> c.getDescription().getOriginDescriptionId()).collect(Collectors.toSet());
final Request<BranchContext, SnomedDescriptions> descriptionSearchRequest = SnomedRequests.prepareSearchDescription().filterByIds(descriptionIds).setLimit(descriptionIds.size()).setExpand(descriptionExpandOptions).setLocales(locales()).build();
final SnomedDescriptions descriptions = new BranchRequest<>(branch, new RevisionIndexReadRequest<>(descriptionSearchRequest)).execute(context());
final Map<String, SnomedDescription> descriptionsById = Maps.uniqueIndex(descriptions, SnomedDescription::getId);
for (final DescriptionChange item : itemsForCurrentBranch) {
final ReasonerDescription reasonerDescription = item.getDescription();
final String descriptionId = reasonerDescription.getOriginDescriptionId();
switch(item.getChangeNature()) {
case NEW:
{
final SnomedDescription expandedDescription = descriptionsById.get(descriptionId);
reasonerDescription.setAcceptabilityMap(expandedDescription.getAcceptabilityMap());
reasonerDescription.setCaseSignificanceId(expandedDescription.getCaseSignificanceId());
// reasonerDescription.setConcept(...) is already set earlier (or expanded)
reasonerDescription.setLanguageCode(expandedDescription.getLanguageCode());
// reasonerMember.setReleased(...) is already set
reasonerDescription.setTerm(expandedDescription.getTerm());
reasonerDescription.setType(expandedDescription.getType());
}
break;
case REDUNDANT:
if (!inferredOnly) {
final SnomedDescription expandedDescription = descriptionsById.get(descriptionId);
reasonerDescription.setAcceptabilityMap(expandedDescription.getAcceptabilityMap());
reasonerDescription.setCaseSignificanceId(expandedDescription.getCaseSignificanceId());
reasonerDescription.setConcept(expandedDescription.getConcept());
reasonerDescription.setLanguageCode(expandedDescription.getLanguageCode());
// reasonerMember.setReleased(...) is already set
reasonerDescription.setTerm(expandedDescription.getTerm());
reasonerDescription.setType(expandedDescription.getType());
}
break;
default:
throw new IllegalStateException(String.format("Unexpected description change '%s' found with SCTID '%s'.", item.getChangeNature(), item.getDescription().getOriginDescriptionId()));
}
}
}
}
use of com.b2international.snowowl.snomed.core.domain.SnomedConcept in project snow-owl by b2ihealthcare.
the class EquivalentConceptSetConverter method expand.
@Override
public void expand(final List<EquivalentConceptSet> results) {
if (!expand().containsKey(EquivalentConceptSet.Expand.EQUIVALENT_CONCEPTS)) {
return;
}
final Set<String> classificationTaskIds = results.stream().map(EquivalentConceptSet::getClassificationId).collect(Collectors.toSet());
final Map<String, String> branchesByClassificationIdMap = ClassificationRequests.prepareSearchClassification().filterByIds(classificationTaskIds).all().build().execute(context()).stream().collect(Collectors.toMap(ClassificationTask::getId, ClassificationTask::getBranch));
final Multimap<String, EquivalentConceptSet> itemsByBranch = Multimaps.index(results, r -> branchesByClassificationIdMap.get(r.getClassificationId()));
final Options expandOptions = expand().get(EquivalentConceptSet.Expand.EQUIVALENT_CONCEPTS, Options.class);
for (final String branch : itemsByBranch.keySet()) {
final Collection<EquivalentConceptSet> itemsForCurrentBranch = itemsByBranch.get(branch);
final Set<String> conceptIds = itemsForCurrentBranch.stream().flatMap(c -> c.getEquivalentConcepts().stream()).map(SnomedConcept::getId).collect(Collectors.toSet());
final SnomedConcepts concepts = SnomedRequests.prepareSearchConcept().filterByIds(conceptIds).all().setExpand(expandOptions.get("expand", Options.class)).setLocales(locales()).build(branch).getRequest().execute(context());
final Map<String, SnomedConcept> conceptsById = Maps.uniqueIndex(concepts, SnomedConcept::getId);
for (final EquivalentConceptSet item : itemsForCurrentBranch) {
final List<SnomedConcept> equivalentConcepts = item.getEquivalentConcepts().getItems();
for (int i = 0; i < equivalentConcepts.size(); i++) {
final SnomedConcept placeholderConcept = equivalentConcepts.get(i);
final SnomedConcept expandedConcept = conceptsById.get(placeholderConcept.getId());
equivalentConcepts.set(i, expandedConcept);
}
}
}
}
use of com.b2international.snowowl.snomed.core.domain.SnomedConcept in project snow-owl by b2ihealthcare.
the class BranchCompareRequestTest method prepareBranchWithNewChanges.
private Set<ComponentIdentifier> prepareBranchWithNewChanges(String branchPath) {
final IBranchPath branch = BranchPathUtils.createPath(branchPath);
final String newConceptId = createNewConcept(branch);
final SnomedConcept concept = getComponent(branch, SnomedComponentType.CONCEPT, newConceptId, "descriptions(expand(members())),relationships()").extract().as(SnomedConcept.class);
final Set<ComponentIdentifier> newIds = newHashSet();
newIds.add(ComponentIdentifier.of(SnomedConcept.TYPE, concept.getId()));
for (SnomedDescription description : concept.getDescriptions()) {
newIds.add(ComponentIdentifier.of(SnomedDescription.TYPE, description.getId()));
for (SnomedReferenceSetMember member : description.getMembers()) {
newIds.add(ComponentIdentifier.of(SnomedReferenceSetMember.TYPE, member.getId()));
}
}
for (SnomedRelationship relationship : concept.getRelationships()) {
newIds.add(ComponentIdentifier.of(SnomedRelationship.TYPE, relationship.getId()));
}
return newIds;
}
use of com.b2international.snowowl.snomed.core.domain.SnomedConcept in project snow-owl by b2ihealthcare.
the class BranchCompareRequestTest method compareBranchWithChangedComponents.
@Test
public void compareBranchWithChangedComponents() throws Exception {
final IBranchPath branch = BranchPathUtils.createPath(branchPath);
final String newConceptId = createNewConcept(branch);
final SnomedConcept concept = getComponent(branch, SnomedComponentType.CONCEPT, newConceptId).extract().as(SnomedConcept.class);
final String taskBranchPath = createBranch(branchPath, "taskBranch");
SnomedRequests.prepareUpdateConcept(concept.getId()).setModuleId(Concepts.MODULE_SCT_MODEL_COMPONENT).build(taskBranchPath, RestExtensions.USER, "Change module ID").execute(bus).getSync();
// compare task branch and its parent
final BranchCompareResult compare = compare(branchPath, taskBranchPath);
assertThat(compare.getNewComponents()).isEmpty();
assertThat(compare.getChangedComponents()).contains(ComponentIdentifier.of(SnomedConcept.TYPE, newConceptId));
assertThat(compare.getDeletedComponents()).isEmpty();
}
use of com.b2international.snowowl.snomed.core.domain.SnomedConcept in project snow-owl by b2ihealthcare.
the class SnomedCompareRestRequestTest method prepareNewChanges.
private Set<ComponentIdentifier> prepareNewChanges(String conceptId, IBranchPath branchPath) {
final SnomedConcept concept = getComponent(branchPath, SnomedComponentType.CONCEPT, conceptId, "descriptions(expand(members())),relationships()").extract().as(SnomedConcept.class);
final Set<ComponentIdentifier> newIds = newHashSet();
newIds.add(ComponentIdentifier.of(SnomedConcept.TYPE, concept.getId()));
for (SnomedDescription description : concept.getDescriptions()) {
newIds.add(ComponentIdentifier.of(SnomedDescription.TYPE, description.getId()));
for (SnomedReferenceSetMember member : description.getMembers()) {
newIds.add(ComponentIdentifier.of(SnomedReferenceSetMember.TYPE, member.getId()));
}
}
for (SnomedRelationship relationship : concept.getRelationships()) {
newIds.add(ComponentIdentifier.of(SnomedRelationship.TYPE, relationship.getId()));
}
return newIds;
}
Aggregations