Skip to content

Commit

Permalink
[26697] filter multiple order status & don't show pea orders by defau…
Browse files Browse the repository at this point in the history
…lt (#741)

Co-authored-by: pdenzler <[email protected]>
  • Loading branch information
PatrickDenzler and pdenzler authored Oct 29, 2024
1 parent ffe91f8 commit 787ac05
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public class MediorderPart implements IRefreshablePart {

public Map<IStock, Integer> imageStockStates = new HashMap<IStock, Integer>();
private List<IStock> filteredStocks = new ArrayList<>();
private Integer currentFilterValue;
private List<Integer> currentFilterValue;
private boolean filterActive = false;

public MediorderPart() {
Expand Down Expand Up @@ -166,7 +166,7 @@ public void reload(@UIEventTopic(ElexisEventTopics.EVENT_RELOAD) Class<?> clazz)
public void refresh(Map<Object, Object> 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);
Expand Down Expand Up @@ -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()));
}
Expand Down Expand Up @@ -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<IStock> 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<IStockEntry> getSelectedStockEntries() {
return tableViewerDetails.getStructuredSelection().toList();
Expand Down Expand Up @@ -736,11 +749,11 @@ public List<IStock> getFilteredStocks() {
return filteredStocks;
}

public void setCurrentFilterValue(Integer value) {
public void setCurrentFilterValue(List<Integer> value) {
this.currentFilterValue = value;
}

public Integer getCurrentFilterValue() {
public List<Integer> getCurrentFilterValue() {
return this.currentFilterValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,26 +194,25 @@ public static int getImageForStock(Map<IStock, Integer> 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<IStock> calculateFilteredStocks(Integer filterValue) {
Map<IStock, Integer> map = new HashMap<IStock, Integer>();
public static List<IStock> calculateFilteredStocks(List<Integer> filterValues) {
Map<IStock, Integer> map = new HashMap<>();

List<IStock> stocks = StockServiceHolder.get().getAllPatientStock();
for (IStock stock : stocks) {
calculateStockState(stock);
map.computeIfAbsent(stock, MediorderPartUtil::calculateStockState);
}

List<IStock> list = new ArrayList<IStock>();
for (Map.Entry<IStock, Integer> values : map.entrySet()) {
if (values.getValue().equals(filterValue)) {
list.add(values.getKey());
List<IStock> filteredList = new ArrayList<>();
for (Map.Entry<IStock, Integer> entry : map.entrySet()) {
if (entry.getValue() != null && filterValues.contains(entry.getValue())) {
filteredList.add(entry.getKey());
}
}
return list;
return filteredList;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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<Integer> 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<Integer> 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);
Expand All @@ -74,12 +79,12 @@ private Map<Integer, String> createValues() {
return map;
}

private List<IStock> filterPatientStock(Integer value) {
private List<IStock> filterPatientStock(List<Integer> values) {
List<IStock> 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();

}
}

0 comments on commit 787ac05

Please sign in to comment.