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;
}
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);
}
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))));
}
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));
}
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());
}
Aggregations