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);
}
}
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;
}
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();
}
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;
}
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);
}
Aggregations