use of com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers in project snow-owl by b2ihealthcare.
the class SnomedDescriptionApiTest method updateAcceptability.
@Test
public void updateAcceptability() {
String descriptionId = createNewDescription(branchPath);
SnomedReferenceSetMembers beforeMembers = getComponent(branchPath, SnomedComponentType.DESCRIPTION, descriptionId, "members()").statusCode(200).extract().as(SnomedDescription.class).getMembers();
assertEquals(1, beforeMembers.getTotal());
SnomedReferenceSetMember beforeMember = Iterables.getOnlyElement(beforeMembers);
Json requestBody = Json.object("acceptability", SnomedApiTestConstants.UK_PREFERRED_MAP, "commitComment", "Updated description acceptability");
updateComponent(branchPath, SnomedComponentType.DESCRIPTION, descriptionId, requestBody).statusCode(204);
SnomedReferenceSetMembers afterMembers = getComponent(branchPath, SnomedComponentType.DESCRIPTION, descriptionId, "members()").statusCode(200).extract().as(SnomedDescription.class).getMembers();
assertEquals(1, afterMembers.getTotal());
SnomedReferenceSetMember afterMember = Iterables.getOnlyElement(afterMembers);
assertEquals(beforeMember.getId(), afterMember.getId());
assertEquals(Concepts.REFSET_DESCRIPTION_ACCEPTABILITY_PREFERRED, afterMember.getProperties().get(SnomedRf2Headers.FIELD_ACCEPTABILITY_ID));
assertEquals(Concepts.REFSET_LANGUAGE_TYPE_UK, afterMember.getRefsetId());
}
use of com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers in project snow-owl by b2ihealthcare.
the class SnomedDescriptionApiTest method updateAcceptabilityWithAddition.
@Test
public void updateAcceptabilityWithAddition() throws Exception {
changeToAcceptable(branchPath, Concepts.ROOT_CONCEPT, Concepts.REFSET_LANGUAGE_TYPE_UK);
String descriptionId = createNewDescription(branchPath, Concepts.ROOT_CONCEPT, Concepts.SYNONYM, SnomedApiTestConstants.UK_PREFERRED_MAP);
changeToAcceptable(branchPath, Concepts.ROOT_CONCEPT, Concepts.REFSET_LANGUAGE_TYPE_US);
Json requestBody = Json.object("acceptability", Json.object(Concepts.REFSET_LANGUAGE_TYPE_UK, Acceptability.ACCEPTABLE, Concepts.REFSET_LANGUAGE_TYPE_US, Acceptability.PREFERRED), "commitComment", "Changed UK, added US acceptability to description");
updateComponent(branchPath, SnomedComponentType.DESCRIPTION, descriptionId, requestBody).statusCode(204);
SnomedReferenceSetMembers members = getComponent(branchPath, SnomedComponentType.DESCRIPTION, descriptionId, "members()").statusCode(200).body("members.items.refsetId", hasItems(Concepts.REFSET_LANGUAGE_TYPE_UK, Concepts.REFSET_LANGUAGE_TYPE_US)).extract().as(SnomedDescription.class).getMembers();
assertEquals(2, members.getTotal());
getComponent(branchPath, SnomedComponentType.CONCEPT, Concepts.ROOT_CONCEPT, "pt()").statusCode(200).body("pt.id", equalTo(descriptionId));
}
use of com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers in project snow-owl by b2ihealthcare.
the class InactivationPropertiesExpander method expand.
void expand(List<? extends SnomedCoreComponent> results, Set<String> referencedComponentIds) {
if (!expand.containsKey(SnomedCoreComponent.Expand.INACTIVATION_PROPERTIES)) {
return;
}
final Multimap<String, SnomedReferenceSetMember> membersByReferencedComponentId = ArrayListMultimap.create();
SnomedRequests.prepareSearchMember().setLimit(10_000).filterByActive(true).filterByRefSet(String.format("<%s OR %s", Concepts.REFSET_ASSOCIATION_TYPE, inactivationIndicatorRefSetId)).filterByReferencedComponent(referencedComponentIds).stream(context).flatMap(SnomedReferenceSetMembers::stream).forEachOrdered(member -> {
membersByReferencedComponentId.put(member.getReferencedComponentId(), member);
});
final Options inactivationPropertiesExpand = expand.getOptions(SnomedCoreComponent.Expand.INACTIVATION_PROPERTIES);
Map<String, SnomedConcept> associationTargetComponentsById = Collections.emptyMap();
Map<String, SnomedConcept> inactivationIndicatorsById = Collections.emptyMap();
final Options nestedExpands = inactivationPropertiesExpand.getOptions("expand");
if (nestedExpands != null && nestedExpands.containsKey(InactivationProperties.Expand.ASSOCIATION_TARGETS)) {
final Options associationTargetsExpand = nestedExpands.getOptions(InactivationProperties.Expand.ASSOCIATION_TARGETS).getOptions("expand");
final Set<String> componentsToExpand = membersByReferencedComponentId.values().stream().filter(member -> SnomedRefSetType.ASSOCIATION.equals(member.type())).map(member -> (String) member.getProperties().get(SnomedRf2Headers.FIELD_TARGET_COMPONENT_ID)).filter(id -> !Strings.isNullOrEmpty(id)).collect(Collectors.toSet());
if (associationTargetsExpand != null && associationTargetsExpand.containsKey(AssociationTarget.Expand.TARGET_COMPONENT)) {
associationTargetComponentsById = expandConceptByIdMap(associationTargetsExpand.getOptions(AssociationTarget.Expand.TARGET_COMPONENT).getOptions("expand"), componentsToExpand, context);
}
}
if (nestedExpands != null && nestedExpands.containsKey(InactivationProperties.Expand.INACTIVATION_INDICATOR)) {
final Options inactivationIndicatorExpand = nestedExpands.getOptions(InactivationProperties.Expand.INACTIVATION_INDICATOR);
final Set<String> componentsToExpand = membersByReferencedComponentId.values().stream().filter(member -> SnomedRefSetType.ATTRIBUTE_VALUE.equals(member.type())).map(member -> (String) member.getProperties().get(SnomedRf2Headers.FIELD_VALUE_ID)).filter(id -> !Strings.isNullOrEmpty(id)).collect(Collectors.toSet());
inactivationIndicatorsById = expandConceptByIdMap(inactivationIndicatorExpand.getOptions("expand"), componentsToExpand, context);
}
for (SnomedCoreComponent result : results) {
final Collection<SnomedReferenceSetMember> referringMembers = membersByReferencedComponentId.get(result.getId());
final ImmutableList.Builder<AssociationTarget> associationTargets = ImmutableList.builder();
final Set<String> inactivationIndicatorIds = Sets.newHashSet();
for (SnomedReferenceSetMember referringMember : referringMembers) {
if (SnomedRefSetType.ASSOCIATION.equals(referringMember.type())) {
final AssociationTarget associationTarget = new AssociationTarget();
final String targetComponentId = (String) referringMember.getProperties().get(SnomedRf2Headers.FIELD_TARGET_COMPONENT_ID);
associationTarget.setReferenceSetId(referringMember.getRefsetId());
associationTarget.setTargetComponentId(targetComponentId);
if (associationTargetComponentsById.containsKey(targetComponentId)) {
associationTarget.setTargetComponent(associationTargetComponentsById.get(targetComponentId));
}
associationTargets.add(associationTarget);
} else if (SnomedRefSetType.ATTRIBUTE_VALUE.equals(referringMember.type())) {
inactivationIndicatorIds.add((String) referringMember.getProperties().get(SnomedRf2Headers.FIELD_VALUE_ID));
}
}
final String inactivationIndicatorId = Iterables.getFirst(inactivationIndicatorIds, null);
InactivationProperties inactivationProperties = new InactivationProperties();
inactivationProperties.setInactivationIndicatorId(inactivationIndicatorId);
inactivationProperties.setAssociationTargets(associationTargets.build());
if (!Strings.isNullOrEmpty(inactivationIndicatorId) && inactivationIndicatorsById.containsKey(inactivationIndicatorId)) {
inactivationProperties.setInactivationIndicator(inactivationIndicatorsById.get(inactivationIndicatorId));
}
result.setInactivationProperties(inactivationProperties);
}
}
use of com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers 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()));
}
}
}
use of com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers in project snow-owl by b2ihealthcare.
the class ConcreteDomainChangeConverter method expand.
@Override
public void expand(final List<ConcreteDomainChange> results) {
if (!expand().containsKey(ConcreteDomainChange.Expand.CONCRETE_DOMAIN_MEMBER)) {
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, ConcreteDomainChange> itemsByBranch = getItemsByBranch(results);
// Check if we only need to load inferred CD members in their entirety
final Options expandOptions = expand().getOptions(ConcreteDomainChange.Expand.CONCRETE_DOMAIN_MEMBER);
final boolean inferredOnly = expandOptions.getBoolean("inferredOnly");
final Options cdMemberExpandOptions = expandOptions.getOptions("expand");
final Options referencedComponentOptions = cdMemberExpandOptions.getOptions(SnomedReferenceSetMember.Expand.REFERENCED_COMPONENT);
/*
* Remove this option from the member expand options map, so that member search
* does not expand the referenced component again
*/
final boolean needsReferencedComponent = cdMemberExpandOptions.keySet().remove(SnomedReferenceSetMember.Expand.REFERENCED_COMPONENT);
for (final String branch : itemsByBranch.keySet()) {
final Collection<ConcreteDomainChange> itemsForCurrentBranch = itemsByBranch.get(branch);
/*
* Expand referenced component on members via a separate search request, as they
* can be different from the referenced component on the "origin" member
*/
if (needsReferencedComponent) {
final List<ReasonerConcreteDomainMember> blankMembers = itemsForCurrentBranch.stream().filter(c -> !inferredOnly || ChangeNature.NEW.equals(c.getChangeNature())).map(ConcreteDomainChange::getConcreteDomainMember).collect(Collectors.toList());
final Multimap<String, ReasonerConcreteDomainMember> membersByReferencedComponent = Multimaps.index(blankMembers, ReasonerConcreteDomainMember::getReferencedComponentId);
final Multimap<ComponentCategory, String> referencedComponentsByCategory = Multimaps.index(membersByReferencedComponent.keySet(), SnomedIdentifiers::getComponentCategory);
for (final Entry<ComponentCategory, Collection<String>> categoryEntry : referencedComponentsByCategory.asMap().entrySet()) {
expandComponentCategory(branch, categoryEntry.getKey(), categoryEntry.getValue(), referencedComponentOptions, membersByReferencedComponent);
}
}
/*
* Then fetch all the required members (these will have a referenced component
* ID that should no longer be copied on inferred members). Note that the same "origin"
* member might be used for multiple eg. "new" counterparts.
*/
final Set<String> cdMemberUuids = itemsForCurrentBranch.stream().filter(c -> !inferredOnly || ChangeNature.NEW.equals(c.getChangeNature())).map(c -> c.getConcreteDomainMember().getOriginMemberId()).collect(Collectors.toSet());
final Request<BranchContext, SnomedReferenceSetMembers> cdMemberSearchRequest = SnomedRequests.prepareSearchMember().filterByIds(cdMemberUuids).setLimit(cdMemberUuids.size()).setExpand(cdMemberExpandOptions).setLocales(locales()).build();
final SnomedReferenceSetMembers cdMembers = new BranchRequest<>(branch, new RevisionIndexReadRequest<>(cdMemberSearchRequest)).execute(context());
final Map<String, SnomedReferenceSetMember> cdMembersByUuid = Maps.uniqueIndex(cdMembers, SnomedReferenceSetMember::getId);
/*
* Finally, set the member on the change item, but preserve the properties that
* were already set in "toResource"
*/
for (final ConcreteDomainChange item : itemsForCurrentBranch) {
final ReasonerConcreteDomainMember reasonerMember = item.getConcreteDomainMember();
final String memberUuid = reasonerMember.getOriginMemberId();
switch(item.getChangeNature()) {
case NEW:
{
final SnomedReferenceSetMember expandedMember = cdMembersByUuid.get(memberUuid);
final Map<String, Object> expandedProperties = expandedMember.getProperties();
// reasonerMember.setCharacteristicTypeId(...) is already set
// reasonerMember.setGroup(...) is already set
// reasonerMember.setReferencedComponent(...) is already set (or expanded)
reasonerMember.setReferenceSetId(expandedMember.getRefsetId());
// reasonerMember.setReleased(...) is already set
reasonerMember.setSerializedValue((String) expandedProperties.get(SnomedRf2Headers.FIELD_VALUE));
reasonerMember.setTypeId((String) expandedProperties.get(SnomedRf2Headers.FIELD_TYPE_ID));
}
break;
case UPDATED:
if (!inferredOnly) {
final SnomedReferenceSetMember expandedMember = cdMembersByUuid.get(memberUuid);
final Map<String, Object> expandedProperties = expandedMember.getProperties();
reasonerMember.setCharacteristicTypeId((String) expandedProperties.get(SnomedRf2Headers.FIELD_CHARACTERISTIC_TYPE_ID));
reasonerMember.setGroup((Integer) expandedProperties.get(SnomedRf2Headers.FIELD_RELATIONSHIP_GROUP));
// reasonerMember.setReferencedComponent(...) is already set (or expanded)
reasonerMember.setReferenceSetId(expandedMember.getRefsetId());
// reasonerMember.setReleased(...) is already set
// reasonerMember.setSerializedValue(...) is already set
reasonerMember.setTypeId((String) expandedProperties.get(SnomedRf2Headers.FIELD_TYPE_ID));
}
break;
case REDUNDANT:
if (!inferredOnly) {
final SnomedReferenceSetMember expandedMember = cdMembersByUuid.get(memberUuid);
final Map<String, Object> expandedProperties = expandedMember.getProperties();
reasonerMember.setCharacteristicTypeId((String) expandedProperties.get(SnomedRf2Headers.FIELD_CHARACTERISTIC_TYPE_ID));
reasonerMember.setGroup((Integer) expandedProperties.get(SnomedRf2Headers.FIELD_RELATIONSHIP_GROUP));
// reasonerMember.setReferencedComponent(...) is already set (or expanded)
reasonerMember.setReferenceSetId(expandedMember.getRefsetId());
// reasonerMember.setReleased(...) is already set
reasonerMember.setSerializedValue((String) expandedProperties.get(SnomedRf2Headers.FIELD_VALUE));
reasonerMember.setTypeId((String) expandedProperties.get(SnomedRf2Headers.FIELD_TYPE_ID));
}
break;
default:
throw new IllegalStateException(String.format("Unexpected CD member change '%s' found with UUID '%s'.", item.getChangeNature(), item.getConcreteDomainMember().getOriginMemberId()));
}
}
}
}
Aggregations