Search in sources :

Example 1 with UserProvider

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

the class ImmunizationController method getImmunizationCreateComponent.

private CommitDiscardWrapperComponent<ImmunizationCreationForm> getImmunizationCreateComponent() {
    UserProvider currentUserProvider = UserProvider.getCurrent();
    if (currentUserProvider != null) {
        ImmunizationCreationForm createForm = new ImmunizationCreationForm();
        ImmunizationDto immunization = ImmunizationDto.build(null);
        immunization.setReportingUser(currentUserProvider.getUserReference());
        createForm.setValue(immunization);
        final CommitDiscardWrapperComponent<ImmunizationCreationForm> viewComponent = new CommitDiscardWrapperComponent<>(createForm, currentUserProvider.hasUserRight(UserRight.IMMUNIZATION_CREATE), createForm.getFieldGroup());
        viewComponent.addCommitListener(() -> {
            if (!createForm.getFieldGroup().isModified()) {
                final ImmunizationDto dto = createForm.getValue();
                PersonDto searchedPerson = createForm.getSearchedPerson();
                if (searchedPerson != null) {
                    dto.setPerson(searchedPerson.toReference());
                    selectOrCreateimmunizationForPerson(dto, searchedPerson.toReference());
                } else {
                    final PersonDto person = createForm.getPerson();
                    ControllerProvider.getPersonController().selectOrCreatePerson(person, I18nProperties.getString(Strings.infoSelectOrCreatePersonForImmunization), selectedPerson -> {
                        if (selectedPerson != null) {
                            selectOrCreateimmunizationForPerson(dto, selectedPerson);
                        }
                    }, true);
                }
            }
        });
        return viewComponent;
    }
    return null;
}
Also used : ImmunizationDto(de.symeda.sormas.api.immunization.ImmunizationDto) UserProvider(de.symeda.sormas.ui.UserProvider) ImmunizationCreationForm(de.symeda.sormas.ui.immunization.components.form.ImmunizationCreationForm) PersonDto(de.symeda.sormas.api.person.PersonDto) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent)

Example 2 with UserProvider

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

the class ImmunizationController method getImmunizationDataEditComponent.

public CommitDiscardWrapperComponent<ImmunizationDataForm> getImmunizationDataEditComponent(ImmunizationDto immunizationDto) {
    ImmunizationDataForm immunizationDataForm = new ImmunizationDataForm(immunizationDto.isPseudonymized(), immunizationDto.getRelatedCase());
    immunizationDataForm.setValue(immunizationDto);
    UserProvider currentUserProvider = UserProvider.getCurrent();
    CommitDiscardWrapperComponent<ImmunizationDataForm> editComponent = new CommitDiscardWrapperComponent<ImmunizationDataForm>(immunizationDataForm, currentUserProvider != null && currentUserProvider.hasUserRight(UserRight.IMMUNIZATION_EDIT), immunizationDataForm.getFieldGroup()) {

        @Override
        public void discard() {
            immunizationDataForm.discard();
            super.discard();
        }
    };
    AutomaticDeletionInfoDto automaticDeletionInfoDto = FacadeProvider.getImmunizationFacade().getAutomaticDeletionInfo(immunizationDto.getUuid());
    if (automaticDeletionInfoDto != null) {
        editComponent.getButtonsPanel().addComponentAsFirst(new AutomaticDeletionLabel(automaticDeletionInfoDto));
    }
    editComponent.addCommitListener(() -> {
        if (!immunizationDataForm.getFieldGroup().isModified()) {
            ImmunizationDto immunizationDtoValue = immunizationDataForm.getValue();
            List<ImmunizationDto> similarImmunizations = findSimilarImmunizations(immunizationDtoValue);
            if (similarImmunizations.isEmpty()) {
                FacadeProvider.getImmunizationFacade().save(immunizationDtoValue);
                if (immunizationDtoValue.getImmunizationStatus() == ImmunizationStatus.ACQUIRED) {
                    NotificationHelper.showNotification(I18nProperties.getString(Strings.messageImmunizationSavedVaccinationStatusUpdated), Notification.Type.WARNING_MESSAGE, -1);
                } else {
                    Notification.show(I18nProperties.getString(Strings.messageImmunizationSaved), Notification.Type.WARNING_MESSAGE);
                }
                SormasUI.refreshView();
            } else {
                showSimilarImmunizationPopup(immunizationDtoValue, similarImmunizations.get(0), this::saveImmunization);
            }
        }
    });
    // Initialize 'Delete' button
    if (UserProvider.getCurrent().hasUserRight(UserRight.IMMUNIZATION_DELETE)) {
        editComponent.addDeleteListener(() -> {
            FacadeProvider.getImmunizationFacade().deleteImmunization(immunizationDto.getUuid());
            UI.getCurrent().getNavigator().navigateTo(ImmunizationsView.VIEW_NAME);
        }, I18nProperties.getString(Strings.entityImmunization));
    }
    // Initialize 'Archive' button
    if (UserProvider.getCurrent().hasUserRight(UserRight.IMMUNIZATION_ARCHIVE)) {
        boolean archived = FacadeProvider.getImmunizationFacade().isArchived(immunizationDto.getUuid());
        Button archiveButton = ButtonHelper.createButton(archived ? Captions.actionDearchive : Captions.actionArchive, e -> {
            if (editComponent.isModified()) {
                editComponent.commit();
            }
            if (archived) {
                ControllerProvider.getArchiveController().dearchiveEntity(immunizationDto, FacadeProvider.getImmunizationFacade(), Strings.headingDearchiveImmunization, Strings.confirmationDearchiveImmunization, Strings.entityImmunization, Strings.messageImmunizationDearchived, () -> navigateToImmunization(immunizationDto.getUuid()));
            } else {
                ControllerProvider.getArchiveController().archiveEntity(immunizationDto, FacadeProvider.getImmunizationFacade(), Strings.headingArchiveImmunization, Strings.confirmationArchiveImmunization, Strings.entityImmunization, Strings.messageImmunizationArchived, () -> navigateToImmunization(immunizationDto.getUuid()));
            }
        }, ValoTheme.BUTTON_LINK);
        editComponent.getButtonsPanel().addComponentAsFirst(archiveButton);
        editComponent.getButtonsPanel().setComponentAlignment(archiveButton, Alignment.BOTTOM_LEFT);
    }
    return editComponent;
}
Also used : ImmunizationDto(de.symeda.sormas.api.immunization.ImmunizationDto) UserProvider(de.symeda.sormas.ui.UserProvider) Button(com.vaadin.ui.Button) ImmunizationDataForm(de.symeda.sormas.ui.immunization.components.form.ImmunizationDataForm) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) AutomaticDeletionInfoDto(de.symeda.sormas.api.deletionconfiguration.AutomaticDeletionInfoDto) AutomaticDeletionLabel(de.symeda.sormas.ui.utils.components.automaticdeletion.AutomaticDeletionLabel)

Example 3 with UserProvider

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

the class EventGroupMemberList method drawDisplayedEntries.

@Override
protected void drawDisplayedEntries() {
    List<EventIndexDto> displayedEntries = getDisplayedEntries();
    for (int i = 0, displayedEntriesSize = displayedEntries.size(); i < displayedEntriesSize; i++) {
        EventIndexDto event = displayedEntries.get(i);
        EventGroupMemberListEntry listEntry = new EventGroupMemberListEntry(event);
        UserProvider user = UserProvider.getCurrent();
        if (user.hasUserRight(UserRight.EVENTGROUP_LINK)) {
            listEntry.addUnlinkEventListener(i, (ClickListener) clickEvent -> {
                if (!user.hasNationalJurisdictionLevel() && !user.hasRegion(new RegionReferenceDto(event.getRegionUuid()))) {
                    new Notification(I18nProperties.getString(Strings.headingEventGroupUnlinkEventIssue), I18nProperties.getString(Strings.errorEventFromAnotherJurisdiction), Notification.Type.ERROR_MESSAGE, false).show(Page.getCurrent());
                    return;
                }
                ControllerProvider.getEventGroupController().unlinkEventGroup(event.toReference(), eventGroupReference);
                reload();
            });
        }
        if (user.hasUserRight(UserRight.EVENTGROUP_EDIT)) {
            listEntry.addEditListener(i, (ClickListener) clickEvent -> ControllerProvider.getEventController().navigateToData(listEntry.getEvent().getUuid()));
        }
        listLayout.addComponent(listEntry);
    }
}
Also used : EventIndexDto(de.symeda.sormas.api.event.EventIndexDto) PaginationList(de.symeda.sormas.ui.utils.PaginationList) ClickListener(com.vaadin.ui.Button.ClickListener) FacadeProvider(de.symeda.sormas.api.FacadeProvider) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) EventGroupReferenceDto(de.symeda.sormas.api.event.EventGroupReferenceDto) Captions(de.symeda.sormas.api.i18n.Captions) ControllerProvider(de.symeda.sormas.ui.ControllerProvider) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) UserRight(de.symeda.sormas.api.user.UserRight) List(java.util.List) EventCriteria(de.symeda.sormas.api.event.EventCriteria) Notification(com.vaadin.ui.Notification) Page(com.vaadin.server.Page) Label(com.vaadin.ui.Label) Strings(de.symeda.sormas.api.i18n.Strings) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) UserProvider(de.symeda.sormas.ui.UserProvider) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) UserProvider(de.symeda.sormas.ui.UserProvider) EventIndexDto(de.symeda.sormas.api.event.EventIndexDto) Notification(com.vaadin.ui.Notification)

Example 4 with UserProvider

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

the class EventGroupList method drawDisplayedEntries.

@Override
protected void drawDisplayedEntries() {
    EventDto event = FacadeProvider.getEventFacade().getEventByUuid(this.event.getUuid(), false);
    List<EventGroupIndexDto> displayedEntries = getDisplayedEntries();
    for (int i = 0, displayedEntriesSize = displayedEntries.size(); i < displayedEntriesSize; i++) {
        EventGroupIndexDto eventGroup = displayedEntries.get(i);
        EventGroupListEntry listEntry = new EventGroupListEntry(eventGroup);
        UserProvider userProvider = UserProvider.getCurrent();
        if (userProvider != null && userProvider.hasUserRight(UserRight.EVENTGROUP_LINK)) {
            listEntry.addUnlinkEventListener(i, (ClickListener) clickEvent -> {
                if (!userProvider.hasNationalJurisdictionLevel() && !userProvider.hasRegion(event.getEventLocation().getRegion())) {
                    new Notification(I18nProperties.getString(Strings.headingEventGroupUnlinkEventIssue), I18nProperties.getString(Strings.errorEventFromAnotherJurisdiction), Notification.Type.ERROR_MESSAGE, false).show(Page.getCurrent());
                    return;
                }
                ControllerProvider.getEventGroupController().unlinkEventGroup(this.event, listEntry.getEventGroup().toReference());
                reload();
            });
        }
        if (userProvider != null && userProvider.hasUserRight(UserRight.EVENTGROUP_EDIT)) {
            listEntry.addEditListener(i, (ClickListener) clickEvent -> {
                ControllerProvider.getEventGroupController().navigateToData(listEntry.getEventGroup().getUuid());
            });
        }
        listEntry.addListEventsListener(i, (ClickListener) clickEvent -> {
            EventCriteria eventCriteria = new EventCriteria();
            eventCriteria.setEventGroup(listEntry.getEventGroup().toReference());
            ControllerProvider.getEventController().navigateTo(eventCriteria);
        });
        listLayout.addComponent(listEntry);
    }
}
Also used : PaginationList(de.symeda.sormas.ui.utils.PaginationList) EventGroupIndexDto(de.symeda.sormas.api.event.EventGroupIndexDto) ClickListener(com.vaadin.ui.Button.ClickListener) FacadeProvider(de.symeda.sormas.api.FacadeProvider) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) EntityRelevanceStatus(de.symeda.sormas.api.EntityRelevanceStatus) EventDto(de.symeda.sormas.api.event.EventDto) EventGroupCriteria(de.symeda.sormas.api.event.EventGroupCriteria) ControllerProvider(de.symeda.sormas.ui.ControllerProvider) UserRight(de.symeda.sormas.api.user.UserRight) List(java.util.List) EventCriteria(de.symeda.sormas.api.event.EventCriteria) Notification(com.vaadin.ui.Notification) EventReferenceDto(de.symeda.sormas.api.event.EventReferenceDto) Page(com.vaadin.server.Page) Label(com.vaadin.ui.Label) Strings(de.symeda.sormas.api.i18n.Strings) UserProvider(de.symeda.sormas.ui.UserProvider) UserProvider(de.symeda.sormas.ui.UserProvider) EventDto(de.symeda.sormas.api.event.EventDto) EventCriteria(de.symeda.sormas.api.event.EventCriteria) Notification(com.vaadin.ui.Notification) EventGroupIndexDto(de.symeda.sormas.api.event.EventGroupIndexDto)

Example 5 with UserProvider

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

Aggregations

UserProvider (de.symeda.sormas.ui.UserProvider)22 Button (com.vaadin.ui.Button)7 Label (com.vaadin.ui.Label)7 FacadeProvider (de.symeda.sormas.api.FacadeProvider)6 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)6 UserRight (de.symeda.sormas.api.user.UserRight)6 ControllerProvider (de.symeda.sormas.ui.ControllerProvider)6 RegionReferenceDto (de.symeda.sormas.api.infrastructure.region.RegionReferenceDto)5 PaginationList (de.symeda.sormas.ui.utils.PaginationList)5 List (java.util.List)5 Notification (com.vaadin.ui.Notification)4 EventCriteria (de.symeda.sormas.api.event.EventCriteria)4 Captions (de.symeda.sormas.api.i18n.Captions)4 Strings (de.symeda.sormas.api.i18n.Strings)4 CommitDiscardWrapperComponent (de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent)4 ClickListener (com.vaadin.ui.Button.ClickListener)3 CustomLayout (com.vaadin.ui.CustomLayout)3 HorizontalLayout (com.vaadin.ui.HorizontalLayout)3 VerticalLayout (com.vaadin.ui.VerticalLayout)3 CaseReferenceDto (de.symeda.sormas.api.caze.CaseReferenceDto)3