Search in sources :

Example 1 with EpiWeekAndDateFilterComponent

use of de.symeda.sormas.ui.utils.EpiWeekAndDateFilterComponent in project SORMAS-Project by hzi-braunschweig.

the class CaseFilterForm method streamFieldsForEmptyCheck.

@SuppressWarnings("rawtypes")
@Override
protected Stream<Field> streamFieldsForEmptyCheck(CustomLayout layout) {
    HorizontalLayout dateFilterLayout = (HorizontalLayout) getMoreFiltersContainer().getComponent(WEEK_AND_DATE_FILTER);
    @SuppressWarnings("unchecked") EpiWeekAndDateFilterComponent<NewCaseDateType> weekAndDateFilter = (EpiWeekAndDateFilterComponent<NewCaseDateType>) dateFilterLayout.getComponent(0);
    return super.streamFieldsForEmptyCheck(layout).filter(f -> f != weekAndDateFilter.getDateFilterOptionFilter());
}
Also used : NewCaseDateType(de.symeda.sormas.api.caze.NewCaseDateType) HorizontalLayout(com.vaadin.ui.HorizontalLayout) EpiWeekAndDateFilterComponent(de.symeda.sormas.ui.utils.EpiWeekAndDateFilterComponent)

Example 2 with EpiWeekAndDateFilterComponent

use of de.symeda.sormas.ui.utils.EpiWeekAndDateFilterComponent 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 3 with EpiWeekAndDateFilterComponent

use of de.symeda.sormas.ui.utils.EpiWeekAndDateFilterComponent 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)

Example 4 with EpiWeekAndDateFilterComponent

use of de.symeda.sormas.ui.utils.EpiWeekAndDateFilterComponent in project SORMAS-Project by hzi-braunschweig.

the class ContactsFilterForm method buildWeekAndDateFilter.

private HorizontalLayout buildWeekAndDateFilter() {
    EpiWeekAndDateFilterComponent<ContactDateType> weekAndDateFilter = new EpiWeekAndDateFilterComponent<>(false, false, null, ContactDateType.values(), I18nProperties.getString(Strings.promptContactDateType), null, this);
    weekAndDateFilter.getWeekFromFilter().setInputPrompt(I18nProperties.getString(Strings.promptContactEpiWeekFrom));
    weekAndDateFilter.getWeekToFilter().setInputPrompt(I18nProperties.getString(Strings.promptContactEpiWeekTo));
    weekAndDateFilter.getDateFromFilter().setInputPrompt(I18nProperties.getString(Strings.promptContactDateFrom));
    weekAndDateFilter.getDateToFilter().setInputPrompt(I18nProperties.getString(Strings.promptContactDateTo));
    addApplyHandler(e -> onApplyClick(weekAndDateFilter));
    HorizontalLayout dateFilterRowLayout = new HorizontalLayout();
    dateFilterRowLayout.setSpacing(true);
    dateFilterRowLayout.setSizeUndefined();
    dateFilterRowLayout.addComponent(weekAndDateFilter);
    return dateFilterRowLayout;
}
Also used : ContactDateType(de.symeda.sormas.api.contact.ContactDateType) EpiWeekAndDateFilterComponent(de.symeda.sormas.ui.utils.EpiWeekAndDateFilterComponent) HorizontalLayout(com.vaadin.ui.HorizontalLayout)

Example 5 with EpiWeekAndDateFilterComponent

use of de.symeda.sormas.ui.utils.EpiWeekAndDateFilterComponent in project SORMAS-Project by hzi-braunschweig.

the class ContactsFilterForm method applyDependenciesOnNewValue.

@Override
protected void applyDependenciesOnNewValue(ContactCriteria newValue) {
    final RegionReferenceDto region = newValue.getRegion();
    final DistrictReferenceDto district = newValue.getDistrict();
    applyRegionAndDistrictFilterDependency(region, ContactCriteria.DISTRICT, district, ContactCriteria.COMMUNITY);
    final UserDto user = currentUserDto();
    ComboBox officerField = getField(ContactCriteria.CONTACT_OFFICER);
    if (user.getRegion() != null) {
        officerField.addItems(FacadeProvider.getUserFacade().getUsersByRegionAndRights(user.getRegion(), newValue.getDisease(), UserRight.CONTACT_RESPONSIBLE));
    } else if (region != null) {
        officerField.addItems(FacadeProvider.getUserFacade().getUsersByRegionAndRights(region, newValue.getDisease(), UserRight.CONTACT_RESPONSIBLE));
    } else {
        officerField.removeAllItems();
    }
    ComboBox birthDateDD = getField(ContactCriteria.BIRTHDATE_DD);
    if (getField(ContactCriteria.BIRTHDATE_YYYY).getValue() != null && getField(ContactCriteria.BIRTHDATE_MM).getValue() != null) {
        birthDateDD.addItems(DateHelper.getDaysInMonth((Integer) getField(ContactCriteria.BIRTHDATE_MM).getValue(), (Integer) getField(ContactCriteria.BIRTHDATE_YYYY).getValue()));
        birthDateDD.setEnabled(true);
    } else {
        birthDateDD.clear();
        birthDateDD.setEnabled(false);
    }
    // Date/Epi week filter
    HorizontalLayout dateFilterLayout = (HorizontalLayout) getMoreFiltersContainer().getComponent(WEEK_AND_DATE_FILTER);
    @SuppressWarnings("unchecked") EpiWeekAndDateFilterComponent<NewCaseDateType> weekAndDateFilter = (EpiWeekAndDateFilterComponent<NewCaseDateType>) dateFilterLayout.getComponent(0);
    ContactDateType contactDateType = newValue.getReportDateFrom() != null ? ContactDateType.REPORT_DATE : newValue.getLastContactDateFrom() != null ? ContactDateType.LAST_CONTACT_DATE : null;
    weekAndDateFilter.getDateTypeSelector().setValue(contactDateType);
    weekAndDateFilter.getDateFilterOptionFilter().setValue(newValue.getDateFilterOption());
    Date dateFrom = contactDateType == ContactDateType.REPORT_DATE ? newValue.getReportDateFrom() : contactDateType == ContactDateType.LAST_CONTACT_DATE ? newValue.getLastContactDateFrom() : null;
    Date dateTo = contactDateType == ContactDateType.REPORT_DATE ? newValue.getReportDateTo() : contactDateType == ContactDateType.LAST_CONTACT_DATE ? newValue.getLastContactDateTo() : null;
    if (DateFilterOption.EPI_WEEK.equals(newValue.getDateFilterOption())) {
        weekAndDateFilter.getWeekFromFilter().setValue(dateFrom == null ? null : DateHelper.getEpiWeek(dateFrom));
        weekAndDateFilter.getWeekToFilter().setValue(dateTo == null ? null : DateHelper.getEpiWeek(dateTo));
    } else {
        weekAndDateFilter.getDateFromFilter().setValue(dateFrom);
        weekAndDateFilter.getDateToFilter().setValue(dateTo);
    }
    if (StringUtils.isBlank(newValue.getEventLike())) {
        clearAndDisableFields(ContactCriteria.ONLY_CONTACTS_SHARING_EVENT_WITH_SOURCE_CASE);
    } else {
        enableFields(ContactCriteria.ONLY_CONTACTS_SHARING_EVENT_WITH_SOURCE_CASE);
    }
    ComboBox diseaseField = getField(ContactIndexDto.DISEASE);
    ComboBox diseaseVariantField = getField(ContactCriteria.DISEASE_VARIANT);
    Disease disease = (Disease) diseaseField.getValue();
    if (disease == null) {
        FieldHelper.updateItems(diseaseVariantField, Collections.emptyList());
        FieldHelper.setEnabled(false, diseaseVariantField);
    } else {
        List<DiseaseVariant> diseaseVariants = FacadeProvider.getCustomizableEnumFacade().getEnumValues(CustomizableEnumType.DISEASE_VARIANT, disease);
        FieldHelper.updateItems(diseaseVariantField, diseaseVariants);
        FieldHelper.setEnabled(CollectionUtils.isNotEmpty(diseaseVariants), diseaseVariantField);
    }
}
Also used : ContactDateType(de.symeda.sormas.api.contact.ContactDateType) NewCaseDateType(de.symeda.sormas.api.caze.NewCaseDateType) Disease(de.symeda.sormas.api.Disease) DiseaseVariant(de.symeda.sormas.api.disease.DiseaseVariant) ComboBox(com.vaadin.v7.ui.ComboBox) UserDto(de.symeda.sormas.api.user.UserDto) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) Date(java.util.Date) HorizontalLayout(com.vaadin.ui.HorizontalLayout) EpiWeekAndDateFilterComponent(de.symeda.sormas.ui.utils.EpiWeekAndDateFilterComponent) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto)

Aggregations

HorizontalLayout (com.vaadin.ui.HorizontalLayout)16 EpiWeekAndDateFilterComponent (de.symeda.sormas.ui.utils.EpiWeekAndDateFilterComponent)16 NewCaseDateType (de.symeda.sormas.api.caze.NewCaseDateType)8 Date (java.util.Date)5 ComboBox (com.vaadin.v7.ui.ComboBox)3 ImmunizationDateType (de.symeda.sormas.api.immunization.ImmunizationDateType)3 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)3 RegionReferenceDto (de.symeda.sormas.api.infrastructure.region.RegionReferenceDto)3 UserDto (de.symeda.sormas.api.user.UserDto)3 DateFilterOption (de.symeda.sormas.api.utils.DateFilterOption)3 Disease (de.symeda.sormas.api.Disease)2 ContactDateType (de.symeda.sormas.api.contact.ContactDateType)2 DiseaseVariant (de.symeda.sormas.api.disease.DiseaseVariant)2 CommunityReferenceDto (de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto)2 FacilityType (de.symeda.sormas.api.infrastructure.facility.FacilityType)2 FacilityTypeGroup (de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup)2 TaskDateType (de.symeda.sormas.api.task.TaskDateType)2 JurisdictionLevel (de.symeda.sormas.api.user.JurisdictionLevel)2 Button (com.vaadin.ui.Button)1 Notification (com.vaadin.ui.Notification)1