use of org.obiba.mica.study.domain.BaseStudy in project mica2 by obiba.
the class CollectedDatasetService method processVariablesForStudyDataset.
public List<DatasetVariable> processVariablesForStudyDataset(StudyDataset dataset, Iterable<DatasetVariable> variables) {
if (!dataset.hasStudyTable()) {
return Lists.newArrayList(variables);
}
StudyTable studyTable = dataset.getStudyTable();
BaseStudy study = studyService.findStudy(dataset.getStudyTable().getStudyId());
Population population = study.findPopulation(studyTable.getPopulationId());
if (population == null) {
return Lists.newArrayList(variables);
}
int populationWeight = population.getWeight();
DataCollectionEvent dataCollectionEvent = population.findDataCollectionEvent(studyTable.getDataCollectionEventId());
if (dataCollectionEvent == null) {
return Lists.newArrayList(variables);
}
int dataCollectionEventWeight = dataCollectionEvent.getWeight();
return StreamSupport.stream(variables.spliterator(), false).map(datasetVariable -> {
datasetVariable.setPopulationWeight(populationWeight);
datasetVariable.setDataCollectionEventWeight(dataCollectionEventWeight);
return datasetVariable;
}).collect(toList());
}
use of org.obiba.mica.study.domain.BaseStudy in project mica2 by obiba.
the class CollectedDatasetService method prepareForIndex.
private void prepareForIndex(StudyDataset dataset) {
if (dataset.hasStudyTable()) {
StudyTable studyTable = dataset.getStudyTable();
BaseStudy study = publishedStudyService.findById(dataset.getStudyTable().getStudyId());
if (study != null) {
Population population = study.findPopulation(studyTable.getPopulationId());
if (population != null) {
studyTable.setPopulationWeight(population.getWeight());
DataCollectionEvent dataCollectionEvent = population.findDataCollectionEvent(studyTable.getDataCollectionEventId());
if (dataCollectionEvent != null) {
studyTable.setDataCollectionEventWeight(dataCollectionEvent.getWeight());
}
}
}
}
}
use of org.obiba.mica.study.domain.BaseStudy in project mica2 by obiba.
the class StudyQuery method processHits.
@Override
public void processHits(QueryResultDto.Builder builder, Searcher.DocumentResults results, QueryScope scope, CountStatsData counts) throws IOException {
StudyResultDto.Builder resBuilder = StudyResultDto.newBuilder();
StudyCountStatsBuilder studyCountStatsBuilder = counts == null ? null : StudyCountStatsBuilder.newBuilder(counts);
Consumer<BaseStudy> addDto = getStudyConsumer(scope, resBuilder, studyCountStatsBuilder);
List<BaseStudy> publishedStudies = getPublishedDocumentsFromHitsByClassName(results, BaseStudy.class);
publishedStudies.forEach(addDto::accept);
builder.setExtension(StudyResultDto.result, resBuilder.build());
}
use of org.obiba.mica.study.domain.BaseStudy in project mica2 by obiba.
the class VariableQuery method processHit.
/**
* Fill the variable resolver dto with user-friendly labels about the variable, the dataset and the study.
*
* @param resolver
* @param variable
* @param studyMap study cache
* @return
*/
private Mica.DatasetVariableResolverDto processHit(DatasetVariable.IdResolver resolver, DatasetVariable variable, Map<String, BaseStudy> studyMap, Map<String, Network> networkMap) {
Mica.DatasetVariableResolverDto.Builder builder = dtos.asDto(resolver);
String studyId = resolver.hasStudyId() ? resolver.getStudyId() : null;
if (resolver.getType() == DatasetVariable.Type.Collected || resolver.getType() == DatasetVariable.Type.Dataschema || resolver.getType() == DatasetVariable.Type.Harmonized) {
studyId = variable.getStudyId();
}
if (studyId != null) {
builder.setStudyId(studyId);
try {
BaseStudy study;
if (studyMap.containsKey(studyId)) {
study = studyMap.get(studyId);
} else {
study = publishedStudyService.findById(studyId);
studyMap.put(studyId, study);
}
if (study != null) {
builder.addAllStudyName(dtos.asDto(study.getName()));
builder.addAllStudyAcronym(dtos.asDto(study.getAcronym()));
}
} catch (NoSuchStudyException e) {
}
}
builder.addAllDatasetAcronym(dtos.asDto(variable.getDatasetAcronym()));
builder.addAllDatasetName(dtos.asDto(variable.getDatasetName()));
if (variable.hasAttribute("label", null)) {
builder.addAllVariableLabel(dtos.asDto(variable.getAttributes().getAttribute("label", null).getValues()));
}
return builder.build();
}
use of org.obiba.mica.study.domain.BaseStudy in project mica2 by obiba.
the class VariableQuery method processHits.
@Override
protected void processHits(MicaSearch.QueryResultDto.Builder builder, Searcher.DocumentResults results, QueryScope scope, CountStatsData counts) throws IOException {
MicaSearch.DatasetVariableResultDto.Builder resBuilder = MicaSearch.DatasetVariableResultDto.newBuilder();
Map<String, BaseStudy> studyMap = Maps.newHashMap();
Map<String, Network> networkMap = Maps.newHashMap();
for (Searcher.DocumentResult result : results.getDocuments()) {
if (result.hasSource()) {
DatasetVariable.IdResolver resolver = DatasetVariable.IdResolver.from(result.getId());
DatasetVariable variable = objectMapper.readValue(result.getSourceInputStream(), DatasetVariable.class);
resBuilder.addSummaries(processHit(resolver, variable, studyMap, networkMap));
}
}
builder.setExtension(MicaSearch.DatasetVariableResultDto.result, resBuilder.build());
}
Aggregations