Search in sources :

Example 6 with CodeSystem

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

the class SnomedExtensionUpgradeTest method upgrade02NewExtensionConceptOnly.

@Test
public void upgrade02NewExtensionConceptOnly() {
    // 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);
    ResourceURI upgradeVersion = CodeSystem.uri(SNOMEDCT, effectiveTime.toString());
    // create new extension version with one new concept, module in this case
    String moduleId = createModule(extension);
    createVersion(extension.getId(), "v1", LocalDate.now()).statusCode(201);
    // start upgrade to the new available upgrade version
    CodeSystem upgradeCodeSystem = createExtensionUpgrade(extension.getResourceURI(), upgradeVersion);
    assertEquals(upgradeVersion, upgradeCodeSystem.getExtensionOf());
    getComponent(upgradeCodeSystem.getResourceURI(), SnomedComponentType.CONCEPT, moduleId).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 7 with CodeSystem

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

the class SnomedExtensionUpgradeTest method upgrade24UpgradeWithEmptyExtension.

@Test
public void upgrade24UpgradeWithEmptyExtension() throws Exception {
    // new SI concept
    ResourceURI base = CodeSystem.uri(SNOMEDCT);
    createConcept(base, createConceptRequestBody(Concepts.ROOT_CONCEPT, Concepts.MODULE_SCT_CORE));
    // create a new INT version
    LocalDate effectiveDate1 = getNextAvailableEffectiveDate(SNOMEDCT);
    createVersion(SNOMEDCT, effectiveDate1).statusCode(201);
    ResourceURI upgradeVersion1 = base.withPath(effectiveDate1.toString());
    // new SI concept
    String conceptId = createConcept(base, createConceptRequestBody(Concepts.ROOT_CONCEPT, Concepts.MODULE_SCT_CORE));
    // create a new INT version
    LocalDate effectiveDate2 = getNextAvailableEffectiveDate(SNOMEDCT);
    createVersion(SNOMEDCT, effectiveDate2).statusCode(201);
    ResourceURI upgradeVersion2 = base.withPath(effectiveDate2.toString());
    // new SI concept
    createConcept(base, createConceptRequestBody(Concepts.ROOT_CONCEPT, Concepts.MODULE_SCT_CORE));
    // create a new INT version
    LocalDate effectiveDate3 = getNextAvailableEffectiveDate(SNOMEDCT);
    createVersion(SNOMEDCT, effectiveDate3).statusCode(201);
    ResourceURI upgradeVersion3 = base.withPath(effectiveDate3.toString());
    // create extension on the latest SI VERSION
    CodeSystem extension = createExtension(upgradeVersion1, branchPath.lastSegment());
    // start upgrade to the new available upgrade version
    CodeSystem upgradeCodeSystem = createExtensionUpgrade(extension.getResourceURI(), upgradeVersion2);
    assertState(upgradeCodeSystem.getBranchPath(), extension.getBranchPath(), BranchState.FORWARD);
    Boolean result = CodeSystemRequests.prepareUpgradeSynchronization(upgradeCodeSystem.getResourceURI(), extension.getResourceURI()).buildAsync().execute(getBus()).getSync(1, TimeUnit.MINUTES);
    assertTrue(result);
    assertState(upgradeCodeSystem.getBranchPath(), extension.getBranchPath(), BranchState.FORWARD);
    Boolean successComplete = CodeSystemRequests.prepareComplete(upgradeCodeSystem.getId()).buildAsync().execute(getBus()).getSync(1, TimeUnit.MINUTES);
    assertTrue(successComplete);
    getComponent(extension.getResourceURI(), SnomedComponentType.CONCEPT, conceptId).statusCode(200);
}
Also used : ResourceURI(com.b2international.snowowl.core.ResourceURI) LocalDate(java.time.LocalDate) CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) Test(org.junit.Test)

Example 8 with CodeSystem

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

the class SnomedExtensionUpgradeTest method upgrade11DonatedConceptAndDescriptionsAndRelationshipsWithCrossReference.

@Test
public void upgrade11DonatedConceptAndDescriptionsAndRelationshipsWithCrossReference() {
    // create extension on the latest SI VERSION
    CodeSystem extension = createExtension(latestInternationalVersion, branchPath.lastSegment());
    String extensionModuleId = createModule(extension);
    String extensionFsnTerm1 = "FSN of concept";
    String extensionPtTerm1 = "PT of concept";
    String extensionSynonymTerm1 = "Synonym of extension concept";
    Json fsnRequestBody1 = Json.object("typeId", Concepts.FULLY_SPECIFIED_NAME, "term", extensionFsnTerm1, "languageCode", DEFAULT_LANGUAGE_CODE, "acceptability", SnomedApiTestConstants.UK_PREFERRED_MAP);
    Json ptRequestBody1 = Json.object("typeId", Concepts.SYNONYM, "term", extensionPtTerm1, "languageCode", DEFAULT_LANGUAGE_CODE, "acceptability", SnomedApiTestConstants.UK_PREFERRED_MAP);
    Json synonymRequestBody1 = Json.object("typeId", Concepts.SYNONYM, "term", extensionSynonymTerm1, "languageCode", DEFAULT_LANGUAGE_CODE, "acceptability", SnomedApiTestConstants.UK_ACCEPTABLE_MAP);
    Json statedIsa = Json.object("typeId", Concepts.IS_A, "destinationId", Concepts.ROOT_CONCEPT, "characteristicTypeId", Concepts.STATED_RELATIONSHIP);
    Json inferredIsa = Json.object("typeId", Concepts.IS_A, "destinationId", Concepts.ROOT_CONCEPT, "characteristicTypeId", Concepts.INFERRED_RELATIONSHIP);
    Json extensionConceptRequestBody = Json.object("namespaceId", Concepts.B2I_NAMESPACE, "moduleId", extensionModuleId, "descriptions", Json.array(fsnRequestBody1, ptRequestBody1, synonymRequestBody1), "relationships", Json.array(statedIsa, inferredIsa));
    String extensionConceptId1 = createConcept(extension.getResourceURI(), extensionConceptRequestBody);
    // create another extension concept which references the previous one
    String extensionFsnTerm2 = "FSN of concept 2";
    String extensionPtTerm2 = "PT of concept 2";
    String extensionSynonymTerm2 = "Synonym of extension concept 2";
    Json referenceToExtensionConcept1 = Json.object("typeId", Concepts.PART_OF, "destinationId", extensionConceptId1, "characteristicTypeId", Concepts.ADDITIONAL_RELATIONSHIP);
    String extensionConceptId2 = createConcept(extension.getResourceURI(), extensionConceptRequestBody.with(Json.object("descriptions", Json.array(fsnRequestBody1.with("term", extensionFsnTerm2), ptRequestBody1.with("term", extensionPtTerm2), synonymRequestBody1.with("term", extensionSynonymTerm2)), "relationships", Json.array(statedIsa, inferredIsa, referenceToExtensionConcept1))));
    // create new extension version
    createVersion(extension.getId(), "v1", LocalDate.now()).statusCode(201);
    SnomedConcept extensionConcept1 = getConcept(extension.getResourceURI(), extensionConceptId1, "descriptions()", "relationships()");
    String extensionFsnId1 = getFirstMatchingDescription(extensionConcept1, extensionFsnTerm1).getId();
    String extensionPtId1 = getFirstMatchingDescription(extensionConcept1, extensionPtTerm1).getId();
    String extensionSynonymId1 = getFirstMatchingDescription(extensionConcept1, extensionSynonymTerm1).getId();
    String extensionStatedIsaId1 = getFirstRelationshipId(extensionConcept1, Concepts.STATED_RELATIONSHIP);
    String extensionInferredIsaId1 = getFirstRelationshipId(extensionConcept1, Concepts.INFERRED_RELATIONSHIP);
    SnomedConcept extensionConcept2 = getConcept(extension.getResourceURI(), extensionConceptId2, "descriptions()", "relationships()");
    String extensionFsnId2 = getFirstMatchingDescription(extensionConcept2, extensionFsnTerm2).getId();
    String extensionPtId2 = getFirstMatchingDescription(extensionConcept2, extensionPtTerm2).getId();
    String extensionSynonymId2 = getFirstMatchingDescription(extensionConcept2, extensionSynonymTerm2).getId();
    String extensionStatedIsaId2 = getFirstRelationshipId(extensionConcept2, Concepts.STATED_RELATIONSHIP);
    String extensionInferredIsaId2 = getFirstRelationshipId(extensionConcept2, Concepts.INFERRED_RELATIONSHIP);
    String referenceToExtensionConcept1RelationshipId = getFirstRelationshipId(extensionConcept2, Concepts.ADDITIONAL_RELATIONSHIP);
    // simulate donation via concept create and versioning
    // donate both concepts without the PART OF relationship reference between them
    String intConceptId1 = createConcept(SnomedContentRule.SNOMEDCT, Json.object("id", extensionConceptId1, "moduleId", Concepts.MODULE_SCT_CORE, "descriptions", Json.array(fsnRequestBody1.with("id", extensionFsnId1), ptRequestBody1.with("id", extensionPtId1)), "relationships", Json.array(statedIsa.with("id", extensionStatedIsaId1), inferredIsa.with("id", extensionInferredIsaId1))));
    String intConceptId2 = createConcept(SnomedContentRule.SNOMEDCT, Json.object("id", extensionConceptId2, "moduleId", Concepts.MODULE_SCT_CORE, "descriptions", Json.array(fsnRequestBody1.with("id", extensionFsnId2), ptRequestBody1.with("id", extensionPtId2)), "relationships", Json.array(statedIsa.with("id", extensionStatedIsaId2), inferredIsa.with("id", extensionInferredIsaId2))));
    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 donatedConceptInExtension1 = getConcept(upgradeCodeSystem.getResourceURI(), intConceptId1, "descriptions()", "relationships()");
    SnomedConcept donatedConceptInExtension2 = getConcept(upgradeCodeSystem.getResourceURI(), intConceptId2, "descriptions()", "relationships()");
    // validate components of donated concepts on extension branch
    // same IDs, different modules
    assertEquals(donatedConceptInExtension1.getId(), extensionConcept1.getId());
    assertNotEquals(donatedConceptInExtension1.getModuleId(), extensionConcept1.getModuleId());
    assertThat(donatedConceptInExtension1.getDescriptions()).extracting(SnomedDescription::getId).containsOnly(extensionFsnId1, extensionPtId1, extensionSynonymId1);
    assertThat(donatedConceptInExtension1.getRelationships()).extracting(SnomedRelationship::getId).containsOnly(extensionStatedIsaId1, extensionInferredIsaId1);
    // check if the other donated extension concept still has the reference relationship
    assertEquals(donatedConceptInExtension2.getId(), extensionConcept2.getId());
    assertNotEquals(donatedConceptInExtension2.getModuleId(), extensionConcept2.getModuleId());
    assertThat(donatedConceptInExtension2.getDescriptions()).extracting(SnomedDescription::getId).containsOnly(extensionFsnId2, extensionPtId2, extensionSynonymId2);
    assertThat(donatedConceptInExtension2.getRelationships()).extracting(SnomedRelationship::getId).containsOnly(extensionStatedIsaId2, extensionInferredIsaId2, referenceToExtensionConcept1RelationshipId);
}
Also used : Json(com.b2international.commons.json.Json) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 9 with CodeSystem

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

the class SnomedExtensionUpgradeTest method upgrade23UpgradeSychronizeVersion.

@Test
public void upgrade23UpgradeSychronizeVersion() throws Exception {
    // create extension on the latest SI VERSION
    CodeSystem extension = createExtension(latestInternationalVersion, branchPath.lastSegment());
    // new SI concept
    createConcept(SnomedContentRule.SNOMEDCT, createConceptRequestBody(Concepts.ROOT_CONCEPT, Concepts.MODULE_SCT_CORE));
    // create a new INT version
    LocalDate effectiveDate = getNextAvailableEffectiveDate(SNOMEDCT);
    createVersion(SNOMEDCT, effectiveDate).statusCode(201);
    ResourceURI upgradeVersion = CodeSystem.uri(SNOMEDCT, effectiveDate.toString());
    // new SE concept
    String extensionModuleId = createModule(extension);
    createConcept(extension.getResourceURI(), createConceptRequestBody(Concepts.ROOT_CONCEPT, extensionModuleId));
    // version extension
    LocalDate effectiveDate2 = LocalDate.now();
    createVersion(extension.getId(), effectiveDate2).statusCode(201);
    ResourceURI extensionVersion = CodeSystem.uri(extension.getId(), effectiveDate2.toString());
    // new SE concept
    createConcept(extension.getResourceURI(), createConceptRequestBody(Concepts.ROOT_CONCEPT, extensionModuleId));
    // version extension
    LocalDate effectiveDate3 = getNextAvailableEffectiveDate(extension.getId());
    createVersion(extension.getId(), effectiveDate3).statusCode(201);
    ResourceURI extensionVersion2 = CodeSystem.uri(extension.getId(), effectiveDate3.toString());
    // new SE concept
    createConcept(extension.getResourceURI(), createConceptRequestBody(Concepts.ROOT_CONCEPT, extensionModuleId));
    // version extension
    LocalDate effectiveDate4 = getNextAvailableEffectiveDate(extension.getId());
    createVersion(extension.getId(), effectiveDate4).statusCode(201);
    ResourceURI extensionVersion3 = CodeSystem.uri(extension.getId(), effectiveDate4.toString());
    // start upgrade to the new available upgrade version
    CodeSystem upgradeCodeSystem = createExtensionUpgrade(extensionVersion, upgradeVersion);
    CodeSystems expandedCodeSystems = CodeSystemRestRequests.search(upgradeCodeSystem.getId(), CodeSystem.Expand.UPGRADE_INFO + "()");
    assertEquals(upgradeVersion, upgradeCodeSystem.getExtensionOf());
    assertThat(expandedCodeSystems.first().get().getUpgradeInfo().getAvailableVersions()).doesNotContainSequence(extensionVersion);
    assertThat(expandedCodeSystems.first().get().getUpgradeInfo().getAvailableVersions()).contains(extensionVersion2);
    Boolean result = CodeSystemRequests.prepareUpgradeSynchronization(upgradeCodeSystem.getResourceURI(), extensionVersion2).buildAsync().execute(getBus()).getSync(1, TimeUnit.MINUTES);
    assertTrue(result);
    CodeSystems expandedCodeSystemsAfterMerge = CodeSystemRestRequests.search(upgradeCodeSystem.getId(), CodeSystem.Expand.UPGRADE_INFO + "()");
    assertThat(expandedCodeSystemsAfterMerge.first().get().getUpgradeInfo().getAvailableVersions()).containsOnly(extensionVersion3);
}
Also used : ResourceURI(com.b2international.snowowl.core.ResourceURI) CodeSystems(com.b2international.snowowl.core.codesystem.CodeSystems) CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 10 with CodeSystem

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

the class SnomedExtensionUpgradeTest method upgrade07DonatedRelationship.

@Test
public void upgrade07DonatedRelationship() throws Exception {
    // create extension on the latest SI VERSION
    CodeSystem extension = createExtension(latestInternationalVersion, branchPath.lastSegment());
    String extensionModuleId = createModule(extension);
    Json extensionRelationshipRequest = Json.object("namespaceId", Concepts.B2I_NAMESPACE, "moduleId", extensionModuleId, "sourceId", Concepts.ROOT_CONCEPT, "typeId", Concepts.PART_OF, "destinationId", Concepts.NAMESPACE_ROOT, "characteristicTypeId", Concepts.ADDITIONAL_RELATIONSHIP, "relationshipGroup", 0, "commitComment", "Created new extension relationship");
    String extensionRelationshipId = createRelationship(extension.getResourceURI(), extensionRelationshipRequest);
    // create new extension version
    createVersion(extension.getId(), "v1", LocalDate.now()).statusCode(201);
    // simulate donation of relationship to INT with slightly different props but same ID
    Json donatedRelationshipRequest = Json.assign(extensionRelationshipRequest, Json.object("id", extensionRelationshipId, "moduleId", Concepts.MODULE_SCT_CORE, "characteristicTypeId", Concepts.INFERRED_RELATIONSHIP, "relationshipGroup", 1, "commitComment", "Created new donated INT relationship"));
    String donatedRelationshipId = createRelationship(SnomedContentRule.SNOMEDCT, donatedRelationshipRequest);
    LocalDate effectiveTime = getNextAvailableEffectiveDate(SNOMEDCT);
    createVersion(SNOMEDCT, effectiveTime).statusCode(201);
    assertEquals(extensionRelationshipId, donatedRelationshipId);
    // start upgrade to the new available upgrade version
    CodeSystem upgradeCodeSystem = createExtensionUpgrade(extension.getResourceURI(), CodeSystem.uri(SNOMEDCT, effectiveTime.toString()));
    SnomedRelationship donatedRelationshipOnUpgrade = getRelationship(upgradeCodeSystem.getResourceURI(), donatedRelationshipId);
    assertEquals(Concepts.MODULE_SCT_CORE, donatedRelationshipOnUpgrade.getModuleId());
    assertEquals(Concepts.INFERRED_RELATIONSHIP, donatedRelationshipOnUpgrade.getCharacteristicTypeId());
    assertEquals(1, donatedRelationshipOnUpgrade.getRelationshipGroup().intValue());
}
Also used : SnomedRelationship(com.b2international.snowowl.snomed.core.domain.SnomedRelationship) Json(com.b2international.commons.json.Json) CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) LocalDate(java.time.LocalDate) 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