Search in sources :

Example 11 with SnomedConcept

use of com.b2international.snowowl.snomed.core.domain.SnomedConcept in project snow-owl by b2ihealthcare.

the class SnomedConceptInactivationApiTest method toggleDefinitionStatusAtStatusChange.

@Test
public void toggleDefinitionStatusAtStatusChange() {
    String conceptId = createNewConcept(branchPath);
    Json requestBody = createRefSetMemberRequestBody(Concepts.REFSET_OWL_AXIOM, conceptId).with(SnomedRf2Headers.FIELD_OWL_EXPRESSION, "EquivalentClasses(:" + conceptId + " :" + Concepts.NAMESPACE_ROOT + ")").with("commitComment", "Created new equivalent class OWL Axiom reference set member");
    assertCreated(createComponent(branchPath, SnomedComponentType.MEMBER, requestBody));
    SnomedReferenceSetMembers members = SnomedComponentRestRequests.searchComponent(branchPath, SnomedComponentType.MEMBER, Map.of("referencedComponentId", conceptId)).extract().as(SnomedReferenceSetMembers.class);
    updateComponent(branchPath, SnomedComponentType.CONCEPT, conceptId, Json.object("members", members, "commitComment", "Update concept members")).statusCode(204);
    SnomedConcept concept = assertGetConcept(conceptId).statusCode(200).extract().as(SnomedConcept.class);
    assertTrue(concept.isActive());
    // Active concept is defined after adding equivalent class axioms to it
    assertTrue(!concept.isPrimitive());
    inactivateConcept(branchPath, conceptId);
    concept = assertGetConcept(conceptId).statusCode(200).extract().as(SnomedConcept.class);
    assertTrue(!concept.isActive());
    // Inactive concept becomes primitive
    assertTrue(concept.isPrimitive());
    updateComponent(branchPath, SnomedComponentType.CONCEPT, conceptId, Json.object("active", true, "commitComment", "Reactivate concept")).statusCode(204);
    concept = assertGetConcept(conceptId).statusCode(200).extract().as(SnomedConcept.class);
    assertTrue(concept.isActive());
    // Reactivated concept with no active members stays primitive
    assertTrue(concept.isPrimitive());
}
Also used : SnomedReferenceSetMembers(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers) Json(com.b2international.commons.json.Json) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) Test(org.junit.Test) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)

Example 12 with SnomedConcept

use of com.b2international.snowowl.snomed.core.domain.SnomedConcept in project snow-owl by b2ihealthcare.

the class SnomedModuleDependencyRefsetTest method updateRelevantModDepMembersForExtensionVersions.

@Test
public void updateRelevantModDepMembersForExtensionVersions() {
    final String shortName = "SNOMEDCT-MODULEDEPENDENCY";
    createCodeSystem(branchPath, shortName).statusCode(201);
    Set<String> INT_MODULE_IDS = Set.of(Concepts.MODULE_SCT_MODEL_COMPONENT, Concepts.MODULE_SCT_CORE, ICD_10_MAPPING_MODULE);
    Map<Pair<String, String>, LocalDate> moduleToReferencedComponentAndEffectiveDateMap = Maps.newHashMap();
    SnomedReferenceSetMembers intModuleDependencyMembers = SnomedRequests.prepareSearchMember().all().filterByActive(true).filterByRefSet(Concepts.REFSET_MODULE_DEPENDENCY_TYPE).filterByModules(INT_MODULE_IDS).filterByReferencedComponent(INT_MODULE_IDS).build(branchPath.getPath()).execute(getBus()).getSync();
    intModuleDependencyMembers.forEach(member -> {
        Pair<String, String> pair = Tuples.pair(member.getModuleId(), member.getReferencedComponent().getId());
        moduleToReferencedComponentAndEffectiveDateMap.put(pair, member.getEffectiveTime());
    });
    // create Norwegian module
    Json norwegianModuleRequestBody = createConceptRequestBody(Concepts.MODULE_ROOT, NORWEGIAN_MODULE_CONCEPT_ID, SnomedApiTestConstants.UK_PREFERRED_MAP).with("id", NORWEGIAN_MODULE_CONCEPT_ID).with("commitComment", "Created norwegian module concept");
    createComponent(branchPath, SnomedComponentType.CONCEPT, norwegianModuleRequestBody).statusCode(201);
    // create both inferred and stated relationships
    Json inferredRelationshipRequestBody = SnomedRestFixtures.createRelationshipRequestBody(NORWEGIAN_MODULE_CONCEPT_ID, Concepts.IS_A, Concepts.MODULE_ROOT, NORWEGIAN_MODULE_CONCEPT_ID, Concepts.INFERRED_RELATIONSHIP, 0).with("commitComment", "Created inferred is_a from the norwegian module concept to SCT_MODULE_CORE");
    Json statedRelationshipRequestBody = SnomedRestFixtures.createRelationshipRequestBody(NORWEGIAN_MODULE_CONCEPT_ID, Concepts.IS_A, Concepts.MODULE_ROOT, NORWEGIAN_MODULE_CONCEPT_ID, Concepts.STATED_RELATIONSHIP, 0).with("commitComment", "Created state is_a from the norwegian module concept to SCT_MODULE_CORE");
    createComponent(branchPath, SnomedComponentType.RELATIONSHIP, inferredRelationshipRequestBody).statusCode(201);
    createComponent(branchPath, SnomedComponentType.RELATIONSHIP, statedRelationshipRequestBody).statusCode(201);
    // check for the newly created module concept to have effective set to null
    SnomedRequests.prepareSearchConcept().filterById(NORWEGIAN_MODULE_CONCEPT_ID).build(branchPath.getPath()).execute(getBus()).getSync().forEach(c -> assertEquals("Effective time must still be null", null, c.getEffectiveTime()));
    // version branch
    final LocalDate effectiveTime = getNextAvailableEffectiveDate(shortName);
    final String versionId = "testForModuleDependencyMembers";
    createVersion(shortName, versionId, effectiveTime).statusCode(201);
    assertGetVersion(shortName, versionId).statusCode(200);
    // check for the newly created module concept after versioning to have effectiveTime set to the correct date
    SnomedConcept norwegianModule = SnomedRequests.prepareGetConcept(NORWEGIAN_MODULE_CONCEPT_ID).build(branchPath.getPath()).execute(getBus()).getSync();
    assertEquals("Effective time should have been set to the date of versioning", effectiveTime, norwegianModule.getEffectiveTime());
    SnomedReferenceSetMembers moduleDependencyMembersAfterVersioning = SnomedRequests.prepareSearchMember().all().filterByActive(true).filterByRefSet(Concepts.REFSET_MODULE_DEPENDENCY_TYPE).build(branchPath.getPath()).execute(getBus()).getSync();
    moduleDependencyMembersAfterVersioning.forEach(member -> {
        final Pair<String, String> pair = Tuples.pair(member.getModuleId(), member.getReferencedComponent().getId());
        final LocalDate originalMemberEffectiveTime = moduleToReferencedComponentAndEffectiveDateMap.get(pair);
        if (originalMemberEffectiveTime != null) {
            assertEquals(String.format("Effective dates on unaffected existing module dependency members shouldn't be updated after versioning. ModuleID: %s", member.getReferencedComponentId()), originalMemberEffectiveTime, member.getEffectiveTime());
        } else {
            assertEquals("The new members effective time should match the versionDate", effectiveTime, member.getEffectiveTime());
        }
    });
}
Also used : SnomedReferenceSetMembers(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers) Json(com.b2international.commons.json.Json) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) LocalDate(java.time.LocalDate) Pair(org.eclipse.xtext.util.Pair) Test(org.junit.Test) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)

Example 13 with SnomedConcept

use of com.b2international.snowowl.snomed.core.domain.SnomedConcept 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 14 with SnomedConcept

use of com.b2international.snowowl.snomed.core.domain.SnomedConcept 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)

Example 15 with SnomedConcept

use of com.b2international.snowowl.snomed.core.domain.SnomedConcept in project snow-owl by b2ihealthcare.

the class Rf2MRCMAttributeRangeRefSetContentType method resolve.

@Override
public void resolve(SnomedReferenceSetMember component, String[] values) {
    component.setType(SnomedRefSetType.MRCM_ATTRIBUTE_RANGE);
    component.setRefsetId(values[4]);
    // XXX actual type is not relevant here
    component.setReferencedComponent(new SnomedConcept(values[5]));
    component.setProperties(ImmutableMap.<String, Object>builder().put(FIELD_MRCM_RANGE_CONSTRAINT, values[6]).put(FIELD_MRCM_ATTRIBUTE_RULE, values[7]).put(FIELD_MRCM_RULE_STRENGTH_ID, values[8]).put(FIELD_MRCM_CONTENT_TYPE_ID, values[9]).build());
}
Also used : SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept)

Aggregations

SnomedConcept (com.b2international.snowowl.snomed.core.domain.SnomedConcept)90 Test (org.junit.Test)42 AbstractSnomedApiTest (com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)17 CodeSystem (com.b2international.snowowl.core.codesystem.CodeSystem)15 SnomedDescription (com.b2international.snowowl.snomed.core.domain.SnomedDescription)15 LocalDate (java.time.LocalDate)15 IBranchPath (com.b2international.snowowl.core.api.IBranchPath)12 SnomedConcepts (com.b2international.snowowl.snomed.core.domain.SnomedConcepts)12 Options (com.b2international.commons.options.Options)10 SnomedRelationship (com.b2international.snowowl.snomed.core.domain.SnomedRelationship)10 Concepts (com.b2international.snowowl.snomed.common.SnomedConstants.Concepts)9 ExtendedLocale (com.b2international.commons.http.ExtendedLocale)8 SnomedReferenceSetMember (com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember)8 CodeSystemRestRequests.createCodeSystem (com.b2international.snowowl.test.commons.codesystem.CodeSystemRestRequests.createCodeSystem)8 List (java.util.List)8 Map (java.util.Map)8 Collectors (java.util.stream.Collectors)8 Json (com.b2international.commons.json.Json)7 SnomedRf2Headers (com.b2international.snowowl.snomed.common.SnomedRf2Headers)7 SnomedRequests (com.b2international.snowowl.snomed.datastore.request.SnomedRequests)5