Search in sources :

Example 6 with DataCollectionEvent

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

the class PopulationDtos method fromDto.

@NotNull
DataCollectionEvent fromDto(@NotNull PopulationDto.DataCollectionEventDto dto) {
    DataCollectionEvent dce = new DataCollectionEvent();
    dce.setId(dto.getId());
    if (dto.getNameCount() > 0)
        dce.setName(localizedStringDtos.fromDto(dto.getNameList()));
    if (dto.getDescriptionCount() > 0)
        dce.setDescription(localizedStringDtos.fromDto(dto.getDescriptionList()));
    if (dto.hasStartYear())
        dce.setStart(dto.getStartYear(), dto.hasStartMonth() ? dto.getStartMonth() : null);
    if (dto.hasEndYear())
        dce.setEnd(dto.getEndYear(), dto.hasEndMonth() ? dto.getEndMonth() : null);
    if (dto.hasContent() && !Strings.isNullOrEmpty(dto.getContent()))
        dce.setModel(JSONUtils.toMap(dto.getContent()));
    else
        dce.setModel(new HashMap<>());
    if (dto.hasWeight()) {
        dce.setWeight(dto.getWeight());
    }
    return dce;
}
Also used : DataCollectionEvent(org.obiba.mica.study.domain.DataCollectionEvent) HashMap(java.util.HashMap) NotNull(javax.validation.constraints.NotNull)

Example 7 with DataCollectionEvent

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

the class TestDataCollectionEventSort method createEvent.

private DataCollectionEvent createEvent(String id, String name, Integer startYear, Integer startMonth, Integer endYear, Integer endMonth) {
    DataCollectionEvent event = new DataCollectionEvent();
    event.setId(id);
    event.setName(en(name));
    event.setDescription(en("Baseline data collection"));
    if (startYear != null)
        event.setStart(startYear, startMonth);
    if (endYear != null)
        event.setEnd(endYear, endMonth);
    return event;
}
Also used : DataCollectionEvent(org.obiba.mica.study.domain.DataCollectionEvent)

Example 8 with DataCollectionEvent

use of org.obiba.mica.study.domain.DataCollectionEvent 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 9 with DataCollectionEvent

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

the class TestDataCollectionEventSort method test_with_null_date_year_month_parts.

@Test
public void test_with_null_date_year_month_parts() {
    DataCollectionEvent event1 = createEvent("A", "A", null, null, null, null);
    DataCollectionEvent evetn2 = createEvent("A", "A", null, null, null, null);
    assertThat(event1.compareTo(evetn2)).isEqualTo(0);
    DataCollectionEvent event3 = createEvent("A", "A", null, null, null, null);
    DataCollectionEvent event4 = createEvent("B", "A", null, null, null, null);
    assertThat(event3.compareTo(event4)).isEqualTo(-1);
    DataCollectionEvent event5 = createEvent("A", "A", null, null, 2020, 12);
    DataCollectionEvent event6 = createEvent("B", "A", 2010, 1, 2020, 12);
    assertThat(event5.compareTo(event6)).isEqualTo(1);
    DataCollectionEvent event7 = createEvent("A", "A", 2010, 1, null, null);
    DataCollectionEvent event8 = createEvent("B", "A", 2010, 1, 2020, 12);
    assertThat(event7.compareTo(event8)).isEqualTo(1);
    DataCollectionEvent event9 = createEvent("A", "A", 2010, 1, 2020, 12);
    DataCollectionEvent event10 = createEvent("B", "A", null, null, 2020, 12);
    assertThat(event9.compareTo(event10)).isEqualTo(-1);
    DataCollectionEvent event11 = createEvent("A", "A", 2010, 1, 2020, 12);
    DataCollectionEvent event12 = createEvent("B", "A", 2010, 1, null, null);
    assertThat(event11.compareTo(event12)).isEqualTo(-1);
    DataCollectionEvent event13 = createEvent("A", "A", 2010, 1, 2020, 12);
    DataCollectionEvent event14 = createEvent("B", "A", null, null, null, null);
    assertThat(event13.compareTo(event14)).isEqualTo(-1);
    DataCollectionEvent event15 = createEvent("A", "A", 2010, 1, 2020, 12);
    DataCollectionEvent event16 = createEvent("A", "A", 2011, 1, 2020, 12);
    assertThat(event15.compareTo(event16)).isEqualTo(-1);
    DataCollectionEvent event17 = createEvent("A", "A", 2011, 1, 2020, 12);
    DataCollectionEvent event18 = createEvent("A", "A", 2010, 1, 2020, 12);
    assertThat(event17.compareTo(event18)).isEqualTo(1);
}
Also used : DataCollectionEvent(org.obiba.mica.study.domain.DataCollectionEvent) Test(org.junit.Test)

Example 10 with DataCollectionEvent

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

the class TestDataCollectionEventSort method test_all_date_fields.

@Test
public void test_all_date_fields() {
    Population population = createPopulation("Test Population", createEvent("A", 2010, 1, 2020, 12), createEvent("A", 1997, 1, 2000, 12), createEvent("A", 1997, 8, 2000, 12));
    population.setName(en("Test Population"));
    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)

Aggregations

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