Search in sources :

Example 1 with ImmunizationDateType

use of de.symeda.sormas.api.immunization.ImmunizationDateType in project SORMAS-Project by hzi-braunschweig.

the class ImmunizationFilterForm method applyDependenciesOnNewValue.

@Override
protected void applyDependenciesOnNewValue(ImmunizationCriteria criteria) {
    final UserDto user = currentUserDto();
    UserProvider currentUserProvider = UserProvider.getCurrent();
    final JurisdictionLevel userJurisdictionLevel = currentUserProvider != null ? UserRole.getJurisdictionLevel(currentUserProvider.getUserRoles()) : null;
    final ComboBox districtField = getField(ImmunizationCriteria.DISTRICT);
    final ComboBox communityField = getField(ImmunizationCriteria.COMMUNITY);
    final ComboBox facilityTypeGroupField = getField(ImmunizationCriteria.FACILITY_TYPE_GROUP);
    final ComboBox facilityTypeField = getField(ImmunizationCriteria.FACILITY_TYPE);
    final ComboBox facilityField = getField(ImmunizationCriteria.HEALTH_FACILITY);
    // Disable all fields
    clearAndDisableFields(districtField, communityField, facilityTypeGroupField, facilityTypeField, facilityField);
    // Get initial field values according to user and criteria
    final RegionReferenceDto region = user.getRegion() == null ? criteria.getRegion() : user.getRegion();
    final DistrictReferenceDto district = user.getDistrict() == null ? criteria.getDistrict() : user.getDistrict();
    final CommunityReferenceDto community = user.getCommunity() == null ? criteria.getCommunity() : user.getCommunity();
    final FacilityTypeGroup facilityTypeGroup = criteria.getFacilityTypeGroup();
    final FacilityType facilityType = criteria.getFacilityType();
    // district
    if (region != null) {
        enableFields(districtField);
        districtField.addItems(FacadeProvider.getDistrictFacade().getAllActiveByRegion(region.getUuid()));
        // community
        if (district != null) {
            districtField.setValue(district);
            communityField.addItems(FacadeProvider.getCommunityFacade().getAllActiveByDistrict(district.getUuid()));
            enableFields(communityField);
            if (community != null) {
                communityField.setValue(community);
            }
        } else {
            clearAndDisableFields(communityField);
        }
    } else {
        clearAndDisableFields(districtField, communityField);
    }
    // facility
    if (userJurisdictionLevel == JurisdictionLevel.HEALTH_FACILITY) {
        facilityField.setValue(user.getHealthFacility());
        disableFields(facilityTypeGroupField, facilityTypeField, facilityField);
    } else if (facilityTypeGroupField != null && district != null) {
        enableFields(facilityTypeGroupField);
        FieldHelper.updateEnumData(facilityTypeGroupField, FacilityTypeGroup.getAccomodationGroups());
        if (facilityTypeGroup != null) {
            facilityTypeGroupField.setValue(facilityTypeGroup);
            enableFields(facilityTypeField);
            FieldHelper.updateEnumData(facilityTypeField, FacilityType.getAccommodationTypes(facilityTypeGroup));
            if (facilityType != null) {
                facilityTypeField.setValue(facilityType);
                enableFields(facilityField);
                if (community != null) {
                    facilityField.addItems(FacadeProvider.getFacilityFacade().getActiveFacilitiesByCommunityAndType(community, facilityType, true, false));
                } else {
                    facilityField.addItems(FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType(district, facilityType, true, false));
                }
            } else {
                disableFields(facilityField);
            }
        } else {
            disableFields(facilityTypeField);
        }
    }
    // Disable fields according to user & jurisdiction
    if (userJurisdictionLevel == JurisdictionLevel.DISTRICT) {
        clearAndDisableFields(districtField);
    } else if (userJurisdictionLevel == JurisdictionLevel.COMMUNITY) {
        clearAndDisableFields(districtField, communityField);
    } else if (userJurisdictionLevel == JurisdictionLevel.HEALTH_FACILITY) {
        clearAndDisableFields(districtField, communityField, facilityTypeGroupField, facilityTypeField, facilityField);
    }
    ComboBox birthDateDD = getField(ImmunizationCriteria.BIRTHDATE_DD);
    if (getField(ImmunizationCriteria.BIRTHDATE_YYYY).getValue() != null && getField(ImmunizationCriteria.BIRTHDATE_MM).getValue() != null) {
        birthDateDD.addItems(DateHelper.getDaysInMonth((Integer) getField(ImmunizationCriteria.BIRTHDATE_MM).getValue(), (Integer) getField(ImmunizationCriteria.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<ImmunizationDateType> weekAndDateFilter = (EpiWeekAndDateFilterComponent<ImmunizationDateType>) dateFilterLayout.getComponent(0);
    ImmunizationDateType immunizationDateType = criteria.getImmunizationDateType();
    weekAndDateFilter.getDateTypeSelector().setValue(immunizationDateType);
    weekAndDateFilter.getDateFilterOptionFilter().setValue(criteria.getDateFilterOption());
    Date dateFrom = criteria.getFromDate();
    Date dateTo = criteria.getToDate();
    if (DateFilterOption.EPI_WEEK.equals(criteria.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);
    }
}
Also used : ComboBox(com.vaadin.v7.ui.ComboBox) UserDto(de.symeda.sormas.api.user.UserDto) JurisdictionLevel(de.symeda.sormas.api.user.JurisdictionLevel) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) Date(java.util.Date) HorizontalLayout(com.vaadin.ui.HorizontalLayout) EpiWeekAndDateFilterComponent(de.symeda.sormas.ui.utils.EpiWeekAndDateFilterComponent) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) UserProvider(de.symeda.sormas.ui.UserProvider) FacilityTypeGroup(de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup) ImmunizationDateType(de.symeda.sormas.api.immunization.ImmunizationDateType) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType)

Example 2 with ImmunizationDateType

use of de.symeda.sormas.api.immunization.ImmunizationDateType in project SORMAS-Project by hzi-braunschweig.

the class ImmunizationFilterForm method buildWeekAndDateFilter.

private HorizontalLayout buildWeekAndDateFilter() {
    EpiWeekAndDateFilterComponent<ImmunizationDateType> weekAndDateFilter = new EpiWeekAndDateFilterComponent<>(false, false, null, ImmunizationDateType.values(), I18nProperties.getString(Strings.promptImmunizationDateType), null, this);
    weekAndDateFilter.getWeekFromFilter().setInputPrompt(I18nProperties.getString(Strings.promptImmunizationEpiWeekFrom));
    weekAndDateFilter.getWeekToFilter().setInputPrompt(I18nProperties.getString(Strings.promptImmunizationEpiWeekTo));
    weekAndDateFilter.getDateFromFilter().setInputPrompt(I18nProperties.getString(Strings.promptImmunizationDateFrom));
    weekAndDateFilter.getDateToFilter().setInputPrompt(I18nProperties.getString(Strings.promptImmunizationDateTo));
    addApplyHandler(e -> onApplyClick(weekAndDateFilter));
    HorizontalLayout dateFilterRowLayout = new HorizontalLayout();
    dateFilterRowLayout.setSpacing(true);
    dateFilterRowLayout.setSizeUndefined();
    dateFilterRowLayout.addComponent(weekAndDateFilter);
    return dateFilterRowLayout;
}
Also used : ImmunizationDateType(de.symeda.sormas.api.immunization.ImmunizationDateType) EpiWeekAndDateFilterComponent(de.symeda.sormas.ui.utils.EpiWeekAndDateFilterComponent) HorizontalLayout(com.vaadin.ui.HorizontalLayout)

Example 3 with ImmunizationDateType

use of de.symeda.sormas.api.immunization.ImmunizationDateType in project SORMAS-Project by hzi-braunschweig.

the class ImmunizationFilterForm method streamFieldsForEmptyCheck.

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

Example 4 with ImmunizationDateType

use of de.symeda.sormas.api.immunization.ImmunizationDateType in project SORMAS-Project by hzi-braunschweig.

the class ImmunizationFilterForm method onApplyClick.

private void onApplyClick(EpiWeekAndDateFilterComponent<ImmunizationDateType> weekAndDateFilter) {
    ImmunizationCriteria 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.setDateFilterOption(dateFilterOption);
        ImmunizationDateType immunizationDateType = (ImmunizationDateType) weekAndDateFilter.getDateTypeSelector().getValue();
        criteria.setImmunizationDateType(immunizationDateType);
        criteria.setFromDate(fromDate);
        criteria.setToDate(toDate);
    } else {
        weekAndDateFilter.setNotificationsForMissingFilters();
    }
}
Also used : ImmunizationCriteria(de.symeda.sormas.api.immunization.ImmunizationCriteria) DateFilterOption(de.symeda.sormas.api.utils.DateFilterOption) ImmunizationDateType(de.symeda.sormas.api.immunization.ImmunizationDateType) Date(java.util.Date) EpiWeek(de.symeda.sormas.api.utils.EpiWeek)

Aggregations

ImmunizationDateType (de.symeda.sormas.api.immunization.ImmunizationDateType)4 HorizontalLayout (com.vaadin.ui.HorizontalLayout)3 EpiWeekAndDateFilterComponent (de.symeda.sormas.ui.utils.EpiWeekAndDateFilterComponent)3 Date (java.util.Date)2 ComboBox (com.vaadin.v7.ui.ComboBox)1 ImmunizationCriteria (de.symeda.sormas.api.immunization.ImmunizationCriteria)1 CommunityReferenceDto (de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto)1 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)1 FacilityType (de.symeda.sormas.api.infrastructure.facility.FacilityType)1 FacilityTypeGroup (de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup)1 RegionReferenceDto (de.symeda.sormas.api.infrastructure.region.RegionReferenceDto)1 JurisdictionLevel (de.symeda.sormas.api.user.JurisdictionLevel)1 UserDto (de.symeda.sormas.api.user.UserDto)1 DateFilterOption (de.symeda.sormas.api.utils.DateFilterOption)1 EpiWeek (de.symeda.sormas.api.utils.EpiWeek)1 UserProvider (de.symeda.sormas.ui.UserProvider)1