use of com.b2international.snowowl.snomed.core.domain.SnomedDescription in project snow-owl by b2ihealthcare.
the class SnomedDescriptionUtilsTest method createDescription.
@SuppressWarnings("deprecation")
private static SnomedDescription createDescription(String id, String term, Map<String, Acceptability> acceptabilityMap) {
SnomedDescription description = new SnomedDescription(id);
description.setTerm(term);
description.setActive(true);
description.setConceptId(Concepts.ROOT_CONCEPT);
description.setAcceptabilityMap(acceptabilityMap);
return description;
}
use of com.b2international.snowowl.snomed.core.domain.SnomedDescription in project snow-owl by b2ihealthcare.
the class SnomedConceptSearchRequest method executeDescriptionSearch.
private Map<String, Float> executeDescriptionSearch(BranchContext context, TermFilter termFilter) {
final SnomedDescriptionSearchRequestBuilder requestBuilder = SnomedRequests.prepareSearchDescription().all().filterByActive(true).setFields(SnomedDescriptionIndexEntry.Fields.ID, SnomedDescriptionIndexEntry.Fields.CONCEPT_ID).sortBy(SCORE);
if (containsKey(SnomedConceptSearchRequest.OptionKey.LANGUAGE_REFSET)) {
List<ExtendedLocale> extendedLocales = getList(SnomedDescriptionSearchRequest.OptionKey.LANGUAGE_REFSET, ExtendedLocale.class);
requestBuilder.filterByLanguageRefSets(SnomedDescriptionUtils.getLanguageRefSetIds(context, extendedLocales));
}
applyIdFilter(requestBuilder, (rb, ids) -> rb.filterByConcepts(ids));
if (containsKey(OptionKey.DESCRIPTION_TYPE)) {
final String type = getString(OptionKey.DESCRIPTION_TYPE);
requestBuilder.filterByType(type);
}
if (termFilter != null) {
requestBuilder.filterByTerm(termFilter);
}
final Collection<SnomedDescription> items = requestBuilder.build().execute(context).getItems();
final Map<String, Float> conceptMap = newHashMap();
for (SnomedDescription description : items) {
if (!conceptMap.containsKey(description.getConceptId())) {
conceptMap.put(description.getConceptId(), description.getScore());
}
}
return conceptMap;
}
use of com.b2international.snowowl.snomed.core.domain.SnomedDescription 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));
}
use of com.b2international.snowowl.snomed.core.domain.SnomedDescription 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());
}
use of com.b2international.snowowl.snomed.core.domain.SnomedDescription 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);
}
Aggregations