Skip to content

Commit

Permalink
[26782] code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pdenzler authored and pdenzler committed Dec 2, 2024
1 parent 7023d57 commit aa963a9
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="ch.elexis.core.services.OrderService">
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.3.0" name="ch.elexis.core.services.OrderService">
<service>
<provide interface="ch.elexis.core.services.IOrderService"/>
</service>
<reference cardinality="1..1" field="modelService" interface="ch.elexis.core.services.IModelService" name="modelService" target="(service.model.name=ch.elexis.core.model)"/>
<implementation class="ch.elexis.core.services.OrderService"/>
</scr:component>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<IOrderEntry> query = CoreModelServiceHolder.get().getQuery(IOrderEntry.class);
IQuery<IOrderEntry> 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]);
Expand All @@ -37,7 +40,7 @@ public IOrderEntry findOpenOrderEntryForStockEntry(IStockEntry stockEntry) {
}

public List<IOrderEntry> findOrderEntryForStock(IStock stock) {
IQuery<IOrderEntry> query = CoreModelServiceHolder.get().getQuery(IOrderEntry.class);
IQuery<IOrderEntry> query = modelService.getQuery(IOrderEntry.class);
query.and("stockid", COMPARATOR.EQUALS, stock.getId());
return query.execute();
}
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -489,15 +489,15 @@ 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
TableViewerColumn tvcMediorderEntryOutreach = new TableViewerColumn(tableViewerDetails, SWT.NONE);
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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 -> {
Expand Down Expand Up @@ -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
Expand All @@ -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()));
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit aa963a9

Please sign in to comment.