Search in sources :

Example 1 with DatatypeSnomedDsvExportItem

use of com.b2international.snowowl.snomed.datastore.internal.rf2.DatatypeSnomedDsvExportItem in project snow-owl by b2ihealthcare.

the class SnomedRefSetDSVExportTest method transformToExportItems.

private List<AbstractSnomedDsvExportItem> transformToExportItems() /*final Iterable<SnomedConstraint> constraints*/
{
    // XXX: Migrate to new MRCM model
    List<AbstractSnomedDsvExportItem> results = Lists.newArrayList();
    // for (final SnomedConstraint constraint : constraints) {
    // SnomedPredicate predicate = constraint.getPredicate();
    // 
    // // Inspect the predicate within the cardinality predicate
    // if (predicate instanceof SnomedCardinalityPredicate) {
    // predicate = ((SnomedCardinalityPredicate) predicate).getPredicate();
    // }
    // 
    // if (predicate instanceof SnomedDescriptionPredicate) {
    // final String descriptionTypeId = ((SnomedDescriptionPredicate) predicate).getTypeId();
    // final ComponentIdSnomedDsvExportItem descriptionExportItem = new ComponentIdSnomedDsvExportItem(SnomedDsvExportItemType.DESCRIPTION, descriptionTypeId, descriptionTypeId);
    // results.add(descriptionExportItem);
    // } else if (predicate instanceof SnomedRelationshipPredicate) {
    // final String typeId = ((SnomedRelationshipPredicate) predicate).getAttributeExpression(); // XXX: only single-SCTID expressions are accepted
    // final ComponentIdSnomedDsvExportItem relationshipExportItem = new ComponentIdSnomedDsvExportItem(SnomedDsvExportItemType.RELATIONSHIP, typeId, typeId);
    // results.add(relationshipExportItem);
    // } else if (predicate instanceof SnomedConcreteDomainPredicate) {
    // final String attributeId = ((SnomedConcreteDomainPredicate) predicate).getAttributeExpression(); // XXX: only single-SCTID expressions are accepted
    // final DataType dataType = ((SnomedConcreteDomainPredicate) predicate).getRange();
    // final boolean dataTypeBoolean = DataType.BOOLEAN.equals(dataType);
    // final DatatypeSnomedDsvExportItem datatypeExportItem = new DatatypeSnomedDsvExportItem(SnomedDsvExportItemType.DATAYPE, attributeId, attributeId, dataTypeBoolean);
    // results.add(datatypeExportItem);
    // }
    // }
    results.add(new SimpleSnomedDsvExportItem(SnomedDsvExportItemType.PREFERRED_TERM));
    results.add(new SimpleSnomedDsvExportItem(SnomedDsvExportItemType.MODULE));
    results.add(new SimpleSnomedDsvExportItem(SnomedDsvExportItemType.EFFECTIVE_TIME));
    results.add(new SimpleSnomedDsvExportItem(SnomedDsvExportItemType.STATUS_LABEL));
    results.add(new SimpleSnomedDsvExportItem(SnomedDsvExportItemType.DEFINITION_STATUS));
    return results;
}
Also used : AbstractSnomedDsvExportItem(com.b2international.snowowl.snomed.datastore.internal.rf2.AbstractSnomedDsvExportItem) SimpleSnomedDsvExportItem(com.b2international.snowowl.snomed.datastore.internal.rf2.SimpleSnomedDsvExportItem)

Example 2 with DatatypeSnomedDsvExportItem

use of com.b2international.snowowl.snomed.datastore.internal.rf2.DatatypeSnomedDsvExportItem 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)

Aggregations

AbstractSnomedDsvExportItem (com.b2international.snowowl.snomed.datastore.internal.rf2.AbstractSnomedDsvExportItem)2 ExtendedLocale (com.b2international.commons.http.ExtendedLocale)1 Dates (com.b2international.snowowl.core.date.Dates)1 EffectiveTimes (com.b2international.snowowl.core.date.EffectiveTimes)1 BranchContext (com.b2international.snowowl.core.domain.BranchContext)1 Sort (com.b2international.snowowl.core.request.SearchResourceRequest.Sort)1 SearchResourceRequestIterator (com.b2international.snowowl.core.request.SearchResourceRequestIterator)1 Concepts (com.b2international.snowowl.snomed.common.SnomedConstants.Concepts)1 SnomedRf2Headers (com.b2international.snowowl.snomed.common.SnomedRf2Headers)1 SnomedConcept (com.b2international.snowowl.snomed.core.domain.SnomedConcept)1 SnomedConcepts (com.b2international.snowowl.snomed.core.domain.SnomedConcepts)1 SnomedDescription (com.b2international.snowowl.snomed.core.domain.SnomedDescription)1 SnomedRelationship (com.b2international.snowowl.snomed.core.domain.SnomedRelationship)1 SnomedRefSetType (com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType)1 SnomedConceptDocument (com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument)1 ComponentIdSnomedDsvExportItem (com.b2international.snowowl.snomed.datastore.internal.rf2.ComponentIdSnomedDsvExportItem)1 DatatypeSnomedDsvExportItem (com.b2international.snowowl.snomed.datastore.internal.rf2.DatatypeSnomedDsvExportItem)1 SimpleSnomedDsvExportItem (com.b2international.snowowl.snomed.datastore.internal.rf2.SimpleSnomedDsvExportItem)1 SnomedRefSetDSVExportModel (com.b2international.snowowl.snomed.datastore.internal.rf2.SnomedRefSetDSVExportModel)1 SnomedConceptSearchRequestBuilder (com.b2international.snowowl.snomed.datastore.request.SnomedConceptSearchRequestBuilder)1