use of de.symeda.sormas.api.CaseMeasure in project SORMAS-Project by hzi-braunschweig.
the class CaseFacadeEjb method getCaseMeasurePerDistrict.
@Override
public List<Pair<DistrictDto, BigDecimal>> getCaseMeasurePerDistrict(Date fromDate, Date toDate, Disease disease, CaseMeasure caseMeasure) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Object[]> cq = cb.createQuery(Object[].class);
Root<Case> caseRoot = cq.from(Case.class);
Root<District> districtRoot = cq.from(District.class);
Predicate filter = service.createDefaultFilter(cb, caseRoot);
if (fromDate != null || toDate != null) {
filter = service.createCaseRelevanceFilter(cb, caseRoot, fromDate, toDate);
}
if (disease != null) {
Predicate diseaseFilter = cb.equal(caseRoot.get(Case.DISEASE), disease);
filter = filter != null ? cb.and(filter, diseaseFilter) : diseaseFilter;
}
Predicate districtFilter = cb.or(cb.equal(caseRoot.get(Case.DISTRICT), districtRoot), cb.and(cb.isNull(caseRoot.get(Case.DISTRICT)), cb.equal(caseRoot.get(Case.RESPONSIBLE_DISTRICT), districtRoot)));
filter = filter != null ? cb.and(filter, districtFilter) : districtFilter;
cq.where(filter);
cq.groupBy(districtRoot);
cq.multiselect(districtRoot, cb.count(caseRoot));
if (caseMeasure == CaseMeasure.CASE_COUNT) {
cq.orderBy(cb.asc(cb.count(caseRoot)));
}
List<Object[]> results = em.createQuery(cq).getResultList();
if (caseMeasure == CaseMeasure.CASE_COUNT) {
List<Pair<DistrictDto, BigDecimal>> resultList = results.stream().map(e -> new Pair<DistrictDto, BigDecimal>(districtFacade.toDto((District) e[0]), new BigDecimal((Long) e[1]))).collect(Collectors.toList());
return resultList;
} else {
List<Pair<DistrictDto, BigDecimal>> resultList = results.stream().map(e -> {
District district = (District) e[0];
Integer population = populationDataFacade.getProjectedDistrictPopulation(district.getUuid());
Long caseCount = (Long) e[1];
if (population == null || population <= 0) {
// No or negative population - these entries will be cut off in the UI
return new Pair<DistrictDto, BigDecimal>(districtFacade.toDto(district), new BigDecimal(0));
} else {
return new Pair<DistrictDto, BigDecimal>(districtFacade.toDto(district), InfrastructureHelper.getCaseIncidence(caseCount.intValue(), population, InfrastructureHelper.CASE_INCIDENCE_DIVISOR));
}
}).sorted(new Comparator<Pair<DistrictDto, BigDecimal>>() {
@Override
public int compare(Pair<DistrictDto, BigDecimal> o1, Pair<DistrictDto, BigDecimal> o2) {
return o1.getElement1().compareTo(o2.getElement1());
}
}).collect(Collectors.toList());
return resultList;
}
}
use of de.symeda.sormas.api.CaseMeasure in project SORMAS-Project by hzi-braunschweig.
the class DashboardMapComponent method createFooter.
private HorizontalLayout createFooter() {
HorizontalLayout mapFooterLayout = new HorizontalLayout();
mapFooterLayout.setWidth(100, Unit.PERCENTAGE);
mapFooterLayout.setSpacing(true);
CssStyles.style(mapFooterLayout, CssStyles.VSPACE_4, CssStyles.VSPACE_TOP_3);
// Map key dropdown button
legendDropdown = ButtonHelper.createPopupButton(Captions.dashboardMapKey, null, CssStyles.BUTTON_SUBTLE);
legendDropdown.setContent(createLegend());
mapFooterLayout.addComponent(legendDropdown);
mapFooterLayout.setComponentAlignment(legendDropdown, Alignment.MIDDLE_RIGHT);
mapFooterLayout.setExpandRatio(legendDropdown, 1);
// Layers dropdown button
VerticalLayout layersLayout = new VerticalLayout();
{
layersLayout.setMargin(true);
layersLayout.setSpacing(false);
layersLayout.setSizeUndefined();
// Add check boxes and apply button
{
// case classifications
OptionGroup caseClassificationOptions = new OptionGroup();
caseClassificationOptions.addItems((Object[]) MapCaseClassificationOption.values());
caseClassificationOptions.setValue(caseClassificationOption);
caseClassificationOptions.addValueChangeListener(event -> {
caseClassificationOption = (MapCaseClassificationOption) event.getProperty().getValue();
refreshMap(true);
});
// Optiongroup to select what property the coordinates should be based on
OptionGroup mapCaseDisplayModeSelect = new OptionGroup();
mapCaseDisplayModeSelect.setWidth(100, Unit.PERCENTAGE);
mapCaseDisplayModeSelect.addItems((Object[]) MapCaseDisplayMode.values());
mapCaseDisplayModeSelect.setValue(mapCaseDisplayMode);
mapCaseDisplayModeSelect.addValueChangeListener(event -> {
mapCaseDisplayMode = (MapCaseDisplayMode) event.getProperty().getValue();
refreshMap(true);
});
HorizontalLayout showCasesLayout = new HorizontalLayout();
{
showCasesLayout.setMargin(false);
showCasesLayout.setSpacing(false);
CheckBox showCasesCheckBox = new CheckBox();
showCasesCheckBox.setId(Captions.dashboardShowCases);
showCasesCheckBox.setCaption(I18nProperties.getCaption(Captions.dashboardShowCases));
showCasesCheckBox.setValue(showCases);
showCasesCheckBox.addValueChangeListener(e -> {
showCases = (boolean) e.getProperty().getValue();
mapCaseDisplayModeSelect.setEnabled(showCases);
mapCaseDisplayModeSelect.setValue(mapCaseDisplayMode);
caseClassificationOptions.setEnabled(showCases);
refreshMap(true);
});
showCasesLayout.addComponent(showCasesCheckBox);
Label infoLabel = new Label(VaadinIcons.INFO_CIRCLE.getHtml(), ContentMode.HTML);
infoLabel.setDescription(I18nProperties.getString(Strings.infoCaseMap));
CssStyles.style(infoLabel, CssStyles.LABEL_MEDIUM, CssStyles.LABEL_SECONDARY, CssStyles.HSPACE_LEFT_3);
infoLabel.setHeightUndefined();
showCasesLayout.addComponent(infoLabel);
showCasesLayout.setComponentAlignment(infoLabel, Alignment.TOP_CENTER);
}
layersLayout.addComponent(showCasesLayout);
layersLayout.addComponent(mapCaseDisplayModeSelect);
mapCaseDisplayModeSelect.setEnabled(showCases);
layersLayout.addComponent(caseClassificationOptions);
caseClassificationOptions.setEnabled(showCases);
CheckBox showConfirmedContactsCheckBox = new CheckBox();
showConfirmedContactsCheckBox.setId(Captions.dashboardShowConfirmedContacts);
CheckBox showUnconfirmedContactsCheckBox = new CheckBox();
showUnconfirmedContactsCheckBox.setId(Captions.dashboardShowUnconfirmedContacts);
CheckBox showContactsCheckBox = new CheckBox();
showContactsCheckBox.setId(Captions.dashboardShowContacts);
showContactsCheckBox.setCaption(I18nProperties.getCaption(Captions.dashboardShowContacts));
showContactsCheckBox.setValue(showContacts);
showContactsCheckBox.addValueChangeListener(e -> {
showContacts = (boolean) e.getProperty().getValue();
showConfirmedContactsCheckBox.setEnabled(showContacts);
showConfirmedContactsCheckBox.setValue(true);
showUnconfirmedContactsCheckBox.setEnabled(showContacts);
showUnconfirmedContactsCheckBox.setValue(true);
refreshMap(true);
});
layersLayout.addComponent(showContactsCheckBox);
showConfirmedContactsCheckBox.setCaption(I18nProperties.getCaption(Captions.dashboardShowConfirmedContacts));
showConfirmedContactsCheckBox.setValue(showConfirmedContacts);
showConfirmedContactsCheckBox.addValueChangeListener(e -> {
showConfirmedContacts = (boolean) e.getProperty().getValue();
refreshMap(true);
});
layersLayout.addComponent(showConfirmedContactsCheckBox);
CssStyles.style(showUnconfirmedContactsCheckBox, CssStyles.VSPACE_3);
showUnconfirmedContactsCheckBox.setCaption(I18nProperties.getCaption(Captions.dashboardShowUnconfirmedContacts));
showUnconfirmedContactsCheckBox.setValue(showUnconfirmedContacts);
showUnconfirmedContactsCheckBox.addValueChangeListener(e -> {
showUnconfirmedContacts = (boolean) e.getProperty().getValue();
refreshMap(true);
});
layersLayout.addComponent(showUnconfirmedContactsCheckBox);
showConfirmedContactsCheckBox.setEnabled(showContacts);
showUnconfirmedContactsCheckBox.setEnabled(showContacts);
CheckBox showEventsCheckBox = new CheckBox();
showEventsCheckBox.setId(Captions.dashboardShowEvents);
CssStyles.style(showEventsCheckBox, CssStyles.VSPACE_3);
showEventsCheckBox.setCaption(I18nProperties.getCaption(Captions.dashboardShowEvents));
showEventsCheckBox.setValue(showEvents);
showEventsCheckBox.addValueChangeListener(e -> {
showEvents = (boolean) e.getProperty().getValue();
refreshMap(true);
});
layersLayout.addComponent(showEventsCheckBox);
if (UserProvider.getCurrent().hasUserRole(UserRole.NATIONAL_USER) || UserProvider.getCurrent().hasUserRole(UserRole.NATIONAL_CLINICIAN) || UserProvider.getCurrent().hasUserRole(UserRole.NATIONAL_OBSERVER)) {
OptionGroup regionMapVisualizationSelect = new OptionGroup();
regionMapVisualizationSelect.setWidth(100, Unit.PERCENTAGE);
regionMapVisualizationSelect.addItems((Object[]) CaseMeasure.values());
regionMapVisualizationSelect.setValue(caseMeasure);
regionMapVisualizationSelect.addValueChangeListener(event -> {
caseMeasure = (CaseMeasure) event.getProperty().getValue();
refreshMap(true);
});
HorizontalLayout showRegionsLayout = new HorizontalLayout();
{
showRegionsLayout.setMargin(false);
showRegionsLayout.setSpacing(false);
CheckBox showRegionsCheckBox = new CheckBox();
showRegionsCheckBox.setId(Captions.dashboardShowRegions);
showRegionsCheckBox.setCaption(I18nProperties.getCaption(Captions.dashboardShowRegions));
showRegionsCheckBox.setValue(showRegions);
showRegionsCheckBox.addValueChangeListener(e -> {
showRegions = (boolean) e.getProperty().getValue();
regionMapVisualizationSelect.setEnabled(showRegions);
regionMapVisualizationSelect.setValue(caseMeasure);
refreshMap(true);
});
showRegionsLayout.addComponent(showRegionsCheckBox);
Label infoLabel = new Label(VaadinIcons.INFO_CIRCLE.getHtml(), ContentMode.HTML);
infoLabel.setDescription(I18nProperties.getString(Strings.infoCaseIncidence));
CssStyles.style(infoLabel, CssStyles.LABEL_MEDIUM, CssStyles.LABEL_SECONDARY, CssStyles.HSPACE_LEFT_3);
infoLabel.setHeightUndefined();
showRegionsLayout.addComponent(infoLabel);
showRegionsLayout.setComponentAlignment(infoLabel, Alignment.TOP_CENTER);
}
layersLayout.addComponent(showRegionsLayout);
layersLayout.addComponent(regionMapVisualizationSelect);
regionMapVisualizationSelect.setEnabled(showRegions);
}
CheckBox hideOtherCountriesCheckBox = new CheckBox();
hideOtherCountriesCheckBox.setId(Captions.dashboardHideOtherCountries);
hideOtherCountriesCheckBox.setCaption(I18nProperties.getCaption(Captions.dashboardHideOtherCountries));
hideOtherCountriesCheckBox.setValue(hideOtherCountries);
hideOtherCountriesCheckBox.addValueChangeListener(e -> {
hideOtherCountries = (boolean) e.getProperty().getValue();
refreshMap(true);
});
CssStyles.style(hideOtherCountriesCheckBox, CssStyles.VSPACE_3);
layersLayout.addComponent(hideOtherCountriesCheckBox);
CheckBox showCurrentEpiSituationCB = new CheckBox();
showCurrentEpiSituationCB.setId(Captions.dashboardMapShowEpiSituation);
showCurrentEpiSituationCB.setCaption(I18nProperties.getCaption(Captions.dashboardMapShowEpiSituation));
showCurrentEpiSituationCB.setValue(false);
showCurrentEpiSituationCB.addValueChangeListener(e -> {
showCurrentEpiSituation = (boolean) e.getProperty().getValue();
refreshMap(true);
});
layersLayout.addComponent(showCurrentEpiSituationCB);
}
}
PopupButton layersDropdown = ButtonHelper.createPopupButton(Captions.dashboardMapLayers, layersLayout, CssStyles.BUTTON_SUBTLE);
mapFooterLayout.addComponent(layersDropdown);
mapFooterLayout.setComponentAlignment(layersDropdown, Alignment.MIDDLE_RIGHT);
return mapFooterLayout;
}
Aggregations