use of com.b2international.snowowl.snomed.core.domain.SnomedRelationship in project snow-owl by b2ihealthcare.
the class SnomedRelationshipApiTest method createRelationshipInferred.
@Test
public void createRelationshipInferred() {
Json requestBody = createRelationshipRequestBody(Concepts.ROOT_CONCEPT, Concepts.PART_OF, Concepts.NAMESPACE_ROOT, Concepts.INFERRED_RELATIONSHIP).with("commitComment", "Created new relationship with inferred characteristic type");
String relationshipId = assertCreated(createComponent(branchPath, SnomedComponentType.RELATIONSHIP, requestBody));
SnomedRelationship relationship = getComponent(branchPath, SnomedComponentType.RELATIONSHIP, relationshipId, "source()", "type()", "destination()", "characteristicType()", "modifier()").statusCode(200).extract().as(SnomedRelationship.class);
assertEquals(Concepts.INFERRED_RELATIONSHIP, relationship.getCharacteristicType().getId());
assertEquals(Concepts.ROOT_CONCEPT, relationship.getSource().getId());
assertEquals(Concepts.PART_OF, relationship.getType().getId());
assertEquals(Concepts.NAMESPACE_ROOT, relationship.getDestination().getId());
assertEquals(Concepts.EXISTENTIAL_RESTRICTION_MODIFIER, relationship.getModifier().getId());
}
use of com.b2international.snowowl.snomed.core.domain.SnomedRelationship in project snow-owl by b2ihealthcare.
the class SnomedSimpleTypeRefSetDSVExporter method computeHeader.
private void computeHeader(SnomedConcepts chunk) {
for (SnomedConcept concept : chunk) {
for (AbstractSnomedDsvExportItem exportItem : exportItems) {
switch(exportItem.getType()) {
case DESCRIPTION:
ComponentIdSnomedDsvExportItem descriptionItem = (ComponentIdSnomedDsvExportItem) exportItem;
String descriptionTypeId = descriptionItem.getComponentId();
Integer matchingDescriptions = concept.getDescriptions().stream().filter(d -> descriptionTypeId.equals(d.getTypeId())).collect(Collectors.reducing(0, description -> 1, Integer::sum));
descriptionCount.merge(descriptionTypeId, matchingDescriptions, Math::max);
break;
case RELATIONSHIP:
ComponentIdSnomedDsvExportItem relationshipItem = (ComponentIdSnomedDsvExportItem) exportItem;
String relationshipTypeId = relationshipItem.getComponentId();
Map<Integer, Integer> matchingRelationships = concept.getRelationships().stream().filter(r -> relationshipTypeId.equals(r.getTypeId()) && (Concepts.INFERRED_RELATIONSHIP.equals(r.getCharacteristicTypeId()) || Concepts.ADDITIONAL_RELATIONSHIP.equals(r.getCharacteristicTypeId()))).collect(Collectors.groupingBy(SnomedRelationship::getRelationshipGroup, Collectors.reducing(0, relationship -> 1, Integer::sum)));
matchingRelationships.entrySet().stream().forEach(entry -> {
propertyCountByGroup.compute(entry.getKey(), (key, oldValue) -> {
Map<String, Integer> propertyCountForGroup = ofNullable(oldValue).orElseGet(HashMap::new);
propertyCountForGroup.merge(relationshipTypeId, entry.getValue(), Math::max);
return propertyCountForGroup;
});
});
break;
case DATAYPE:
ComponentIdSnomedDsvExportItem dataTypeItem = (ComponentIdSnomedDsvExportItem) exportItem;
String dataTypeId = dataTypeItem.getComponentId();
Map<Integer, Integer> matchingMembers = concept.getMembers().stream().filter(m -> SnomedRefSetType.CONCRETE_DATA_TYPE.equals(m.type()) && m.isActive() && dataTypeId.equals(m.getProperties().get(SnomedRf2Headers.FIELD_TYPE_ID)) && (Concepts.INFERRED_RELATIONSHIP.equals(m.getProperties().get(SnomedRf2Headers.FIELD_CHARACTERISTIC_TYPE_ID)) || Concepts.ADDITIONAL_RELATIONSHIP.equals(m.getProperties().get(SnomedRf2Headers.FIELD_CHARACTERISTIC_TYPE_ID)))).collect(Collectors.groupingBy(m -> (Integer) m.getProperties().get(SnomedRf2Headers.FIELD_RELATIONSHIP_GROUP), Collectors.reducing(0, relationship -> 1, Integer::sum)));
matchingMembers.entrySet().stream().forEach(entry -> {
propertyCountByGroup.compute(entry.getKey(), (key, oldValue) -> {
Map<String, Integer> propertyCountForGroup = ofNullable(oldValue).orElseGet(HashMap::new);
propertyCountForGroup.merge(dataTypeId, entry.getValue(), Math::max);
return propertyCountForGroup;
});
});
break;
default:
// Single-use fields don't need to be counted in advance
break;
}
}
}
}
use of com.b2international.snowowl.snomed.core.domain.SnomedRelationship in project snow-owl by b2ihealthcare.
the class SnomedConcreteValueApiTest method updateConcreteValueWithSamePropertiesShouldNotCauseAnyChange.
@Test
public void updateConcreteValueWithSamePropertiesShouldNotCauseAnyChange() throws Exception {
final String relationshipId = createNewConcreteValue(branchPath);
final SnomedRelationship concreteValue = getRelationship(relationshipId);
// explicitly create a new Boolean object with same value to simulate deserialization "bug"
concreteValue.setActive(new Boolean(true));
// same value as set in createNewConcreteValue(String)
concreteValue.setValueAsObject(new RelationshipValue("Hello World!"));
Boolean updated = SnomedRequests.prepareCommit().setCommitComment("Update concrete value").setBody(concreteValue.toUpdateRequest()).build(branchPath.getPath()).execute(getBus()).getSync(1, TimeUnit.MINUTES).getResultAs(Boolean.class);
assertFalse(updated);
}
use of com.b2international.snowowl.snomed.core.domain.SnomedRelationship in project snow-owl by b2ihealthcare.
the class SnomedRelationshipConverter method expandType.
private void expandType(List<SnomedRelationship> results) {
if (expand().containsKey(SnomedRelationship.Expand.TYPE)) {
final Options typeOptions = expand().get(SnomedRelationship.Expand.TYPE, Options.class);
final Iterable<String> typeConceptIds = FluentIterable.from(results).transform(SnomedRelationship::getTypeId);
context().service(SnomedConceptRequestCache.class).request(typeConceptIds, typeOptions.getOptions("expand"), locales(), typeConceptsById -> {
for (SnomedRelationship relationship : results) {
final String typeId = relationship.getTypeId();
if (typeConceptsById.containsKey(typeId)) {
final SnomedConcept typeConcept = typeConceptsById.get(typeId);
((SnomedRelationship) relationship).setType(typeConcept);
}
}
});
}
}
use of com.b2international.snowowl.snomed.core.domain.SnomedRelationship in project snow-owl by b2ihealthcare.
the class SnomedRelationshipConverter method expandSource.
private void expandSource(List<SnomedRelationship> results) {
if (expand().containsKey(SnomedRelationship.Expand.SOURCE)) {
final Options sourceOptions = expand().get(SnomedRelationship.Expand.SOURCE, Options.class);
final Iterable<String> sourceConceptIds = FluentIterable.from(results).transform(SnomedRelationship::getSourceId);
context().service(SnomedConceptRequestCache.class).request(sourceConceptIds, sourceOptions.getOptions("expand"), locales(), sourceConceptsById -> {
for (SnomedRelationship relationship : results) {
final String sourceId = relationship.getSourceId();
if (sourceConceptsById.containsKey(sourceId)) {
final SnomedConcept sourceConcept = sourceConceptsById.get(sourceId);
((SnomedRelationship) relationship).setSource(sourceConcept);
}
}
});
}
}
Aggregations