Search in sources :

Example 6 with SnomedReferenceSetMember

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());
}
Also used : SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) Json(com.b2international.commons.json.Json) Test(org.junit.Test)

Example 7 with SnomedReferenceSetMember

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));
}
Also used : SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) InactivationProperties(com.b2international.snowowl.snomed.core.domain.InactivationProperties) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) Test(org.junit.Test) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)

Example 8 with SnomedReferenceSetMember

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());
    }
}
Also used : SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) SnomedReferenceSetMembers(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers) Json(com.b2international.commons.json.Json) LocalDate(java.time.LocalDate) Test(org.junit.Test) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)

Example 9 with SnomedReferenceSetMember

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;
}
Also used : SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) DataOutputStream(java.io.DataOutputStream) FileOutputStream(java.io.FileOutputStream) SnomedReferenceSetMembers(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) File(java.io.File) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException) IOException(java.io.IOException) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException)

Example 10 with SnomedReferenceSetMember

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;
}
Also used : SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) SnomedCoreComponent(com.b2international.snowowl.snomed.core.domain.SnomedCoreComponent) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) SnomedRelationship(com.b2international.snowowl.snomed.core.domain.SnomedRelationship) SnomedConcepts(com.b2international.snowowl.snomed.core.domain.SnomedConcepts) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept)

Aggregations

SnomedReferenceSetMember (com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember)41 Test (org.junit.Test)17 AbstractSnomedApiTest (com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)13 Json (com.b2international.commons.json.Json)12 SnomedRf2Headers (com.b2international.snowowl.snomed.common.SnomedRf2Headers)11 SnomedReferenceSetMembers (com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers)11 Options (com.b2international.commons.options.Options)8 SnomedConcept (com.b2international.snowowl.snomed.core.domain.SnomedConcept)8 SnomedDescription (com.b2international.snowowl.snomed.core.domain.SnomedDescription)8 List (java.util.List)8 Concepts (com.b2international.snowowl.snomed.common.SnomedConstants.Concepts)7 Map (java.util.Map)7 SnomedRefSetType (com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType)6 IBranchPath (com.b2international.snowowl.core.api.IBranchPath)5 BranchContext (com.b2international.snowowl.core.domain.BranchContext)5 TransactionContext (com.b2international.snowowl.core.domain.TransactionContext)5 ComponentCategory (com.b2international.snowowl.core.terminology.ComponentCategory)5 Collectors (java.util.stream.Collectors)5 BranchPathUtils (com.b2international.snowowl.core.branch.BranchPathUtils)4 EffectiveTimes (com.b2international.snowowl.core.date.EffectiveTimes)4