use of com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember in project snow-owl by b2ihealthcare.
the class SnomedConceptApiTest method testUpdateConceptDefinitionStatusWithAxiomMembersShouldNotChange.
@Test
public void testUpdateConceptDefinitionStatusWithAxiomMembersShouldNotChange() {
final String conceptId = createNewConcept(branchPath);
// Update the definition status on concept
final Map<?, ?> definitionStatusUpdateRequestBody = Json.object("definitionStatusId", Concepts.FULLY_DEFINED, "commitComment", "Changed definition status of concept to fully defined");
updateComponent(branchPath, SnomedComponentType.CONCEPT, conceptId, definitionStatusUpdateRequestBody).statusCode(204);
// Add a reference set member
final SnomedReferenceSetMember newMember = new SnomedReferenceSetMember();
newMember.setId(UUID.randomUUID().toString());
newMember.setActive(true);
newMember.setRefsetId(Concepts.REFSET_OWL_AXIOM);
newMember.setProperties(Json.object(SnomedRf2Headers.FIELD_OWL_EXPRESSION, String.format("EquivalentClasses(:%s ObjectIntersectionOf(:%s :%s))", conceptId, Concepts.AMBIGUOUS, Concepts.NAMESPACE_ROOT)));
newMember.setType(SnomedRefSetType.OWL_AXIOM);
newMember.setModuleId(Concepts.MODULE_SCT_CORE);
final Json updateRequestBody = Json.object("members", SnomedReferenceSetMembers.of(Json.array(newMember)), "definitionStatusId", Concepts.PRIMITIVE, "commitComment", "Add new reference set member via concept update");
updateComponent(branchPath, SnomedComponentType.CONCEPT, conceptId, updateRequestBody).statusCode(204);
final SnomedConcept updatedConcept = getComponent(branchPath, SnomedComponentType.CONCEPT, conceptId, "members()").statusCode(200).extract().as(SnomedConcept.class);
assertEquals(1, updatedConcept.getMembers().getTotal());
// Verify that definition status is still fully defined
assertEquals(Concepts.FULLY_DEFINED, updatedConcept.getDefinitionStatusId());
}
use of com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember in project snow-owl by b2ihealthcare.
the class SnomedComponentInactivationApiTest method reuseConceptAndDescriptionInactivationIndicators.
@Test
public void reuseConceptAndDescriptionInactivationIndicators() throws Exception {
// create a concept
String conceptId = createNewConcept(branchPath);
SnomedConcept concept = getConcept(conceptId, "descriptions()");
// add pending move to concept and descriptions
Map<?, ?> pendingMoveUpdate = ImmutableMap.of("inactivationProperties", new InactivationProperties(Concepts.PENDING_MOVE, null), "commitComment", "Set to Pending Move");
updateComponent(branchPath, SnomedComponentType.CONCEPT, conceptId, pendingMoveUpdate).statusCode(204);
for (SnomedDescription description : concept.getDescriptions()) {
updateComponent(branchPath, SnomedComponentType.DESCRIPTION, description.getId(), pendingMoveUpdate).statusCode(204);
}
// XXX intentionally using the members() expand here to check duplication
SnomedConcept pendingMoveConcept = getConcept(conceptId, "members(),descriptions(expand(members()))");
// verify and collect inactivation indicator members
SnomedReferenceSetMember conceptInactivationIndicatorMember = getIndicatorMember(pendingMoveConcept, Concepts.REFSET_CONCEPT_INACTIVITY_INDICATOR);
SnomedReferenceSetMember fsnInactivationIndicatorMember = null;
SnomedReferenceSetMember ptInactivationIndicatorMember = null;
for (SnomedDescription description : pendingMoveConcept.getDescriptions()) {
if (Concepts.FULLY_SPECIFIED_NAME.equals(description.getTypeId())) {
fsnInactivationIndicatorMember = getIndicatorMember(description, Concepts.REFSET_DESCRIPTION_INACTIVITY_INDICATOR);
} else if (Concepts.SYNONYM.equals(description.getTypeId())) {
ptInactivationIndicatorMember = getIndicatorMember(description, Concepts.REFSET_DESCRIPTION_INACTIVITY_INDICATOR);
} else {
throw new UnsupportedOperationException();
}
}
Map<?, ?> inactivationConceptRequest = ImmutableMap.builder().put("active", false).put("inactivationProperties", new InactivationProperties(Concepts.DUPLICATE, null)).put("commitComment", "Inactivated concept").build();
updateComponent(branchPath, SnomedComponentType.CONCEPT, conceptId, inactivationConceptRequest).statusCode(204);
// XXX intentionally using the members() expand here to check duplication/member issues
SnomedConcept inactivatedConcept = getConcept(conceptId, "members(),descriptions(expand(members()))");
SnomedReferenceSetMember afterInactivationConceptInactivationIndicatorMember = getIndicatorMember(inactivatedConcept, Concepts.REFSET_CONCEPT_INACTIVITY_INDICATOR);
SnomedReferenceSetMember afterInactivationFsnInactivationIndicatorMember = null;
SnomedReferenceSetMember afterInactivationPtInactivationIndicatorMember = null;
for (SnomedDescription description : inactivatedConcept.getDescriptions()) {
if (Concepts.FULLY_SPECIFIED_NAME.equals(description.getTypeId())) {
afterInactivationFsnInactivationIndicatorMember = getIndicatorMember(description, Concepts.REFSET_DESCRIPTION_INACTIVITY_INDICATOR);
} else if (Concepts.SYNONYM.equals(description.getTypeId())) {
afterInactivationPtInactivationIndicatorMember = getIndicatorMember(description, Concepts.REFSET_DESCRIPTION_INACTIVITY_INDICATOR);
} else {
throw new UnsupportedOperationException();
}
}
assertEquals(conceptInactivationIndicatorMember.getId(), afterInactivationConceptInactivationIndicatorMember.getId());
assertEquals(null, afterInactivationConceptInactivationIndicatorMember.getEffectiveTime());
assertEquals(false, afterInactivationConceptInactivationIndicatorMember.isReleased());
assertEquals(Concepts.DUPLICATE, afterInactivationConceptInactivationIndicatorMember.getProperties().get(SnomedRf2Headers.FIELD_VALUE_ID));
assertEquals(fsnInactivationIndicatorMember.getId(), afterInactivationFsnInactivationIndicatorMember.getId());
assertEquals(null, afterInactivationFsnInactivationIndicatorMember.getEffectiveTime());
assertEquals(false, afterInactivationFsnInactivationIndicatorMember.isReleased());
assertEquals(Concepts.CONCEPT_NON_CURRENT, afterInactivationFsnInactivationIndicatorMember.getProperties().get(SnomedRf2Headers.FIELD_VALUE_ID));
assertEquals(ptInactivationIndicatorMember.getId(), afterInactivationPtInactivationIndicatorMember.getId());
assertEquals(null, afterInactivationPtInactivationIndicatorMember.getEffectiveTime());
assertEquals(false, afterInactivationPtInactivationIndicatorMember.isReleased());
assertEquals(Concepts.CONCEPT_NON_CURRENT, afterInactivationPtInactivationIndicatorMember.getProperties().get(SnomedRf2Headers.FIELD_VALUE_ID));
}
use of com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember in project snow-owl by b2ihealthcare.
the class SnomedModuleDependencyRefsetTest method updateExistingModuleDependencyMembers.
@Test
public void updateExistingModuleDependencyMembers() {
Json conceptRequestBody = createConceptRequestBody(// it must belong to the core module
Concepts.MODULE_ROOT, // it must belong to the core module
Concepts.MODULE_SCT_CORE, SnomedApiTestConstants.UK_PREFERRED_MAP).with("commitComment", "Created concept with INT core module");
String conceptId = createConcept(SnomedContentRule.SNOMEDCT, conceptRequestBody);
assertThat(getConcept(SnomedContentRule.SNOMEDCT, conceptId).getEffectiveTime()).isNull();
// version branch
final LocalDate versionEffectiveTime = getNextAvailableEffectiveDate(SnomedContentRule.SNOMEDCT_ID);
final String versionId = "updateExistingModuleDependencyMembers";
createVersion(SnomedContentRule.SNOMEDCT_ID, versionId, versionEffectiveTime).statusCode(201);
assertGetVersion(SnomedContentRule.SNOMEDCT_ID, versionId).statusCode(200);
assertThat(getConcept(SnomedContentRule.SNOMEDCT, conceptId).getEffectiveTime()).isEqualTo(versionEffectiveTime);
SnomedReferenceSetMembers coreModuleDependencyMembersAfterVersioning = SnomedRequests.prepareSearchMember().all().filterByActive(true).filterByModule(// filter for members where the module id is the SCT core module
Concepts.MODULE_SCT_CORE).filterByRefSet(Concepts.REFSET_MODULE_DEPENDENCY_TYPE).build(SnomedContentRule.SNOMEDCT).execute(getBus()).getSync();
for (SnomedReferenceSetMember member : coreModuleDependencyMembersAfterVersioning) {
assertEquals(versionEffectiveTime, member.getEffectiveTime());
}
}
use of com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember in project snow-owl by b2ihealthcare.
the class MapTypeRefSetDSVExporter method executeDSVExport.
@Override
public File executeDSVExport(IProgressMonitor monitor) throws IOException {
final int memberNumberToSignal = 100;
final SnomedConcept refSetToExport = SnomedRequests.prepareGetConcept(exportSetting.getRefSetId()).setLocales(exportSetting.getLocales()).setExpand("referenceSet(expand(members(limit:" + Integer.MAX_VALUE + ", expand(referencedComponent(expand(fsn()))))))").build().execute(context);
final SnomedReferenceSetMembers membersToExport = refSetToExport.getReferenceSet().getMembers();
final int activeMemberCount = membersToExport.getTotal();
if (activeMemberCount < memberNumberToSignal) {
monitor.beginTask("Exporting RefSet to DSV", 1);
} else {
monitor.beginTask("Exporting RefSet to DSV", activeMemberCount / memberNumberToSignal);
}
final File file = Files.createTempFile("dsv-export-" + refSetToExport.getId() + Dates.now(), ".csv").toFile();
try (DataOutputStream os = new DataOutputStream(new FileOutputStream(file))) {
if (exportSetting.getExportItems().isEmpty()) {
return file;
}
writeLine(os, toHeader());
Map<String, String> labels = prepareLabelCache(membersToExport);
int count = 0;
for (final SnomedReferenceSetMember member : membersToExport) {
writeLine(os, toDsvLine(member, labels));
count++;
if (count % memberNumberToSignal == 0) {
monitor.worked(1);
}
}
} catch (final Exception e) {
throw new SnowowlRuntimeException(e);
} finally {
if (null != monitor) {
monitor.done();
}
}
return file;
}
use of com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember 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;
}
Aggregations