Search in sources :

Example 1 with StudyTable

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

the class PublishedCollectedDatasetVariableResource method getVariableAggregations.

@GET
@Path("/aggregation")
@Timed
public Mica.DatasetVariableAggregationDto getVariableAggregations() {
    StudyDataset dataset = getDataset(StudyDataset.class, datasetId);
    StudyTable studyTable = dataset.getSafeStudyTable();
    Mica.DatasetVariableAggregationDto.Builder aggDto = // 
    Mica.DatasetVariableAggregationDto.newBuilder().setStudyTable(dtos.asDto(studyTable));
    try {
        return dtos.asDto(studyTable, datasetService.getVariableSummary(dataset, variableName).getWrappedDto()).build();
    } catch (Exception e) {
        log.warn("Unable to retrieve statistics: " + e.getMessage(), e);
        return dtos.asDto(studyTable, null).build();
    }
}
Also used : StudyTable(org.obiba.mica.core.domain.StudyTable) StudyDataset(org.obiba.mica.dataset.domain.StudyDataset) BadRequestException(javax.ws.rs.BadRequestException) IOException(java.io.IOException) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 2 with StudyTable

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

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

the class PublishedHarmonizedDatasetResource method getVariable.

@Path("/study/{study}/population/{population}/data-collection-event/{dce}/variable/{variable}")
public PublishedHarmonizedDatasetVariableResource getVariable(@PathParam("id") String id, @PathParam("study") String studyId, @PathParam("population") String populationId, @PathParam("dce") String dceId, @PathParam("variable") String variable) {
    checkAccess(id);
    PublishedHarmonizedDatasetVariableResource resource = applicationContext.getBean(PublishedHarmonizedDatasetVariableResource.class);
    resource.setDatasetId(id);
    resource.setVariableName(variable);
    resource.setStudyId(studyId);
    HarmonizationDataset dataset = getDataset(HarmonizationDataset.class, id);
    dataset.getStudyTables().stream().filter(t -> t.appliesTo(studyId, populationId, dceId)).forEach(t -> {
        resource.setTableType(t instanceof StudyTable ? DatasetVariable.OPAL_STUDY_TABLE_PREFIX : DatasetVariable.OPAL_HARMONIZATION_TABLE_PREFIX);
    });
    return resource;
}
Also used : PathParam(javax.ws.rs.PathParam) AbstractPublishedDatasetResource(org.obiba.mica.dataset.search.rest.AbstractPublishedDatasetResource) SubjectAclService(org.obiba.mica.security.service.SubjectAclService) Logger(org.slf4j.Logger) Produces(javax.ws.rs.Produces) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GET(javax.ws.rs.GET) DatasetVariable(org.obiba.mica.dataset.domain.DatasetVariable) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) IOException(java.io.IOException) Scope(org.springframework.context.annotation.Scope) Inject(javax.inject.Inject) Timed(com.codahale.metrics.annotation.Timed) Component(org.springframework.stereotype.Component) Lists(com.google.common.collect.Lists) QueryParam(javax.ws.rs.QueryParam) Response(javax.ws.rs.core.Response) Mica(org.obiba.mica.web.model.Mica) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset) DefaultValue(javax.ws.rs.DefaultValue) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) StudyTable(org.obiba.mica.core.domain.StudyTable) StudyTable(org.obiba.mica.core.domain.StudyTable) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset) Path(javax.ws.rs.Path)

Example 4 with StudyTable

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

the class HarmonizationDatasetUpgrade method execute.

@Override
public void execute(Version version) {
    log.info("Executing harmonization datasets network tables upgrade");
    List<HarmonizationDataset> datasets = harmonizationDatasetRepository.findAll();
    datasets.forEach(dataset -> {
        int i = 0;
        for (StudyTable st : dataset.getStudyTables()) {
            st.setWeight(i++);
        }
    });
    harmonizationDatasetRepository.save(datasets);
    eventBus.post(new IndexDatasetsEvent());
}
Also used : StudyTable(org.obiba.mica.core.domain.StudyTable) IndexDatasetsEvent(org.obiba.mica.dataset.event.IndexDatasetsEvent) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset)

Example 5 with StudyTable

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

the class DatasetDtos method fromDto.

private StudyTable fromDto(Mica.DatasetDto.StudyTableDto dto) {
    StudyTable table = new StudyTable();
    table.setStudyId(dto.getStudyId());
    table.setPopulationId(dto.getPopulationId());
    table.setDataCollectionEventId(dto.getDataCollectionEventId());
    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) StudyTable(org.obiba.mica.core.domain.StudyTable)

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