Search in sources :

Example 21 with SnomedDescription

use of com.b2international.snowowl.snomed.core.domain.SnomedDescription in project snow-owl by b2ihealthcare.

the class SnomedSimpleTypeRefSetDSVExporter method writeValues.

private void writeValues(BufferedWriter writer, SnomedConcepts chunk) throws IOException {
    List<String> dataRow = newArrayList();
    for (SnomedConcept concept : chunk) {
        dataRow.clear();
        for (AbstractSnomedDsvExportItem exportItem : exportItems) {
            switch(exportItem.getType()) {
                case DESCRIPTION:
                    {
                        final ComponentIdSnomedDsvExportItem descriptionItem = (ComponentIdSnomedDsvExportItem) exportItem;
                        final String typeId = descriptionItem.getComponentId();
                        int occurrences = descriptionCount.get(typeId);
                        final Map<String, String> termsById = concept.getDescriptions().stream().filter(d -> typeId.equals(d.getTypeId())).collect(Collectors.toMap(SnomedDescription::getId, SnomedDescription::getTerm));
                        addCells(dataRow, occurrences, includeDescriptionId, termsById);
                        break;
                    }
                case RELATIONSHIP:
                    {
                        final ComponentIdSnomedDsvExportItem relationshipItem = (ComponentIdSnomedDsvExportItem) exportItem;
                        for (Integer propertyGroup : propertyCountByGroup.keySet()) {
                            final String typeId = relationshipItem.getComponentId();
                            final Map<String, Integer> groupOccurrences = propertyCountByGroup.getOrDefault(propertyGroup, NO_OCCURRENCES);
                            final int occurrences = groupOccurrences.getOrDefault(typeId, 0);
                            concept.getRelationships().stream().filter(r -> typeId.equals(r.getTypeId()) && Objects.equals(r.getRelationshipGroup(), propertyGroup) && (Concepts.INFERRED_RELATIONSHIP.equals(r.getCharacteristicTypeId()) || Concepts.ADDITIONAL_RELATIONSHIP.equals(r.getCharacteristicTypeId()))).forEach(relationship -> {
                                if (relationship.hasValue()) {
                                    addCells(dataRow, occurrences, includeRelationshipId, ImmutableMap.of(relationship.getValue(), ""));
                                } else {
                                    addCells(dataRow, occurrences, includeRelationshipId, ImmutableMap.of(relationship.getDestinationId(), getPreferredTerm(relationship.getDestination())));
                                }
                            });
                        }
                        break;
                    }
                case DATAYPE:
                    {
                        final DatatypeSnomedDsvExportItem datatypeItem = (DatatypeSnomedDsvExportItem) exportItem;
                        for (Integer propertyGroup : propertyCountByGroup.keySet()) {
                            Map<String, Integer> groupedOccurrences = propertyCountByGroup.getOrDefault(propertyGroup, NO_OCCURRENCES);
                            final String typeId = datatypeItem.getComponentId();
                            int occurrences = groupedOccurrences.getOrDefault(typeId, 0);
                            if (occurrences < 1) {
                                break;
                            }
                            final List<String> properties = concept.getMembers().stream().filter(m -> SnomedRefSetType.CONCRETE_DATA_TYPE.equals(m.type()) && m.isActive() && typeId.equals(m.getProperties().get(SnomedRf2Headers.FIELD_TYPE_ID)) && Objects.equals(m.getProperties().get(SnomedRf2Headers.FIELD_RELATIONSHIP_GROUP), propertyGroup) && (Concepts.INFERRED_RELATIONSHIP.equals(m.getProperties().get(SnomedRf2Headers.FIELD_CHARACTERISTIC_TYPE_ID)) || Concepts.ADDITIONAL_RELATIONSHIP.equals(m.getProperties().get(SnomedRf2Headers.FIELD_CHARACTERISTIC_TYPE_ID)))).map(m -> m.getProperties().get(SnomedRf2Headers.FIELD_VALUE)).map(p -> {
                                if (datatypeItem.isBooleanDatatype()) {
                                    return "1".equals(p) ? "Yes" : "No";
                                } else {
                                    return p.toString();
                                }
                            }).sorted().collect(Collectors.toList());
                            for (String value : properties) {
                                dataRow.add(value);
                                occurrences--;
                            }
                            while (occurrences > 0) {
                                dataRow.add("");
                                occurrences--;
                            }
                        }
                        break;
                    }
                case PREFERRED_TERM:
                    if (includeDescriptionId) {
                        dataRow.add(getPreferredTermId(concept));
                        dataRow.add(getPreferredTerm(concept));
                    } else {
                        dataRow.add(getPreferredTerm(concept));
                    }
                    break;
                case CONCEPT_ID:
                    dataRow.add(concept.getId());
                    break;
                case MODULE:
                    dataRow.add(concept.getModuleId());
                    break;
                case EFFECTIVE_TIME:
                    dataRow.add(EffectiveTimes.format(concept.getEffectiveTime()));
                    break;
                case STATUS_LABEL:
                    dataRow.add(concept.isActive() ? "Active" : "Inactive");
                    break;
                case DEFINITION_STATUS:
                    dataRow.add(concept.getDefinitionStatusId());
                    break;
                default:
                    break;
            }
        }
        writer.write(joiner.join(dataRow));
        writer.write(lineSeparator);
    }
}
Also used : EffectiveTimes(com.b2international.snowowl.core.date.EffectiveTimes) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) java.util(java.util) SnomedConceptSearchRequestBuilder(com.b2international.snowowl.snomed.datastore.request.SnomedConceptSearchRequestBuilder) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) ExtendedLocale(com.b2international.commons.http.ExtendedLocale) SnomedRequests(com.b2international.snowowl.snomed.datastore.request.SnomedRequests) ComponentIdSnomedDsvExportItem(com.b2international.snowowl.snomed.datastore.internal.rf2.ComponentIdSnomedDsvExportItem) SnomedConceptDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument) Path(java.nio.file.Path) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Charsets(com.google.common.base.Charsets) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Files(java.nio.file.Files) ImmutableMap(com.google.common.collect.ImmutableMap) Optional.ofNullable(java.util.Optional.ofNullable) BufferedWriter(java.io.BufferedWriter) Dates(com.b2international.snowowl.core.date.Dates) SnomedConcepts(com.b2international.snowowl.snomed.core.domain.SnomedConcepts) AbstractSnomedDsvExportItem(com.b2international.snowowl.snomed.datastore.internal.rf2.AbstractSnomedDsvExportItem) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SnomedRelationship(com.b2international.snowowl.snomed.core.domain.SnomedRelationship) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) SnomedRefSetDSVExportModel(com.b2international.snowowl.snomed.datastore.internal.rf2.SnomedRefSetDSVExportModel) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) DatatypeSnomedDsvExportItem(com.b2international.snowowl.snomed.datastore.internal.rf2.DatatypeSnomedDsvExportItem) Ordering(com.google.common.collect.Ordering) Sort(com.b2international.snowowl.core.request.SearchResourceRequest.Sort) SearchResourceRequestIterator(com.b2international.snowowl.core.request.SearchResourceRequestIterator) SnomedRf2Headers(com.b2international.snowowl.snomed.common.SnomedRf2Headers) BranchContext(com.b2international.snowowl.core.domain.BranchContext) SnomedRefSetType(com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType) Joiner(com.google.common.base.Joiner) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) ImmutableMap(com.google.common.collect.ImmutableMap) AbstractSnomedDsvExportItem(com.b2international.snowowl.snomed.datastore.internal.rf2.AbstractSnomedDsvExportItem) DatatypeSnomedDsvExportItem(com.b2international.snowowl.snomed.datastore.internal.rf2.DatatypeSnomedDsvExportItem) ComponentIdSnomedDsvExportItem(com.b2international.snowowl.snomed.datastore.internal.rf2.ComponentIdSnomedDsvExportItem)

Example 22 with SnomedDescription

use of com.b2international.snowowl.snomed.core.domain.SnomedDescription in project snow-owl by b2ihealthcare.

the class SnomedDescriptionApiTest method updateInactivationIndicatorOnActiveReleasedDescription.

@Test
public void updateInactivationIndicatorOnActiveReleasedDescription() throws Exception {
    String descriptionToInactivate = createNewDescription(branchPath);
    assertInactivation(branchPath, descriptionToInactivate, new InactivationProperties(Concepts.PENDING_MOVE, Collections.emptyList()));
    // release component
    createCodeSystemAndVersion(branchPath, "SNOMEDCT-RELDESC-INACTIVATIONINDICATOR", "v1", LocalDate.parse("2018-07-01"));
    SnomedDescription description = assertInactivation(branchPath, descriptionToInactivate, new InactivationProperties(Concepts.CONCEPT_NON_CURRENT, Collections.emptyList())).extract().as(SnomedDescription.class);
    List<SnomedReferenceSetMember> inactivationIndicators = description.getMembers().stream().filter(member -> Concepts.REFSET_DESCRIPTION_INACTIVITY_INDICATOR.equals(member.getRefsetId())).collect(Collectors.toList());
    final SnomedReferenceSetMember inactivationIndicator = Iterables.getOnlyElement(inactivationIndicators);
    assertEquals(Concepts.CONCEPT_NON_CURRENT, inactivationIndicator.getProperties().get(SnomedRf2Headers.FIELD_VALUE_ID));
    assertNull(inactivationIndicator.getEffectiveTime());
}
Also used : SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) CoreMatchers(org.hamcrest.CoreMatchers) RestExtensions.assertCreated(com.b2international.snowowl.test.commons.rest.RestExtensions.assertCreated) SnomedRefSetMemberIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry) Json(com.b2international.commons.json.Json) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SnomedRestFixtures(com.b2international.snowowl.snomed.core.rest.SnomedRestFixtures) SnomedComponentType(com.b2international.snowowl.snomed.core.rest.SnomedComponentType) IdentifierStatus(com.b2international.snowowl.snomed.cis.domain.IdentifierStatus) ApplicationContext.getServiceForClass(com.b2international.snowowl.core.ApplicationContext.getServiceForClass) Map(java.util.Map) RevisionIndex(com.b2international.index.revision.RevisionIndex) RepositoryRequest(com.b2international.snowowl.core.request.RepositoryRequest) ISnomedIdentifierService(com.b2international.snowowl.snomed.cis.ISnomedIdentifierService) ConflictException(com.b2international.commons.exceptions.ConflictException) BulkRequestBuilder(com.b2international.snowowl.core.events.bulk.BulkRequestBuilder) RepositoryManager(com.b2international.snowowl.core.RepositoryManager) ContentType(io.restassured.http.ContentType) TimestampProvider(com.b2international.index.revision.TimestampProvider) InactivationProperties(com.b2international.snowowl.snomed.core.domain.InactivationProperties) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) LocalDate(java.time.LocalDate) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest) SnomedComponentRestRequests(com.b2international.snowowl.snomed.core.rest.SnomedComponentRestRequests) CodeSystemVersionRestRequests.getNextAvailableEffectiveDate(com.b2international.snowowl.test.commons.codesystem.CodeSystemVersionRestRequests.getNextAvailableEffectiveDate) Acceptability(com.b2international.snowowl.snomed.core.domain.Acceptability) Iterables(com.google.common.collect.Iterables) CodeSystemVersionRestRequests.createVersion(com.b2international.snowowl.test.commons.codesystem.CodeSystemVersionRestRequests.createVersion) SnomedRefSetRestRequests.updateRefSetComponent(com.b2international.snowowl.snomed.core.rest.SnomedRefSetRestRequests.updateRefSetComponent) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) ModuleIdProvider(com.b2international.snowowl.snomed.datastore.request.ModuleRequest.ModuleIdProvider) AssociationTarget(com.b2international.snowowl.snomed.core.domain.AssociationTarget) TermFilter(com.b2international.snowowl.core.request.TermFilter) Environment(com.b2international.snowowl.core.setup.Environment) SnomedRequests(com.b2international.snowowl.snomed.datastore.request.SnomedRequests) CodeSystemVersionRestRequests.createCodeSystemAndVersion(com.b2international.snowowl.test.commons.codesystem.CodeSystemVersionRestRequests.createCodeSystemAndVersion) BulkRequest(com.b2international.snowowl.core.events.bulk.BulkRequest) RestExtensions.givenAuthenticatedRequest(com.b2international.snowowl.test.commons.rest.RestExtensions.givenAuthenticatedRequest) SctId(com.b2international.snowowl.snomed.cis.domain.SctId) SnomedReferenceSetMembers(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers) BranchPathUtils(com.b2international.snowowl.core.branch.BranchPathUtils) SnomedApiTestConstants(com.b2international.snowowl.snomed.core.rest.SnomedApiTestConstants) SnomedRefSetRestRequests.bulkUpdateMembers(com.b2international.snowowl.snomed.core.rest.SnomedRefSetRestRequests.bulkUpdateMembers) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) SnomedTerminologyComponentConstants(com.b2international.snowowl.snomed.common.SnomedTerminologyComponentConstants) TextConstants(com.b2international.index.compat.TextConstants) CodeSystemRestRequests.createCodeSystem(com.b2international.snowowl.test.commons.codesystem.CodeSystemRestRequests.createCodeSystem) TimeUnit(java.util.concurrent.TimeUnit) Assert.assertNull(org.junit.Assert.assertNull) TransactionContext(com.b2international.snowowl.core.domain.TransactionContext) SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) DateTimeFormatter(java.time.format.DateTimeFormatter) SnomedRf2Headers(com.b2international.snowowl.snomed.common.SnomedRf2Headers) Collections(java.util.Collections) IBranchPath(com.b2international.snowowl.core.api.IBranchPath) Assert.assertEquals(org.junit.Assert.assertEquals) ApplicationContext(com.b2international.snowowl.core.ApplicationContext) ComponentCategory(com.b2international.snowowl.core.terminology.ComponentCategory) SnomedRefSetType(com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType) InactivationProperties(com.b2international.snowowl.snomed.core.domain.InactivationProperties) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest) Test(org.junit.Test)

Example 23 with SnomedDescription

use of com.b2international.snowowl.snomed.core.domain.SnomedDescription in project snow-owl by b2ihealthcare.

the class SnomedDescriptionApiTest method testDuplicateMemberCleanupEmptiesAcceptabilityMap.

@Test
public void testDuplicateMemberCleanupEmptiesAcceptabilityMap() throws Exception {
    String descriptionId = createNewDescription(branchPath);
    // Inject inactive language member with different acceptability (API won't allow it)
    String memberIdToUpdate = UUID.randomUUID().toString();
    SnomedRefSetMemberIndexEntry member = SnomedRefSetMemberIndexEntry.builder().id(memberIdToUpdate).active(false).released(false).moduleId(Concepts.MODULE_SCT_CORE).refsetId(Concepts.REFSET_LANGUAGE_TYPE_UK).referencedComponentId(descriptionId).referenceSetType(SnomedRefSetType.LANGUAGE).field(SnomedRf2Headers.FIELD_ACCEPTABILITY_ID, Concepts.REFSET_DESCRIPTION_ACCEPTABILITY_PREFERRED).build();
    new RepositoryRequest<>(SnomedTerminologyComponentConstants.TOOLING_ID, context -> {
        ApplicationContext.getServiceForClass(RepositoryManager.class).get(SnomedTerminologyComponentConstants.TOOLING_ID).service(RevisionIndex.class).prepareCommit(branchPath.getPath()).stageNew(member).withContext(context.inject().bind(ModuleIdProvider.class, c -> c.getModuleId()).build()).commit(ApplicationContext.getServiceForClass(TimestampProvider.class).getTimestamp(), "test", "Added duplicate language reference set member to " + descriptionId);
        return null;
    }).execute(ApplicationContext.getServiceForClass(Environment.class));
    // Check the acceptability map; the description should be acceptable in the UK reference set
    SnomedDescription description = getComponent(branchPath, SnomedComponentType.DESCRIPTION, descriptionId, "members()").statusCode(200).extract().as(SnomedDescription.class);
    assertEquals(Acceptability.ACCEPTABLE, description.getAcceptabilityMap().get(Concepts.REFSET_LANGUAGE_TYPE_UK));
    assertEquals(2, description.getMembers().getTotal());
    String memberIdToDelete = null;
    for (SnomedReferenceSetMember descriptionMember : description.getMembers()) {
        if (Concepts.REFSET_DESCRIPTION_ACCEPTABILITY_ACCEPTABLE.equals(descriptionMember.getProperties().get(SnomedRf2Headers.FIELD_ACCEPTABILITY_ID))) {
            memberIdToDelete = descriptionMember.getId();
            break;
        }
    }
    assertNotNull(memberIdToDelete);
    // Using bulk update, remove the currently active member and activate the inactive one, also changing its acceptability
    Json bulkRequest = Json.object("requests", Json.array(Json.object("action", "delete", "memberId", memberIdToDelete), Json.object("action", "update", "memberId", memberIdToUpdate, "active", true, "acceptabilityId", Concepts.REFSET_DESCRIPTION_ACCEPTABILITY_ACCEPTABLE)), "commitComment", "Consolidated language reference set members");
    bulkUpdateMembers(branchPath, Concepts.REFSET_LANGUAGE_TYPE_UK, bulkRequest).statusCode(204);
    // Verify that description acceptability is still acceptable, but only one member remains
    SnomedDescription newDescription = getComponent(branchPath, SnomedComponentType.DESCRIPTION, descriptionId, "members()").statusCode(200).extract().as(SnomedDescription.class);
    assertEquals(Acceptability.ACCEPTABLE, newDescription.getAcceptabilityMap().get(Concepts.REFSET_LANGUAGE_TYPE_UK));
    assertEquals(1, newDescription.getMembers().getTotal());
    SnomedReferenceSetMember languageMember = Iterables.getOnlyElement(newDescription.getMembers());
    assertEquals(memberIdToUpdate, languageMember.getId());
    assertEquals(true, languageMember.isActive());
}
Also used : SnomedRefSetMemberIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry) CoreMatchers(org.hamcrest.CoreMatchers) RestExtensions.assertCreated(com.b2international.snowowl.test.commons.rest.RestExtensions.assertCreated) SnomedRefSetMemberIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry) Json(com.b2international.commons.json.Json) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SnomedRestFixtures(com.b2international.snowowl.snomed.core.rest.SnomedRestFixtures) SnomedComponentType(com.b2international.snowowl.snomed.core.rest.SnomedComponentType) IdentifierStatus(com.b2international.snowowl.snomed.cis.domain.IdentifierStatus) ApplicationContext.getServiceForClass(com.b2international.snowowl.core.ApplicationContext.getServiceForClass) Map(java.util.Map) RevisionIndex(com.b2international.index.revision.RevisionIndex) RepositoryRequest(com.b2international.snowowl.core.request.RepositoryRequest) ISnomedIdentifierService(com.b2international.snowowl.snomed.cis.ISnomedIdentifierService) ConflictException(com.b2international.commons.exceptions.ConflictException) BulkRequestBuilder(com.b2international.snowowl.core.events.bulk.BulkRequestBuilder) RepositoryManager(com.b2international.snowowl.core.RepositoryManager) ContentType(io.restassured.http.ContentType) TimestampProvider(com.b2international.index.revision.TimestampProvider) InactivationProperties(com.b2international.snowowl.snomed.core.domain.InactivationProperties) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) LocalDate(java.time.LocalDate) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest) SnomedComponentRestRequests(com.b2international.snowowl.snomed.core.rest.SnomedComponentRestRequests) CodeSystemVersionRestRequests.getNextAvailableEffectiveDate(com.b2international.snowowl.test.commons.codesystem.CodeSystemVersionRestRequests.getNextAvailableEffectiveDate) Acceptability(com.b2international.snowowl.snomed.core.domain.Acceptability) Iterables(com.google.common.collect.Iterables) CodeSystemVersionRestRequests.createVersion(com.b2international.snowowl.test.commons.codesystem.CodeSystemVersionRestRequests.createVersion) SnomedRefSetRestRequests.updateRefSetComponent(com.b2international.snowowl.snomed.core.rest.SnomedRefSetRestRequests.updateRefSetComponent) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) ModuleIdProvider(com.b2international.snowowl.snomed.datastore.request.ModuleRequest.ModuleIdProvider) AssociationTarget(com.b2international.snowowl.snomed.core.domain.AssociationTarget) TermFilter(com.b2international.snowowl.core.request.TermFilter) Environment(com.b2international.snowowl.core.setup.Environment) SnomedRequests(com.b2international.snowowl.snomed.datastore.request.SnomedRequests) CodeSystemVersionRestRequests.createCodeSystemAndVersion(com.b2international.snowowl.test.commons.codesystem.CodeSystemVersionRestRequests.createCodeSystemAndVersion) BulkRequest(com.b2international.snowowl.core.events.bulk.BulkRequest) RestExtensions.givenAuthenticatedRequest(com.b2international.snowowl.test.commons.rest.RestExtensions.givenAuthenticatedRequest) SctId(com.b2international.snowowl.snomed.cis.domain.SctId) SnomedReferenceSetMembers(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers) BranchPathUtils(com.b2international.snowowl.core.branch.BranchPathUtils) SnomedApiTestConstants(com.b2international.snowowl.snomed.core.rest.SnomedApiTestConstants) SnomedRefSetRestRequests.bulkUpdateMembers(com.b2international.snowowl.snomed.core.rest.SnomedRefSetRestRequests.bulkUpdateMembers) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) SnomedTerminologyComponentConstants(com.b2international.snowowl.snomed.common.SnomedTerminologyComponentConstants) TextConstants(com.b2international.index.compat.TextConstants) CodeSystemRestRequests.createCodeSystem(com.b2international.snowowl.test.commons.codesystem.CodeSystemRestRequests.createCodeSystem) TimeUnit(java.util.concurrent.TimeUnit) Assert.assertNull(org.junit.Assert.assertNull) TransactionContext(com.b2international.snowowl.core.domain.TransactionContext) SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) DateTimeFormatter(java.time.format.DateTimeFormatter) SnomedRf2Headers(com.b2international.snowowl.snomed.common.SnomedRf2Headers) Collections(java.util.Collections) IBranchPath(com.b2international.snowowl.core.api.IBranchPath) Assert.assertEquals(org.junit.Assert.assertEquals) ApplicationContext(com.b2international.snowowl.core.ApplicationContext) ComponentCategory(com.b2international.snowowl.core.terminology.ComponentCategory) SnomedRefSetType(com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType) SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) TimestampProvider(com.b2international.index.revision.TimestampProvider) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) RevisionIndex(com.b2international.index.revision.RevisionIndex) Environment(com.b2international.snowowl.core.setup.Environment) RepositoryManager(com.b2international.snowowl.core.RepositoryManager) Json(com.b2international.commons.json.Json) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest) Test(org.junit.Test)

Example 24 with SnomedDescription

use of com.b2international.snowowl.snomed.core.domain.SnomedDescription in project snow-owl by b2ihealthcare.

the class SnomedDescriptionConverter method toResource.

@Override
protected SnomedDescription toResource(final SnomedDescriptionIndexEntry input) {
    final SnomedDescription result = new SnomedDescription();
    result.setAcceptabilityMap(input.getAcceptabilityMap());
    result.setActive(input.isActive());
    result.setCaseSignificanceId(input.getCaseSignificanceId());
    result.setConceptId(input.getConceptId());
    result.setEffectiveTime(toEffectiveTime(input.getEffectiveTime()));
    result.setId(input.getId());
    result.setLanguageCode(input.getLanguageCode());
    result.setModuleId(input.getModuleId());
    result.setIconId(input.getIconId());
    result.setReleased(input.isReleased());
    result.setTerm(input.getTerm());
    result.setSemanticTag(input.getSemanticTag());
    result.setTypeId(input.getTypeId());
    result.setType(new SnomedConcept(input.getTypeId()));
    result.setScore(input.getScore());
    if (input.getMemberOf() != null) {
        result.setMemberOf(ImmutableSortedSet.copyOf(input.getMemberOf()));
    }
    if (input.getActiveMemberOf() != null) {
        result.setActiveMemberOf(ImmutableSortedSet.copyOf(input.getActiveMemberOf()));
    }
    return result;
}
Also used : SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept)

Example 25 with SnomedDescription

use of com.b2international.snowowl.snomed.core.domain.SnomedDescription in project snow-owl by b2ihealthcare.

the class SnomedDescriptionConverter method expandAcceptabilities.

private void expandAcceptabilities(List<SnomedDescription> results) {
    if (!expand().containsKey("acceptabilities")) {
        return;
    }
    // expand the acceptability objects first
    for (SnomedDescription result : results) {
        if (!CompareUtils.isEmpty(result.getAcceptabilityMap())) {
            List<AcceptabilityMembership> acceptabilities = result.getAcceptabilityMap().entrySet().stream().map(entry -> new AcceptabilityMembership(entry.getKey(), entry.getValue().getConceptId())).sorted().collect(Collectors.toList());
            result.setAcceptabilities(acceptabilities);
        } else {
            result.setAcceptabilities(Collections.emptyList());
        }
    }
    // additional expansions supported inside the acceptabilities() expand
    final Options expandOptions = expand().get("acceptabilities", Options.class).getOptions("expand");
    if (expandOptions.containsKey("acceptability")) {
        final Options acceptabilityExpand = expandOptions.get("acceptability", Options.class);
        final Iterable<String> acceptabilityIds = results.stream().flatMap(d -> d.getAcceptabilities().stream().map(AcceptabilityMembership::getAcceptabilityId))::iterator;
        context().service(SnomedConceptRequestCache.class).request(acceptabilityIds, acceptabilityExpand.getOptions("expand"), locales(), acceptabilitiesById -> {
            for (SnomedDescription result : results) {
                result.getAcceptabilities().forEach(acceptabilityMembership -> {
                    acceptabilityMembership.setAcceptability(acceptabilitiesById.get(acceptabilityMembership.getAcceptabilityId()));
                });
            }
        });
    }
    if (expandOptions.containsKey("languageRefSet")) {
        final Options languageRefSetExpand = expandOptions.get("languageRefSet", Options.class);
        final Iterable<String> languageRefSetIds = results.stream().flatMap(d -> d.getAcceptabilities().stream().map(AcceptabilityMembership::getLanguageRefSetId))::iterator;
        context().service(SnomedConceptRequestCache.class).request(languageRefSetIds, languageRefSetExpand.getOptions("expand"), locales(), languageRefSetsById -> {
            for (SnomedDescription result : results) {
                result.getAcceptabilities().forEach(acceptabilityMembership -> {
                    acceptabilityMembership.setLanguageRefSet(languageRefSetsById.get(acceptabilityMembership.getLanguageRefSetId()));
                });
            }
        });
    }
}
Also used : SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) AcceptabilityMembership(com.b2international.snowowl.snomed.core.domain.AcceptabilityMembership) Set(java.util.Set) Collectors(java.util.stream.Collectors) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) BaseRevisionResourceConverter(com.b2international.snowowl.core.request.BaseRevisionResourceConverter) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) List(java.util.List) ExtendedLocale(com.b2international.commons.http.ExtendedLocale) Options(com.b2international.commons.options.Options) FluentIterable(com.google.common.collect.FluentIterable) SnomedDescriptions(com.b2international.snowowl.snomed.core.domain.SnomedDescriptions) SnomedDescriptionIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionIndexEntry) CompareUtils(com.b2international.commons.CompareUtils) BranchContext(com.b2international.snowowl.core.domain.BranchContext) Collections(java.util.Collections) SnomedConceptRequestCache(com.b2international.snowowl.snomed.datastore.request.SnomedConceptRequestCache) Options(com.b2international.commons.options.Options) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) AcceptabilityMembership(com.b2international.snowowl.snomed.core.domain.AcceptabilityMembership) SnomedConceptRequestCache(com.b2international.snowowl.snomed.datastore.request.SnomedConceptRequestCache)

Aggregations

SnomedDescription (com.b2international.snowowl.snomed.core.domain.SnomedDescription)25 SnomedConcept (com.b2international.snowowl.snomed.core.domain.SnomedConcept)14 Test (org.junit.Test)8 Json (com.b2international.commons.json.Json)7 SnomedReferenceSetMember (com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember)6 LocalDate (java.time.LocalDate)6 ExtendedLocale (com.b2international.commons.http.ExtendedLocale)5 Options (com.b2international.commons.options.Options)4 CodeSystem (com.b2international.snowowl.core.codesystem.CodeSystem)4 Concepts (com.b2international.snowowl.snomed.common.SnomedConstants.Concepts)4 SnomedRelationship (com.b2international.snowowl.snomed.core.domain.SnomedRelationship)4 SnomedRequests (com.b2international.snowowl.snomed.datastore.request.SnomedRequests)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 IBranchPath (com.b2international.snowowl.core.api.IBranchPath)3 BranchContext (com.b2international.snowowl.core.domain.BranchContext)3 SnomedRf2Headers (com.b2international.snowowl.snomed.common.SnomedRf2Headers)3 InactivationProperties (com.b2international.snowowl.snomed.core.domain.InactivationProperties)3 SnomedRefSetType (com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType)3 SnomedConceptRequestCache (com.b2international.snowowl.snomed.datastore.request.SnomedConceptRequestCache)3