Search in sources :

Example 6 with Population

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));
}
Also used : Study(org.obiba.mica.study.domain.Study) DataCollectionEvent(org.obiba.mica.study.domain.DataCollectionEvent) Population(org.obiba.mica.study.domain.Population) Test(org.junit.Test)

Example 7 with Population

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;
}
Also used : DataCollectionEvent(org.obiba.mica.study.domain.DataCollectionEvent) Population(org.obiba.mica.study.domain.Population)

Example 8 with 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;
}
Also used : HashMap(java.util.HashMap) Population(org.obiba.mica.study.domain.Population) NotNull(javax.validation.constraints.NotNull)

Example 9 with 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));
}
Also used : DataCollectionEvent(org.obiba.mica.study.domain.DataCollectionEvent) Population(org.obiba.mica.study.domain.Population) Test(org.junit.Test)

Example 10 with Population

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));
}
Also used : Study(org.obiba.mica.study.domain.Study) Population(org.obiba.mica.study.domain.Population) Test(org.junit.Test)

Aggregations

Population (org.obiba.mica.study.domain.Population)15 DataCollectionEvent (org.obiba.mica.study.domain.DataCollectionEvent)9 Test (org.junit.Test)7 Study (org.obiba.mica.study.domain.Study)5 BaseStudy (org.obiba.mica.study.domain.BaseStudy)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Collectors.toList (java.util.stream.Collectors.toList)2 NotNull (javax.validation.constraints.NotNull)2 StudyTable (org.obiba.mica.core.domain.StudyTable)2 Strings (com.google.common.base.Strings)1 ImmutableList (com.google.common.collect.ImmutableList)1 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 EventBus (com.google.common.eventbus.EventBus)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1