Search in sources :

Example 16 with CodeSystem

use of com.b2international.snowowl.core.codesystem.CodeSystem in project snow-owl by b2ihealthcare.

the class SnomedExtensionUpgradeTest method upgrade05DonatedConcept.

@Test
public void upgrade05DonatedConcept() {
    // create extension on the latest SI VERSION
    CodeSystem extension = createExtension(latestInternationalVersion, branchPath.lastSegment());
    String extensionModuleId = createModule(extension);
    String extensionConceptId = createConcept(extension.getResourceURI(), createConceptRequestBody(Concepts.ROOT_CONCEPT, extensionModuleId).with("namespaceId", Concepts.B2I_NAMESPACE));
    // put additional relationships and acceptable synonym on the concept
    String additionalSynonymId = createDescription(extension.getResourceURI(), createDescriptionRequestBody(extensionConceptId).with("moduleId", extensionModuleId).with("namespaceId", Concepts.B2I_NAMESPACE).with("term", "Additional Synonym"));
    String additionalRelationshipId = createRelationship(extension.getResourceURI(), createRelationshipRequestBody(extensionConceptId, Concepts.FINDING_SITE, Concepts.ROOT_CONCEPT).with("moduleId", extensionModuleId).with(SnomedRf2Headers.FIELD_CHARACTERISTIC_TYPE_ID, Concepts.ADDITIONAL_RELATIONSHIP).with("namespaceId", Concepts.B2I_NAMESPACE));
    SnomedConcept extensionConcept = getConcept(extension.getResourceURI(), extensionConceptId, "descriptions()", "relationships()", "fsn()", "pt()");
    // create new extension version
    createVersion(extension.getId(), "v1", LocalDate.now()).statusCode(201);
    // simulate donation to SI and new version import
    String donatedConceptId = createConcept(SnomedContentRule.SNOMEDCT, createConceptRequestBody(Concepts.ROOT_CONCEPT, Concepts.MODULE_SCT_CORE).with("id", extensionConceptId));
    LocalDate effectiveTime = getNextAvailableEffectiveDate(SNOMEDCT);
    createVersion(SNOMEDCT, effectiveTime).statusCode(201);
    // start upgrade to the new available upgrade version
    CodeSystem upgradeCodeSystem = createExtensionUpgrade(extension.getResourceURI(), CodeSystem.uri(SNOMEDCT, effectiveTime.toString()));
    SnomedConcept donatedConceptAfterUpgrade = getConcept(upgradeCodeSystem.getResourceURI(), donatedConceptId, "descriptions()", "relationships()", "fsn()", "pt()");
    // validate components of donated concept on extension branch
    assertEquals(extensionConcept.getId(), donatedConceptAfterUpgrade.getId());
    assertNotEquals(extensionConcept.getModuleId(), donatedConceptAfterUpgrade.getModuleId());
    // additional not donated extension content should remain on the concept
    assertTrue(donatedConceptAfterUpgrade.getDescriptions().stream().filter(desc -> additionalSynonymId.equals(desc.getId())).findFirst().isPresent());
    assertTrue(donatedConceptAfterUpgrade.getRelationships().stream().filter(rel -> additionalRelationshipId.equals(rel.getId())).findFirst().isPresent());
}
Also used : CodeSystemVersionRestRequests.getNextAvailableEffectiveDate(com.b2international.snowowl.test.commons.codesystem.CodeSystemVersionRestRequests.getNextAvailableEffectiveDate) MethodSorters(org.junit.runners.MethodSorters) BaseRevisionBranching(com.b2international.index.revision.BaseRevisionBranching) CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) Acceptability(com.b2international.snowowl.snomed.core.domain.Acceptability) CodeSystemVersionRestRequests.createVersion(com.b2international.snowowl.test.commons.codesystem.CodeSystemVersionRestRequests.createVersion) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Json(com.b2international.commons.json.Json) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RestExtensions.lastPathSegment(com.b2international.snowowl.test.commons.rest.RestExtensions.lastPathSegment) SnomedRestFixtures(com.b2international.snowowl.snomed.core.rest.SnomedRestFixtures) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) SnomedComponentType(com.b2international.snowowl.snomed.core.rest.SnomedComponentType) SnomedComponentRestRequests.getComponent(com.b2international.snowowl.snomed.core.rest.SnomedComponentRestRequests.getComponent) SnomedContentRule(com.b2international.snowowl.test.commons.SnomedContentRule) Map(java.util.Map) SnomedMergingRestRequests.createMerge(com.b2international.snowowl.snomed.core.rest.SnomedMergingRestRequests.createMerge) Before(org.junit.Before) ResourceURI(com.b2international.snowowl.core.ResourceURI) BranchState(com.b2international.index.revision.RevisionBranch.BranchState) BranchPathUtils(com.b2international.snowowl.core.branch.BranchPathUtils) SnomedApiTestConstants(com.b2international.snowowl.snomed.core.rest.SnomedApiTestConstants) CodeSystemRestRequests(com.b2international.snowowl.test.commons.codesystem.CodeSystemRestRequests) RepositoryManager(com.b2international.snowowl.core.RepositoryManager) CodeSystemVersionRestRequests.getLatestVersion(com.b2international.snowowl.test.commons.codesystem.CodeSystemVersionRestRequests.getLatestVersion) Set(java.util.Set) Merge(com.b2international.snowowl.core.merge.Merge) SnomedMergingRestRequests.waitForMergeJob(com.b2international.snowowl.snomed.core.rest.SnomedMergingRestRequests.waitForMergeJob) Test(org.junit.Test) SnomedTerminologyComponentConstants(com.b2international.snowowl.snomed.common.SnomedTerminologyComponentConstants) Collectors(java.util.stream.Collectors) SnomedRelationship(com.b2international.snowowl.snomed.core.domain.SnomedRelationship) TimeUnit(java.util.concurrent.TimeUnit) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) LocalDate(java.time.LocalDate) IComponent(com.b2international.snowowl.core.domain.IComponent) CodeSystems(com.b2international.snowowl.core.codesystem.CodeSystems) CodeSystemRequests(com.b2international.snowowl.core.codesystem.CodeSystemRequests) SnomedRf2Headers(com.b2international.snowowl.snomed.common.SnomedRf2Headers) Assert(org.junit.Assert) FixMethodOrder(org.junit.FixMethodOrder) IBranchPath(com.b2international.snowowl.core.api.IBranchPath) ApplicationContext(com.b2international.snowowl.core.ApplicationContext) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 17 with CodeSystem

use of com.b2international.snowowl.core.codesystem.CodeSystem in project snow-owl by b2ihealthcare.

the class SnomedExtensionUpgradeTest method upgrade13SemanticallySameChangesAppliedTwiceBeforeUpgradeAndAfterUpgrade.

@Test
public void upgrade13SemanticallySameChangesAppliedTwiceBeforeUpgradeAndAfterUpgrade() throws Exception {
    // create extension on the latest SI VERSION
    CodeSystem extension = createExtension(latestInternationalVersion, branchPath.lastSegment());
    // create new extension version with one new concept and one member on INT concept
    String moduleId = createModule(extension);
    SnomedConcept concept = searchConcepts(baseInternationalCodeSystem, Map.of("module", Concepts.MODULE_SCT_CORE, "expand", "descriptions()"), 1).stream().findFirst().get();
    String descriptionId = concept.getDescriptions().stream().findFirst().get().getId();
    // create new inactivation indicator for one of the description, pending move
    createMember(extension.getResourceURI(), Map.of("moduleId", moduleId, "refsetId", Concepts.REFSET_DESCRIPTION_INACTIVITY_INDICATOR, "referencedComponentId", descriptionId, "valueId", Concepts.PENDING_MOVE));
    // version extension
    createVersion(extension.getId(), "v1", LocalDate.now()).statusCode(201);
    // add another member on INT representing a change in INT and allow extension to upgrade
    createMember(SnomedContentRule.SNOMEDCT, Map.of("moduleId", Concepts.MODULE_SCT_CORE, "refsetId", Concepts.REFSET_DESCRIPTION_INACTIVITY_INDICATOR, "referencedComponentId", descriptionId, "valueId", Concepts.PENDING_MOVE));
    LocalDate effectiveTime = getNextAvailableEffectiveDate(SNOMEDCT);
    createVersion(SNOMEDCT, effectiveTime).statusCode(201);
    ResourceURI upgradeVersion = CodeSystem.uri(SNOMEDCT, effectiveTime.toString());
    // start the upgrade
    CodeSystem upgradeCodeSystem = createExtensionUpgrade(extension.getResourceURI(), upgradeVersion);
    // add another extension member to the same int concept with same meaning to the original extension branch
    createMember(extension.getResourceURI(), Map.of("moduleId", moduleId, "refsetId", Concepts.REFSET_DESCRIPTION_INACTIVITY_INDICATOR, "referencedComponentId", descriptionId, "valueId", Concepts.AMBIGUOUS));
    // synchronize upgrade
    final String mergeLocation = createMerge(extension.getBranchPath(), upgradeCodeSystem.getBranchPath(), "Sync Upgrade CodeSystem", false).statusCode(202).extract().header("Location");
    waitForMergeJob(lastPathSegment(mergeLocation));
    // each component should have a single revision after successful sync
    getConcept(upgradeCodeSystem.getResourceURI(), concept.getId());
}
Also used : ResourceURI(com.b2international.snowowl.core.ResourceURI) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 18 with CodeSystem

use of com.b2international.snowowl.core.codesystem.CodeSystem in project snow-owl by b2ihealthcare.

the class SnomedExtensionUpgradeTest method upgrade01Nochanges.

@Test
public void upgrade01Nochanges() {
    // create extension on the latest SI VERSION
    CodeSystem extension = createExtension(latestInternationalVersion, branchPath.lastSegment());
    // create a new INT version without any changes
    LocalDate effectiveTime = getNextAvailableEffectiveDate(SNOMEDCT);
    createVersion(SNOMEDCT, effectiveTime).statusCode(201);
    // start upgrade
    final ResourceURI newExtensionOf = CodeSystem.uri(SNOMEDCT, effectiveTime.toString());
    CodeSystem upgradeCodeSystem = createExtensionUpgrade(extension.getResourceURI(), newExtensionOf);
    assertEquals(newExtensionOf, upgradeCodeSystem.getExtensionOf());
}
Also used : ResourceURI(com.b2international.snowowl.core.ResourceURI) CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 19 with CodeSystem

use of com.b2international.snowowl.core.codesystem.CodeSystem in project snow-owl by b2ihealthcare.

the class SnomedExtensionUpgradeTest method upgrade03NewInternationalConceptOnly.

@Test
public void upgrade03NewInternationalConceptOnly() {
    // create extension on the latest SI VERSION
    CodeSystem extension = createExtension(latestInternationalVersion, branchPath.lastSegment());
    // new SI concept
    String newConceptId = createConcept(SnomedContentRule.SNOMEDCT, createConceptRequestBody(Concepts.ROOT_CONCEPT, Concepts.MODULE_SCT_CORE));
    // create a new INT version
    LocalDate effectiveTime = getNextAvailableEffectiveDate(SNOMEDCT);
    createVersion(SNOMEDCT, effectiveTime).statusCode(201);
    ResourceURI upgradeVersion = CodeSystem.uri(SNOMEDCT, effectiveTime.toString());
    // start upgrade to the new available upgrade version
    CodeSystem upgradeCodeSystem = createExtensionUpgrade(extension.getResourceURI(), upgradeVersion);
    assertEquals(upgradeVersion, upgradeCodeSystem.getExtensionOf());
    getComponent(upgradeCodeSystem.getResourceURI(), SnomedComponentType.CONCEPT, newConceptId).statusCode(200);
}
Also used : ResourceURI(com.b2international.snowowl.core.ResourceURI) CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 20 with CodeSystem

use of com.b2international.snowowl.core.codesystem.CodeSystem in project snow-owl by b2ihealthcare.

the class SnomedExportApiTest method exportRf2WithoutConfiguration.

@Test
public void exportRf2WithoutConfiguration() throws Exception {
    String codeSystemId = "SNOMEDCT-default-rf2-export-config";
    createCodeSystem(branchPath, codeSystemId).statusCode(201);
    CodeSystem codeSystem = CodeSystemRestRequests.getCodeSystem(codeSystemId);
    final File exportArchive = doExport(codeSystemId, codeSystem.getSettings());
    final Map<String, Boolean> files = ImmutableMap.<String, Boolean>builder().put("der2_sssssssRefset_MRCMDomainSnapshot_INT", true).put("sct2_Relationship_Snapshot_INT", true).put("sct2_Description_Snapshot-en_INT", true).put("der2_sRefset_SimpleMapSnapshot_INT", true).build();
    assertArchiveContainsFiles(exportArchive, files);
}
Also used : CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) CodeSystemRestRequests.createCodeSystem(com.b2international.snowowl.test.commons.codesystem.CodeSystemRestRequests.createCodeSystem) File(java.io.File) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest) Test(org.junit.Test)

Aggregations

CodeSystem (com.b2international.snowowl.core.codesystem.CodeSystem)45 Test (org.junit.Test)34 LocalDate (java.time.LocalDate)33 ResourceURI (com.b2international.snowowl.core.ResourceURI)21 SnomedConcept (com.b2international.snowowl.snomed.core.domain.SnomedConcept)14 Json (com.b2international.commons.json.Json)8 CodeSystemRestRequests.createCodeSystem (com.b2international.snowowl.test.commons.codesystem.CodeSystemRestRequests.createCodeSystem)6 CodeSystems (com.b2international.snowowl.core.codesystem.CodeSystems)5 SnomedDescription (com.b2international.snowowl.snomed.core.domain.SnomedDescription)5 CodeSystemRequests (com.b2international.snowowl.core.codesystem.CodeSystemRequests)4 TimeUnit (java.util.concurrent.TimeUnit)4 Collectors (java.util.stream.Collectors)4 BadRequestException (com.b2international.commons.exceptions.BadRequestException)3 NotFoundException (com.b2international.commons.exceptions.NotFoundException)3 TerminologyResource (com.b2international.snowowl.core.TerminologyResource)3 SnowowlRuntimeException (com.b2international.snowowl.core.api.SnowowlRuntimeException)3 Attachment (com.b2international.snowowl.core.attachments.Attachment)3 AttachmentRegistry (com.b2international.snowowl.core.attachments.AttachmentRegistry)3 DateFormats (com.b2international.snowowl.core.date.DateFormats)3 EffectiveTimes (com.b2international.snowowl.core.date.EffectiveTimes)3