Search in sources :

Example 1 with PersistableYearMonth

use of org.obiba.mica.study.date.PersistableYearMonth in project mica2 by obiba.

the class StudySummaryDtos method asDto.

@NotNull
Mica.DataCollectionEventSummaryDto asDto(@NotNull DataCollectionEvent dce) {
    Mica.DataCollectionEventSummaryDto.Builder builder = Mica.DataCollectionEventSummaryDto.newBuilder().setId(dce.getId()).addAllName(localizedStringDtos.asDto(dce.getName()));
    if (dce.getDescription() != null)
        builder.addAllDescription(localizedStringDtos.asDto(dce.getDescription()));
    if (dce.hasModel())
        builder.setContent(JSONUtils.toJSON(dce.getModel()));
    if (dce.hasStart()) {
        PersistableYearMonth start = dce.getStart();
        builder.setStart(start.getDay() != null ? start.getDay().format(DateTimeFormatter.ISO_DATE) : dce.getStart().getYearMonth());
    }
    if (dce.hasEnd()) {
        PersistableYearMonth end = dce.getEnd();
        builder.setEnd(end.getDay() != null ? end.getDay().format(DateTimeFormatter.ISO_DATE) : end.getYearMonth());
    }
    return builder.build();
}
Also used : PersistableYearMonth(org.obiba.mica.study.date.PersistableYearMonth) NotNull(javax.validation.constraints.NotNull)

Example 2 with PersistableYearMonth

use of org.obiba.mica.study.date.PersistableYearMonth in project mica2 by obiba.

the class PersistableDateTest method test_year_month_day_creation_format.

@Test
public void test_year_month_day_creation_format() {
    PersistableYearMonth ym = PersistableYearMonth.of(2010, 2, LocalDate.parse("2010-02-22", DateTimeFormatter.ISO_DATE));
    assertThat(ym.getYearMonth()).isEqualTo("2010-02");
    assertThat(ym.getDay().getDayOfMonth()).isEqualTo(22);
}
Also used : PersistableYearMonth(org.obiba.mica.study.date.PersistableYearMonth) Test(org.junit.Test)

Example 3 with PersistableYearMonth

use of org.obiba.mica.study.date.PersistableYearMonth in project mica2 by obiba.

the class StudyPopulationDCECsvReportGenerator method writeEachLine.

@Override
protected void writeEachLine(CSVWriter writer) {
    studies.forEach(study -> study.getPopulationsSorted().forEach(pop -> pop.getDataCollectionEventsSorted().forEach(dce -> {
        List<String> line = Lists.newArrayList();
        line.add(study.getId());
        line.add(pop.getId());
        line.add(dce.getId());
        line.add(translate(dce.getName()));
        line.add(translate(dce.getDescription()));
        if (dce.hasStart()) {
            PersistableYearMonth start = dce.getStart();
            line.add(start.getDay() != null ? start.getDay().format(DateTimeFormatter.ISO_DATE) : dce.getStart().getYearMonth());
        } else {
            line.add("");
        }
        if (dce.hasEnd()) {
            PersistableYearMonth end = dce.getEnd();
            line.add(end.getDay() != null ? end.getDay().format(DateTimeFormatter.ISO_DATE) : dce.getEnd().getYearMonth());
        } else {
            line.add("");
        }
        Map<String, Object> model = getModels().get(getIdKey(study, pop, dce));
        for (String key : getModelKeys()) {
            Object value = model.get(key);
            line.add(value == null ? "" : value.toString());
        }
        writer.writeNext(line.toArray(new String[line.size()]));
    })));
}
Also used : PersistableYearMonth(org.obiba.mica.study.date.PersistableYearMonth) List(java.util.List) CSVWriter(au.com.bytecode.opencsv.CSVWriter) BaseStudy(org.obiba.mica.study.domain.BaseStudy) DateTimeFormatter(java.time.format.DateTimeFormatter) Map(java.util.Map) Population(org.obiba.mica.study.domain.Population) Lists(jersey.repackaged.com.google.common.collect.Lists) DataCollectionEvent(org.obiba.mica.study.domain.DataCollectionEvent) PersistableYearMonth(org.obiba.mica.study.date.PersistableYearMonth)

Aggregations

PersistableYearMonth (org.obiba.mica.study.date.PersistableYearMonth)3 CSVWriter (au.com.bytecode.opencsv.CSVWriter)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 List (java.util.List)1 Map (java.util.Map)1 NotNull (javax.validation.constraints.NotNull)1 Lists (jersey.repackaged.com.google.common.collect.Lists)1 Test (org.junit.Test)1 BaseStudy (org.obiba.mica.study.domain.BaseStudy)1 DataCollectionEvent (org.obiba.mica.study.domain.DataCollectionEvent)1 Population (org.obiba.mica.study.domain.Population)1