Search in sources :

Example 1 with PointOfEntry

use of de.symeda.sormas.backend.infrastructure.pointofentry.PointOfEntry in project SORMAS-Project by hzi-braunschweig.

the class StartupShutdownService method createDefaultInfrastructureData.

private void createDefaultInfrastructureData() {
    if (!configFacade.isCreateDefaultEntities()) {
        // return if isCreateDefaultEntities() is false
        logger.info("Skipping the creation of default infrastructure data");
        return;
    }
    // Region
    Region region = null;
    if (regionService.count() == 0) {
        region = defaultEntitiesCreator.createDefaultRegion(false);
        regionService.ensurePersisted(region);
    }
    // District
    District district = null;
    if (districtService.count() == 0) {
        if (region == null) {
            region = regionService.getAll().get(0);
        }
        district = defaultEntitiesCreator.createDefaultDistrict(region, false);
        districtService.ensurePersisted(district);
        region.getDistricts().add(district);
    }
    // Community
    Community community = null;
    if (communityService.count() == 0) {
        if (district == null) {
            district = districtService.getAll().get(0);
        }
        community = defaultEntitiesCreator.createDefaultCommunity(district, false);
        communityService.ensurePersisted(community);
        district.getCommunities().add(community);
    }
    // Facility
    Facility facility;
    FacilityCriteria facilityCriteria = new FacilityCriteria();
    if (facilityFacade.count(facilityCriteria) == 0) {
        if (community == null) {
            community = communityService.getAll().get(0);
        }
        if (district == null) {
            district = districtService.getAll().get(0);
        }
        if (region == null) {
            region = regionService.getAll().get(0);
        }
        facility = defaultEntitiesCreator.createDefaultFacility(region, district, community);
        facilityService.ensurePersisted(facility);
    }
    // Laboratory
    Facility laboratory;
    facilityCriteria.type(FacilityType.LABORATORY);
    if (facilityFacade.count(facilityCriteria) == 0) {
        if (community == null) {
            community = communityService.getAll().get(0);
        }
        if (district == null) {
            district = districtService.getAll().get(0);
        }
        if (region == null) {
            region = regionService.getAll().get(0);
        }
        laboratory = defaultEntitiesCreator.createDefaultLaboratory(region, district, community);
        facilityService.ensurePersisted(laboratory);
    }
    // Point of Entry
    PointOfEntry pointOfEntry;
    if (pointOfEntryService.count() == 0) {
        if (district == null) {
            district = districtService.getAll().get(0);
        }
        if (region == null) {
            region = regionService.getAll().get(0);
        }
        pointOfEntry = defaultEntitiesCreator.createDefaultPointOfEntry(region, district);
        pointOfEntryService.ensurePersisted(pointOfEntry);
    }
}
Also used : Region(de.symeda.sormas.backend.infrastructure.region.Region) FacilityCriteria(de.symeda.sormas.api.infrastructure.facility.FacilityCriteria) Facility(de.symeda.sormas.backend.infrastructure.facility.Facility) PointOfEntry(de.symeda.sormas.backend.infrastructure.pointofentry.PointOfEntry) District(de.symeda.sormas.backend.infrastructure.district.District) Community(de.symeda.sormas.backend.infrastructure.community.Community)

Example 2 with PointOfEntry

use of de.symeda.sormas.backend.infrastructure.pointofentry.PointOfEntry in project SORMAS-Project by hzi-braunschweig.

the class CaseService method createUserFilter.

@SuppressWarnings("rawtypes")
public Predicate createUserFilter(CriteriaBuilder cb, CriteriaQuery cq, From<?, Case> casePath, CaseUserFilterCriteria userFilterCriteria) {
    User currentUser = getCurrentUser();
    if (currentUser == null) {
        return null;
    }
    Predicate filterResponsible = null;
    Predicate filter = null;
    final JurisdictionLevel jurisdictionLevel = currentUser.getCalculatedJurisdictionLevel();
    if (jurisdictionLevel != JurisdictionLevel.NATION && !currentUser.hasAnyUserRole(UserRole.REST_USER, UserRole.REST_EXTERNAL_VISITS_USER)) {
        // whoever created the case or is assigned to it is allowed to access it
        if (userFilterCriteria == null || (userFilterCriteria.getIncludeCasesFromOtherJurisdictions())) {
            filterResponsible = cb.equal(casePath.get(Case.REPORTING_USER).get(User.ID), currentUser.getId());
            filterResponsible = cb.or(filterResponsible, cb.equal(casePath.get(Case.SURVEILLANCE_OFFICER).get(User.ID), currentUser.getId()));
            filterResponsible = cb.or(filterResponsible, cb.equal(casePath.get(Case.CASE_OFFICER).get(User.ID), currentUser.getId()));
        }
        switch(jurisdictionLevel) {
            case REGION:
                final Region region = currentUser.getRegion();
                if (region != null) {
                    filter = CriteriaBuilderHelper.or(cb, filter, cb.equal(casePath.get(Case.REGION).get(Region.ID), region.getId()), cb.equal(casePath.get(Case.RESPONSIBLE_REGION).get(Region.ID), region.getId()));
                }
                break;
            case DISTRICT:
                final District district = currentUser.getDistrict();
                if (district != null) {
                    filter = CriteriaBuilderHelper.or(cb, filter, cb.equal(casePath.get(Case.DISTRICT).get(District.ID), district.getId()), cb.equal(casePath.get(Case.RESPONSIBLE_DISTRICT).get(District.ID), district.getId()));
                }
                break;
            case HEALTH_FACILITY:
                final Facility healthFacility = currentUser.getHealthFacility();
                if (healthFacility != null) {
                    filter = CriteriaBuilderHelper.or(cb, filter, cb.equal(casePath.get(Case.HEALTH_FACILITY).get(Facility.ID), healthFacility.getId()));
                }
                break;
            case COMMUNITY:
                final Community community = currentUser.getCommunity();
                if (community != null) {
                    filter = CriteriaBuilderHelper.or(cb, filter, cb.equal(casePath.get(Case.COMMUNITY).get(Community.ID), community.getId()), cb.equal(casePath.get(Case.RESPONSIBLE_COMMUNITY).get(Community.ID), community.getId()));
                }
                break;
            case POINT_OF_ENTRY:
                final PointOfEntry pointOfEntry = currentUser.getPointOfEntry();
                if (pointOfEntry != null) {
                    filter = CriteriaBuilderHelper.or(cb, filter, cb.equal(casePath.get(Case.POINT_OF_ENTRY).get(PointOfEntry.ID), pointOfEntry.getId()));
                }
                break;
            case LABORATORY:
                final Subquery<Long> sampleSubQuery = cq.subquery(Long.class);
                final Root<Sample> sampleRoot = sampleSubQuery.from(Sample.class);
                final SampleJoins joins = new SampleJoins(sampleRoot);
                final Join cazeJoin = joins.getCaze();
                sampleSubQuery.where(cb.and(cb.equal(cazeJoin, casePath), sampleService.createUserFilterWithoutAssociations(cb, joins)));
                sampleSubQuery.select(sampleRoot.get(Sample.ID));
                filter = CriteriaBuilderHelper.or(cb, filter, cb.exists(sampleSubQuery));
                break;
            default:
        }
        // get all cases based on the user's contact association
        if (userFilterCriteria == null || (!userFilterCriteria.isExcludeCasesFromContacts() && Boolean.TRUE.equals(userFilterCriteria.getIncludeCasesFromOtherJurisdictions()))) {
            filter = CriteriaBuilderHelper.or(cb, filter, contactService.createUserFilterWithoutCase(new ContactQueryContext(cb, cq, casePath.join(Case.CONTACTS, JoinType.LEFT))));
        }
        // all users (without specific restrictions) get access to cases that have been made available to the whole country
        if ((userFilterCriteria == null || userFilterCriteria.getIncludeCasesFromOtherJurisdictions()) && !featureConfigurationFacade.isFeatureDisabled(FeatureType.NATIONAL_CASE_SHARING)) {
            filter = CriteriaBuilderHelper.or(cb, filter, cb.isTrue(casePath.get(Case.SHARED_TO_COUNTRY)));
        }
    }
    // only show cases of a specific disease if a limited disease is set
    if (currentUser.getLimitedDisease() != null) {
        filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(casePath.get(Case.DISEASE), currentUser.getLimitedDisease()));
    }
    // port health users can only see port health cases
    if (UserRole.isPortHealthUser(currentUser.getUserRoles())) {
        filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(casePath.get(Case.CASE_ORIGIN), CaseOrigin.POINT_OF_ENTRY));
    }
    filter = CriteriaBuilderHelper.or(cb, filter, filterResponsible);
    return filter;
}
Also used : User(de.symeda.sormas.backend.user.User) Sample(de.symeda.sormas.backend.sample.Sample) ContactQueryContext(de.symeda.sormas.backend.contact.ContactQueryContext) JurisdictionLevel(de.symeda.sormas.api.user.JurisdictionLevel) Join(javax.persistence.criteria.Join) Predicate(javax.persistence.criteria.Predicate) Region(de.symeda.sormas.backend.infrastructure.region.Region) Facility(de.symeda.sormas.backend.infrastructure.facility.Facility) PointOfEntry(de.symeda.sormas.backend.infrastructure.pointofentry.PointOfEntry) District(de.symeda.sormas.backend.infrastructure.district.District) SampleJoins(de.symeda.sormas.backend.sample.SampleJoins) Community(de.symeda.sormas.backend.infrastructure.community.Community)

Example 3 with PointOfEntry

use of de.symeda.sormas.backend.infrastructure.pointofentry.PointOfEntry in project SORMAS-Project by hzi-braunschweig.

the class TravelEntryListService method getEntriesList.

public List<TravelEntryListEntryDto> getEntriesList(Long personId, Long caseId, Integer first, Integer max) {
    final CriteriaBuilder cb = em.getCriteriaBuilder();
    final CriteriaQuery<Object[]> cq = cb.createQuery(Object[].class);
    final Root<TravelEntry> travelEntry = cq.from(TravelEntry.class);
    final TravelEntryQueryContext travelEntryQueryContext = new TravelEntryQueryContext(cb, cq, travelEntry);
    final TravelEntryJoins<TravelEntry> joins = (TravelEntryJoins<TravelEntry>) travelEntryQueryContext.getJoins();
    final Join<TravelEntry, PointOfEntry> pointOfEntry = joins.getPointOfEntry();
    cq.multiselect(travelEntry.get(TravelEntry.UUID), travelEntry.get(TravelEntry.REPORT_DATE), travelEntry.get(TravelEntry.DISEASE), pointOfEntry.get(PointOfEntry.NAME), travelEntry.get(TravelEntry.POINT_OF_ENTRY_DETAILS), JurisdictionHelper.booleanSelector(cb, inJurisdictionOrOwned(travelEntryQueryContext)), travelEntry.get(TravelEntry.CHANGE_DATE));
    final Predicate criteriaFilter = buildListEntryCriteriaFilter(personId, caseId, travelEntryQueryContext);
    if (criteriaFilter != null) {
        cq.where(criteriaFilter);
    }
    cq.orderBy(cb.desc(travelEntry.get(TravelEntry.CHANGE_DATE)));
    cq.distinct(true);
    return createQuery(cq, first, max).unwrap(org.hibernate.query.Query.class).setResultTransformer(new TravelEntryListEntryDtoResultTransformer()).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) TravelEntry(de.symeda.sormas.backend.travelentry.TravelEntry) TravelEntryJoins(de.symeda.sormas.backend.travelentry.TravelEntryJoins) Predicate(javax.persistence.criteria.Predicate) TravelEntryQueryContext(de.symeda.sormas.backend.travelentry.TravelEntryQueryContext) TravelEntryListEntryDtoResultTransformer(de.symeda.sormas.backend.travelentry.transformers.TravelEntryListEntryDtoResultTransformer) PointOfEntry(de.symeda.sormas.backend.infrastructure.pointofentry.PointOfEntry)

Example 4 with PointOfEntry

use of de.symeda.sormas.backend.infrastructure.pointofentry.PointOfEntry in project SORMAS-Project by hzi-braunschweig.

the class SormasToSormasTest method createRDCF.

protected MappableRdcf createRDCF(boolean withExternalId) {
    String regionName = "Region";
    String districtName = "District";
    String communityName = "Community";
    String facilityName = "Facility";
    String pointOfEntryName = "Point of Entry";
    String regionExternalId = null;
    String districtExternalId = null;
    String communityExternalId = null;
    String facilityExternalId = null;
    String pointOfEntryExternalId = null;
    if (withExternalId) {
        regionExternalId = "RegionExtId";
        districtExternalId = "DistrictExtId";
        communityExternalId = "CommunityExtId";
        facilityExternalId = "FacilityExtId";
        pointOfEntryExternalId = "Point of EntryExtId";
    }
    MappableRdcf rdcf = new MappableRdcf();
    rdcf.invalidLocalRdcf = new TestDataCreator.RDCF(new RegionReferenceDto(DataHelper.createUuid(), withExternalId ? null : regionName, regionExternalId), new DistrictReferenceDto(DataHelper.createUuid(), withExternalId ? null : districtName, districtExternalId), new CommunityReferenceDto(DataHelper.createUuid(), withExternalId ? null : communityName, communityExternalId), new FacilityReferenceDto(DataHelper.createUuid(), withExternalId ? null : facilityName, facilityExternalId), new PointOfEntryReferenceDto(DataHelper.createUuid(), withExternalId ? null : pointOfEntryName, PointOfEntryType.AIRPORT, pointOfEntryExternalId));
    Region region = creator.createRegionCentrally(regionName + "Central", regionExternalId);
    District district = creator.createDistrictCentrally(districtName + "Central", region, districtExternalId);
    Community community = creator.createCommunityCentrally(communityName + "Central", district, communityExternalId);
    Facility facility = creator.createFacility(facilityName + "Central", FacilityType.HOSPITAL, region, district, community, facilityExternalId);
    PointOfEntry pointOfEntry = creator.createPointOfEntry(pointOfEntryName + "Central", region, district, pointOfEntryExternalId);
    rdcf.centralRdcf = new TestDataCreator.RDCF(new RegionReferenceDto(region.getUuid(), region.getName(), region.getExternalID()), new DistrictReferenceDto(district.getUuid(), district.getName(), district.getExternalID()), new CommunityReferenceDto(community.getUuid(), community.getName(), community.getExternalID()), new FacilityReferenceDto(facility.getUuid(), facility.getName(), facility.getExternalID()), new PointOfEntryReferenceDto(pointOfEntry.getUuid(), pointOfEntry.getName(), PointOfEntryType.AIRPORT, pointOfEntry.getExternalID()));
    return rdcf;
}
Also used : FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) TestDataCreator(de.symeda.sormas.backend.TestDataCreator) Region(de.symeda.sormas.backend.infrastructure.region.Region) PointOfEntryReferenceDto(de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryReferenceDto) Facility(de.symeda.sormas.backend.infrastructure.facility.Facility) PointOfEntry(de.symeda.sormas.backend.infrastructure.pointofentry.PointOfEntry) District(de.symeda.sormas.backend.infrastructure.district.District) Community(de.symeda.sormas.backend.infrastructure.community.Community)

Example 5 with PointOfEntry

use of de.symeda.sormas.backend.infrastructure.pointofentry.PointOfEntry in project SORMAS-Project by hzi-braunschweig.

the class TestDataCreator method createRDCF.

public RDCF createRDCF(String regionName, String districtName, String communityName, String facilityName, String pointOfEntryName) {
    Region region = createRegion(regionName);
    District district = createDistrict(districtName, region);
    Community community = createCommunity(communityName, district);
    Facility facility = createFacility(facilityName, region, district, community);
    PointOfEntry pointOfEntry = null;
    if (pointOfEntryName != null) {
        pointOfEntry = createPointOfEntry(pointOfEntryName, region, district);
    }
    return new RDCF(new RegionReferenceDto(region.getUuid(), region.getName(), region.getExternalID()), new DistrictReferenceDto(district.getUuid(), district.getName(), district.getExternalID()), new CommunityReferenceDto(community.getUuid(), community.getName(), community.getExternalID()), new FacilityReferenceDto(facility.getUuid(), facility.getName(), facility.getExternalID()), pointOfEntry != null ? new PointOfEntryReferenceDto(pointOfEntry.getUuid(), pointOfEntry.getName(), pointOfEntry.getPointOfEntryType(), pointOfEntry.getExternalID()) : null);
}
Also used : CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) Region(de.symeda.sormas.backend.infrastructure.region.Region) PointOfEntryReferenceDto(de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryReferenceDto) Facility(de.symeda.sormas.backend.infrastructure.facility.Facility) PointOfEntry(de.symeda.sormas.backend.infrastructure.pointofentry.PointOfEntry) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) District(de.symeda.sormas.backend.infrastructure.district.District) Community(de.symeda.sormas.backend.infrastructure.community.Community)

Aggregations

PointOfEntry (de.symeda.sormas.backend.infrastructure.pointofentry.PointOfEntry)10 District (de.symeda.sormas.backend.infrastructure.district.District)7 Community (de.symeda.sormas.backend.infrastructure.community.Community)6 Region (de.symeda.sormas.backend.infrastructure.region.Region)6 Facility (de.symeda.sormas.backend.infrastructure.facility.Facility)5 CommunityReferenceDto (de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto)3 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)3 PointOfEntryReferenceDto (de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryReferenceDto)3 RegionReferenceDto (de.symeda.sormas.api.infrastructure.region.RegionReferenceDto)3 User (de.symeda.sormas.backend.user.User)3 Predicate (javax.persistence.criteria.Predicate)3 FacilityReferenceDto (de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto)2 TravelEntry (de.symeda.sormas.backend.travelentry.TravelEntry)2 TravelEntryJoins (de.symeda.sormas.backend.travelentry.TravelEntryJoins)2 TravelEntryQueryContext (de.symeda.sormas.backend.travelentry.TravelEntryQueryContext)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 Disease (de.symeda.sormas.api.Disease)1 FacilityCriteria (de.symeda.sormas.api.infrastructure.facility.FacilityCriteria)1 JurisdictionLevel (de.symeda.sormas.api.user.JurisdictionLevel)1 SortProperty (de.symeda.sormas.api.utils.SortProperty)1