Search in sources :

Example 6 with StudyTable

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

the class DatasetDtos method asDtoBuilder.

@NotNull
Mica.DatasetDto.Builder asDtoBuilder(@NotNull HarmonizationDataset dataset, boolean asDraft, boolean studySummary) {
    Mica.DatasetDto.Builder builder = asBuilder(dataset);
    builder.setVariableType(DatasetVariable.Type.Dataschema.name());
    Mica.HarmonizedDatasetDto.Builder hbuilder = Mica.HarmonizedDatasetDto.newBuilder();
    if (dataset.hasHarmonizationTable() && !Strings.isNullOrEmpty(dataset.getHarmonizationTable().getStudyId()) && isStudyTablePermitted(asDraft, "harmonization", dataset.getHarmonizationTable().getStudyId())) {
        hbuilder.setHarmonizationTable(createHarmonizationLinkDtoFromHarmonizationTable(dataset.getHarmonizationTable(), asDraft));
    }
    if (!dataset.getStudyTables().isEmpty()) {
        dataset.getStudyTables().stream().filter(studyTable -> isStudyTablePermitted(asDraft, "individual", studyTable.getStudyId())).forEach(studyTable -> hbuilder.addStudyTables(asDto(studyTable, studySummary)));
    }
    if (!dataset.getHarmonizationTables().isEmpty()) {
        dataset.getHarmonizationTables().stream().filter(studyTable -> isStudyTablePermitted(asDraft, "harmonization", studyTable.getStudyId())).forEach(harmonizationTable -> hbuilder.addHarmonizationTables(asDto(harmonizationTable, studySummary)));
    }
    builder.setExtension(Mica.HarmonizedDatasetDto.type, hbuilder.build());
    Mica.PermissionsDto permissionsDto = permissionsDtos.asDto(dataset);
    if (asDraft) {
        HarmonizationDatasetState state = harmonizationDatasetStateRepository.findOne(dataset.getId());
        if (state != null) {
            builder.setPublished(state.isPublished());
            builder.setExtension(Mica.EntityStateDto.datasetState, entityStateDtos.asDto(state).setPermissions(permissionsDto).build());
        }
    }
    builder.setPermissions(permissionsDto);
    return builder;
}
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) HarmonizationDatasetState(org.obiba.mica.dataset.domain.HarmonizationDatasetState) NotNull(javax.validation.constraints.NotNull)

Example 7 with StudyTable

use of org.obiba.mica.core.domain.StudyTable 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 8 with StudyTable

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

the class CollectedDatasetServiceTest method buildStudyDataset.

private StudyDataset buildStudyDataset() {
    StudyDataset ds = new StudyDataset();
    StudyTable st = new StudyTable();
    st.setProject("proj");
    st.setTable("tab");
    ds.setStudyTable(st);
    ds.setName(new LocalizedString(Locale.CANADA, "test"));
    return ds;
}
Also used : StudyTable(org.obiba.mica.core.domain.StudyTable) LocalizedString(org.obiba.mica.core.domain.LocalizedString) StudyDataset(org.obiba.mica.dataset.domain.StudyDataset)

Example 9 with StudyTable

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

the class HarmonizedDatasetServiceTest method buildStudyTable.

private StudyTable buildStudyTable(String project, String table, String studyId) {
    StudyTable st = new StudyTable();
    st.setProject(project);
    st.setTable(table);
    st.setStudyId(studyId);
    st.setPopulationId("pop");
    st.setDataCollectionEventId("ev");
    return st;
}
Also used : StudyTable(org.obiba.mica.core.domain.StudyTable)

Example 10 with StudyTable

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

the class HarmonizedDatasetServiceTest method buildHarmonizationDataset.

private HarmonizationDataset buildHarmonizationDataset(String id, StudyTable... studyTables) {
    HarmonizationDataset ds = new HarmonizationDataset();
    for (StudyTable s : studyTables) {
        ds.addStudyTable(s);
    }
    ds.setId(id);
    ds.setName(new LocalizedString(Locale.CANADA, "dataset" + id));
    return ds;
}
Also used : StudyTable(org.obiba.mica.core.domain.StudyTable) LocalizedString(org.obiba.mica.core.domain.LocalizedString) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset)

Aggregations

StudyTable (org.obiba.mica.core.domain.StudyTable)14 StudyDataset (org.obiba.mica.dataset.domain.StudyDataset)6 HarmonizationStudyTable (org.obiba.mica.core.domain.HarmonizationStudyTable)5 HarmonizationDataset (org.obiba.mica.dataset.domain.HarmonizationDataset)5 Lists (com.google.common.collect.Lists)4 Inject (javax.inject.Inject)4 DatasetVariable (org.obiba.mica.dataset.domain.DatasetVariable)4 Component (org.springframework.stereotype.Component)4 Strings (com.google.common.base.Strings)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 NotNull (javax.validation.constraints.NotNull)3 LocalizedString (org.obiba.mica.core.domain.LocalizedString)3 StudyDatasetStateRepository (org.obiba.mica.dataset.StudyDatasetStateRepository)3 StudyDatasetState (org.obiba.mica.dataset.domain.StudyDatasetState)3 SubjectAclService (org.obiba.mica.security.service.SubjectAclService)3 PublishedStudyService (org.obiba.mica.study.service.PublishedStudyService)3 Search (org.obiba.opal.web.model.Search)3 Timed (com.codahale.metrics.annotation.Timed)2 Maps (com.google.common.collect.Maps)2