diff --git a/bundles/ch.elexis.core.services/OSGI-INF/ch.elexis.core.services.OrderService.xml b/bundles/ch.elexis.core.services/OSGI-INF/ch.elexis.core.services.OrderService.xml index 3cdcef40f2..0d0d6565f1 100644 --- a/bundles/ch.elexis.core.services/OSGI-INF/ch.elexis.core.services.OrderService.xml +++ b/bundles/ch.elexis.core.services/OSGI-INF/ch.elexis.core.services.OrderService.xml @@ -1,7 +1,8 @@ - + + \ No newline at end of file diff --git a/bundles/ch.elexis.core.services/src/ch/elexis/core/services/OrderService.java b/bundles/ch.elexis.core.services/src/ch/elexis/core/services/OrderService.java index 48270d79d4..b6db309fbe 100644 --- a/bundles/ch.elexis.core.services/src/ch/elexis/core/services/OrderService.java +++ b/bundles/ch.elexis.core.services/src/ch/elexis/core/services/OrderService.java @@ -3,6 +3,7 @@ import java.util.List; import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; import ch.elexis.core.model.IArticle; import ch.elexis.core.model.IOrder; @@ -11,19 +12,21 @@ import ch.elexis.core.model.IStockEntry; import ch.elexis.core.model.OrderEntryState; import ch.elexis.core.services.IQuery.COMPARATOR; -import ch.elexis.core.services.holder.CoreModelServiceHolder; import ch.elexis.core.services.holder.StoreToStringServiceHolder; @Component public class OrderService implements IOrderService { + @Reference(target = "(" + IModelService.SERVICEMODELNAME + "=ch.elexis.core.model)") + private IModelService modelService; + public IOrderEntry findOpenOrderEntryForStockEntry(IStockEntry stockEntry) { IArticle article = stockEntry.getArticle(); if (article != null) { String[] articleStoreToStringParts = StoreToStringServiceHolder.getStoreToString(article) .split(IStoreToStringContribution.DOUBLECOLON); - IQuery query = CoreModelServiceHolder.get().getQuery(IOrderEntry.class); + IQuery query = modelService.getQuery(IOrderEntry.class); query.and("stockid", COMPARATOR.EQUALS, stockEntry.getStock().getId()); query.and("articleType", COMPARATOR.EQUALS, articleStoreToStringParts[0]); query.and("articleId", COMPARATOR.EQUALS, articleStoreToStringParts[1]); @@ -37,7 +40,7 @@ public IOrderEntry findOpenOrderEntryForStockEntry(IStockEntry stockEntry) { } public List findOrderEntryForStock(IStock stock) { - IQuery query = CoreModelServiceHolder.get().getQuery(IOrderEntry.class); + IQuery query = modelService.getQuery(IOrderEntry.class); query.and("stockid", COMPARATOR.EQUALS, stock.getId()); return query.execute(); } @@ -52,7 +55,7 @@ public IOrderEntry addRefillForStockEntryToOrder(IStockEntry ise, IOrder order) int toOrder = max - current; if (toOrder > 0) { IOrderEntry orderEntry = order.addEntry(ise.getArticle(), ise.getStock(), ise.getProvider(), toOrder); - CoreModelServiceHolder.get().save(orderEntry); + modelService.save(orderEntry); return orderEntry; } return null; diff --git a/bundles/ch.elexis.core.ui.mediorder/src/ch/elexis/core/ui/mediorder/MedicationHistoryComparator.java b/bundles/ch.elexis.core.ui.mediorder/src/ch/elexis/core/ui/mediorder/MedicationHistoryComparator.java new file mode 100644 index 0000000000..11e4b2fa91 --- /dev/null +++ b/bundles/ch.elexis.core.ui.mediorder/src/ch/elexis/core/ui/mediorder/MedicationHistoryComparator.java @@ -0,0 +1,54 @@ +package ch.elexis.core.ui.mediorder; + +import java.time.format.DateTimeFormatter; +import java.util.Comparator; +import java.util.Objects; + +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerComparator; + +import ch.elexis.core.model.IOrderEntry; + +public class MedicationHistoryComparator extends ViewerComparator { + private int propertyIndex; + private int direction; + private DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd.MM.yyyy"); + + public MedicationHistoryComparator() { + this.propertyIndex = 0; + this.direction = -1; + } + + public void setColumn(int column) { + if (column == this.propertyIndex) { + direction *= -1; + } + this.propertyIndex = column; + } + + @Override + public int compare(Viewer viewer, Object o1, Object o2) { + IOrderEntry orderEntry1 = (IOrderEntry) o1; + IOrderEntry orderEntry2 = (IOrderEntry) o2; + + switch (propertyIndex) { + case 0: + String articleName1 = orderEntry1.getArticle().getName(); + String articleName2 = orderEntry2.getArticle().getName(); + return Objects.compare(articleName1, articleName2, Comparator.nullsFirst(Comparator.naturalOrder())) + * direction; + case 1: + String orderAmount1 = String.valueOf(orderEntry1.getAmount()); + String orderAmount2 = String.valueOf(orderEntry2.getAmount()); + return Objects.compare(orderAmount1, orderAmount2, Comparator.nullsFirst(Comparator.naturalOrder())) + * direction; + case 2: + String orderDate1 = orderEntry1.getOrder().getTimestamp().format(dateFormatter); + String orderDate2 = orderEntry2.getOrder().getTimestamp().format(dateFormatter); + return Objects.compare(orderDate1, orderDate2, Comparator.nullsFirst(Comparator.naturalOrder())) + * direction; + } + + return super.compare(viewer, o1, o2); + } +} 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 95b47ed346..8b0f3f8b50 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 @@ -35,7 +35,7 @@ import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.CellEditor; import org.eclipse.jface.viewers.ColumnLabelProvider; -import org.eclipse.jface.viewers.ColumnPixelData; +import org.eclipse.jface.viewers.ColumnWeightData; import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.EditingSupport; import org.eclipse.jface.viewers.IStructuredSelection; @@ -303,7 +303,7 @@ public String getText(Object element) { }); TableColumn tblclmntvcOrderState = tvcOrderState.getColumn(); - tcLayout.setColumnData(tblclmntvcOrderState, new ColumnPixelData(20, true, true)); + tcLayout.setColumnData(tblclmntvcOrderState, new ColumnWeightData(0, 20, true)); tblclmntvcOrderState.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { @@ -322,7 +322,7 @@ public String getText(Object element) { } }); TableColumn tblclmntvcPatientNumber = tvcPatientNumber.getColumn(); - tcLayout.setColumnData(tblclmntvcPatientNumber, new ColumnPixelData(100, true, true)); + tcLayout.setColumnData(tblclmntvcPatientNumber, new ColumnWeightData(10, 70, true)); tblclmntvcPatientNumber.setText(Messages.Core_Patient_Number); tblclmntvcPatientNumber.addSelectionListener(new SelectionAdapter() { @Override @@ -337,7 +337,7 @@ public void widgetSelected(SelectionEvent e) { tvcPatientLastName .setLabelProvider(ColumnLabelProvider.createTextProvider(e -> ((IStock) e).getOwner().getLastName())); TableColumn tblclmntvcPatientLastName = tvcPatientLastName.getColumn(); - tcLayout.setColumnData(tblclmntvcPatientLastName, new ColumnPixelData(200, true, true)); + tcLayout.setColumnData(tblclmntvcPatientLastName, new ColumnWeightData(30, 200, true)); tblclmntvcPatientLastName.setText(Messages.Core_Name); tblclmntvcPatientLastName.addSelectionListener(new SelectionAdapter() { @Override @@ -352,7 +352,7 @@ public void widgetSelected(SelectionEvent e) { tvcPatientFirstName .setLabelProvider(ColumnLabelProvider.createTextProvider(e -> ((IStock) e).getOwner().getFirstName())); TableColumn tblclmntvcPatientFirstName = tvcPatientFirstName.getColumn(); - tcLayout.setColumnData(tblclmntvcPatientFirstName, new ColumnPixelData(200, true, true)); + tcLayout.setColumnData(tblclmntvcPatientFirstName, new ColumnWeightData(30, 200, true)); tblclmntvcPatientFirstName.setText(Messages.Core_Firstname); tblclmntvcPatientFirstName.addSelectionListener(new SelectionAdapter() { @Override @@ -373,7 +373,7 @@ public String getText(Object element) { } }); TableColumn tblclmntvcPatientBirthdate = tvcPatientBirthdate.getColumn(); - tcLayout.setColumnData(tblclmntvcPatientBirthdate, new ColumnPixelData(100, true, true)); + tcLayout.setColumnData(tblclmntvcPatientBirthdate, new ColumnWeightData(10, 90, true)); tblclmntvcPatientBirthdate.setText(Messages.Core_Enter_Birthdate); tblclmntvcPatientBirthdate.addSelectionListener(new SelectionAdapter() { @Override @@ -452,7 +452,7 @@ private void createPatientorderDetailViewer(Composite parent) { // MediorderEntryState TableViewerColumn tvcMediorderEntryState = new TableViewerColumn(tableViewerDetails, SWT.NONE); TableColumn tblclmntvcMedicationOrdered = tvcMediorderEntryState.getColumn(); - tcLayout_cDetails.setColumnData(tblclmntvcMedicationOrdered, new ColumnPixelData(120, true, true)); + tcLayout_cDetails.setColumnData(tblclmntvcMedicationOrdered, new ColumnWeightData(10, 120, true)); tblclmntvcMedicationOrdered.setText(Messages.Mediorder_Order_status); tblclmntvcMedicationOrdered.setImage(Images.IMG_PERSPECTIVE_ORDERS.getImage()); tblclmntvcMedicationOrdered.setToolTipText(Messages.Mediorder_Order_status_Tooltip); @@ -464,7 +464,7 @@ private void createPatientorderDetailViewer(Composite parent) { tvcMedication.setLabelProvider( ColumnLabelProvider.createTextProvider(e -> ((IStockEntry) e).getArticle().getLabel())); TableColumn tblclmntvcMedication = tvcMedication.getColumn(); - tcLayout_cDetails.setColumnData(tblclmntvcMedication, new ColumnPixelData(200, true, true)); + tcLayout_cDetails.setColumnData(tblclmntvcMedication, new ColumnWeightData(30, 400, true)); tblclmntvcMedication.setText(Messages.Core_Article); tblclmntvcMedication.addSelectionListener(new SelectionAdapter() { @Override @@ -489,7 +489,7 @@ public void widgetSelected(SelectionEvent e) { return ""; })); TableColumn tblclmntvcMedicationDosage = tvcMedicationDosage.getColumn(); - tcLayout_cDetails.setColumnData(tblclmntvcMedicationDosage, new ColumnPixelData(80, true, true)); + tcLayout_cDetails.setColumnData(tblclmntvcMedicationDosage, new ColumnWeightData(10, 70, true)); tblclmntvcMedicationDosage.setText(Messages.Core_Dosage); // medication no days consumption per dosage @@ -497,7 +497,7 @@ public void widgetSelected(SelectionEvent e) { tvcMediorderEntryOutreach.setLabelProvider( ColumnLabelProvider.createTextProvider(MediorderPartUtil::createMediorderEntryOutreachLabel)); TableColumn tblclmntvcMedicationAmountDay = tvcMediorderEntryOutreach.getColumn(); - tcLayout_cDetails.setColumnData(tblclmntvcMedicationAmountDay, new ColumnPixelData(110, true, true)); + tcLayout_cDetails.setColumnData(tblclmntvcMedicationAmountDay, new ColumnWeightData(10, 100, true)); tblclmntvcMedicationAmountDay.setText(Messages.Mediorder_sufficient_for); // medication designated amount for ordering @@ -538,7 +538,7 @@ protected void setValue(Object element, Object value) { }); TableColumn tblclmntvcMedicationAmount = tvcMedicationAmount.getColumn(); - tcLayout_cDetails.setColumnData(tblclmntvcMedicationAmount, new ColumnPixelData(110, true, true)); + tcLayout_cDetails.setColumnData(tblclmntvcMedicationAmount, new ColumnWeightData(10, 110, true)); tblclmntvcMedicationAmount.setText(Messages.Mediorder_requested); tblclmntvcMedicationAmount.setImage(Images.IMG_ACHTUNG.getImage()); tblclmntvcMedicationAmount.setToolTipText(Messages.Mediorder_requested_Tooltip); @@ -580,14 +580,14 @@ protected void setValue(Object element, Object value) { }); TableColumn tblclmntvcMedicationClearance = tvcMedicationClearance.getColumn(); - tcLayout_cDetails.setColumnData(tblclmntvcMedicationClearance, new ColumnPixelData(110, true, true)); + tcLayout_cDetails.setColumnData(tblclmntvcMedicationClearance, new ColumnWeightData(10, 110, true)); tblclmntvcMedicationClearance.setImage(Images.IMG_TICK.getImage()); tblclmntvcMedicationClearance.setText(Messages.Mediorder_approved); tblclmntvcMedicationClearance.setToolTipText(Messages.Mediorder_approved_Tooltip); TableViewerColumn tvcOrderDate = new TableViewerColumn(tableViewerDetails, SWT.NONE); TableColumn tblclmntvcOrderDate = tvcOrderDate.getColumn(); - tcLayout_cDetails.setColumnData(tblclmntvcOrderDate, new ColumnPixelData(110, true, true)); + tcLayout_cDetails.setColumnData(tblclmntvcOrderDate, new ColumnWeightData(10, 80, true)); tblclmntvcOrderDate.setText(Messages.Mediorder_order_date); tblclmntvcOrderDate.setToolTipText(Messages.Mediorder_order_date_Tooltip); tvcOrderDate.setLabelProvider(ColumnLabelProvider.createTextProvider(element -> { @@ -648,7 +648,7 @@ public void keyReleased(KeyEvent ke) { tvcMediorderOrderDate.setLabelProvider(ColumnLabelProvider .createTextProvider(e -> ((IOrderEntry) e).getOrder().getTimestamp().format(dateFormatter))); TableColumn tblclmntvcMedicationDosage = tvcMediorderOrderDate.getColumn(); - tcLayout_cHistory.setColumnData(tblclmntvcMedicationDosage, new ColumnPixelData(120, true, true)); + tcLayout_cHistory.setColumnData(tblclmntvcMedicationDosage, new ColumnWeightData(10, 70, true)); tblclmntvcMedicationDosage.setText(Messages.Core_Date); tblclmntvcMedicationDosage.addSelectionListener(new SelectionAdapter() { @Override @@ -660,7 +660,7 @@ public void widgetSelected(SelectionEvent e) { TableViewerColumn tvcMediorderArticle = new TableViewerColumn(tableViewerHistory, SWT.NONE); TableColumn tblclmntvcMedicationArticle = tvcMediorderArticle.getColumn(); - tcLayout_cHistory.setColumnData(tblclmntvcMedicationArticle, new ColumnPixelData(400, true, true)); + tcLayout_cHistory.setColumnData(tblclmntvcMedicationArticle, new ColumnWeightData(30, 400, true)); tblclmntvcMedicationArticle.setText(Messages.Core_Article); tvcMediorderArticle.setLabelProvider( ColumnLabelProvider.createTextProvider(e -> ((IOrderEntry) e).getArticle().getLabel())); @@ -676,7 +676,7 @@ public void widgetSelected(SelectionEvent e) { tvcMediorderAmount.setLabelProvider( ColumnLabelProvider.createTextProvider(e -> (String.valueOf(((IOrderEntry) e).getAmount())))); TableColumn tblclmntvcMediorderAmount = tvcMediorderAmount.getColumn(); - tcLayout_cHistory.setColumnData(tblclmntvcMediorderAmount, new ColumnPixelData(100, true, true)); + tcLayout_cHistory.setColumnData(tblclmntvcMediorderAmount, new ColumnWeightData(10, 50, true)); tblclmntvcMediorderAmount.setText(Messages.Core_Count); tblclmntvcMediorderAmount.addSelectionListener(new SelectionAdapter() { @Override @@ -804,49 +804,6 @@ public int compare(Viewer viewer, Object o1, Object o2) { } } - public class MedicationHistoryComparator extends ViewerComparator { - private int propertyIndex; - private int direction; - - public MedicationHistoryComparator() { - this.propertyIndex = 0; - this.direction = -1; - } - - public void setColumn(int column) { - if (column == this.propertyIndex) { - direction *= -1; - } - this.propertyIndex = column; - } - - @Override - public int compare(Viewer viewer, Object o1, Object o2) { - IOrderEntry orderEntry1 = (IOrderEntry) o1; - IOrderEntry orderEntry2 = (IOrderEntry) o2; - - switch (propertyIndex) { - case 0: - String articleName1 = orderEntry1.getArticle().getName(); - String articleName2 = orderEntry2.getArticle().getName(); - return Objects.compare(articleName1, articleName2, Comparator.nullsFirst(Comparator.naturalOrder())) - * direction; - case 1: - String orderAmount1 = String.valueOf(orderEntry1.getAmount()); - String orderAmount2 = String.valueOf(orderEntry2.getAmount()); - return Objects.compare(orderAmount1, orderAmount2, Comparator.nullsFirst(Comparator.naturalOrder())) - * direction; - case 2: - String orderDate1 = orderEntry1.getOrder().getTimestamp().format(dateFormatter); - String orderDate2 = orderEntry2.getOrder().getTimestamp().format(dateFormatter); - return Objects.compare(orderDate1, orderDate2, Comparator.nullsFirst(Comparator.naturalOrder())) - * direction; - } - - return super.compare(viewer, o1, o2); - } - } - private void addMedicationOrderEntryToStock(IStock stock, IArticle article) { if (StringUtils.isBlank(article.getGtin())) { // TODO inform user not possible