Search in sources :

Example 21 with UserRole

use of de.symeda.sormas.api.user.UserRole in project SORMAS-Project by hzi-braunschweig.

the class UserFacadeEjb method getUsersWithSuperiorJurisdiction.

@Override
public /*
	 * Get all users with the next higher jurisdiction, whose location contains the current users location
	 * For facility users, this includes district and community users, if their district/community is identical with that of the facility
	 */
List<UserReferenceDto> getUsersWithSuperiorJurisdiction(UserDto user) {
    JurisdictionLevel superordinateJurisdiction = JurisdictionHelper.getSuperordinateJurisdiction(UserRole.getJurisdictionLevel(user.getUserRoles()));
    List<UserReference> superiorUsersList = Collections.emptyList();
    switch(superordinateJurisdiction) {
        case NATION:
            superiorUsersList = userService.getReferenceList(null, null, null, false, false, true, UserRole.getWithJurisdictionLevels(superordinateJurisdiction));
            break;
        case REGION:
            superiorUsersList = userService.getReferenceList(Collections.singletonList(user.getRegion().getUuid()), null, null, false, false, true, UserRole.getWithJurisdictionLevels(superordinateJurisdiction));
            break;
        case DISTRICT:
            // if user is assigned to a facility, but that facility is not assigned to a district, show no superordinate users. Else, show users of the district (and community) in which the facility is located
            District district = null;
            Community community = null;
            List<UserRole> superordinateRoles = UserRole.getWithJurisdictionLevels(superordinateJurisdiction);
            if (user.getDistrict() != null) {
                district = districtService.getByReferenceDto(user.getDistrict());
            } else if (user.getHealthFacility() != null) {
                Facility facility = facilityService.getByReferenceDto(user.getHealthFacility());
                district = facility.getDistrict();
                community = facility.getCommunity();
                superordinateRoles.addAll(UserRole.getWithJurisdictionLevels(JurisdictionLevel.COMMUNITY));
            }
            if (community == null) {
                superiorUsersList = userService.getReferenceList(null, Collections.singletonList(district.getUuid()), null, false, false, true, superordinateRoles);
            } else if (district != null) {
                superiorUsersList = userService.getReferenceList(null, Collections.singletonList(district.getUuid()), Collections.singletonList(community.getUuid()), false, false, true, superordinateRoles);
            }
            break;
    }
    return superiorUsersList.stream().map(UserFacadeEjb::toReferenceDto).collect(Collectors.toList());
}
Also used : UserRole(de.symeda.sormas.api.user.UserRole) JurisdictionLevel(de.symeda.sormas.api.user.JurisdictionLevel) Facility(de.symeda.sormas.backend.infrastructure.facility.Facility) District(de.symeda.sormas.backend.infrastructure.district.District) Community(de.symeda.sormas.backend.infrastructure.community.Community)

Example 22 with UserRole

use of de.symeda.sormas.api.user.UserRole in project SORMAS-Project by hzi-braunschweig.

the class UserRoleConfigService method getByUserRole.

public UserRoleConfig getByUserRole(UserRole userRole) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    ParameterExpression<UserRole> userRoleParam = cb.parameter(UserRole.class, UserRoleConfig.USER_ROLE);
    CriteriaQuery<UserRoleConfig> cq = cb.createQuery(UserRoleConfig.class);
    Root<UserRoleConfig> from = cq.from(UserRoleConfig.class);
    cq.where(cb.equal(from.get(UserRoleConfig.USER_ROLE), userRoleParam));
    TypedQuery<UserRoleConfig> q = em.createQuery(cq).setParameter(userRoleParam, userRole);
    UserRoleConfig entity = q.getResultList().stream().findFirst().orElse(null);
    return entity;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) UserRole(de.symeda.sormas.api.user.UserRole)

Example 23 with UserRole

use of de.symeda.sormas.api.user.UserRole in project SORMAS-Project by hzi-braunschweig.

the class TestDataCreator method createUser.

public UserDto createUser(String regionUuid, String districtUuid, String facilityUuid, String pointOfEntryUuid, String firstName, String lastName, Language language, UserRole... roles) {
    UserDto user = UserDto.build();
    user.setFirstName(firstName);
    user.setLastName(lastName);
    user.setUserName(firstName + lastName);
    user.setUserRoles(new HashSet<UserRole>(Arrays.asList(roles)));
    user.setRegion(FacadeProvider.getRegionFacade().getReferenceByUuid(regionUuid));
    user.setDistrict(FacadeProvider.getDistrictFacade().getReferenceByUuid(districtUuid));
    user.setHealthFacility(FacadeProvider.getFacilityFacade().getReferenceByUuid(facilityUuid));
    if (pointOfEntryUuid != null) {
        PointOfEntryDto pointOfEntry = FacadeProvider.getPointOfEntryFacade().getByUuid(pointOfEntryUuid);
        if (pointOfEntry != null) {
            user.setPointOfEntry(pointOfEntry.toReference());
        }
    }
    user.setLanguage(language);
    user = FacadeProvider.getUserFacade().saveUser(user);
    return user;
}
Also used : UserRole(de.symeda.sormas.api.user.UserRole) UserDto(de.symeda.sormas.api.user.UserDto) PointOfEntryDto(de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryDto)

Example 24 with UserRole

use of de.symeda.sormas.api.user.UserRole in project SORMAS-Project by hzi-braunschweig.

the class StatisticsView method fillCaseCriteria.

private void fillCaseCriteria(boolean showCaseIncidence) {
    caseCriteria = new StatisticsCaseCriteria();
    for (StatisticsFilterComponent filterComponent : filterComponents) {
        StatisticsFilterElement filterElement = filterComponent.getFilterElement();
        switch(filterComponent.getSelectedAttribute()) {
            case SEX:
                if (filterElement.getSelectedValues() != null) {
                    List<Sex> sexes = new ArrayList<>();
                    for (TokenizableValue tokenizableValue : filterElement.getSelectedValues()) {
                        if (tokenizableValue.getValue().equals(I18nProperties.getString(Strings.notSpecified))) {
                            caseCriteria.sexUnknown(true);
                        } else {
                            sexes.add((Sex) tokenizableValue.getValue());
                        }
                    }
                    caseCriteria.sexes(sexes);
                }
                break;
            case DISEASE:
                if (filterElement.getSelectedValues() != null) {
                    List<Disease> diseases = new ArrayList<>();
                    for (TokenizableValue tokenizableValue : filterElement.getSelectedValues()) {
                        diseases.add((Disease) tokenizableValue.getValue());
                    }
                    caseCriteria.diseases(diseases);
                }
                break;
            case CLASSIFICATION:
                if (filterElement.getSelectedValues() != null) {
                    List<CaseClassification> classifications = new ArrayList<>();
                    for (TokenizableValue tokenizableValue : filterElement.getSelectedValues()) {
                        classifications.add((CaseClassification) tokenizableValue.getValue());
                    }
                    caseCriteria.classifications(classifications);
                }
                break;
            case OUTCOME:
                if (filterElement.getSelectedValues() != null) {
                    List<CaseOutcome> outcomes = new ArrayList<>();
                    for (TokenizableValue tokenizableValue : filterElement.getSelectedValues()) {
                        outcomes.add((CaseOutcome) tokenizableValue.getValue());
                    }
                    caseCriteria.outcomes(outcomes);
                }
                break;
            case AGE_INTERVAL_1_YEAR:
            case AGE_INTERVAL_5_YEARS:
            case AGE_INTERVAL_CHILDREN_COARSE:
            case AGE_INTERVAL_CHILDREN_FINE:
            case AGE_INTERVAL_CHILDREN_MEDIUM:
            case AGE_INTERVAL_BASIC:
                if (filterElement.getSelectedValues() != null) {
                    List<IntegerRange> ageIntervals = new ArrayList<>();
                    for (TokenizableValue tokenizableValue : filterElement.getSelectedValues()) {
                        ageIntervals.add((IntegerRange) tokenizableValue.getValue());
                    }
                    caseCriteria.addAgeIntervals(ageIntervals);
                    // Fill age groups if 5 years interval has been selected and case incidence is shown
                    if (showCaseIncidence && filterComponent.getSelectedAttribute() == StatisticsCaseAttribute.AGE_INTERVAL_5_YEARS) {
                        List<AgeGroup> ageGroups = new ArrayList<>();
                        for (IntegerRange ageInterval : ageIntervals) {
                            if (ageInterval.getFrom() != null || ageInterval.getTo() != null) {
                                ageGroups.add(AgeGroup.getAgeGroupFromIntegerRange(ageInterval));
                            }
                        }
                        caseCriteria.addAgeGroups(ageGroups);
                    }
                }
                break;
            case JURISDICTION:
                StatisticsFilterJurisdictionElement jurisdictionElement = (StatisticsFilterJurisdictionElement) filterElement;
                if (jurisdictionElement.getSelectedRegions() != null) {
                    List<RegionReferenceDto> regions = new ArrayList<>();
                    for (TokenizableValue tokenizableValue : jurisdictionElement.getSelectedRegions()) {
                        regions.add((RegionReferenceDto) tokenizableValue.getValue());
                    }
                    caseCriteria.regions(regions);
                }
                if (jurisdictionElement.getSelectedDistricts() != null) {
                    List<DistrictReferenceDto> districts = new ArrayList<>();
                    for (TokenizableValue tokenizableValue : jurisdictionElement.getSelectedDistricts()) {
                        districts.add((DistrictReferenceDto) tokenizableValue.getValue());
                    }
                    caseCriteria.districts(districts);
                }
                if (jurisdictionElement.getSelectedCommunities() != null) {
                    List<CommunityReferenceDto> communities = new ArrayList<>();
                    for (TokenizableValue tokenizableValue : jurisdictionElement.getSelectedCommunities()) {
                        communities.add((CommunityReferenceDto) tokenizableValue.getValue());
                    }
                    caseCriteria.communities(communities);
                }
                if (jurisdictionElement.getSelectedHealthFacilities() != null) {
                    List<FacilityReferenceDto> facilities = new ArrayList<>();
                    for (TokenizableValue tokenizableValue : jurisdictionElement.getSelectedHealthFacilities()) {
                        facilities.add((FacilityReferenceDto) tokenizableValue.getValue());
                    }
                    caseCriteria.healthFacilities(facilities);
                }
                break;
            case PLACE_OF_RESIDENCE:
                StatisticsFilterResidenceElement residenceElement = (StatisticsFilterResidenceElement) filterElement;
                if (residenceElement.getSelectedRegions() != null) {
                    List<RegionReferenceDto> regions = new ArrayList<>();
                    for (TokenizableValue tokenizableValue : residenceElement.getSelectedRegions()) {
                        regions.add((RegionReferenceDto) tokenizableValue.getValue());
                    }
                    caseCriteria.personRegions(regions);
                }
                if (residenceElement.getSelectedDistricts() != null) {
                    List<DistrictReferenceDto> districts = new ArrayList<>();
                    for (TokenizableValue tokenizableValue : residenceElement.getSelectedDistricts()) {
                        districts.add((DistrictReferenceDto) tokenizableValue.getValue());
                    }
                    caseCriteria.personDistricts(districts);
                }
                if (residenceElement.getSelectedCommunities() != null) {
                    List<CommunityReferenceDto> communities = new ArrayList<>();
                    for (TokenizableValue tokenizableValue : residenceElement.getSelectedCommunities()) {
                        communities.add((CommunityReferenceDto) tokenizableValue.getValue());
                    }
                    caseCriteria.personCommunities(communities);
                }
                if (residenceElement.getCity() != null) {
                    caseCriteria.setPersonCity(residenceElement.getCity());
                }
                if (residenceElement.getPostcode() != null) {
                    caseCriteria.setPersonPostcode(residenceElement.getPostcode());
                }
                break;
            case REPORTING_USER_ROLE:
                if (filterElement.getSelectedValues() != null) {
                    List<UserRole> reportingUserRoles = new ArrayList<>();
                    for (TokenizableValue tokenizableValue : filterElement.getSelectedValues()) {
                        reportingUserRoles.add((UserRole) tokenizableValue.getValue());
                    }
                    caseCriteria.reportingUserRoles(reportingUserRoles);
                }
                break;
            default:
                switch(filterComponent.getSelectedSubAttribute()) {
                    case YEAR:
                        if (filterElement.getSelectedValues() != null) {
                            List<Year> years = new ArrayList<>();
                            for (TokenizableValue tokenizableValue : filterElement.getSelectedValues()) {
                                years.add((Year) tokenizableValue.getValue());
                            }
                            caseCriteria.years(years, filterComponent.getSelectedAttribute());
                        }
                        break;
                    case QUARTER:
                        if (filterElement.getSelectedValues() != null) {
                            List<Quarter> quarters = new ArrayList<>();
                            for (TokenizableValue tokenizableValue : filterElement.getSelectedValues()) {
                                quarters.add((Quarter) tokenizableValue.getValue());
                            }
                            caseCriteria.quarters(quarters, filterComponent.getSelectedAttribute());
                        }
                        break;
                    case MONTH:
                        if (filterElement.getSelectedValues() != null) {
                            List<Month> months = new ArrayList<>();
                            for (TokenizableValue tokenizableValue : filterElement.getSelectedValues()) {
                                months.add((Month) tokenizableValue.getValue());
                            }
                            caseCriteria.months(months, filterComponent.getSelectedAttribute());
                        }
                        break;
                    case EPI_WEEK:
                        if (filterElement.getSelectedValues() != null) {
                            List<EpiWeek> epiWeeks = new ArrayList<>();
                            for (TokenizableValue tokenizableValue : filterElement.getSelectedValues()) {
                                epiWeeks.add((EpiWeek) tokenizableValue.getValue());
                            }
                            caseCriteria.epiWeeks(epiWeeks, filterComponent.getSelectedAttribute());
                        }
                        break;
                    case QUARTER_OF_YEAR:
                        if (filterElement.getSelectedValues() != null) {
                            List<QuarterOfYear> quartersOfYear = new ArrayList<>();
                            for (TokenizableValue tokenizableValue : filterElement.getSelectedValues()) {
                                quartersOfYear.add((QuarterOfYear) tokenizableValue.getValue());
                            }
                            caseCriteria.quartersOfYear(quartersOfYear, filterComponent.getSelectedAttribute());
                        }
                        break;
                    case MONTH_OF_YEAR:
                        if (filterElement.getSelectedValues() != null) {
                            List<MonthOfYear> monthsOfYear = new ArrayList<>();
                            for (TokenizableValue tokenizableValue : filterElement.getSelectedValues()) {
                                monthsOfYear.add((MonthOfYear) tokenizableValue.getValue());
                            }
                            caseCriteria.monthsOfYear(monthsOfYear, filterComponent.getSelectedAttribute());
                        }
                        break;
                    case EPI_WEEK_OF_YEAR:
                        if (filterElement.getSelectedValues() != null) {
                            List<EpiWeek> epiWeeksOfYear = new ArrayList<>();
                            for (TokenizableValue tokenizableValue : filterElement.getSelectedValues()) {
                                epiWeeksOfYear.add((EpiWeek) tokenizableValue.getValue());
                            }
                            caseCriteria.epiWeeksOfYear(epiWeeksOfYear, filterComponent.getSelectedAttribute());
                        }
                        break;
                    case DATE_RANGE:
                        caseCriteria.dateRange((Date) filterElement.getSelectedValues().get(0).getValue(), (Date) filterElement.getSelectedValues().get(1).getValue(), filterComponent.getSelectedAttribute());
                        break;
                    default:
                        throw new IllegalArgumentException(filterComponent.getSelectedSubAttribute().toString());
                }
        }
    }
}
Also used : Quarter(de.symeda.sormas.api.Quarter) Disease(de.symeda.sormas.api.Disease) MonthOfYear(de.symeda.sormas.api.MonthOfYear) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) Sex(de.symeda.sormas.api.person.Sex) ArrayList(java.util.ArrayList) EpiWeek(de.symeda.sormas.api.utils.EpiWeek) Month(de.symeda.sormas.api.Month) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) QuarterOfYear(de.symeda.sormas.api.QuarterOfYear) TokenizableValue(de.symeda.sormas.ui.statistics.StatisticsFilterElement.TokenizableValue) IntegerRange(de.symeda.sormas.api.IntegerRange) CaseClassification(de.symeda.sormas.api.caze.CaseClassification) CaseOutcome(de.symeda.sormas.api.caze.CaseOutcome) AgeGroup(de.symeda.sormas.api.AgeGroup) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) QuarterOfYear(de.symeda.sormas.api.QuarterOfYear) Year(de.symeda.sormas.api.Year) MonthOfYear(de.symeda.sormas.api.MonthOfYear) UserRole(de.symeda.sormas.api.user.UserRole) StatisticsCaseCriteria(de.symeda.sormas.api.statistics.StatisticsCaseCriteria)

Example 25 with UserRole

use of de.symeda.sormas.api.user.UserRole in project SORMAS-Project by hzi-braunschweig.

the class CaseBackendTest method testEditCasePermissionWhenDistrictDoesNotMatchAndCaseNotCreatedByUser.

@Test
public void testEditCasePermissionWhenDistrictDoesNotMatchAndCaseNotCreatedByUser() {
    Case caze = TestEntityCreator.createCase();
    District secondDistrict = DatabaseHelper.getDistrictDao().queryUuid(TestHelper.SECOND_DISTRICT_UUID);
    caze.setResponsibleDistrict(secondDistrict);
    UserRole userRole = UserRole.SURVEILLANCE_OFFICER;
    Set<UserRole> userRoles = new HashSet<>();
    userRoles.add(userRole);
    ConfigProvider.getUser().setUserRoles(userRoles);
    ConfigProvider.getUser().setUuid("");
    User user = ConfigProvider.getUser();
    assertFalse(CaseEditAuthorization.isCaseEditAllowed(caze));
}
Also used : User(de.symeda.sormas.app.backend.user.User) UserRole(de.symeda.sormas.api.user.UserRole) District(de.symeda.sormas.app.backend.region.District) Case(de.symeda.sormas.app.backend.caze.Case) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

UserRole (de.symeda.sormas.api.user.UserRole)29 Test (org.junit.Test)7 HashSet (java.util.HashSet)6 Case (de.symeda.sormas.app.backend.caze.Case)5 User (de.symeda.sormas.backend.user.User)5 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)5 UserDto (de.symeda.sormas.api.user.UserDto)4 User (de.symeda.sormas.app.backend.user.User)4 Predicate (javax.persistence.criteria.Predicate)4 CaseDao (de.symeda.sormas.app.backend.caze.CaseDao)3 District (de.symeda.sormas.app.backend.region.District)3 Task (de.symeda.sormas.app.backend.task.Task)3 TaskDao (de.symeda.sormas.app.backend.task.TaskDao)3 Set (java.util.Set)3 AuthProvider (de.symeda.sormas.api.AuthProvider)2 JurisdictionLevel (de.symeda.sormas.api.user.JurisdictionLevel)2 UserRight (de.symeda.sormas.api.user.UserRight)2 Community (de.symeda.sormas.app.backend.region.Community)2 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)2 RDCF (de.symeda.sormas.backend.TestDataCreator.RDCF)2