From 787ac05129beb9dbd17f49090c7d2908f7d1e446 Mon Sep 17 00:00:00 2001 From: pdenzler Date: Tue, 29 Oct 2024 14:52:42 +0100 Subject: [PATCH] [26697] filter multiple order status & don't show pea orders by default (#741) Co-authored-by: pdenzler --- .../ch/elexis/core/l10n/messages.properties | 2 +- .../elexis/core/l10n/messages_de.properties | 2 +- .../elexis/core/l10n/messages_en.properties | 2 +- .../elexis/core/l10n/messages_fr.properties | 2 +- .../elexis/core/l10n/messages_it.properties | 2 +- .../core/ui/mediorder/MediorderPart.java | 23 +++++++-- .../core/ui/mediorder/MediorderPartUtil.java | 19 ++++---- .../handler/FilterByOrderStatusHandler.java | 47 ++++++++++--------- 8 files changed, 58 insertions(+), 41 deletions(-) diff --git a/bundles/ch.elexis.core.l10n/src/ch/elexis/core/l10n/messages.properties b/bundles/ch.elexis.core.l10n/src/ch/elexis/core/l10n/messages.properties index b37f30b317..964f45bfc4 100644 --- a/bundles/ch.elexis.core.l10n/src/ch/elexis/core/l10n/messages.properties +++ b/bundles/ch.elexis.core.l10n/src/ch/elexis/core/l10n/messages.properties @@ -6127,7 +6127,7 @@ Mediorder_updateArticle_successful = Successful Mediorder_updateArticle_error = error -Mediorder_activate_patient_order = Activate patient order via pea +Mediorder_activate_patient_order = Activate medication order via pea Mediroder_missing_email = missing e-mail diff --git a/bundles/ch.elexis.core.l10n/src/ch/elexis/core/l10n/messages_de.properties b/bundles/ch.elexis.core.l10n/src/ch/elexis/core/l10n/messages_de.properties index b84c1b39b4..c6f1c54900 100644 --- a/bundles/ch.elexis.core.l10n/src/ch/elexis/core/l10n/messages_de.properties +++ b/bundles/ch.elexis.core.l10n/src/ch/elexis/core/l10n/messages_de.properties @@ -6105,7 +6105,7 @@ Mediorder_updateArticle_successful = Erfolgreich Mediorder_updateArticle_error = Fehlgeschlagen -Mediorder_activate_patient_order = Patientenbestellung \u00FCber PEA aktivieren +Mediorder_activate_patient_order = Medikamentenbestellung \u00FCber PEA aktivieren Mediroder_missing_email = Fehlende E-Mail diff --git a/bundles/ch.elexis.core.l10n/src/ch/elexis/core/l10n/messages_en.properties b/bundles/ch.elexis.core.l10n/src/ch/elexis/core/l10n/messages_en.properties index a66967ddeb..cf73c6690e 100644 --- a/bundles/ch.elexis.core.l10n/src/ch/elexis/core/l10n/messages_en.properties +++ b/bundles/ch.elexis.core.l10n/src/ch/elexis/core/l10n/messages_en.properties @@ -6045,7 +6045,7 @@ Mediorder_updateArticle_successful = Successful Mediorder_updateArticle_error = error -Mediorder_activate_patient_order = Activate patient order via pea +Mediorder_activate_patient_order = Activate medication order via pea Mediroder_missing_email = missing e-mail diff --git a/bundles/ch.elexis.core.l10n/src/ch/elexis/core/l10n/messages_fr.properties b/bundles/ch.elexis.core.l10n/src/ch/elexis/core/l10n/messages_fr.properties index 5e441daa1e..4b5224daaa 100644 --- a/bundles/ch.elexis.core.l10n/src/ch/elexis/core/l10n/messages_fr.properties +++ b/bundles/ch.elexis.core.l10n/src/ch/elexis/core/l10n/messages_fr.properties @@ -6041,7 +6041,7 @@ Mediorder_updateArticle_successful = avec succ\u00E8s Mediorder_updateArticle_error = \u00E9chou\u00E9 -Mediorder_activate_patient_order = Activer la commande des patients via PEA +Mediorder_activate_patient_order = Activer la commande des médicaments via PEA Mediroder_missing_email = E-mail manquante diff --git a/bundles/ch.elexis.core.l10n/src/ch/elexis/core/l10n/messages_it.properties b/bundles/ch.elexis.core.l10n/src/ch/elexis/core/l10n/messages_it.properties index 38d89bafd5..fb8e9aa029 100644 --- a/bundles/ch.elexis.core.l10n/src/ch/elexis/core/l10n/messages_it.properties +++ b/bundles/ch.elexis.core.l10n/src/ch/elexis/core/l10n/messages_it.properties @@ -6043,7 +6043,7 @@ Mediorder_updateArticle_successful = con successo Mediorder_updateArticle_error = fallito -Mediorder_activate_patient_order = Attivare l'ordine dei pazienti tramite PEA +Mediorder_activate_patient_order = Attivare l'ordine di medicazione tramite PEA Mediroder_missing_email = Email mancante diff --git a/bundles/ch.elexis.core.ui.mediorder/src/ch/elexis/core/ui/mediorder/MediorderPart.java b/bundles/ch.elexis.core.ui.mediorder/src/ch/elexis/core/ui/mediorder/MediorderPart.java index f76f98070f..3b8948a294 100644 --- a/bundles/ch.elexis.core.ui.mediorder/src/ch/elexis/core/ui/mediorder/MediorderPart.java +++ b/bundles/ch.elexis.core.ui.mediorder/src/ch/elexis/core/ui/mediorder/MediorderPart.java @@ -124,7 +124,7 @@ public class MediorderPart implements IRefreshablePart { public Map imageStockStates = new HashMap(); private List filteredStocks = new ArrayList<>(); - private Integer currentFilterValue; + private List currentFilterValue; private boolean filterActive = false; public MediorderPart() { @@ -166,7 +166,7 @@ public void reload(@UIEventTopic(ElexisEventTopics.EVENT_RELOAD) Class clazz) public void refresh(Map filterParameters) { Object firstElement = tableViewer.getStructuredSelection().getFirstElement(); tableViewer.setInput(filterActive ? MediorderPartUtil.calculateFilteredStocks(currentFilterValue) - : stockService.getAllPatientStock()); + : getStocksExcludingAwaitingRequests()); if (tableViewer.contains(firstElement)) { tableViewer.setSelection(new StructuredSelection(firstElement)); MediorderPartUtil.updateStockImageState(imageStockStates, (IStock) firstElement); @@ -194,7 +194,7 @@ public void postConstruct(Composite parent, EMenuService menuService, IExtension menuService.registerContextMenu(tableViewerDetails.getTable(), "ch.elexis.core.ui.mediorder.popupmenu.viewerdetails"); //$NON-NLS-1$ - tableViewer.setInput(stockService.getAllPatientStock()); + tableViewer.setInput(getStocksExcludingAwaitingRequests()); selectedDetailStock.addChangeListener(ev -> selectionService.setSelection(selectedDetailStock.getValue())); } @@ -700,6 +700,19 @@ private void addMedicationOrderEntryToStock(IStock stock, IArticle article) { MediorderPartUtil.updateStockImageState(imageStockStates, stock); } + /** + * Retrieves a list of patient stocks that doesn't contain stockEntries with the + * status {@link MediorderEntryState#AWAITING_REQUEST} + * + * @return + */ + private List getStocksExcludingAwaitingRequests() { + return stockService.getAllPatientStock().stream().filter(stock -> !stock.getStockEntries().isEmpty()) + .filter(stock -> stock.getStockEntries().stream().noneMatch( + entry -> MediorderEntryState.AWAITING_REQUEST.equals(MediorderPartUtil.determineState(entry)))) + .toList(); + } + @SuppressWarnings("unchecked") public List getSelectedStockEntries() { return tableViewerDetails.getStructuredSelection().toList(); @@ -736,11 +749,11 @@ public List getFilteredStocks() { return filteredStocks; } - public void setCurrentFilterValue(Integer value) { + public void setCurrentFilterValue(List value) { this.currentFilterValue = value; } - public Integer getCurrentFilterValue() { + public List getCurrentFilterValue() { return this.currentFilterValue; } } \ No newline at end of file diff --git a/bundles/ch.elexis.core.ui.mediorder/src/ch/elexis/core/ui/mediorder/MediorderPartUtil.java b/bundles/ch.elexis.core.ui.mediorder/src/ch/elexis/core/ui/mediorder/MediorderPartUtil.java index 96e067061b..77b266be56 100644 --- a/bundles/ch.elexis.core.ui.mediorder/src/ch/elexis/core/ui/mediorder/MediorderPartUtil.java +++ b/bundles/ch.elexis.core.ui.mediorder/src/ch/elexis/core/ui/mediorder/MediorderPartUtil.java @@ -194,26 +194,25 @@ public static int getImageForStock(Map imageStockStates, IStock /** * Filters the list of all available patient stocks based on the current filter - * value. The filtering process is performed by calculating the stock state for - * each {@link IStock} and comparing it to the current filter value. + * values. The filtering process is performed by calculating the stock state for + * each {@link IStock} and comparing it to the current filter values. * * @return */ - public static List calculateFilteredStocks(Integer filterValue) { - Map map = new HashMap(); + public static List calculateFilteredStocks(List filterValues) { + Map map = new HashMap<>(); List stocks = StockServiceHolder.get().getAllPatientStock(); for (IStock stock : stocks) { - calculateStockState(stock); map.computeIfAbsent(stock, MediorderPartUtil::calculateStockState); } - List list = new ArrayList(); - for (Map.Entry values : map.entrySet()) { - if (values.getValue().equals(filterValue)) { - list.add(values.getKey()); + List filteredList = new ArrayList<>(); + for (Map.Entry entry : map.entrySet()) { + if (entry.getValue() != null && filterValues.contains(entry.getValue())) { + filteredList.add(entry.getKey()); } } - return list; + return filteredList; } } \ No newline at end of file diff --git a/bundles/ch.elexis.core.ui.mediorder/src/ch/elexis/core/ui/mediorder/internal/handler/FilterByOrderStatusHandler.java b/bundles/ch.elexis.core.ui.mediorder/src/ch/elexis/core/ui/mediorder/internal/handler/FilterByOrderStatusHandler.java index b13ddba112..cb6635d027 100644 --- a/bundles/ch.elexis.core.ui.mediorder/src/ch/elexis/core/ui/mediorder/internal/handler/FilterByOrderStatusHandler.java +++ b/bundles/ch.elexis.core.ui.mediorder/src/ch/elexis/core/ui/mediorder/internal/handler/FilterByOrderStatusHandler.java @@ -1,5 +1,8 @@ package ch.elexis.core.ui.mediorder.internal.handler; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -14,7 +17,7 @@ import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.ToolItem; -import org.eclipse.ui.dialogs.ListDialog; +import org.eclipse.ui.dialogs.ListSelectionDialog; import ch.elexis.core.l10n.Messages; import ch.elexis.core.model.IStock; @@ -37,26 +40,28 @@ public Object execute(MPart part, MHandledToolItem item, @Named(IServiceConstant mediorderPart.setFilterActive(false); mediorderPart.refresh(); } else { - ListDialog selectFilterDialog = new ListDialog(shell); - selectFilterDialog.setContentProvider(ArrayContentProvider.getInstance()); - selectFilterDialog.setInput(stockStateMap.keySet().toArray()); - selectFilterDialog.setTitle(Messages.Core_Filter); - selectFilterDialog.setMessage(Messages.Mediorder_filter_by_status); - selectFilterDialog.setLabelProvider(new LabelProvider() { - @Override - public String getText(Object element) { - Integer key = (Integer) element; - return stockStateMap.getOrDefault(key, null); - } - }); - if (selectFilterDialog.open() == ListDialog.OK) { - Object[] selection = selectFilterDialog.getResult(); - Integer value = (Integer) selection[0]; + List reversedKeys = new ArrayList<>(stockStateMap.keySet()); + Collections.reverse(reversedKeys); - mediorderPart.setCurrentFilterValue(value); + ListSelectionDialog dialog = ListSelectionDialog.of(reversedKeys.toArray()) + .contentProvider(ArrayContentProvider.getInstance()).labelProvider(new LabelProvider() { + @Override + public String getText(Object element) { + Integer key = (Integer) element; + return stockStateMap.getOrDefault(key, null); + } + }) + .message(Messages.Mediorder_filter_by_status).create(shell); + dialog.setTitle(Messages.Core_Filter); + + if (dialog.open() == ListSelectionDialog.OK) { + List selections = Arrays.stream(dialog.getResult()).filter(obj -> obj instanceof Integer) + .map(obj -> (Integer) obj).toList(); + + mediorderPart.setCurrentFilterValue(selections); mediorderPart.setFilterActive(true); - mediorderPart.setFilteredStocks(filterPatientStock(value)); + mediorderPart.setFilteredStocks(filterPatientStock(selections)); mediorderPart.refresh(); } else { widget.setSelection(false); @@ -74,12 +79,12 @@ private Map createValues() { return map; } - private List filterPatientStock(Integer value) { + private List filterPatientStock(List values) { List stocks = StockServiceHolder.get().getAllPatientStock(); return stocks.stream().filter(stock -> { Integer state = MediorderPartUtil.calculateStockState(stock); - return state != null && state.equals(value); + return state != null && values.contains(state); }).toList(); - + } } \ No newline at end of file