use of com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionFragment in project snow-owl by b2ihealthcare.
the class PreferredDescriptionPreCommitHookTest method updateTermOfConceptFsn.
@Test
public void updateTermOfConceptFsn() throws Exception {
final SnomedConceptDocument concept = concept().build();
final SnomedDescriptionIndexEntry fsn = fsn(concept.getId(), Collections.singletonMap(Concepts.REFSET_LANGUAGE_TYPE_UK, Acceptability.PREFERRED));
initRevisions(docWithDefaults(concept).preferredDescriptions(ImmutableList.of(new SnomedDescriptionFragment(fsn.getId(), fsn.getTypeId(), fsn.getTerm(), Concepts.REFSET_LANGUAGE_TYPE_UK))).build(), fsn);
stageChange(fsn, SnomedDescriptionIndexEntry.builder(fsn).term("Term (changed)").build());
final ConceptChangeProcessor processor = process();
final SnomedConceptDocument expected = docWithDefaults(concept).semanticTags(ImmutableSortedSet.of("changed")).preferredDescriptions(ImmutableList.of(new SnomedDescriptionFragment(fsn.getId(), fsn.getTypeId(), "Term (changed)", Concepts.REFSET_LANGUAGE_TYPE_UK))).build();
final Revision actual = Iterables.getOnlyElement(processor.getChangedMappings().values()).getNewRevision();
assertDocEquals(expected, actual);
assertEquals(0, processor.getNewMappings().size());
assertEquals(0, processor.getDeletions().size());
}
use of com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionFragment in project snow-owl by b2ihealthcare.
the class PreferredDescriptionPreCommitHookTest method inactivateFsnOfConcept.
@Test
public void inactivateFsnOfConcept() throws Exception {
final SnomedConceptDocument concept = concept().build();
final SnomedDescriptionIndexEntry fsn = fsn(concept.getId(), Collections.singletonMap(Concepts.REFSET_LANGUAGE_TYPE_UK, Acceptability.PREFERRED));
initRevisions(docWithDefaults(concept).preferredDescriptions(ImmutableList.of(new SnomedDescriptionFragment(fsn.getId(), fsn.getTypeId(), fsn.getTerm(), Concepts.REFSET_LANGUAGE_TYPE_UK))).build(), fsn);
stageChange(fsn, SnomedDescriptionIndexEntry.builder(fsn).active(false).build());
final ConceptChangeProcessor processor = process();
final SnomedConceptDocument expected = docWithDefaults(concept).build();
final Revision actual = Iterables.getOnlyElement(processor.getChangedMappings().values()).getNewRevision();
assertDocEquals(expected, actual);
assertEquals(0, processor.getNewMappings().size());
assertEquals(0, processor.getDeletions().size());
}
use of com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionFragment in project snow-owl by b2ihealthcare.
the class PreferredDescriptionPreCommitHookTest method indexNewFsnForExistingConcept.
@Test
public void indexNewFsnForExistingConcept() throws Exception {
final SnomedConceptDocument concept = concept().build();
initRevisions(docWithDefaults(concept).build());
final SnomedDescriptionIndexEntry fsn = fsn(concept.getId(), Collections.singletonMap(Concepts.REFSET_LANGUAGE_TYPE_UK, Acceptability.PREFERRED));
stageNew(fsn);
final ConceptChangeProcessor processor = process();
final SnomedConceptDocument expected = docWithDefaults(concept).semanticTags(ImmutableSortedSet.of("semantic tag")).preferredDescriptions(ImmutableList.of(new SnomedDescriptionFragment(fsn.getId(), fsn.getTypeId(), fsn.getTerm(), Concepts.REFSET_LANGUAGE_TYPE_UK))).build();
assertEquals(1, processor.getChangedMappings().size());
final Revision actual = Iterables.getOnlyElement(processor.getChangedMappings().values()).getNewRevision();
assertDocEquals(expected, actual);
assertEquals(0, processor.getNewMappings().size());
assertEquals(0, processor.getDeletions().size());
}
use of com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionFragment in project snow-owl by b2ihealthcare.
the class PreferredDescriptionPreCommitHookTest method removeFsnFromExistingConcept.
@Test
public void removeFsnFromExistingConcept() throws Exception {
final SnomedConceptDocument concept = concept().build();
final SnomedDescriptionIndexEntry fsn = fsn(concept.getId(), Collections.singletonMap(Concepts.REFSET_LANGUAGE_TYPE_UK, Acceptability.PREFERRED));
initRevisions(docWithDefaults(concept).preferredDescriptions(ImmutableList.of(new SnomedDescriptionFragment(fsn.getId(), fsn.getTypeId(), fsn.getTerm(), Concepts.REFSET_LANGUAGE_TYPE_UK))).build(), fsn);
stageRemove(fsn);
final ConceptChangeProcessor processor = process();
final SnomedConceptDocument expected = docWithDefaults(concept).build();
final Revision actual = Iterables.getOnlyElement(processor.getChangedMappings().values()).getNewRevision();
assertDocEquals(expected, actual);
assertEquals(0, processor.getNewMappings().size());
assertEquals(0, processor.getDeletions().size());
}
use of com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionFragment in project snow-owl by b2ihealthcare.
the class ConceptChangeProcessor method update.
/*
* Updates already existing concept document with changes from concept and the current revision.
* New concepts does not have currentRevision and dirty concepts may not have a loaded Concept CDOObject,
* therefore both can be null, but not at the same time.
* In case of new objects the Concept object should not be null, in case of dirty, the currentVersion should not be null,
* but there can be a dirty concept if a property changed on it.
* We will use whatever we actually have locally to compute the new revision.
*/
private void update(SnomedConceptDocument.Builder doc, List<SnomedDescriptionFragment> preferredDescriptions, @Nullable SnomedConceptDocument newOrDirtyRevision, SnomedConceptDocument cleanRevision) {
checkArgument(newOrDirtyRevision != null || cleanRevision != null, "Either the newOrDirtyRevision is null or the cleanRevision but not both");
final String id = newOrDirtyRevision != null ? newOrDirtyRevision.getId() : cleanRevision.getId();
final long idLong = Long.parseLong(id);
final boolean active = newOrDirtyRevision != null ? newOrDirtyRevision.isActive() : cleanRevision.isActive();
if (newOrDirtyRevision != null) {
doc.active(active).released(newOrDirtyRevision.isReleased()).effectiveTime(newOrDirtyRevision.getEffectiveTime()).moduleId(newOrDirtyRevision.getModuleId()).exhaustive(newOrDirtyRevision.isExhaustive()).definitionStatusId(newOrDirtyRevision.getDefinitionStatusId()).refSetType(newOrDirtyRevision.getRefSetType()).referencedComponentType(newOrDirtyRevision.getReferencedComponentType()).mapTargetComponentType(newOrDirtyRevision.getMapTargetComponentType()).doi(doiData.getDoiScore(idLong));
} else {
doc.active(active).released(cleanRevision.isReleased()).effectiveTime(cleanRevision.getEffectiveTime()).moduleId(cleanRevision.getModuleId()).exhaustive(cleanRevision.isExhaustive()).definitionStatusId(cleanRevision.getDefinitionStatusId()).refSetType(cleanRevision.getRefSetType()).referencedComponentType(cleanRevision.getReferencedComponentType()).mapTargetComponentType(cleanRevision.getMapTargetComponentType()).doi(doiData.getDoiScore(idLong));
}
/*
* Extract semantic tags from active FSNs received in preferredDescriptions (these are expected to be preferred in at
* least one language reference set).
*/
final SortedSet<String> semanticTags = preferredDescriptions.stream().filter(f -> Concepts.FULLY_SPECIFIED_NAME.equals(f.getTypeId())).map(f -> SnomedDescriptionIndexEntry.extractSemanticTag(f.getTerm())).filter(semanticTag -> !semanticTag.isEmpty()).collect(Collectors.toCollection(TreeSet::new));
final boolean inStated = statedTaxonomy.getNewTaxonomy().containsNode(idLong);
final boolean inInferred = inferredTaxonomy.getNewTaxonomy().containsNode(idLong);
if (inStated || inInferred) {
iconId.update(id, Iterables.getFirst(semanticTags, ""), active, doc);
}
if (inStated) {
stated.update(id, doc);
}
if (inInferred) {
inferred.update(id, doc);
}
final Collection<String> currentMemberOf = cleanRevision == null ? Collections.emptySet() : cleanRevision.getMemberOf();
final Collection<String> currentActiveMemberOf = cleanRevision == null ? Collections.emptySet() : cleanRevision.getActiveMemberOf();
new ReferenceSetMembershipUpdater(referringRefSets.removeAll(id), currentMemberOf, currentActiveMemberOf).update(doc);
doc.semanticTags(semanticTags);
doc.preferredDescriptions(preferredDescriptions);
}
Aggregations