Search in sources :

Example 46 with Study

use of org.obiba.mica.study.domain.Study in project mica2 by obiba.

the class VariableController method addStudyTableParameters.

private void addStudyTableParameters(Map<String, Object> params, DatasetVariable variable) {
    try {
        String studyId = variable.getStudyId();
        boolean published = studyService.isPublished(studyId);
        BaseStudy study = getStudy(studyId, published);
        params.put("studyPublished", published);
        params.put("study", study);
        Population population = study.findPopulation(variable.getPopulationId().replace(variable.getStudyId() + ":", ""));
        params.put("population", population);
        DataCollectionEvent dce = population.findDataCollectionEvent(variable.getDceId().replace(variable.getPopulationId() + ":", ""));
        params.put("dce", dce);
        if (DatasetVariable.Type.Harmonized.equals(variable.getVariableType())) {
            HarmonizationDataset dataset = getHarmonizationDataset(variable.getDatasetId());
            if (DatasetVariable.OpalTableType.Study.equals(variable.getOpalTableType())) {
                Optional<StudyTable> studyTable = dataset.getStudyTables().stream().filter(st -> variable.getStudyId().equals(st.getStudyId()) && variable.getProject().equals(st.getProject()) && variable.getTable().equals(st.getTable())).findFirst();
                if (studyTable.isPresent())
                    params.put("opalTable", studyTable.get());
            } else {
                Optional<HarmonizationStudyTable> harmoStudyTable = dataset.getHarmonizationTables().stream().filter(st -> variable.getStudyId().equals(st.getStudyId()) && variable.getProject().equals(st.getProject()) && variable.getTable().equals(st.getTable())).findFirst();
                if (harmoStudyTable.isPresent())
                    params.put("opalTable", harmoStudyTable.get());
            }
        }
    } catch (Exception e) {
        // ignore
        log.warn("Failed at retrieving collected dataset's study/population/dce", e);
    }
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) Taxonomy(org.obiba.opal.core.domain.taxonomy.Taxonomy) LoggerFactory(org.slf4j.LoggerFactory) HarmonizationStudyTable(org.obiba.mica.core.domain.HarmonizationStudyTable) Controller(org.springframework.stereotype.Controller) NoSuchVariableException(org.obiba.magma.NoSuchVariableException) Indexer(org.obiba.mica.spi.search.Indexer) Inject(javax.inject.Inject) Lists(com.google.common.collect.Lists) Map(java.util.Map) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) GetMapping(org.springframework.web.bind.annotation.GetMapping) NoSuchDatasetException(org.obiba.mica.dataset.NoSuchDatasetException) TaxonomyEntity(org.obiba.opal.core.domain.taxonomy.TaxonomyEntity) NoSuchElementException(java.util.NoSuchElementException) Logger(org.slf4j.Logger) Searcher(org.obiba.mica.spi.search.Searcher) DatasetVariable(org.obiba.mica.dataset.domain.DatasetVariable) BaseStudy(org.obiba.mica.study.domain.BaseStudy) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Population(org.obiba.mica.study.domain.Population) CollectedDatasetService(org.obiba.mica.dataset.service.CollectedDatasetService) StudyService(org.obiba.mica.study.service.StudyService) IOException(java.io.IOException) DataCollectionEvent(org.obiba.mica.study.domain.DataCollectionEvent) Collectors(java.util.stream.Collectors) HarmonizedDatasetService(org.obiba.mica.dataset.service.HarmonizedDatasetService) NoSuchStudyException(org.obiba.mica.study.NoSuchStudyException) HarmonizationAnnotations(org.obiba.mica.web.controller.domain.HarmonizationAnnotations) PublishedStudyService(org.obiba.mica.study.service.PublishedStudyService) ModelAndView(org.springframework.web.servlet.ModelAndView) List(java.util.List) Study(org.obiba.mica.study.domain.Study) Annotation(org.obiba.mica.web.controller.domain.Annotation) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset) TaxonomyService(org.obiba.mica.micaConfig.service.TaxonomyService) Optional(java.util.Optional) StudyTable(org.obiba.mica.core.domain.StudyTable) InputStream(java.io.InputStream) DataCollectionEvent(org.obiba.mica.study.domain.DataCollectionEvent) HarmonizationStudyTable(org.obiba.mica.core.domain.HarmonizationStudyTable) StudyTable(org.obiba.mica.core.domain.StudyTable) HarmonizationStudyTable(org.obiba.mica.core.domain.HarmonizationStudyTable) Population(org.obiba.mica.study.domain.Population) BaseStudy(org.obiba.mica.study.domain.BaseStudy) NoSuchVariableException(org.obiba.magma.NoSuchVariableException) NoSuchDatasetException(org.obiba.mica.dataset.NoSuchDatasetException) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException) NoSuchStudyException(org.obiba.mica.study.NoSuchStudyException) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset)

Aggregations

Study (org.obiba.mica.study.domain.Study)46 BaseStudy (org.obiba.mica.study.domain.BaseStudy)17 Test (org.junit.Test)16 Collectors (java.util.stream.Collectors)10 Inject (javax.inject.Inject)10 List (java.util.List)9 HarmonizationStudy (org.obiba.mica.study.domain.HarmonizationStudy)9 Strings (com.google.common.base.Strings)8 Population (org.obiba.mica.study.domain.Population)8 NotNull (javax.validation.constraints.NotNull)7 DataCollectionEvent (org.obiba.mica.study.domain.DataCollectionEvent)7 Timed (com.codahale.metrics.annotation.Timed)6 Lists (com.google.common.collect.Lists)6 Map (java.util.Map)6 Collectors.toList (java.util.stream.Collectors.toList)6 PublishedStudyService (org.obiba.mica.study.service.PublishedStudyService)6 Sets (com.google.common.collect.Sets)5 HashMap (java.util.HashMap)5 NoSuchEntityException (org.obiba.mica.NoSuchEntityException)5 StudyService (org.obiba.mica.study.service.StudyService)5