use of de.symeda.sormas.api.infrastructure.facility.FacilityIndexDto in project SORMAS-Project by hzi-braunschweig.
the class FacilityFacadeEjb method getIndexList.
@Override
public List<FacilityIndexDto> getIndexList(FacilityCriteria facilityCriteria, Integer first, Integer max, List<SortProperty> sortProperties) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<FacilityIndexDto> cq = cb.createQuery(FacilityIndexDto.class);
Root<Facility> facility = cq.from(Facility.class);
Join<Facility, Region> region = facility.join(Facility.REGION, JoinType.LEFT);
Join<Facility, District> district = facility.join(Facility.DISTRICT, JoinType.LEFT);
Join<Facility, Community> community = facility.join(Facility.COMMUNITY, JoinType.LEFT);
Predicate filter = service.buildCriteriaFilter(facilityCriteria, cb, facility);
Predicate excludeFilter = cb.and(cb.notEqual(facility.get(Facility.UUID), FacilityDto.OTHER_FACILITY_UUID), cb.notEqual(facility.get(Facility.UUID), FacilityDto.NONE_FACILITY_UUID));
if (filter != null) {
filter = CriteriaBuilderHelper.and(cb, filter, excludeFilter);
} else {
filter = excludeFilter;
}
if (filter != null) {
cq.where(filter);
}
if (CollectionUtils.isNotEmpty(sortProperties)) {
List<Order> order = new ArrayList<>(sortProperties.size());
for (SortProperty sortProperty : sortProperties) {
Expression<?> expression;
switch(sortProperty.propertyName) {
case Facility.NAME:
case Facility.CITY:
case Facility.LATITUDE:
case Facility.LONGITUDE:
case Facility.EXTERNAL_ID:
case Facility.TYPE:
expression = facility.get(sortProperty.propertyName);
break;
case Facility.REGION:
expression = region.get(Region.NAME);
break;
case Facility.DISTRICT:
expression = district.get(District.NAME);
break;
case Facility.COMMUNITY:
expression = community.get(Community.NAME);
break;
default:
throw new IllegalArgumentException(sortProperty.propertyName);
}
order.add(sortProperty.ascending ? cb.asc(expression) : cb.desc(expression));
}
cq.orderBy(order);
} else {
cq.orderBy(cb.asc(region.get(Region.NAME)), cb.asc(district.get(District.NAME)), cb.asc(community.get(Community.NAME)), cb.asc(facility.get(Facility.NAME)));
}
cq.multiselect(facility.get(Facility.UUID), facility.get(Facility.NAME), facility.get(Facility.TYPE), region.get(Region.UUID), region.get(Region.NAME), district.get(District.UUID), district.get(District.NAME), community.get(Community.UUID), community.get(Community.NAME), facility.get(Facility.CITY), facility.get(Facility.LATITUDE), facility.get(Facility.LONGITUDE), facility.get(Facility.EXTERNAL_ID));
return QueryHelper.getResultList(em, cq, first, max);
}
use of de.symeda.sormas.api.infrastructure.facility.FacilityIndexDto in project SORMAS-Project by hzi-braunschweig.
the class FacilityFacadeEjbTest method testGetIndexListMappedSorting.
@Test
public void testGetIndexListMappedSorting() {
FacilityCriteria facilityCriteria = new FacilityCriteria();
// 0. No sortProperties
List<FacilityIndexDto> result = getFacilityFacade().getIndexList(facilityCriteria, null, null, new ArrayList<>());
assertThat(result, is(empty()));
List<SortProperty> allSortProperties = new ArrayList<>();
allSortProperties.add(new SortProperty(FacilityDto.NAME));
allSortProperties.add(new SortProperty(FacilityDto.TYPE));
allSortProperties.add(new SortProperty(FacilityDto.REGION));
allSortProperties.add(new SortProperty(FacilityDto.DISTRICT));
allSortProperties.add(new SortProperty(FacilityDto.COMMUNITY));
allSortProperties.add(new SortProperty(FacilityDto.CITY));
allSortProperties.add(new SortProperty(FacilityDto.LATITUDE));
allSortProperties.add(new SortProperty(FacilityDto.LONGITUDE));
allSortProperties.add(new SortProperty(FacilityDto.EXTERNAL_ID));
// 1. Sort by every property
for (SortProperty sortProperty : allSortProperties) {
getFacilityFacade().getIndexList(facilityCriteria, null, null, Collections.singletonList(sortProperty));
assertThat(sortProperty.toString(), result, is(empty()));
}
// 2. Sort by all properties at once
getFacilityFacade().getIndexList(facilityCriteria, null, null, allSortProperties);
assertThat(result, is(empty()));
}
use of de.symeda.sormas.api.infrastructure.facility.FacilityIndexDto in project SORMAS-Project by hzi-braunschweig.
the class InfrastructureController method archiveOrDearchiveAllSelectedItems.
@SuppressWarnings("unchecked")
public void archiveOrDearchiveAllSelectedItems(boolean archive, Collection<?> selectedRows, InfrastructureType infrastructureType, Runnable callback) {
// Check that at least one entry is selected
if (selectedRows.isEmpty()) {
new Notification(I18nProperties.getString(Strings.headingNoRowsSelected), I18nProperties.getString(Strings.messageNoRowsSelected), Type.WARNING_MESSAGE, false).show(Page.getCurrent());
return;
}
// Check if archiving/dearchiving is allowed concerning the hierarchy
Set<String> selectedRowsUuids = selectedRows.stream().map(row -> ((HasUuid) row).getUuid()).collect(Collectors.toSet());
if (InfrastructureType.AREA.equals(infrastructureType) && FacadeProvider.getAreaFacade().isUsedInOtherInfrastructureData(selectedRowsUuids) || InfrastructureType.CONTINENT.equals(infrastructureType) && FacadeProvider.getContinentFacade().isUsedInOtherInfrastructureData(selectedRowsUuids) || InfrastructureType.SUBCONTINENT.equals(infrastructureType) && FacadeProvider.getSubcontinentFacade().isUsedInOtherInfrastructureData(selectedRowsUuids) || InfrastructureType.REGION.equals(infrastructureType) && FacadeProvider.getRegionFacade().isUsedInOtherInfrastructureData(selectedRowsUuids) || InfrastructureType.DISTRICT.equals(infrastructureType) && FacadeProvider.getDistrictFacade().isUsedInOtherInfrastructureData(selectedRowsUuids) || InfrastructureType.COMMUNITY.equals(infrastructureType) && FacadeProvider.getCommunityFacade().isUsedInOtherInfrastructureData(selectedRowsUuids)) {
showArchivingNotPossibleWindow(infrastructureType, true);
return;
}
if (InfrastructureType.COUNTRY.equals(infrastructureType) && FacadeProvider.getCountryFacade().hasArchivedParentInfrastructure(selectedRowsUuids) || InfrastructureType.SUBCONTINENT.equals(infrastructureType) && FacadeProvider.getSubcontinentFacade().hasArchivedParentInfrastructure(selectedRowsUuids) || InfrastructureType.DISTRICT.equals(infrastructureType) && FacadeProvider.getDistrictFacade().hasArchivedParentInfrastructure(selectedRowsUuids) || InfrastructureType.COMMUNITY.equals(infrastructureType) && FacadeProvider.getCommunityFacade().hasArchivedParentInfrastructure(selectedRowsUuids) || InfrastructureType.FACILITY.equals(infrastructureType) && FacadeProvider.getFacilityFacade().hasArchivedParentInfrastructure(selectedRowsUuids) || InfrastructureType.POINT_OF_ENTRY.equals(infrastructureType) && FacadeProvider.getPointOfEntryFacade().hasArchivedParentInfrastructure(selectedRowsUuids)) {
showDearchivingNotPossibleWindow(infrastructureType, false);
return;
}
final String confirmationMessage;
final String notificationMessage;
switch(infrastructureType) {
case CONTINENT:
confirmationMessage = archive ? I18nProperties.getString(Strings.confirmationArchiveContinents) : I18nProperties.getString(Strings.confirmationDearchiveContinents);
notificationMessage = archive ? I18nProperties.getString(Strings.messageContinentsArchived) : I18nProperties.getString(Strings.messageContinentsDearchived);
break;
case SUBCONTINENT:
confirmationMessage = archive ? I18nProperties.getString(Strings.confirmationArchiveSubcontinents) : I18nProperties.getString(Strings.confirmationDearchiveSubcontinents);
notificationMessage = archive ? I18nProperties.getString(Strings.messageSubcontinentsArchived) : I18nProperties.getString(Strings.messageSubcontinentsDearchived);
break;
case AREA:
confirmationMessage = archive ? I18nProperties.getString(Strings.confirmationArchiveAreas) : I18nProperties.getString(Strings.confirmationDearchiveAreas);
notificationMessage = archive ? I18nProperties.getString(Strings.messageAreasArchived) : I18nProperties.getString(Strings.messageAreasDearchived);
break;
case COUNTRY:
confirmationMessage = archive ? I18nProperties.getString(Strings.confirmationArchiveCountries) : I18nProperties.getString(Strings.confirmationDearchiveCountries);
notificationMessage = archive ? I18nProperties.getString(Strings.messageCountriesArchived) : I18nProperties.getString(Strings.messageCountriesDearchived);
break;
case REGION:
confirmationMessage = archive ? I18nProperties.getString(Strings.confirmationArchiveRegions) : I18nProperties.getString(Strings.confirmationDearchiveRegions);
notificationMessage = archive ? I18nProperties.getString(Strings.messageRegionsArchived) : I18nProperties.getString(Strings.messageRegionsDearchived);
break;
case DISTRICT:
confirmationMessage = archive ? I18nProperties.getString(Strings.confirmationArchiveDistricts) : I18nProperties.getString(Strings.confirmationDearchiveDistricts);
notificationMessage = archive ? I18nProperties.getString(Strings.messageDistrictsArchived) : I18nProperties.getString(Strings.messageDistrictsDearchived);
break;
case COMMUNITY:
confirmationMessage = archive ? I18nProperties.getString(Strings.confirmationArchiveCommunities) : I18nProperties.getString(Strings.confirmationDearchiveCommunities);
notificationMessage = archive ? I18nProperties.getString(Strings.messageCommunitiesArchived) : I18nProperties.getString(Strings.messageCommunitiesDearchived);
break;
case FACILITY:
confirmationMessage = archive ? I18nProperties.getString(Strings.confirmationArchiveFacilities) : I18nProperties.getString(Strings.confirmationDearchiveFacilities);
notificationMessage = archive ? I18nProperties.getString(Strings.messageFacilitiesArchived) : I18nProperties.getString(Strings.messageFacilitiesDearchived);
break;
case POINT_OF_ENTRY:
confirmationMessage = archive ? I18nProperties.getString(Strings.confirmationArchivePointsOfEntry) : I18nProperties.getString(Strings.confirmationDearchivePointsOfEntry);
notificationMessage = archive ? I18nProperties.getString(Strings.messagePointsOfEntryArchived) : I18nProperties.getString(Strings.messagePointsOfEntryDearchived);
break;
default:
throw new IllegalArgumentException(infrastructureType.name());
}
VaadinUiUtil.showConfirmationPopup(I18nProperties.getString(Strings.headingConfirmArchiving), new Label(String.format(confirmationMessage, selectedRows.size())), I18nProperties.getString(Strings.yes), I18nProperties.getString(Strings.no), null, e -> {
if (e.booleanValue()) {
switch(infrastructureType) {
case CONTINENT:
for (ContinentDto selectedRow : (Collection<ContinentDto>) selectedRows) {
if (archive) {
FacadeProvider.getContinentFacade().archive(selectedRow.getUuid());
} else {
FacadeProvider.getContinentFacade().dearchive(selectedRow.getUuid());
}
}
break;
case SUBCONTINENT:
for (SubcontinentDto selectedRow : (Collection<SubcontinentDto>) selectedRows) {
if (archive) {
FacadeProvider.getSubcontinentFacade().archive(selectedRow.getUuid());
} else {
FacadeProvider.getSubcontinentFacade().dearchive(selectedRow.getUuid());
}
}
break;
case AREA:
for (AreaDto selectedRow : (Collection<AreaDto>) selectedRows) {
if (archive) {
FacadeProvider.getAreaFacade().archive(selectedRow.getUuid());
} else {
FacadeProvider.getAreaFacade().dearchive(selectedRow.getUuid());
}
}
break;
case COUNTRY:
for (CountryIndexDto selectedRow : (Collection<CountryIndexDto>) selectedRows) {
if (archive) {
FacadeProvider.getCountryFacade().archive(selectedRow.getUuid());
} else {
FacadeProvider.getCountryFacade().dearchive(selectedRow.getUuid());
}
}
break;
case REGION:
for (RegionIndexDto selectedRow : (Collection<RegionIndexDto>) selectedRows) {
if (archive) {
FacadeProvider.getRegionFacade().archive(selectedRow.getUuid());
} else {
FacadeProvider.getRegionFacade().dearchive(selectedRow.getUuid());
}
}
break;
case DISTRICT:
for (DistrictIndexDto selectedRow : (Collection<DistrictIndexDto>) selectedRows) {
if (archive) {
FacadeProvider.getDistrictFacade().archive(selectedRow.getUuid());
} else {
FacadeProvider.getDistrictFacade().dearchive(selectedRow.getUuid());
}
}
break;
case COMMUNITY:
for (CommunityDto selectedRow : (Collection<CommunityDto>) selectedRows) {
if (archive) {
FacadeProvider.getCommunityFacade().archive(selectedRow.getUuid());
} else {
FacadeProvider.getCommunityFacade().dearchive(selectedRow.getUuid());
}
}
break;
case FACILITY:
for (FacilityIndexDto selectedRow : (Collection<FacilityIndexDto>) selectedRows) {
if (archive) {
FacadeProvider.getFacilityFacade().archive(selectedRow.getUuid());
} else {
FacadeProvider.getFacilityFacade().dearchive(selectedRow.getUuid());
}
}
break;
case POINT_OF_ENTRY:
for (PointOfEntryDto selectedRow : (Collection<PointOfEntryDto>) selectedRows) {
if (archive) {
FacadeProvider.getPointOfEntryFacade().archive(selectedRow.getUuid());
} else {
FacadeProvider.getPointOfEntryFacade().dearchive(selectedRow.getUuid());
}
}
break;
default:
throw new IllegalArgumentException(infrastructureType.name());
}
callback.run();
Notification.show(notificationMessage, Type.ASSISTIVE_NOTIFICATION);
}
});
}
use of de.symeda.sormas.api.infrastructure.facility.FacilityIndexDto in project SORMAS-Project by hzi-braunschweig.
the class DevModeView method generateEvents.
private void generateEvents() {
initializeRandomGenerator();
EventGenerationConfig config = eventGeneratorConfigBinder.getBean();
int generatedParticipants = 0;
int generatedCases = 0;
int generatedContacts = 0;
Disease disease = config.getDisease();
float baseOffset = random().nextFloat();
int daysBetween = (int) ChronoUnit.DAYS.between(config.startDate, config.endDate);
// this should be adjusted to be much more complex
FacilityCriteria facilityCriteria = new FacilityCriteria();
facilityCriteria.region(config.getRegion());
facilityCriteria.district(config.getDistrict());
List<FacilityIndexDto> healthFacilities = FacadeProvider.getFacilityFacade().getIndexList(facilityCriteria, 0, (int) (config.getMaxParticipantsPerEvent() * config.getPercentageOfCases() / 100), null);
// Filter list, so that only health facilities meant for accomodation are selected
healthFacilities.removeIf(el -> (!el.getType().isAccommodation()));
long dt = System.nanoTime();
for (int i = 0; i < config.getEventCount(); i++) {
LocalDateTime referenceDateTime;
EventDto event = EventDto.build();
// disease
if (disease != null) {
// reset
event.setDisease(disease);
if (event.getDisease() == Disease.OTHER) {
event.setDiseaseDetails("RD " + (random().nextInt(20) + 1));
}
referenceDateTime = getReferenceDateTime(i, config.getEventCount(), baseOffset, disease, config.getStartDate(), daysBetween);
fieldVisibilityCheckers = FieldVisibilityCheckers.withDisease(disease).andWithCountry(FacadeProvider.getConfigFacade().getCountryLocale());
} else {
referenceDateTime = getReferenceDateTime(i, config.getEventCount(), baseOffset, Disease.OTHER, config.getStartDate(), daysBetween);
fieldVisibilityCheckers = FieldVisibilityCheckers.withDisease(Disease.OTHER).andWithCountry(FacadeProvider.getConfigFacade().getCountryLocale());
}
// title
event.setEventTitle(random(eventTitles));
// description
event.setEventDesc("Event generated using DevMode on " + LocalDate.now());
// report
UserReferenceDto userReference = UserProvider.getCurrent().getUserReference();
event.setReportingUser(userReference);
event.setReportDateTime(Date.from(referenceDateTime.atZone(ZoneId.systemDefault()).toInstant()));
// region & district
event.getEventLocation().setRegion(config.getRegion());
event.getEventLocation().setDistrict(config.getDistrict());
// status
event.setEventStatus(EventStatus.EVENT);
FacadeProvider.getEventFacade().save(event);
// EventParticipants
int numParticipants = randomInt(config.getMinParticipantsPerEvent(), config.getMaxParticipantsPerEvent());
for (int j = 0; j < numParticipants; j++) {
EventParticipantDto eventParticipant = EventParticipantDto.build(event.toReference(), UserProvider.getCurrent().getUserReference());
// person
// instead of creating new persons everytime, it would be nice if some persons came of the original database
PersonDto person = PersonDto.build();
fillEntity(person, referenceDateTime);
person.setSymptomJournalStatus(null);
setPersonName(person);
FacadeProvider.getPersonFacade().savePerson(person);
eventParticipant.setPerson(person);
eventParticipant.setInvolvementDescription("Participant");
if (disease != null) {
// generate cases for some participants
if (randomPercent(config.getPercentageOfCases()) && !healthFacilities.isEmpty()) {
CaseDataDto caze = CaseDataDto.buildFromEventParticipant(eventParticipant, person, event.getDisease());
fillEntity(caze, referenceDateTime);
caze.setDisease(event.getDisease());
caze.setReportingUser(UserProvider.getCurrent().getUserReference());
caze.setReportDate(Date.from(referenceDateTime.atZone(ZoneId.systemDefault()).toInstant()));
caze.setCaseOrigin(CaseOrigin.IN_COUNTRY);
caze.setResponsibleRegion(config.getRegion());
caze.setResponsibleDistrict(config.getDistrict());
FacilityIndexDto facility = random(healthFacilities);
caze.setHealthFacility(facility.toReference());
caze.setFacilityType(facility.getType());
caze.setAdditionalDetails("Case generated using DevMode on " + LocalDate.now());
FacadeProvider.getCaseFacade().save(caze);
eventParticipant.setResultingCase(caze.toReference());
generatedCases++;
}
// generate contacts for some participants
List<CaseReferenceDto> cases = FacadeProvider.getCaseFacade().getRandomCaseReferences(new CaseCriteria().region(config.getRegion()).district(config.getDistrict()).disease(event.getDisease()), numParticipants * 2, random());
int numContacts = randomInt(config.getMinContactsPerParticipant(), config.getMaxContactsPerParticipant());
for (int k = 0; (k < numContacts && (cases != null)); k++) {
ContactDto contact = ContactDto.build(eventParticipant);
contact.setDisease(event.getDisease());
contact.setCaze(random(cases));
contact.setReportingUser(UserProvider.getCurrent().getUserReference());
contact.setReportDateTime(Date.from(referenceDateTime.atZone(ZoneId.systemDefault()).toInstant()));
contact.setDescription("Contact generated using DevMode on " + LocalDate.now());
FacadeProvider.getContactFacade().save(contact);
generatedContacts++;
}
}
FacadeProvider.getEventParticipantFacade().saveEventParticipant(eventParticipant);
generatedParticipants++;
}
}
dt = System.nanoTime() - dt;
long perCase = dt / config.getEventCount();
String msg = String.format("Generating %d events with a total of %d participants (%d contacts, %d cases) took %.2f s (%.1f ms per event)", config.getEventCount(), generatedParticipants, generatedContacts, generatedCases, (double) dt / 1_000_000_000, (double) perCase / 1_000_000);
logger.info(msg);
Notification.show("", msg, Notification.Type.TRAY_NOTIFICATION);
}
use of de.symeda.sormas.api.infrastructure.facility.FacilityIndexDto in project SORMAS-Project by hzi-braunschweig.
the class DevModeView method generateCases.
private void generateCases() {
initializeRandomGenerator();
CaseGenerationConfig config = caseGeneratorConfigBinder.getBean();
List<Disease> diseases = FacadeProvider.getDiseaseConfigurationFacade().getAllDiseases(true, true, true);
float baseOffset = random().nextFloat();
int daysBetween = (int) ChronoUnit.DAYS.between(config.startDate, config.endDate);
FacilityCriteria facilityCriteria = new FacilityCriteria();
facilityCriteria.region(config.getRegion());
facilityCriteria.district(config.getDistrict());
// just load some health facilities. Alphabetical order is not random, but the best we can get
List<FacilityIndexDto> healthFacilities = FacadeProvider.getFacilityFacade().getIndexList(facilityCriteria, 0, Math.min(config.getCaseCount() * 2, 300), Arrays.asList(new SortProperty(FacilityDto.NAME)));
// Filter list, so that only health facilities meant for accomodation are selected
healthFacilities.removeIf(el -> (!el.getType().isAccommodation()));
long dt = System.nanoTime();
for (int i = 0; i < config.getCaseCount(); i++) {
Disease disease = config.getDisease();
if (disease == null) {
disease = random(diseases);
}
fieldVisibilityCheckers = FieldVisibilityCheckers.withDisease(disease).andWithCountry(FacadeProvider.getConfigFacade().getCountryLocale());
LocalDateTime referenceDateTime = getReferenceDateTime(i, config.getCaseCount(), baseOffset, disease, config.getStartDate(), daysBetween);
// person
PersonDto person = PersonDto.build();
fillEntity(person, referenceDateTime);
person.setSymptomJournalStatus(null);
setPersonName(person);
CaseDataDto caze = CaseDataDto.build(person.toReference(), disease);
fillEntity(caze, referenceDateTime);
// reset
caze.setDisease(disease);
if (caze.getDisease() == Disease.OTHER) {
caze.setDiseaseDetails("RD " + (random().nextInt(20) + 1));
}
if (!QuarantineType.isQuarantineInEffect(caze.getQuarantine())) {
caze.setQuarantineFrom(null);
caze.setQuarantineTo(null);
caze.setQuarantineExtended(false);
caze.setQuarantineReduced(false);
}
// description
caze.setAdditionalDetails("Case generated using DevMode on " + LocalDate.now());
// report
UserReferenceDto userReference = UserProvider.getCurrent().getUserReference();
caze.setReportingUser(userReference);
caze.setReportDate(Date.from(referenceDateTime.atZone(ZoneId.systemDefault()).toInstant()));
// region & facility
if (healthFacilities.isEmpty() || randomPercent(20)) {
FacilityReferenceDto noFacilityRef = FacadeProvider.getFacilityFacade().getByUuid(FacilityDto.NONE_FACILITY_UUID).toReference();
caze.setCaseOrigin(CaseOrigin.IN_COUNTRY);
caze.setHealthFacility(noFacilityRef);
caze.setFacilityType(null);
caze.setResponsibleRegion(config.getRegion());
caze.setResponsibleDistrict(config.getDistrict());
} else {
FacilityIndexDto healthFacility = random(healthFacilities);
caze.setCaseOrigin(CaseOrigin.IN_COUNTRY);
caze.setResponsibleRegion(healthFacility.getRegion());
caze.setResponsibleDistrict(healthFacility.getDistrict());
caze.setResponsibleCommunity(healthFacility.getCommunity());
caze.setHealthFacility(healthFacility.toReference());
caze.setFacilityType(healthFacility.getType());
caze.setReportLat(healthFacility.getLatitude());
caze.setReportLon(healthFacility.getLongitude());
}
FacadeProvider.getPersonFacade().savePerson(person);
FacadeProvider.getCaseFacade().save(caze);
}
dt = System.nanoTime() - dt;
long perCase = dt / config.getCaseCount();
String msg = String.format("Generating %,d cases took %,d ms (%,d ms per case)", config.getCaseCount(), dt / 1_000_000, perCase / 1_000_000);
logger.info(msg);
Notification.show("", msg, Notification.Type.TRAY_NOTIFICATION);
}
Aggregations