Search in sources :

Example 1 with HarmonizationStudyTable

use of org.obiba.mica.core.domain.HarmonizationStudyTable in project mica2 by obiba.

the class CsvHarmonizationVariablesWriter method writeBody.

private void writeBody(CSVWriter writer, HarmonizationDataset dataset, DatasetVariablesHarmonizationsDto harmonizationVariables, String locale) {
    harmonizationVariables.getVariableHarmonizationsList().forEach(variableHarmonization -> {
        List<String> row = Lists.newArrayList();
        dataset.getBaseStudyTables().forEach(table -> {
            final boolean[] found = { false };
            variableHarmonization.getDatasetVariableSummariesList().forEach(summary -> {
                String id = table instanceof StudyTable ? ((StudyTable) table).getStudyId() : ((HarmonizationStudyTable) table).getStudyId();
                Mica.DatasetVariableResolverDto resolver = summary.getResolver();
                if ((resolver.getStudyId().equals(id) && resolver.getProject().equals(table.getProject()) && resolver.getTable().equals(table.getTable()))) {
                    row.add(getStatus(summary, locale));
                    found[0] = true;
                    return;
                }
            });
            if (row.size() == 0 || !found[0]) {
                row.add(EMPTY_STATUS);
            }
        });
        row.add(0, variableHarmonization.getResolver().getName());
        writer.writeNext(row.toArray(new String[row.size()]));
    });
}
Also used : HarmonizationStudyTable(org.obiba.mica.core.domain.HarmonizationStudyTable) StudyTable(org.obiba.mica.core.domain.StudyTable) LocalizedString(org.obiba.mica.core.domain.LocalizedString) Mica(org.obiba.mica.web.model.Mica)

Example 2 with HarmonizationStudyTable

use of org.obiba.mica.core.domain.HarmonizationStudyTable in project mica2 by obiba.

the class HarmonizedDatasetHelperTest method createHarmonizationStudyTable.

private HarmonizationStudyTable createHarmonizationStudyTable(String studyId) {
    HarmonizationStudyTable table = new HarmonizationStudyTable();
    initTable(studyId, table);
    return table;
}
Also used : HarmonizationStudyTable(org.obiba.mica.core.domain.HarmonizationStudyTable)

Example 3 with HarmonizationStudyTable

use of org.obiba.mica.core.domain.HarmonizationStudyTable in project mica2 by obiba.

the class DatasetDtos method fromDto.

private Dataset fromDto(@NotNull Mica.HarmonizedDatasetDto dto) {
    Assert.notNull(dto, "HarmonizationDataset dt cannot be null.");
    HarmonizationDataset harmonizationDataset = new HarmonizationDataset();
    if (dto.getStudyTablesCount() > 0) {
        dto.getStudyTablesList().forEach(tableDto -> harmonizationDataset.addStudyTable(fromDto(tableDto)));
    }
    if (dto.getHarmonizationTablesCount() > 0) {
        dto.getHarmonizationTablesList().forEach(tableDto -> harmonizationDataset.addHarmonizationTable(fromDto(tableDto)));
    }
    if (dto.hasHarmonizationTable()) {
        HarmonizationStudyTable harmonizationLink = new HarmonizationStudyTable();
        harmonizationLink.setProject(dto.getHarmonizationTable().getProject());
        harmonizationLink.setTable(dto.getHarmonizationTable().getTable());
        harmonizationLink.setStudyId(dto.getHarmonizationTable().getStudyId());
        harmonizationLink.setPopulationId(dto.getHarmonizationTable().getPopulationId());
        harmonizationDataset.setHarmonizationTable(harmonizationLink);
    }
    return harmonizationDataset;
}
Also used : HarmonizationStudyTable(org.obiba.mica.core.domain.HarmonizationStudyTable) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset)

Example 4 with HarmonizationStudyTable

use of org.obiba.mica.core.domain.HarmonizationStudyTable in project mica2 by obiba.

the class DatasetDtos method asContingencyDto.

public Mica.DatasetVariableContingencyDto.Builder asContingencyDto(@NotNull OpalTable opalTable, DatasetVariable variable, DatasetVariable crossVariable, @Nullable Search.QueryResultDto results) {
    Mica.DatasetVariableContingencyDto.Builder crossDto = Mica.DatasetVariableContingencyDto.newBuilder();
    if (opalTable instanceof StudyTable)
        crossDto.setStudyTable(asDto((StudyTable) opalTable, true));
    else if (opalTable instanceof HarmonizationStudyTable)
        crossDto.setHarmonizationStudyTable(asDto((HarmonizationStudyTable) opalTable));
    Mica.DatasetVariableAggregationDto.Builder allAggBuilder = Mica.DatasetVariableAggregationDto.newBuilder();
    if (results == null) {
        allAggBuilder.setN(0);
        allAggBuilder.setTotal(0);
        crossDto.setAll(allAggBuilder);
        return crossDto;
    }
    allAggBuilder.setTotal(results.getTotalHits());
    MicaConfig micaConfig = micaConfigService.getConfig();
    int privacyThreshold = micaConfig.getPrivacyThreshold();
    crossDto.setPrivacyThreshold(privacyThreshold);
    boolean privacyChecks = crossVariable.hasCategories() ? validatePrivacyThreshold(results, privacyThreshold) : true;
    boolean totalPrivacyChecks = validateTotalPrivacyThreshold(results, privacyThreshold);
    // add facet results in the same order as the variable categories
    variable.getCategories().forEach(cat -> results.getFacetsList().stream().filter(facet -> facet.hasFacet() && cat.getName().equals(facet.getFacet())).forEach(facet -> {
        boolean privacyCheck = privacyChecks && checkPrivacyThreshold(facet.getFilters(0).getCount(), privacyThreshold);
        Mica.DatasetVariableAggregationDto.Builder aggBuilder = Mica.DatasetVariableAggregationDto.newBuilder();
        aggBuilder.setTotal(totalPrivacyChecks ? results.getTotalHits() : 0);
        aggBuilder.setTerm(facet.getFacet());
        DatasetCategory category = variable.getCategory(facet.getFacet());
        aggBuilder.setMissing(category != null && category.isMissing());
        addSummaryStatistics(crossVariable, aggBuilder, facet, privacyCheck, totalPrivacyChecks);
        crossDto.addAggregations(aggBuilder);
    }));
    // add total facet for all variable categories
    results.getFacetsList().stream().filter(facet -> facet.hasFacet() && "_total".equals(facet.getFacet())).forEach(facet -> {
        boolean privacyCheck = privacyChecks && facet.getFilters(0).getCount() > micaConfig.getPrivacyThreshold();
        addSummaryStatistics(crossVariable, allAggBuilder, facet, privacyCheck, totalPrivacyChecks);
    });
    crossDto.setAll(allAggBuilder);
    return crossDto;
}
Also used : Search(org.obiba.opal.web.model.Search) OpalTable(org.obiba.mica.core.domain.OpalTable) MicaConfig(org.obiba.mica.micaConfig.domain.MicaConfig) Taxonomy(org.obiba.opal.core.domain.taxonomy.Taxonomy) HarmonizationStudyTable(org.obiba.mica.core.domain.HarmonizationStudyTable) Inject(javax.inject.Inject) Term(org.obiba.opal.core.domain.taxonomy.Term) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) Map(java.util.Map) JSONUtils(org.obiba.mica.JSONUtils) Attributes(org.obiba.mica.core.domain.Attributes) HarmonizationDatasetState(org.obiba.mica.dataset.domain.HarmonizationDatasetState) StudyDataset(org.obiba.mica.dataset.domain.StudyDataset) Nullable(javax.annotation.Nullable) SubjectAclService(org.obiba.mica.security.service.SubjectAclService) Math(org.obiba.opal.web.model.Math) Collection(java.util.Collection) DatasetCategory(org.obiba.mica.dataset.domain.DatasetCategory) DatasetVariable(org.obiba.mica.dataset.domain.DatasetVariable) NotNull(javax.validation.constraints.NotNull) Dataset(org.obiba.mica.dataset.domain.Dataset) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) PublishedStudyService(org.obiba.mica.study.service.PublishedStudyService) List(java.util.List) Component(org.springframework.stereotype.Component) HarmonizationDatasetStateRepository(org.obiba.mica.dataset.HarmonizationDatasetStateRepository) StudyDatasetState(org.obiba.mica.dataset.domain.StudyDatasetState) StudyDatasetStateRepository(org.obiba.mica.dataset.StudyDatasetStateRepository) MicaConfigService(org.obiba.mica.micaConfig.service.MicaConfigService) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset) Optional(java.util.Optional) Vocabulary(org.obiba.opal.core.domain.taxonomy.Vocabulary) Collections(java.util.Collections) StudyTable(org.obiba.mica.core.domain.StudyTable) Assert(org.springframework.util.Assert) MicaConfig(org.obiba.mica.micaConfig.domain.MicaConfig) DatasetCategory(org.obiba.mica.dataset.domain.DatasetCategory) HarmonizationStudyTable(org.obiba.mica.core.domain.HarmonizationStudyTable) StudyTable(org.obiba.mica.core.domain.StudyTable) HarmonizationStudyTable(org.obiba.mica.core.domain.HarmonizationStudyTable)

Example 5 with HarmonizationStudyTable

use of org.obiba.mica.core.domain.HarmonizationStudyTable in project mica2 by obiba.

the class DatasetDtos method fromDto.

private HarmonizationStudyTable fromDto(Mica.DatasetDto.HarmonizationTableDto dto) {
    HarmonizationStudyTable table = new HarmonizationStudyTable();
    table.setStudyId(dto.getStudyId());
    table.setPopulationId(dto.getPopulationId());
    table.setPopulationId(dto.getPopulationId());
    table.setProject(dto.getProject());
    table.setTable(dto.getTable());
    table.setWeight(dto.getWeight());
    table.setName(localizedStringDtos.fromDto(dto.getNameList()));
    table.setDescription(localizedStringDtos.fromDto(dto.getDescriptionList()));
    return table;
}
Also used : HarmonizationStudyTable(org.obiba.mica.core.domain.HarmonizationStudyTable)

Aggregations

HarmonizationStudyTable (org.obiba.mica.core.domain.HarmonizationStudyTable)6 HarmonizationDataset (org.obiba.mica.dataset.domain.HarmonizationDataset)3 StudyTable (org.obiba.mica.core.domain.StudyTable)2 Strings (com.google.common.base.Strings)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Nullable (javax.annotation.Nullable)1 Inject (javax.inject.Inject)1 NotNull (javax.validation.constraints.NotNull)1 JSONUtils (org.obiba.mica.JSONUtils)1 Attributes (org.obiba.mica.core.domain.Attributes)1 LocalizedString (org.obiba.mica.core.domain.LocalizedString)1 OpalTable (org.obiba.mica.core.domain.OpalTable)1 HarmonizationDatasetStateRepository (org.obiba.mica.dataset.HarmonizationDatasetStateRepository)1