use of com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember in project snow-owl by b2ihealthcare.
the class SnomedRefSetMemberApiTest method createAndUpdateModuleDependencyMemberWithEffectiveTime.
@Test
public void createAndUpdateModuleDependencyMemberWithEffectiveTime() {
Json requestBody = createRefSetMemberRequestBody(Concepts.REFSET_MODULE_DEPENDENCY_TYPE, Concepts.MODULE_SCT_MODEL_COMPONENT).with(SnomedRf2Headers.FIELD_SOURCE_EFFECTIVE_TIME, "20181001").with(SnomedRf2Headers.FIELD_TARGET_EFFECTIVE_TIME, "20181001").with("commitComment", "Created new module dependency reference set member");
String memberId = assertCreated(createComponent(branchPath, SnomedComponentType.MEMBER, requestBody));
SnomedReferenceSetMember member = getComponent(branchPath, SnomedComponentType.MEMBER, memberId).statusCode(200).extract().as(SnomedReferenceSetMember.class);
assertEquals(EffectiveTimes.parse("20181001", DateFormats.SHORT), member.getProperties().get(SnomedRf2Headers.FIELD_SOURCE_EFFECTIVE_TIME));
assertEquals(EffectiveTimes.parse("20181001", DateFormats.SHORT), member.getProperties().get(SnomedRf2Headers.FIELD_TARGET_EFFECTIVE_TIME));
Json updateRequest = Json.object(SnomedRf2Headers.FIELD_SOURCE_EFFECTIVE_TIME, "", SnomedRf2Headers.FIELD_TARGET_EFFECTIVE_TIME, "", "commitComment", "Updated reference set member");
updateRefSetComponent(branchPath, SnomedComponentType.MEMBER, memberId, updateRequest, false).statusCode(204);
SnomedReferenceSetMember updatedMember = getComponent(branchPath, SnomedComponentType.MEMBER, memberId).statusCode(200).extract().as(SnomedReferenceSetMember.class);
assertNull(updatedMember.getProperties().get(SnomedRf2Headers.FIELD_SOURCE_EFFECTIVE_TIME));
assertNull(updatedMember.getProperties().get(SnomedRf2Headers.FIELD_TARGET_EFFECTIVE_TIME));
}
use of com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember 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.SnomedReferenceSetMember in project snow-owl by b2ihealthcare.
the class SnomedRefSetMemberApiTest method updateOwlAxiomRefsetMembers.
@Test
public void updateOwlAxiomRefsetMembers() {
String conceptId = createNewConcept(branchPath);
Json createRequestBody = createRefSetMemberRequestBody(Concepts.REFSET_OWL_AXIOM, conceptId).with(SnomedRf2Headers.FIELD_OWL_EXPRESSION, SnomedApiTestConstants.owlAxiom3(conceptId)).with("commitComment", "Created new OWL Axiom reference set member");
String memberId = assertCreated(createComponent(branchPath, SnomedComponentType.MEMBER, createRequestBody));
final SnomedReferenceSetMember member = SnomedRequests.prepareGetMember(memberId).setExpand("owlRelationships()").build(branchPath.getPath()).execute(getBus()).getSync();
assertThat(member.getClassOWLRelationships()).containsOnly(SnomedOWLRelationshipDocument.create(Concepts.IS_A, "410680006", 0), SnomedOWLRelationshipDocument.create("734136001", "900000000000470007", 1));
final Json updateRequestBody = Json.object(SnomedRf2Headers.FIELD_OWL_EXPRESSION, SnomedApiTestConstants.owlAxiom4(conceptId), "commitComment", "Update OWL Axiom reference set member");
updateRefSetComponent(branchPath, SnomedComponentType.MEMBER, memberId, updateRequestBody, true).statusCode(204);
final SnomedReferenceSetMember updatedMember = SnomedRequests.prepareGetMember(memberId).setExpand("owlRelationships()").build(branchPath.getPath()).execute(getBus()).getSync();
assertThat(updatedMember.getClassOWLRelationships()).containsOnly(SnomedOWLRelationshipDocument.create(Concepts.IS_A, "410680006", 0), SnomedOWLRelationshipDocument.create("734136001", "900000000000470007", 1), SnomedOWLRelationshipDocument.create("371881003", "900000000000450001", 1));
}
use of com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember 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.SnomedReferenceSetMember 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