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