Search in sources :

Example 81 with Json

use of com.b2international.commons.json.Json in project snow-owl by b2ihealthcare.

the class SnomedRelationshipApiTest method createInactiveRelationship.

private void createInactiveRelationship(String typeId) {
    Json requestBody = createRelationshipRequestBody(Concepts.ROOT_CONCEPT, typeId, Concepts.NAMESPACE_ROOT).with("active", false).with("commitComment", "Created inactive relationship");
    String relationshipId = assertCreated(createComponent(branchPath, SnomedComponentType.RELATIONSHIP, requestBody));
    getComponent(branchPath, SnomedComponentType.RELATIONSHIP, relationshipId).statusCode(200).body("active", equalTo(false));
}
Also used : Json(com.b2international.commons.json.Json)

Example 82 with Json

use of com.b2international.commons.json.Json in project snow-owl by b2ihealthcare.

the class SnomedExtensionUpgradeTest method upgrade12WithDonatedConceptAndDescriptionsAndRelationshipsWithExternalReference.

@Test
public void upgrade12WithDonatedConceptAndDescriptionsAndRelationshipsWithExternalReference() {
    // 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 intConceptId = 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))));
    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(), intConceptId, "descriptions()", "relationships()");
    SnomedConcept extensionConcept2OnUpgrade = getConcept(upgradeCodeSystem.getResourceURI(), extensionConceptId2, "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 external reference extension concept still has the reference relationship and all its content
    assertThat(extensionConcept2OnUpgrade.getDescriptions()).extracting(SnomedDescription::getId).containsOnly(extensionFsnId2, extensionPtId2, extensionSynonymId2);
    assertThat(extensionConcept2OnUpgrade.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 83 with Json

use of com.b2international.commons.json.Json in project snow-owl by b2ihealthcare.

the class SnomedExtensionUpgradeTest method upgrade06DonatedDescription.

@Test
public void upgrade06DonatedDescription() throws Exception {
    // create extension on the latest SI VERSION
    CodeSystem extension = createExtension(latestInternationalVersion, branchPath.lastSegment());
    String extensionModuleId = createModule(extension);
    String descriptionTerm = "Donated synonym of root concept";
    Json extensionDescriptionRequest = Json.object("conceptId", Concepts.ROOT_CONCEPT, "namespaceId", Concepts.B2I_NAMESPACE, "moduleId", extensionModuleId, "typeId", Concepts.SYNONYM, "term", descriptionTerm, "languageCode", DEFAULT_LANGUAGE_CODE, "acceptability", SnomedApiTestConstants.US_ACCEPTABLE_MAP, "caseSignificanceId", Concepts.ONLY_INITIAL_CHARACTER_CASE_INSENSITIVE, "commitComment", "Created new extension synonym");
    String extensionDescriptionId = createDescription(extension.getResourceURI(), extensionDescriptionRequest);
    // create new extension version
    createVersion(extension.getId(), "v1", LocalDate.now()).statusCode(201);
    // simulate donation to SI with same ID but with slightly different properties
    Json donatedDescriptionRequest = Json.assign(extensionDescriptionRequest, Json.object("id", extensionDescriptionId, "moduleId", Concepts.MODULE_SCT_CORE, "languageCode", "en", "acceptability", SnomedApiTestConstants.UK_ACCEPTABLE_MAP, "caseSignificanceId", Concepts.ENTIRE_TERM_CASE_SENSITIVE, "commitComment", "Created new donated synonym"));
    String donatedDescriptionId = createDescription(SnomedContentRule.SNOMEDCT, donatedDescriptionRequest);
    LocalDate effectiveTime = getNextAvailableEffectiveDate(SNOMEDCT);
    createVersion(SNOMEDCT, effectiveTime).statusCode(201);
    assertEquals(extensionDescriptionId, donatedDescriptionId);
    // start upgrade to the new available upgrade version
    CodeSystem upgradeCodeSystem = createExtensionUpgrade(extension.getResourceURI(), CodeSystem.uri(SNOMEDCT, effectiveTime.toString()));
    SnomedDescription donatedDescriptionOnUpgrade = getDescription(upgradeCodeSystem.getResourceURI(), donatedDescriptionId);
    assertEquals(Concepts.MODULE_SCT_CORE, donatedDescriptionOnUpgrade.getModuleId());
    assertEquals(Concepts.ENTIRE_TERM_CASE_SENSITIVE, donatedDescriptionOnUpgrade.getCaseSignificanceId());
    // acceptability should come from both INT
    assertThat(donatedDescriptionOnUpgrade.getAcceptabilityMap().containsKey(Concepts.REFSET_LANGUAGE_TYPE_UK));
    assertEquals(Acceptability.ACCEPTABLE, donatedDescriptionOnUpgrade.getAcceptabilityMap().get(Concepts.REFSET_LANGUAGE_TYPE_UK));
    // and EXT should keep its acceptability values
    assertThat(donatedDescriptionOnUpgrade.getAcceptabilityMap().containsKey(Concepts.REFSET_LANGUAGE_TYPE_US));
    assertEquals(Acceptability.ACCEPTABLE, donatedDescriptionOnUpgrade.getAcceptabilityMap().get(Concepts.REFSET_LANGUAGE_TYPE_US));
}
Also used : SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) Json(com.b2international.commons.json.Json) CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 84 with Json

use of com.b2international.commons.json.Json in project snow-owl by b2ihealthcare.

the class SnomedExtensionUpgradeTest method upgrade08WithBackAndForthDonatedConcept.

@Test
public void upgrade08WithBackAndForthDonatedConcept() {
    // create new version on INT with core module and initial char case insensitive case significance
    String descriptionTerm = "Description term";
    Json initialInternationalDescriptionRequest = Json.object("conceptId", Concepts.ROOT_CONCEPT, "moduleId", Concepts.MODULE_SCT_CORE, "typeId", Concepts.SYNONYM, "term", descriptionTerm, "languageCode", DEFAULT_LANGUAGE_CODE, "acceptability", SnomedApiTestConstants.UK_ACCEPTABLE_MAP, "caseSignificanceId", Concepts.ONLY_INITIAL_CHARACTER_CASE_INSENSITIVE, "commitComment", "Created new synonym");
    String internationalDescriptionId = createDescription(SnomedContentRule.SNOMEDCT, initialInternationalDescriptionRequest);
    LocalDate effectiveTime = getNextAvailableEffectiveDate(SNOMEDCT);
    createVersion(SNOMEDCT, effectiveTime).statusCode(201);
    // create extension on the latest SI VERSION
    CodeSystem extension = createExtension(CodeSystem.uri(SNOMEDCT, effectiveTime.toString()), branchPath.lastSegment());
    String extensionModuleId = createModule(extension);
    // update international description on extension, changing module and case significance
    Json extensionDescriptionUpdateRequest = Json.object("moduleId", extensionModuleId, "caseSignificanceId", Concepts.ENTIRE_TERM_CASE_SENSITIVE, "commitComment", "Changed case significance on description");
    updateDescription(extension.getResourceURI(), internationalDescriptionId, extensionDescriptionUpdateRequest);
    SnomedDescription updatedInternationalDescription = getDescription(extension.getResourceURI(), internationalDescriptionId);
    assertEquals(true, updatedInternationalDescription.isReleased());
    assertEquals(null, updatedInternationalDescription.getEffectiveTime());
    assertEquals(extensionModuleId, updatedInternationalDescription.getModuleId());
    assertEquals(Concepts.ENTIRE_TERM_CASE_SENSITIVE, updatedInternationalDescription.getCaseSignificanceId());
    // create new extension version
    createVersion(extension.getId(), "v1", LocalDate.now()).statusCode(201);
    // donate extension changes to international via RF2 update simulation
    Json descriptionDonateRequest = Json.object("caseSignificanceId", Concepts.ENTIRE_TERM_CASE_SENSITIVE, "commitComment", "Changed case significance on description");
    updateDescription(SnomedContentRule.SNOMEDCT, internationalDescriptionId, descriptionDonateRequest);
    LocalDate donationEffectiveDate = getNextAvailableEffectiveDate(SNOMEDCT);
    createVersion(SNOMEDCT, donationEffectiveDate).statusCode(201);
    // upgrade extension to new INT version with donations
    // start upgrade to the new available upgrade version
    CodeSystem upgradeCodeSystem = createExtensionUpgrade(extension.getResourceURI(), CodeSystem.uri(SNOMEDCT, donationEffectiveDate.toString()));
    SnomedDescription updatedInternationalDescriptionOnUpgrade = getDescription(upgradeCodeSystem.getResourceURI(), internationalDescriptionId);
    assertEquals(true, updatedInternationalDescriptionOnUpgrade.isReleased());
    assertEquals(donationEffectiveDate, updatedInternationalDescriptionOnUpgrade.getEffectiveTime());
    assertEquals(Concepts.MODULE_SCT_CORE, updatedInternationalDescriptionOnUpgrade.getModuleId());
    assertEquals(Concepts.ENTIRE_TERM_CASE_SENSITIVE, updatedInternationalDescriptionOnUpgrade.getCaseSignificanceId());
}
Also used : SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) Json(com.b2international.commons.json.Json) LocalDate(java.time.LocalDate) CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) Test(org.junit.Test)

Example 85 with Json

use of com.b2international.commons.json.Json in project snow-owl by b2ihealthcare.

the class SnomedExtensionUpgradeTest method upgrade10DonatedConceptAndDescriptionsAndRelationships.

@Test
public void upgrade10DonatedConceptAndDescriptionsAndRelationships() {
    // create extension on the latest SI VERSION
    CodeSystem extension = createExtension(latestInternationalVersion, branchPath.lastSegment());
    String extensionModuleId = createModule(extension);
    String extensionFsnTerm = "FSN of concept";
    String extensionPtTerm = "PT of concept";
    String extensionSynonymTerm = "Synonym of extension concept";
    Json fsnRequestBody = Json.object("typeId", Concepts.FULLY_SPECIFIED_NAME, "term", extensionFsnTerm, "languageCode", DEFAULT_LANGUAGE_CODE, "acceptability", SnomedApiTestConstants.UK_PREFERRED_MAP);
    Json ptRequestBody = Json.object("typeId", Concepts.SYNONYM, "term", extensionPtTerm, "languageCode", DEFAULT_LANGUAGE_CODE, "acceptability", SnomedApiTestConstants.UK_PREFERRED_MAP);
    Json synonymRequestBody = Json.object("typeId", Concepts.SYNONYM, "term", extensionSynonymTerm, "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(fsnRequestBody, ptRequestBody, synonymRequestBody), "relationships", Json.array(statedIsa, inferredIsa));
    String extensionConceptId = createConcept(extension.getResourceURI(), extensionConceptRequestBody);
    // create new extension version
    createVersion(extension.getId(), "v1", LocalDate.now()).statusCode(201);
    SnomedConcept extensionConcept = getConcept(extension.getResourceURI(), extensionConceptId, "descriptions()", "relationships()");
    String extensionFsnId = getFirstMatchingDescription(extensionConcept, extensionFsnTerm).getId();
    String extensionPtId = getFirstMatchingDescription(extensionConcept, extensionPtTerm).getId();
    String extensionSynonymId = getFirstMatchingDescription(extensionConcept, extensionSynonymTerm).getId();
    String extensionStatedIsaId = getFirstRelationshipId(extensionConcept, Concepts.STATED_RELATIONSHIP);
    String extensionInferredIsaId = getFirstRelationshipId(extensionConcept, Concepts.INFERRED_RELATIONSHIP);
    // simulate donation via concept create and versioning
    // create INT concept with same ID and with same description and relationship IDs
    String intConceptId = createConcept(SnomedContentRule.SNOMEDCT, Json.object("id", extensionConceptId, "moduleId", Concepts.MODULE_SCT_CORE, "descriptions", Json.array(fsnRequestBody.with("id", extensionFsnId), ptRequestBody.with("id", extensionPtId)), "relationships", Json.array(statedIsa.with("id", extensionStatedIsaId), inferredIsa.with("id", extensionInferredIsaId))));
    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 donatedConceptInExtension = getConcept(upgradeCodeSystem.getResourceURI(), intConceptId, "descriptions()", "relationships()");
    // validate components of donated concept on extension branch
    // same ID, different module
    assertEquals(donatedConceptInExtension.getId(), extensionConcept.getId());
    assertNotEquals(donatedConceptInExtension.getModuleId(), extensionConcept.getModuleId());
    SnomedDescription donatedFsn = getFirstMatchingDescription(donatedConceptInExtension, extensionFsnTerm);
    assertEquals(extensionFsnId, donatedFsn.getId());
    assertEquals(Concepts.MODULE_SCT_CORE, donatedFsn.getModuleId());
    SnomedDescription donatedPt = getFirstMatchingDescription(donatedConceptInExtension, extensionPtTerm);
    assertEquals(extensionPtId, donatedPt.getId());
    assertEquals(Concepts.MODULE_SCT_CORE, donatedPt.getModuleId());
    Set<String> descriptionIds = donatedConceptInExtension.getDescriptions().getItems().stream().map(SnomedDescription::getId).collect(Collectors.toSet());
    assertThat(descriptionIds).hasSize(3).contains(extensionSynonymId);
    Set<String> relationshipIds = donatedConceptInExtension.getRelationships().getItems().stream().map(SnomedRelationship::getId).collect(Collectors.toSet());
    assertThat(relationshipIds).hasSize(2).contains(extensionStatedIsaId, extensionInferredIsaId);
}
Also used : SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) 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)

Aggregations

Json (com.b2international.commons.json.Json)139 Test (org.junit.Test)134 AbstractSnomedApiTest (com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)111 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)33 LocalDate (java.time.LocalDate)17 RelationshipValue (com.b2international.snowowl.snomed.core.domain.RelationshipValue)11 SnomedDescription (com.b2international.snowowl.snomed.core.domain.SnomedDescription)11 SnomedReferenceSetMember (com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember)11 BaseResourceApiTest (com.b2international.snowowl.core.rest.BaseResourceApiTest)10 SnomedReferenceSetMembers (com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers)10 CodeSystem (com.b2international.snowowl.core.codesystem.CodeSystem)7 ISnomedIdentifierService (com.b2international.snowowl.snomed.cis.ISnomedIdentifierService)6 SnomedConcept (com.b2international.snowowl.snomed.core.domain.SnomedConcept)6 SctId (com.b2international.snowowl.snomed.cis.domain.SctId)4 Pair (com.b2international.commons.Pair)3 ValidatableResponse (io.restassured.response.ValidatableResponse)3 File (java.io.File)3 NotFoundException (com.b2international.commons.exceptions.NotFoundException)2 IBranchPath (com.b2international.snowowl.core.api.IBranchPath)2 TransactionContext (com.b2international.snowowl.core.domain.TransactionContext)2