use of com.b2international.snowowl.snomed.core.domain.SnomedRelationship in project snow-owl by b2ihealthcare.
the class MapTypeRefSetDSVExporter method prepareLabelCache.
private Map<String, String> prepareLabelCache(SnomedReferenceSetMembers membersToExport) {
final SnomedConcepts modelComponents = SnomedRequests.prepareSearchConcept().all().filterByActive(true).filterByEcl(String.format("< (%s OR %s) ", Concepts.MODULE_ROOT, Concepts.REFSET_ATTRIBUTE)).setExpand("fsn()").setLocales(exportSetting.getLocales()).build().execute(context);
final Map<String, String> labels = newHashMapWithExpectedSize(membersToExport.getTotal() + modelComponents.getTotal());
modelComponents.forEach(modelComponent -> {
labels.put(modelComponent.getId(), getFsnOrId(modelComponent));
});
for (SnomedReferenceSetMember snomedReferenceSetMember : membersToExport) {
SnomedCoreComponent referencedComponent = snomedReferenceSetMember.getReferencedComponent();
String id = referencedComponent.getId();
if (referencedComponent instanceof SnomedConcept) {
labels.put(id, getFsnOrId((SnomedConcept) referencedComponent));
} else if (referencedComponent instanceof SnomedDescription) {
labels.put(id, ((SnomedDescription) referencedComponent).getTerm());
} else if (referencedComponent instanceof SnomedRelationship) {
SnomedRelationship relationship = (SnomedRelationship) referencedComponent;
if (relationship.hasValue()) {
labels.put(id, String.format("%s - %s - %s", relationship.getSourceId(), relationship.getTypeId(), relationship.getValue()));
} else {
labels.put(id, String.format("%s - %s - %s", relationship.getSourceId(), relationship.getTypeId(), relationship.getDestinationId()));
}
}
}
return labels;
}
use of com.b2international.snowowl.snomed.core.domain.SnomedRelationship in project snow-owl by b2ihealthcare.
the class SnomedExtensionUpgradeTest method upgrade07DonatedRelationship.
@Test
public void upgrade07DonatedRelationship() throws Exception {
// create extension on the latest SI VERSION
CodeSystem extension = createExtension(latestInternationalVersion, branchPath.lastSegment());
String extensionModuleId = createModule(extension);
Json extensionRelationshipRequest = Json.object("namespaceId", Concepts.B2I_NAMESPACE, "moduleId", extensionModuleId, "sourceId", Concepts.ROOT_CONCEPT, "typeId", Concepts.PART_OF, "destinationId", Concepts.NAMESPACE_ROOT, "characteristicTypeId", Concepts.ADDITIONAL_RELATIONSHIP, "relationshipGroup", 0, "commitComment", "Created new extension relationship");
String extensionRelationshipId = createRelationship(extension.getResourceURI(), extensionRelationshipRequest);
// create new extension version
createVersion(extension.getId(), "v1", LocalDate.now()).statusCode(201);
// simulate donation of relationship to INT with slightly different props but same ID
Json donatedRelationshipRequest = Json.assign(extensionRelationshipRequest, Json.object("id", extensionRelationshipId, "moduleId", Concepts.MODULE_SCT_CORE, "characteristicTypeId", Concepts.INFERRED_RELATIONSHIP, "relationshipGroup", 1, "commitComment", "Created new donated INT relationship"));
String donatedRelationshipId = createRelationship(SnomedContentRule.SNOMEDCT, donatedRelationshipRequest);
LocalDate effectiveTime = getNextAvailableEffectiveDate(SNOMEDCT);
createVersion(SNOMEDCT, effectiveTime).statusCode(201);
assertEquals(extensionRelationshipId, donatedRelationshipId);
// start upgrade to the new available upgrade version
CodeSystem upgradeCodeSystem = createExtensionUpgrade(extension.getResourceURI(), CodeSystem.uri(SNOMEDCT, effectiveTime.toString()));
SnomedRelationship donatedRelationshipOnUpgrade = getRelationship(upgradeCodeSystem.getResourceURI(), donatedRelationshipId);
assertEquals(Concepts.MODULE_SCT_CORE, donatedRelationshipOnUpgrade.getModuleId());
assertEquals(Concepts.INFERRED_RELATIONSHIP, donatedRelationshipOnUpgrade.getCharacteristicTypeId());
assertEquals(1, donatedRelationshipOnUpgrade.getRelationshipGroup().intValue());
}
use of com.b2international.snowowl.snomed.core.domain.SnomedRelationship 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.SnomedRelationship 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;
}
use of com.b2international.snowowl.snomed.core.domain.SnomedRelationship in project snow-owl by b2ihealthcare.
the class EclExpression method resolveToGroupedOnly.
private Promise<Multimap<String, Integer>> resolveToGroupedOnly(BranchContext context, Set<String> sourceIds) {
final Set<String> characteristicTypes = isInferred() ? SnomedEclRefinementEvaluator.INFERRED_CHARACTERISTIC_TYPES : SnomedEclRefinementEvaluator.STATED_CHARACTERISTIC_TYPES;
List<Promise<Multimap<String, Integer>>> promises = newArrayListWithCapacity(3);
// search relationships
promises.add(SnomedRequests.prepareSearchRelationship().all().filterByActive(true).filterByCharacteristicTypes(characteristicTypes).filterBySources(sourceIds).filterByGroup(1, Integer.MAX_VALUE).setEclExpressionForm(expressionForm).setFields(SnomedRelationshipIndexEntry.Fields.ID, SnomedRelationshipIndexEntry.Fields.SOURCE_ID, SnomedRelationshipIndexEntry.Fields.RELATIONSHIP_GROUP).build(context.service(ResourceURI.class)).execute(context.service(IEventBus.class)).then(new Function<SnomedRelationships, Multimap<String, Integer>>() {
@Override
public Multimap<String, Integer> apply(SnomedRelationships input) {
final Multimap<String, SnomedRelationship> relationshipsBySource = Multimaps.index(input, SnomedRelationship::getSourceId);
final Multimap<String, Integer> groupsByRelationshipId = Multimaps.transformValues(relationshipsBySource, SnomedRelationship::getRelationshipGroup);
return ImmutableSetMultimap.copyOf(groupsByRelationshipId);
}
}));
// search concrete domain members
if (context.service(SnomedCoreConfiguration.class).isConcreteDomainSupported()) {
final Options propFilter = Options.builder().put(SnomedRf2Headers.FIELD_CHARACTERISTIC_TYPE_ID, characteristicTypes).put(SearchResourceRequest.operator(SnomedRf2Headers.FIELD_RELATIONSHIP_GROUP), SearchResourceRequest.Operator.NOT_EQUALS).put(SnomedRf2Headers.FIELD_RELATIONSHIP_GROUP, 0).build();
promises.add(SnomedRequests.prepareSearchMember().all().filterByActive(true).filterByReferencedComponent(sourceIds).filterByRefSetType(SnomedRefSetType.CONCRETE_DATA_TYPE).filterByProps(propFilter).setEclExpressionForm(expressionForm).build(context.service(ResourceURI.class)).execute(context.service(IEventBus.class)).then(members -> {
final Multimap<String, SnomedReferenceSetMember> relationshipsBySource = Multimaps.index(members, m -> m.getReferencedComponent().getId());
return Multimaps.transformValues(relationshipsBySource, m -> (Integer) m.getProperties().get(SnomedRf2Headers.FIELD_RELATIONSHIP_GROUP));
}));
} else {
promises.add(Promise.immediate(ImmutableSetMultimap.of()));
}
// search owl axiom members
if (isStated()) {
ImmutableSetMultimap.Builder<String, Integer> groupedAxioms = ImmutableSetMultimap.builder();
SnomedEclRefinementEvaluator.evalAxiomStatements(context, true, sourceIds, null, null).forEach(property -> groupedAxioms.put(property.getObjectId(), property.getGroup()));
promises.add(Promise.immediate(groupedAxioms.build()));
} else {
promises.add(Promise.immediate(ImmutableSetMultimap.of()));
}
return Promise.all(promises).then(statements -> {
Multimap<String, Integer> relationshipStatements = (Multimap<String, Integer>) statements.get(0);
Multimap<String, Integer> concreteDomainStatements = (Multimap<String, Integer>) statements.get(1);
Multimap<String, Integer> axiomStatements = (Multimap<String, Integer>) statements.get(2);
return ImmutableSetMultimap.<String, Integer>builder().putAll(relationshipStatements).putAll(concreteDomainStatements).putAll(axiomStatements).build();
});
}
Aggregations