use of org.obiba.mica.study.domain.Population in project mica2 by obiba.
the class TestDataCollectionEventSort method test_study_population_sort_with_duplicate_events.
@Test
public void test_study_population_sort_with_duplicate_events() {
Study study = new Study();
study.setId("01234567889");
study.addPopulation(createPopulation("Population001", createEvent("A", "A", 2010, 1, 2020, 12), createEvent("A", "A", 2014, 1, 2035, 12), createEvent("A", "A", 2010, 1, 2020, 12)));
Population population = Iterables.get(study.getPopulations(), 0);
SortedSet<DataCollectionEvent> events = population.getDataCollectionEvents();
assertThat(events.size()).isEqualTo(2);
assertThat(Iterables.get(events, 0).getStart()).isEqualTo(of(2010, 1));
assertThat(Iterables.get(events, 1).getStart()).isEqualTo(of(2014, 1));
}
use of org.obiba.mica.study.domain.Population in project mica2 by obiba.
the class TestDataCollectionEventSort method createPopulation.
private Population createPopulation(String name, DataCollectionEvent... events) {
Population population = new Population();
population.setName(en(name));
for (DataCollectionEvent event : events) {
population.addDataCollectionEvent(event);
}
return population;
}
use of org.obiba.mica.study.domain.Population in project mica2 by obiba.
the class PopulationDtos method fromDto.
@NotNull
Population fromDto(Mica.PopulationDtoOrBuilder dto) {
Population population = new Population();
population.setId(dto.getId());
if (dto.getNameCount() > 0)
population.setName(localizedStringDtos.fromDto(dto.getNameList()));
if (dto.getDescriptionCount() > 0)
population.setDescription(localizedStringDtos.fromDto(dto.getDescriptionList()));
if (dto.getDataCollectionEventsCount() > 0) {
dto.getDataCollectionEventsList().forEach(dceDto -> population.addDataCollectionEvent(fromDto(dceDto)));
}
if (dto.hasContent() && !Strings.isNullOrEmpty(dto.getContent()))
population.setModel(JSONUtils.toMap(dto.getContent()));
else
population.setModel(new HashMap<>());
if (dto.hasWeight()) {
population.setWeight(dto.getWeight());
}
return population;
}
use of org.obiba.mica.study.domain.Population in project mica2 by obiba.
the class TestDataCollectionEventSort method test_no_end_year_date_fields.
@Test
public void test_no_end_year_date_fields() {
Population population = createPopulation("Test Population", createEvent("A", 2010, null, null, null), createEvent("A", 1997, null, null, null));
DataCollectionEvent event = Iterables.get(population.getDataCollectionEvents(), 0);
assertThat(event.getStart()).isEqualTo(of(1997, 1));
}
use of org.obiba.mica.study.domain.Population in project mica2 by obiba.
the class TestDataCollectionEventSort method test_study_populations_sort_with_duplicate_events.
@Test
public void test_study_populations_sort_with_duplicate_events() {
Study study = new Study();
study.setId("01234567889");
study.addPopulation(createPopulation("Population001", createEvent("A", "A", 2010, 1, 2020, 12)));
study.addPopulation(createPopulation("Population002", createEvent("A", "A", 2010, 1, 2020, 12)));
study.addPopulation(createPopulation("Population003", createEvent("A", "A", 2010, 1, 2020, 12)));
SortedSet<Population> populations = study.getPopulations();
assertThat(populations.size()).isEqualTo(3);
assertThat(Iterables.get(Iterables.get(populations, 0).getDataCollectionEvents(), 0).getStart()).isEqualTo(of(2010, 1));
assertThat(Iterables.get(Iterables.get(populations, 1).getDataCollectionEvents(), 0).getStart()).isEqualTo(of(2010, 1));
assertThat(Iterables.get(Iterables.get(populations, 2).getDataCollectionEvents(), 0).getStart()).isEqualTo(of(2010, 1));
}
Aggregations