Search in sources :

Example 16 with SnomedDescriptionFragment

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());
}
Also used : SnomedConceptDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument) SnomedDescriptionFragment(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionFragment) Revision(com.b2international.index.revision.Revision) SnomedDescriptionIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionIndexEntry) Test(org.junit.Test)

Example 17 with SnomedDescriptionFragment

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());
}
Also used : SnomedConceptDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument) SnomedDescriptionFragment(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionFragment) Revision(com.b2international.index.revision.Revision) SnomedDescriptionIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionIndexEntry) Test(org.junit.Test)

Example 18 with SnomedDescriptionFragment

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());
}
Also used : SnomedConceptDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument) SnomedDescriptionFragment(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionFragment) Revision(com.b2international.index.revision.Revision) SnomedDescriptionIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionIndexEntry) Test(org.junit.Test)

Example 19 with SnomedDescriptionFragment

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());
}
Also used : SnomedConceptDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument) SnomedDescriptionFragment(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionFragment) Revision(com.b2international.index.revision.Revision) SnomedDescriptionIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionIndexEntry) Test(org.junit.Test)

Example 20 with SnomedDescriptionFragment

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);
}
Also used : SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) ChangeSetProcessorBase(com.b2international.snowowl.core.repository.ChangeSetProcessorBase) Acceptability(com.b2international.snowowl.snomed.core.domain.Acceptability) java.util(java.util) SnomedRefSetMemberIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry) RevisionDiff(com.b2international.index.revision.StagingArea.RevisionDiff) IconIdUpdater(com.b2international.snowowl.snomed.datastore.index.update.IconIdUpdater) TaxonomyGraph(com.b2international.snowowl.snomed.datastore.taxonomy.TaxonomyGraph) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) LongSets(com.b2international.commons.collect.LongSets) RevisionSearcher(com.b2international.index.revision.RevisionSearcher) ObjectId(com.b2international.index.revision.ObjectId) SnomedDescriptionFragment(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionFragment) ReferenceSetMembershipUpdater(com.b2international.snowowl.snomed.datastore.index.update.ReferenceSetMembershipUpdater) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) SnomedConceptDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument) com.google.common.collect(com.google.common.collect) Nullable(javax.annotation.Nullable) RefSetMemberChange(com.b2international.snowowl.snomed.datastore.index.refset.RefSetMemberChange) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Revision(com.b2international.index.revision.Revision) IOException(java.io.IOException) Taxonomy(com.b2international.snowowl.snomed.datastore.taxonomy.Taxonomy) Collectors(java.util.stream.Collectors) ParentageUpdater(com.b2international.snowowl.snomed.datastore.index.update.ParentageUpdater) StagingArea(com.b2international.index.revision.StagingArea) SnomedDescriptionIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionIndexEntry) Builder(com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument.Builder) ReferenceSetMembershipUpdater(com.b2international.snowowl.snomed.datastore.index.update.ReferenceSetMembershipUpdater)

Aggregations

SnomedConceptDocument (com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument)22 SnomedDescriptionFragment (com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionFragment)22 SnomedDescriptionIndexEntry (com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionIndexEntry)22 Revision (com.b2international.index.revision.Revision)21 Test (org.junit.Test)19 SnomedRefSetMemberIndexEntry (com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry)9 LongSets (com.b2international.commons.collect.LongSets)3 ObjectId (com.b2international.index.revision.ObjectId)3 RevisionSearcher (com.b2international.index.revision.RevisionSearcher)3 StagingArea (com.b2international.index.revision.StagingArea)3 RevisionDiff (com.b2international.index.revision.StagingArea.RevisionDiff)3 ChangeSetProcessorBase (com.b2international.snowowl.core.repository.ChangeSetProcessorBase)3 Concepts (com.b2international.snowowl.snomed.common.SnomedConstants.Concepts)3 Acceptability (com.b2international.snowowl.snomed.core.domain.Acceptability)3 SnomedConcept (com.b2international.snowowl.snomed.core.domain.SnomedConcept)3 Builder (com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument.Builder)3 RefSetMemberChange (com.b2international.snowowl.snomed.datastore.index.refset.RefSetMemberChange)3 IconIdUpdater (com.b2international.snowowl.snomed.datastore.index.update.IconIdUpdater)3 ParentageUpdater (com.b2international.snowowl.snomed.datastore.index.update.ParentageUpdater)3 ReferenceSetMembershipUpdater (com.b2international.snowowl.snomed.datastore.index.update.ReferenceSetMembershipUpdater)3