Search in sources :

Example 1 with DateFilterOption

use of de.symeda.sormas.api.utils.DateFilterOption 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 DateFilterOption

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

the class SampleGridFilterForm method applyDependenciesOnNewValue.

@Override
protected void applyDependenciesOnNewValue(SampleCriteria criteria) {
    UserDto user = currentUserDto();
    ComboBox districtField = (ComboBox) getField(SampleCriteria.DISTRICT);
    if (user.getRegion() != null) {
        districtField.addItems(FacadeProvider.getDistrictFacade().getAllActiveByRegion(user.getRegion().getUuid()));
        districtField.setEnabled(true);
    } else {
        RegionReferenceDto region = criteria.getRegion();
        if (region != null) {
            districtField.addItems(FacadeProvider.getDistrictFacade().getAllActiveByRegion(region.getUuid()));
            districtField.setEnabled(true);
        } else {
            districtField.setEnabled(false);
        }
    }
    HorizontalLayout dateFilterLayout = (HorizontalLayout) getMoreFiltersContainer().getComponent(WEEK_AND_DATE_FILTER);
    EpiWeekAndDateFilterComponent<DateFilterOption> weekAndDateFilter;
    weekAndDateFilter = (EpiWeekAndDateFilterComponent<DateFilterOption>) dateFilterLayout.getComponent(0);
    weekAndDateFilter.getDateFilterOptionFilter().setValue(criteria.getDateFilterOption());
    Date sampleDateFrom = criteria.getSampleReportDateFrom();
    Date sampleDateTo = criteria.getSampleReportDateTo();
    if (DateFilterOption.EPI_WEEK.equals(criteria.getDateFilterOption())) {
        weekAndDateFilter.getWeekFromFilter().setValue(sampleDateFrom == null ? null : DateHelper.getEpiWeek(sampleDateFrom));
        weekAndDateFilter.getWeekToFilter().setValue(sampleDateTo == null ? null : DateHelper.getEpiWeek(sampleDateTo));
    } else {
        weekAndDateFilter.getDateFromFilter().setValue(sampleDateFrom);
        weekAndDateFilter.getDateToFilter().setValue(sampleDateTo);
    }
}
Also used : RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) DateFilterOption(de.symeda.sormas.api.utils.DateFilterOption) ComboBox(com.vaadin.v7.ui.ComboBox) UserDto(de.symeda.sormas.api.user.UserDto) Date(java.util.Date) HorizontalLayout(com.vaadin.ui.HorizontalLayout)

Example 3 with DateFilterOption

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

the class SampleGridFilterForm method buildWeekAndDateFilter.

private HorizontalLayout buildWeekAndDateFilter() {
    EpiWeekAndDateFilterComponent<DateFilterOption> weekAndDateFilter = new EpiWeekAndDateFilterComponent<>(false, false, null, this);
    weekAndDateFilter.getWeekFromFilter().setInputPrompt(I18nProperties.getString(Strings.promptSampleEpiWeekFrom));
    weekAndDateFilter.getWeekToFilter().setInputPrompt(I18nProperties.getString(Strings.promptSampleEpiWeekTo));
    weekAndDateFilter.getDateFromFilter().setInputPrompt(I18nProperties.getString(Strings.promptSampleDateFrom));
    weekAndDateFilter.getDateToFilter().setInputPrompt(I18nProperties.getString(Strings.promptSampleDateTo));
    addApplyHandler(e -> onApplyClick(weekAndDateFilter));
    HorizontalLayout dateFilterRowLayout = new HorizontalLayout();
    dateFilterRowLayout.setSpacing(true);
    dateFilterRowLayout.setSizeUndefined();
    dateFilterRowLayout.addComponent(weekAndDateFilter);
    return dateFilterRowLayout;
}
Also used : DateFilterOption(de.symeda.sormas.api.utils.DateFilterOption) EpiWeekAndDateFilterComponent(de.symeda.sormas.ui.utils.EpiWeekAndDateFilterComponent) HorizontalLayout(com.vaadin.ui.HorizontalLayout)

Example 4 with DateFilterOption

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

the class SampleGridFilterForm method onApplyClick.

private void onApplyClick(EpiWeekAndDateFilterComponent<DateFilterOption> weekAndDateFilter) {
    SampleCriteria criteria = getValue();
    DateFilterOption dateFilterOption = (DateFilterOption) weekAndDateFilter.getDateFilterOptionFilter().getValue();
    Date fromDate, toDate;
    if (dateFilterOption == DateFilterOption.DATE) {
        Date dateFrom = weekAndDateFilter.getDateFromFilter().getValue();
        fromDate = dateFrom != null ? DateHelper.getStartOfDay(dateFrom) : null;
        Date dateTo = weekAndDateFilter.getDateToFilter().getValue();
        toDate = dateFrom != null ? DateHelper.getEndOfDay(dateTo) : null;
    } else {
        fromDate = DateHelper.getEpiWeekStart((EpiWeek) weekAndDateFilter.getWeekFromFilter().getValue());
        toDate = DateHelper.getEpiWeekEnd((EpiWeek) weekAndDateFilter.getWeekToFilter().getValue());
    }
    if ((fromDate != null && toDate != null) || (fromDate == null && toDate == null)) {
        criteria.reportDateBetween(fromDate, toDate, dateFilterOption);
    } else {
        weekAndDateFilter.setNotificationsForMissingFilters();
    }
}
Also used : DateFilterOption(de.symeda.sormas.api.utils.DateFilterOption) SampleCriteria(de.symeda.sormas.api.sample.SampleCriteria) Date(java.util.Date) EpiWeek(de.symeda.sormas.api.utils.EpiWeek)

Example 5 with DateFilterOption

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

the class DashboardFilterLayout method createCustomDateFilterLayout.

private HorizontalLayout createCustomDateFilterLayout() {
    // Custom filter
    customDateFilterLayout = new HorizontalLayout();
    customDateFilterLayout.setSpacing(true);
    customDateFilterLayout.setVisible(false);
    // 'Apply custom filter' button
    Button applyButton = ButtonHelper.createButton(Captions.dashboardApplyCustomFilter, null, CssStyles.FORCE_CAPTION, CssStyles.BUTTON_FILTER_LIGHT);
    // Date & Epi Week filter
    EpiWeekAndDateFilterComponent<NewCaseDateType> weekAndDateFilter = new EpiWeekAndDateFilterComponent<>(true, true, I18nProperties.getString(Strings.infoCaseDate), null);
    customDateFilterLayout.addComponents(weekAndDateFilter, applyButton);
    // Apply button listener
    applyButton.addClickListener(e -> {
        currentDateFilterType = DateFilterType.CUSTOM;
        DateFilterOption dateFilterOption = (DateFilterOption) weekAndDateFilter.getDateFilterOptionFilter().getValue();
        Date fromDate = null;
        Date toDate = null;
        EpiWeek fromWeek = null;
        EpiWeek toWeek = null;
        if (dateFilterOption == DateFilterOption.DATE) {
            fromDate = weekAndDateFilter.getDateFromFilter().getValue();
            toDate = weekAndDateFilter.getDateToFilter().getValue();
            setDateFilter(DateHelper.getStartOfDay(fromDate), DateHelper.getEndOfDay(toDate));
        } else {
            fromWeek = (EpiWeek) weekAndDateFilter.getWeekFromFilter().getValue();
            toWeek = (EpiWeek) weekAndDateFilter.getWeekToFilter().getValue();
            setDateFilter(DateHelper.getEpiWeekStart(fromWeek), DateHelper.getEpiWeekEnd(toWeek));
        }
        if ((fromDate != null && toDate != null) || (fromWeek != null && toWeek != null)) {
            if (dateFilterOption == DateFilterOption.DATE) {
                btnCurrentPeriod.setCaption(DateFormatHelper.buildPeriodString(fromDate, toDate));
                int activePeriodLength = DateHelper.getDaysBetween(fromDate, toDate);
                btnPeriodBefore.setCaption(String.format(I18nProperties.getCaption(Captions.dashboardPeriodBefore), DateFormatHelper.buildPeriodString(DateHelper.subtractDays(fromDate, activePeriodLength), DateHelper.subtractDays(toDate, activePeriodLength))));
                btnPeriodLastYear.setCaption(String.format(I18nProperties.getCaption(Captions.dashboardSamePeriodLastYear), DateFormatHelper.buildPeriodString(DateHelper.subtractYears(fromDate, 1), DateHelper.subtractYears(toDate, 1))));
            } else {
                btnCurrentPeriod.setCaption(fromWeek.toShortString() + " - " + toWeek.toShortString());
                Date firstEpiWeekStart = DateHelper.getEpiWeekStart(fromWeek);
                Date lastEpiWeekStart = DateHelper.getEpiWeekStart(toWeek);
                int epiWeeksBetween = DateHelper.getWeeksBetween(firstEpiWeekStart, lastEpiWeekStart);
                btnPeriodBefore.setCaption(String.format(I18nProperties.getCaption(Captions.dashboardPeriodBefore), DateHelper.getEpiWeek(DateHelper.subtractWeeks(firstEpiWeekStart, epiWeeksBetween)).toShortString() + " - " + DateHelper.getEpiWeek(DateHelper.subtractWeeks(lastEpiWeekStart, epiWeeksBetween)).toShortString()));
                btnPeriodLastYear.setCaption(String.format(I18nProperties.getCaption(Captions.dashboardSamePeriodLastYear), DateHelper.getEpiWeekYearBefore(fromWeek).toShortString() + " - " + DateHelper.getEpiWeekYearBefore(toWeek).toShortString()));
            }
            updateComparisonButtons(DateFilterType.CUSTOM, null, null, true);
        } else {
            if (dateFilterOption == DateFilterOption.DATE) {
                new Notification(I18nProperties.getString(Strings.headingMissingDateFilter), I18nProperties.getString(Strings.messageMissingDateFilter), Type.ERROR_MESSAGE, false).show(Page.getCurrent());
            } else {
                new Notification(I18nProperties.getString(Strings.headingMissingEpiWeekFilter), I18nProperties.getString(Strings.messageMissingEpiWeekFilter), Type.ERROR_MESSAGE, false).show(Page.getCurrent());
            }
        }
    });
    return customDateFilterLayout;
}
Also used : NewCaseDateType(de.symeda.sormas.api.caze.NewCaseDateType) PopupButton(org.vaadin.hene.popupbutton.PopupButton) Button(com.vaadin.ui.Button) DateFilterOption(de.symeda.sormas.api.utils.DateFilterOption) Date(java.util.Date) Notification(com.vaadin.ui.Notification) HorizontalLayout(com.vaadin.ui.HorizontalLayout) EpiWeekAndDateFilterComponent(de.symeda.sormas.ui.utils.EpiWeekAndDateFilterComponent) EpiWeek(de.symeda.sormas.api.utils.EpiWeek)

Aggregations

DateFilterOption (de.symeda.sormas.api.utils.DateFilterOption)16 Date (java.util.Date)11 EpiWeek (de.symeda.sormas.api.utils.EpiWeek)9 HorizontalLayout (com.vaadin.ui.HorizontalLayout)8 EpiWeekAndDateFilterComponent (de.symeda.sormas.ui.utils.EpiWeekAndDateFilterComponent)3 Button (com.vaadin.ui.Button)2 Notification (com.vaadin.ui.Notification)2 EventCriteria (de.symeda.sormas.api.event.EventCriteria)2 CriteriaDateType (de.symeda.sormas.api.utils.criteria.CriteriaDateType)2 ComboBox (com.vaadin.v7.ui.ComboBox)1 CaseCriteria (de.symeda.sormas.api.caze.CaseCriteria)1 NewCaseDateType (de.symeda.sormas.api.caze.NewCaseDateType)1 ContactCriteria (de.symeda.sormas.api.contact.ContactCriteria)1 ContactDateType (de.symeda.sormas.api.contact.ContactDateType)1 EventCriteriaDateType (de.symeda.sormas.api.event.EventCriteriaDateType)1 ImmunizationCriteria (de.symeda.sormas.api.immunization.ImmunizationCriteria)1 ImmunizationDateType (de.symeda.sormas.api.immunization.ImmunizationDateType)1 RegionReferenceDto (de.symeda.sormas.api.infrastructure.region.RegionReferenceDto)1 SampleCriteria (de.symeda.sormas.api.sample.SampleCriteria)1 TaskCriteria (de.symeda.sormas.api.task.TaskCriteria)1