Search in sources :

Example 6 with SnomedReferenceSetMembers

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

the class MapTypeRefSetDSVExporter method executeDSVExport.

@Override
public File executeDSVExport(IProgressMonitor monitor) throws IOException {
    final int memberNumberToSignal = 100;
    final SnomedConcept refSetToExport = SnomedRequests.prepareGetConcept(exportSetting.getRefSetId()).setLocales(exportSetting.getLocales()).setExpand("referenceSet(expand(members(limit:" + Integer.MAX_VALUE + ", expand(referencedComponent(expand(fsn()))))))").build().execute(context);
    final SnomedReferenceSetMembers membersToExport = refSetToExport.getReferenceSet().getMembers();
    final int activeMemberCount = membersToExport.getTotal();
    if (activeMemberCount < memberNumberToSignal) {
        monitor.beginTask("Exporting RefSet to DSV", 1);
    } else {
        monitor.beginTask("Exporting RefSet to DSV", activeMemberCount / memberNumberToSignal);
    }
    final File file = Files.createTempFile("dsv-export-" + refSetToExport.getId() + Dates.now(), ".csv").toFile();
    try (DataOutputStream os = new DataOutputStream(new FileOutputStream(file))) {
        if (exportSetting.getExportItems().isEmpty()) {
            return file;
        }
        writeLine(os, toHeader());
        Map<String, String> labels = prepareLabelCache(membersToExport);
        int count = 0;
        for (final SnomedReferenceSetMember member : membersToExport) {
            writeLine(os, toDsvLine(member, labels));
            count++;
            if (count % memberNumberToSignal == 0) {
                monitor.worked(1);
            }
        }
    } catch (final Exception e) {
        throw new SnowowlRuntimeException(e);
    } finally {
        if (null != monitor) {
            monitor.done();
        }
    }
    return file;
}
Also used : SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) DataOutputStream(java.io.DataOutputStream) FileOutputStream(java.io.FileOutputStream) SnomedReferenceSetMembers(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) File(java.io.File) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException) IOException(java.io.IOException) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException)

Example 7 with SnomedReferenceSetMembers

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

the class SnomedExportApiTest method exportLangRefset_acceptabilityChangesOnly.

@Test
public void exportLangRefset_acceptabilityChangesOnly() throws Exception {
    final String codeSystemShortName = "SNOMEDCT-EXPORT-UNPUBLISHED-LANG-REFSET-MEMBERS";
    createCodeSystem(branchPath, codeSystemShortName).statusCode(201);
    // create new concept
    final String conceptId = createNewConcept(branchPath);
    Map<String, Acceptability> acceptabilityMap = ImmutableMap.<String, Acceptability>builder().put(Concepts.REFSET_LANGUAGE_TYPE_UK, Acceptability.PREFERRED).put(Concepts.REFSET_LANGUAGE_TYPE_US, Acceptability.ACCEPTABLE).build();
    final String descriptionId = createNewDescription(branchPath, conceptId, Concepts.SYNONYM, acceptabilityMap, "en");
    // version new concept
    final String versionEffectiveTime = "20170801";
    createVersion(codeSystemShortName, "v1", EffectiveTimes.parse(versionEffectiveTime, DateFormats.SHORT)).statusCode(201);
    SnomedReferenceSetMembers versionedMembers = getComponent(branchPath, SnomedComponentType.DESCRIPTION, descriptionId, "members()").statusCode(200).extract().as(SnomedDescription.class).getMembers();
    assertEquals(2, versionedMembers.getTotal());
    versionedMembers.forEach(m -> assertEquals(EffectiveTimes.parse(versionEffectiveTime, DateFormats.SHORT), m.getEffectiveTime()));
    Map<String, Acceptability> updatedAcceptabilityMap = ImmutableMap.<String, Acceptability>builder().put(Concepts.REFSET_LANGUAGE_TYPE_UK, Acceptability.ACCEPTABLE).put(Concepts.REFSET_LANGUAGE_TYPE_US, Acceptability.PREFERRED).build();
    Map<?, ?> requestBody = ImmutableMap.builder().put("acceptability", updatedAcceptabilityMap).put("commitComment", "Updated description acceptability").build();
    updateComponent(branchPath, SnomedComponentType.DESCRIPTION, descriptionId, requestBody).statusCode(204);
    SnomedReferenceSetMembers unpublishedMembers = getComponent(branchPath, SnomedComponentType.DESCRIPTION, descriptionId, "members()").statusCode(200).extract().as(SnomedDescription.class).getMembers();
    assertEquals(2, unpublishedMembers.getTotal());
    unpublishedMembers.forEach(m -> assertNull(m.getEffectiveTime()));
    // do not create new version
    final Map<String, Object> config = ImmutableMap.<String, Object>builder().put("type", Rf2ReleaseType.DELTA.name()).put("includeUnpublished", true).build();
    final File exportArchive = doExport(branchPath, config);
    String englishDescriptionLine = createDescriptionLine(descriptionId, versionEffectiveTime, conceptId, "en", Concepts.SYNONYM, DEFAULT_TERM);
    String ukMember = createLanguageRefsetMemberLine(branchPath, descriptionId, "", Concepts.REFSET_LANGUAGE_TYPE_UK, Acceptability.ACCEPTABLE.getConceptId());
    String usMember = createLanguageRefsetMemberLine(branchPath, descriptionId, "", Concepts.REFSET_LANGUAGE_TYPE_US, Acceptability.PREFERRED.getConceptId());
    final Multimap<String, Pair<Boolean, String>> fileToLinesMap = ArrayListMultimap.<String, Pair<Boolean, String>>create();
    fileToLinesMap.put("sct2_Description_Delta-en", Pair.of(false, englishDescriptionLine));
    fileToLinesMap.put("der2_cRefset_LanguageDelta-en", Pair.of(true, ukMember));
    fileToLinesMap.put("der2_cRefset_LanguageDelta-en", Pair.of(true, usMember));
    assertArchiveContainsLines(exportArchive, fileToLinesMap);
}
Also used : SnomedReferenceSetMembers(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers) File(java.io.File) Pair(com.b2international.commons.Pair) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest) Test(org.junit.Test)

Example 8 with SnomedReferenceSetMembers

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

the class ValueSetMemberSearchSnomedReferenceSetTest method filterByComponentIdAndUri.

@Test
public void filterByComponentIdAndUri() {
    final String filteredId = Concepts.FINDING_SITE;
    final String refSetId = createSimpleMapTypeRefSet();
    createSimpleMapTypeRefSetMember(refSetId, filteredId, Concepts.IS_A);
    createSimpleMapTypeRefSetMember(refSetId, filteredId, Concepts.IS_A);
    createSimpleMapTypeRefSetMember(refSetId, Concepts.IS_A, filteredId);
    createSimpleMapTypeRefSetMember(refSetId, Concepts.IS_A, Concepts.IS_A);
    final ComponentURI uri = ComponentURI.of(SnomedContentRule.SNOMEDCT, SnomedConcept.TYPE, filteredId);
    final SnomedReferenceSetMembers refSetMembers = SnomedRequests.prepareSearchMember().filterByRefSet(refSetId).filterByComponentIds(Set.of(uri.toString(), uri.identifier())).build(CODESYSTEM).execute(Services.bus()).getSync(1, TimeUnit.MINUTES);
    assertEquals(3, refSetMembers.getTotal());
    refSetMembers.forEach(refSetMember -> assertTrue(filteredId.equals(refSetMember.getReferencedComponentId()) || filteredId.equals(refSetMember.getProperties().get(SnomedRf2Headers.FIELD_MAP_TARGET))));
}
Also used : ComponentURI(com.b2international.snowowl.core.uri.ComponentURI) SnomedReferenceSetMembers(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers) Test(org.junit.Test)

Example 9 with SnomedReferenceSetMembers

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

the class ValueSetMemberSearchSnomedReferenceSetTest method filterByRefsetUri.

@Test
public void filterByRefsetUri() throws Exception {
    SnomedReferenceSetMembers members = SnomedRequests.prepareSearchMember().all().filterByRefSet(Concepts.REFSET_DESCRIPTION_TYPE).build(CODESYSTEM).execute(Services.bus()).getSync(1, TimeUnit.MINUTES);
    ValueSetMembers setMembers = CodeSystemRequests.prepareSearchMembers().all().filterByValueSet(ComponentURI.of(CODESYSTEM, SnomedConcept.REFSET_TYPE, Concepts.REFSET_DESCRIPTION_TYPE).toString()).buildAsync().execute(Services.bus()).getSync(1, TimeUnit.MINUTES);
    assertThat(setMembers.getTotal()).isEqualTo(members.getTotal());
    assertThat(setMembers.stream().allMatch(m -> SnomedContentRule.SNOMEDCT.equals(m.getReferencedComponentURI().resourceUri())));
    Set<String> setMemberSourceCodes = FluentIterable.from(setMembers).transform(m -> m.getReferencedComponentURI().identifier()).toSet();
    Set<String> setMemberSourceTerms = FluentIterable.from(setMembers).transform(m -> m.getReferencedComponentURI().identifier()).toSet();
    assertThat(setMemberSourceCodes.contains(Concepts.TEXT_DEFINITION));
    assertThat(setMemberSourceCodes.contains(Concepts.FULLY_SPECIFIED_NAME));
    assertThat(setMemberSourceCodes.contains(Concepts.SYNONYM));
    assertThat(setMemberSourceTerms.contains(DEFINITION));
    assertThat(setMemberSourceTerms.contains(FSN));
    assertThat(setMemberSourceTerms.contains(SYNONYM));
}
Also used : SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) Acceptability(com.b2international.snowowl.snomed.core.domain.Acceptability) RestExtensions(com.b2international.snowowl.test.commons.rest.RestExtensions) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SnomedRefSetUtil(com.b2international.snowowl.snomed.datastore.SnomedRefSetUtil) ValueSetMembers(com.b2international.snowowl.core.domain.ValueSetMembers) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) SnomedContentRule(com.b2international.snowowl.test.commons.SnomedContentRule) SnomedRelationshipCreateRequestBuilder(com.b2international.snowowl.snomed.datastore.request.SnomedRelationshipCreateRequestBuilder) SnomedRequests(com.b2international.snowowl.snomed.datastore.request.SnomedRequests) FluentIterable(com.google.common.collect.FluentIterable) Map(java.util.Map) SnomedDescriptionCreateRequestBuilder(com.b2international.snowowl.snomed.datastore.request.SnomedDescriptionCreateRequestBuilder) ResourceURI(com.b2international.snowowl.core.ResourceURI) SnomedReferenceSetMembers(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) ComponentURI(com.b2international.snowowl.core.uri.ComponentURI) Test(org.junit.Test) UUID(java.util.UUID) TimeUnit(java.util.concurrent.TimeUnit) Services(com.b2international.snowowl.test.commons.Services) CodeSystemRequests(com.b2international.snowowl.core.codesystem.CodeSystemRequests) SnomedRf2Headers(com.b2international.snowowl.snomed.common.SnomedRf2Headers) SnomedConstants(com.b2international.snowowl.snomed.common.SnomedConstants) Assert.assertEquals(org.junit.Assert.assertEquals) SnomedRefSetType(com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType) SnomedReferenceSetMembers(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers) ValueSetMembers(com.b2international.snowowl.core.domain.ValueSetMembers) Test(org.junit.Test)

Example 10 with SnomedReferenceSetMembers

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

the class SnomedConceptMapSearchRequestEvaluator method toCollectionResource.

private ConceptMapMappings toCollectionResource(SnomedReferenceSetMembers referenceSetMembers, ResourceURI uri, ServiceProvider context, Options search, SnomedDisplayTermType snomedDisplayTermType) {
    final Set<String> refSetsToFetch = referenceSetMembers.stream().map(SnomedReferenceSetMember::getRefsetId).collect(Collectors.toSet());
    final Map<String, SnomedConcept> refSetsById = SnomedRequests.prepareSearchConcept().all().filterByIds(refSetsToFetch).setLocales(search.getList(OptionKey.LOCALES, ExtendedLocale.class)).setExpand("pt(),referenceSet()").build(uri).execute(context.service(IEventBus.class)).getSync(1, TimeUnit.MINUTES).stream().collect(Collectors.toMap(SnomedConcept::getId, concept -> concept));
    final Map<String, ComponentURI> targetComponentsByRefSetId = getTargetComponentsByRefSetId(context, refSetsById);
    List<ConceptMapMapping> mappings = referenceSetMembers.stream().filter(m -> SnomedConcept.TYPE.equals(m.getReferencedComponent().getComponentType())).map(m -> {
        return toMapping(m, uri, targetComponentsByRefSetId.get(m.getRefsetId()), snomedDisplayTermType, refSetsById);
    }).collect(Collectors.toList());
    if (!mappings.isEmpty()) {
        final Map<String, Concept> conceptsById = Multimaps.index(mappings, mapping -> mapping.getTargetComponentURI().resourceUri()).asMap().entrySet().stream().filter(entry -> !TerminologyRegistry.UNSPECIFIED.equals(entry.getKey().getResourceId())).map(entry -> {
            final Set<String> idsToFetch = entry.getValue().stream().map(map -> map.getTargetComponentURI().identifier()).collect(Collectors.toSet());
            return CodeSystemRequests.prepareSearchConcepts().all().filterByCodeSystemUri(entry.getKey()).filterByIds(idsToFetch).buildAsync().execute(context.service(IEventBus.class)).getSync(5, TimeUnit.MINUTES).stream().collect(Collectors.toMap(Concept::getId, c -> c));
        }).flatMap(map -> map.entrySet().stream()).collect(Collectors.toMap(entry -> entry.getKey(), entry -> entry.getValue(), (concept1, concept2) -> concept1));
        mappings = mappings.stream().map(mapping -> {
            final String mapTargetId = mapping.getTargetComponentURI().identifier();
            if (conceptsById.containsKey(mapTargetId) && !mapping.getTargetComponentURI().isUnspecified()) {
                final Concept concept = conceptsById.get(mapTargetId);
                return mapping.toBuilder().targetTerm(concept.getTerm()).targetIconId(concept.getIconId()).build();
            } else {
                return mapping;
            }
        }).collect(Collectors.toList());
    }
    return new ConceptMapMappings(mappings, referenceSetMembers.getSearchAfter(), referenceSetMembers.getLimit(), referenceSetMembers.getTotal());
}
Also used : CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) SnomedRefSetUtil(com.b2international.snowowl.snomed.datastore.SnomedRefSetUtil) ConceptMapMappingSearchRequestEvaluator(com.b2international.snowowl.core.request.ConceptMapMappingSearchRequestEvaluator) SnomedDisplayTermType(com.b2international.snowowl.snomed.core.SnomedDisplayTermType) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) Multimaps(com.google.common.collect.Multimaps) Strings(com.google.common.base.Strings) ExtendedLocale(com.b2international.commons.http.ExtendedLocale) Options(com.b2international.commons.options.Options) ConceptMapMappings(com.b2international.snowowl.core.domain.ConceptMapMappings) Map(java.util.Map) ResourceURI(com.b2international.snowowl.core.ResourceURI) SnomedReferenceSetMembers(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers) ConceptMapMapping(com.b2international.snowowl.core.domain.ConceptMapMapping) Collection(java.util.Collection) MappingCorrelation(com.b2international.snowowl.core.request.MappingCorrelation) Set(java.util.Set) ComponentURI(com.b2international.snowowl.core.uri.ComponentURI) Builder(com.b2international.snowowl.core.domain.ConceptMapMapping.Builder) IEventBus(com.b2international.snowowl.eventbus.IEventBus) Collectors(java.util.stream.Collectors) TerminologyRegistry(com.b2international.snowowl.core.terminology.TerminologyRegistry) TimeUnit(java.util.concurrent.TimeUnit) ResourceDocument(com.b2international.snowowl.core.internal.ResourceDocument) List(java.util.List) Concept(com.b2international.snowowl.core.domain.Concept) SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) ServiceProvider(com.b2international.snowowl.core.ServiceProvider) CodeSystemRequests(com.b2international.snowowl.core.codesystem.CodeSystemRequests) SnomedRf2Headers(com.b2international.snowowl.snomed.common.SnomedRf2Headers) SnomedReferenceSet(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSet) OptionsBuilder(com.b2international.commons.options.OptionsBuilder) SnomedRefSetType(com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) Concept(com.b2international.snowowl.core.domain.Concept) ConceptMapMapping(com.b2international.snowowl.core.domain.ConceptMapMapping) ComponentURI(com.b2international.snowowl.core.uri.ComponentURI) ExtendedLocale(com.b2international.commons.http.ExtendedLocale) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) ConceptMapMappings(com.b2international.snowowl.core.domain.ConceptMapMappings)

Aggregations

SnomedReferenceSetMembers (com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers)20 Test (org.junit.Test)14 AbstractSnomedApiTest (com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)10 Json (com.b2international.commons.json.Json)9 SnomedReferenceSetMember (com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember)9 SnomedConcept (com.b2international.snowowl.snomed.core.domain.SnomedConcept)5 SnomedDescription (com.b2international.snowowl.snomed.core.domain.SnomedDescription)5 Options (com.b2international.commons.options.Options)4 SnomedRf2Headers (com.b2international.snowowl.snomed.common.SnomedRf2Headers)4 ExtendedLocale (com.b2international.commons.http.ExtendedLocale)3 ComponentURI (com.b2international.snowowl.core.uri.ComponentURI)3 Concepts (com.b2international.snowowl.snomed.common.SnomedConstants.Concepts)3 SnomedRefSetType (com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType)3 OptionsBuilder (com.b2international.commons.options.OptionsBuilder)2 ResourceURI (com.b2international.snowowl.core.ResourceURI)2 CodeSystemRequests (com.b2international.snowowl.core.codesystem.CodeSystemRequests)2 BranchContext (com.b2international.snowowl.core.domain.BranchContext)2 SnomedDisplayTermType (com.b2international.snowowl.snomed.core.SnomedDisplayTermType)2 SnomedCoreComponent (com.b2international.snowowl.snomed.core.domain.SnomedCoreComponent)2 SnomedRefSetUtil (com.b2international.snowowl.snomed.datastore.SnomedRefSetUtil)2