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;
}
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;
}
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));
}
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);
}
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));
}
Aggregations