Search in sources :

Example 1 with EpiWeek

use of de.symeda.sormas.api.utils.EpiWeek in project SORMAS-Project by hzi-braunschweig.

the class EventSelectionField method buildWeekAndDateFilter.

public HorizontalLayout buildWeekAndDateFilter() {
    applyButton = ButtonHelper.createButton(Captions.actionApplyDateFilter, null);
    weekAndDateFilter = new EpiWeekAndDateFilterComponent<>(false, false, null, null);
    weekAndDateFilter.getWeekFromFilter().setInputPrompt(I18nProperties.getString(Strings.promptEventEpiWeekFrom));
    weekAndDateFilter.getWeekToFilter().setInputPrompt(I18nProperties.getString(Strings.promptEventEpiWeekTo));
    weekAndDateFilter.getDateFromFilter().setInputPrompt(I18nProperties.getString(Strings.promptEventDateFrom));
    weekAndDateFilter.getDateToFilter().setInputPrompt(I18nProperties.getString(Strings.promptEventDateTo));
    applyButton.addClickListener(e -> {
        DateFilterOption dateFilterOption = (DateFilterOption) weekAndDateFilter.getDateFilterOptionFilter().getValue();
        Date fromDate = null;
        Date toDate = null;
        if (dateFilterOption == DateFilterOption.DATE) {
            if (weekAndDateFilter.getDateFromFilter().getValue() != null) {
                fromDate = DateHelper.getStartOfDay(weekAndDateFilter.getDateFromFilter().getValue());
            }
            if (weekAndDateFilter.getDateToFilter().getValue() != null) {
                toDate = DateHelper.getEndOfDay(weekAndDateFilter.getDateToFilter().getValue());
            }
        } else {
            fromDate = DateHelper.getEpiWeekStart((EpiWeek) weekAndDateFilter.getWeekFromFilter().getValue());
            toDate = DateHelper.getEpiWeekEnd((EpiWeek) weekAndDateFilter.getWeekToFilter().getValue());
        }
        if (setDefaultFilters != null) {
            EventCriteria defaultCriteria = new EventCriteria();
            setDefaultFilters.accept(defaultCriteria);
            fromDate = fromDate == null ? defaultCriteria.getEventDateFrom() : fromDate;
            toDate = toDate == null ? defaultCriteria.getEventDateTo() : toDate;
        }
        applyButton.removeStyleName(ValoTheme.BUTTON_PRIMARY);
        criteria.eventDateBetween(fromDate, toDate, EventCriteriaDateType.EVENT_DATE, dateFilterOption);
        eventGrid.setCriteria(criteria);
        eventGrid.getSelectedItems();
    });
    Button resetButton = ButtonHelper.createButton(Captions.caseEventsResetDateFilter, null);
    resetButton.addClickListener(e -> {
        weekAndDateFilter.getDateFromFilter().setValue(null);
        weekAndDateFilter.getDateToFilter().setValue(null);
        weekAndDateFilter.getWeekFromFilter().setValue(null);
        weekAndDateFilter.getWeekToFilter().setValue(null);
        criteria.freeText(null);
        if (setDefaultFilters != null) {
            setDefaultFilters.accept(criteria);
        } else {
            criteria.eventDateBetween(null, null, null, DateFilterOption.DATE);
        }
        eventGrid.setCriteria(criteria);
        eventGrid.getSelectedItems();
    });
    HorizontalLayout dateFilterRowLayout = new HorizontalLayout();
    dateFilterRowLayout.setSpacing(true);
    dateFilterRowLayout.setSizeUndefined();
    dateFilterRowLayout.addComponent(weekAndDateFilter);
    dateFilterRowLayout.addComponent(applyButton);
    dateFilterRowLayout.addComponent(resetButton);
    return dateFilterRowLayout;
}
Also used : DateFilterOption(de.symeda.sormas.api.utils.DateFilterOption) Button(com.vaadin.ui.Button) EventCriteria(de.symeda.sormas.api.event.EventCriteria) Date(java.util.Date) EpiWeek(de.symeda.sormas.api.utils.EpiWeek) HorizontalLayout(com.vaadin.ui.HorizontalLayout)

Example 2 with EpiWeek

use of de.symeda.sormas.api.utils.EpiWeek in project SORMAS-Project by hzi-braunschweig.

the class EventSelectionField method forSubordinateEvent.

public static EventSelectionField forSubordinateEvent(EventDto eventDto, Set<String> excludedUuids) {
    EventSelectionField eventSelectionField = new EventSelectionField(eventDto.getDisease(), I18nProperties.getString(Strings.infoPickOrCreateSuperordinateEventForEvent), eventCriteria -> {
        eventCriteria.setExcludedUuids(excludedUuids);
        eventCriteria.eventDateBetween(EventHelper.getStartOrEndDate(eventDto.getStartDate(), eventDto.getEndDate()), null, null, DateFilterOption.DATE);
        eventCriteria.setHasNoSuperordinateEvent(Boolean.TRUE);
    });
    eventSelectionField.weekAndDateFilter.getDateFromFilter().addValueChangeListener(valueChangeEvent -> {
        Date selectedFromDate = eventSelectionField.weekAndDateFilter.getDateFromFilter().getValue();
        prepareSubordinateFilters(eventDto, eventSelectionField, selectedFromDate, eventSelectionField.weekAndDateFilter.getDateFromFilter());
    });
    eventSelectionField.weekAndDateFilter.getWeekFromFilter().addValueChangeListener(valueChangeEvent -> {
        EpiWeek epiWeek = (EpiWeek) eventSelectionField.weekAndDateFilter.getWeekFromFilter().getValue();
        Date epiWeekStartDate = DateHelper.getEpiWeekStart(epiWeek);
        prepareSubordinateFilters(eventDto, eventSelectionField, epiWeekStartDate, eventSelectionField.weekAndDateFilter.getWeekFromFilter());
    });
    return eventSelectionField;
}
Also used : Date(java.util.Date) EpiWeek(de.symeda.sormas.api.utils.EpiWeek)

Example 3 with EpiWeek

use of de.symeda.sormas.api.utils.EpiWeek in project SORMAS-Project by hzi-braunschweig.

the class EventSelectionField method forSuperordinateEvent.

public static EventSelectionField forSuperordinateEvent(EventDto eventDto, Set<String> excludedUuids) {
    EventSelectionField eventSelectionField = new EventSelectionField(eventDto.getDisease(), I18nProperties.getString(Strings.infoPickOrCreateSuperordinateEventForEvent), eventCriteria -> {
        eventCriteria.setExcludedUuids(excludedUuids);
        eventCriteria.eventDateBetween(null, EventHelper.getStartOrEndDate(eventDto.getStartDate(), eventDto.getEndDate()), null, DateFilterOption.DATE);
    });
    eventSelectionField.weekAndDateFilter.getDateToFilter().addValueChangeListener(valueChangeEvent -> {
        Date selectedToDate = eventSelectionField.weekAndDateFilter.getDateToFilter().getValue();
        prepareSuperordinateFilters(eventDto, eventSelectionField, selectedToDate, eventSelectionField.weekAndDateFilter.getDateToFilter());
    });
    eventSelectionField.weekAndDateFilter.getWeekToFilter().addValueChangeListener(valueChangeEvent -> {
        EpiWeek epiWeek = (EpiWeek) eventSelectionField.weekAndDateFilter.getWeekToFilter().getValue();
        Date epiWeekEndDate = DateHelper.getEpiWeekEnd(epiWeek);
        prepareSuperordinateFilters(eventDto, eventSelectionField, epiWeekEndDate, eventSelectionField.weekAndDateFilter.getWeekToFilter());
    });
    return eventSelectionField;
}
Also used : Date(java.util.Date) EpiWeek(de.symeda.sormas.api.utils.EpiWeek)

Example 4 with EpiWeek

use of de.symeda.sormas.api.utils.EpiWeek in project SORMAS-Project by hzi-braunschweig.

the class StatisticsHelperTest method testBuildGroupingKey.

@Test
public void testBuildGroupingKey() {
    EpiWeek epiWeek = (EpiWeek) StatisticsHelper.buildGroupingKey(1803, StatisticsCaseAttribute.REPORT_TIME, StatisticsCaseSubAttribute.EPI_WEEK_OF_YEAR, null, null, null, null);
    assertThat(epiWeek.getYear(), equalTo(18));
    assertThat(epiWeek.getWeek(), equalTo(3));
    MonthOfYear monthOfYear = (MonthOfYear) StatisticsHelper.buildGroupingKey(1811, StatisticsCaseAttribute.REPORT_TIME, StatisticsCaseSubAttribute.MONTH_OF_YEAR, null, null, null, null);
    assertThat(monthOfYear.getYear().getValue(), equalTo(18));
    assertThat(monthOfYear.getMonth(), equalTo(Month.NOVEMBER));
    QuarterOfYear quarterOfYear = (QuarterOfYear) StatisticsHelper.buildGroupingKey(182, StatisticsCaseAttribute.REPORT_TIME, StatisticsCaseSubAttribute.QUARTER_OF_YEAR, null, null, null, null);
    assertThat(quarterOfYear.getYear().getValue(), equalTo(18));
    assertThat(quarterOfYear.getQuarter().getValue(), equalTo(2));
}
Also used : MonthOfYear(de.symeda.sormas.api.MonthOfYear) QuarterOfYear(de.symeda.sormas.api.QuarterOfYear) EpiWeek(de.symeda.sormas.api.utils.EpiWeek) Test(org.junit.Test)

Example 5 with EpiWeek

use of de.symeda.sormas.api.utils.EpiWeek in project SORMAS-Project by hzi-braunschweig.

the class ReportsView method updateEpiWeeks.

private void updateEpiWeeks(int year, int week) {
    List<EpiWeek> epiWeekList = DateHelper.createEpiWeekList(year);
    for (EpiWeek epiWeek : epiWeekList) {
        epiWeekFilter.addItem(epiWeek.getWeek());
        epiWeekFilter.setItemCaption(epiWeek.getWeek(), epiWeek.toString());
    }
    epiWeekFilter.select(week);
}
Also used : EpiWeek(de.symeda.sormas.api.utils.EpiWeek)

Aggregations

EpiWeek (de.symeda.sormas.api.utils.EpiWeek)34 Date (java.util.Date)24 DateFilterOption (de.symeda.sormas.api.utils.DateFilterOption)9 WeeklyReportOfficerSummaryDto (de.symeda.sormas.api.report.WeeklyReportOfficerSummaryDto)4 Test (org.junit.Test)4 Button (com.vaadin.ui.Button)3 HorizontalLayout (com.vaadin.ui.HorizontalLayout)3 MonthOfYear (de.symeda.sormas.api.MonthOfYear)3 QuarterOfYear (de.symeda.sormas.api.QuarterOfYear)3 WeeklyReportDto (de.symeda.sormas.api.report.WeeklyReportDto)3 WeeklyReportRegionSummaryDto (de.symeda.sormas.api.report.WeeklyReportRegionSummaryDto)3 TaskCriteria (de.symeda.sormas.api.task.TaskCriteria)3 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)3 LocalDate (java.time.LocalDate)3 ArrayList (java.util.ArrayList)3 Month (de.symeda.sormas.api.Month)2 Quarter (de.symeda.sormas.api.Quarter)2 Year (de.symeda.sormas.api.Year)2 EventCriteria (de.symeda.sormas.api.event.EventCriteria)2 RegionReferenceDto (de.symeda.sormas.api.infrastructure.region.RegionReferenceDto)2