From ecfec0674f8137e9844849b2331df8cea87971ed Mon Sep 17 00:00:00 2001 From: thuster Date: Thu, 15 Jun 2023 10:51:25 +0200 Subject: [PATCH] [25356] fix findings dynamic view create, edit, reload --- .../service/FindingsTemplateService.java | 11 +++--- .../ui/handler/FindingCreateHandler.java | 35 +++++++++---------- .../service/IFindingsTemplateService.java | 3 +- .../ui/handler/FindingEditHandler.java | 7 ++-- .../ui/handler/SelectVisibleCodesHandler.java | 7 ++-- .../ui/views/FindingsViewDynamic.java | 3 +- .../views/nattable/DynamicDataProvider.java | 8 ++--- .../ch/elexis/core/ui/e4/util/CoreUiUtil.java | 5 +-- 8 files changed, 38 insertions(+), 41 deletions(-) diff --git a/bundles/ch.elexis.core.findings.templates.po/src/ch/elexis/core/findings/templates/service/FindingsTemplateService.java b/bundles/ch.elexis.core.findings.templates.po/src/ch/elexis/core/findings/templates/service/FindingsTemplateService.java index 13773f56c1..4d01203971 100644 --- a/bundles/ch.elexis.core.findings.templates.po/src/ch/elexis/core/findings/templates/service/FindingsTemplateService.java +++ b/bundles/ch.elexis.core.findings.templates.po/src/ch/elexis/core/findings/templates/service/FindingsTemplateService.java @@ -1,6 +1,5 @@ package ch.elexis.core.findings.templates.service; -import org.apache.commons.lang3.StringUtils; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; @@ -15,6 +14,7 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.ObjectUtils; +import org.apache.commons.lang3.StringUtils; import org.eclipse.core.runtime.Assert; import org.eclipse.emf.common.util.ECollections; import org.eclipse.emf.common.util.URI; @@ -56,6 +56,7 @@ import ch.elexis.core.findings.templates.model.ModelFactory; import ch.elexis.core.findings.templates.model.Type; import ch.elexis.core.model.IBlob; +import ch.elexis.core.model.IPatient; import ch.elexis.core.services.IModelService; import ch.elexis.core.services.IQuery; import ch.elexis.core.services.IQuery.COMPARATOR; @@ -213,9 +214,9 @@ public void addComponent(IFinding iFinding, FindingsTemplate findingsTemplate) { } @Override - public IFinding createFinding(Patient patient, FindingsTemplate findingsTemplate) throws ElexisException { + public IFinding createFinding(IPatient patient, FindingsTemplate findingsTemplate) throws ElexisException { IFinding iFinding = null; - if (patient != null && patient.exists()) { + if (patient != null) { validateCycleDetection(findingsTemplate, 0, 100); Type type = findingsTemplate.getType(); @@ -310,7 +311,7 @@ public Optional findOneCode(List coding, CodingSystem codingSy return Optional.empty(); } - private void setFindingsAttributes(IFinding iFinding, Patient patient, FindingsTemplate findingsTemplate) { + private void setFindingsAttributes(IFinding iFinding, IPatient patient, FindingsTemplate findingsTemplate) { if (iFinding != null) { iFinding.setPatientId(patient.getId()); String text = findingsTemplate.getTitle(); @@ -355,7 +356,7 @@ public void validateCycleDetection(FindingsTemplate findingsTemplate, int depth, } } - private IFinding createObservation(Patient patient, FindingsTemplate findingsTemplate) throws ElexisException { + private IFinding createObservation(IPatient patient, FindingsTemplate findingsTemplate) throws ElexisException { IObservation iObservation = create(IObservation.class); iObservation.setEffectiveTime(LocalDateTime.now()); switch (findingsTemplate.getType()) { diff --git a/bundles/ch.elexis.core.findings.templates.ui/src/ch/elexis/core/findings/templates/ui/handler/FindingCreateHandler.java b/bundles/ch.elexis.core.findings.templates.ui/src/ch/elexis/core/findings/templates/ui/handler/FindingCreateHandler.java index f27f81972a..a1055cd0bd 100644 --- a/bundles/ch.elexis.core.findings.templates.ui/src/ch/elexis/core/findings/templates/ui/handler/FindingCreateHandler.java +++ b/bundles/ch.elexis.core.findings.templates.ui/src/ch/elexis/core/findings/templates/ui/handler/FindingCreateHandler.java @@ -9,14 +9,14 @@ import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.widgets.Display; -import ch.elexis.core.data.events.ElexisEvent; -import ch.elexis.core.data.events.ElexisEventDispatcher; import ch.elexis.core.exceptions.ElexisException; import ch.elexis.core.findings.IFinding; import ch.elexis.core.findings.templates.model.FindingsTemplate; import ch.elexis.core.findings.templates.ui.dlg.FindingsSelectionDialog; import ch.elexis.core.findings.templates.ui.util.FindingsServiceHolder; import ch.elexis.core.findings.ui.util.FindingsUiUtil; +import ch.elexis.core.model.IPatient; +import ch.elexis.core.services.holder.ContextServiceHolder; import ch.elexis.core.ui.UiDesk; public class FindingCreateHandler extends AbstractHandler implements IHandler { @@ -32,23 +32,22 @@ public Object execute(ExecutionEvent event) throws ExecutionException { if (selection != null) { IFinding iFinding; try { - iFinding = FindingsServiceHolder.findingsTemplateService - .createFinding(ElexisEventDispatcher.getSelectedPatient(), selection); + IPatient patient = ContextServiceHolder.get().getActivePatient().orElse(null); + if (patient != null) { + iFinding = FindingsServiceHolder.findingsTemplateService.createFinding(patient, selection); - Boolean okPressed = (Boolean) FindingsUiUtil - .executeCommand("ch.elexis.core.findings.ui.commandEdit", iFinding); - if (okPressed) { - ElexisEventDispatcher.getInstance().fire(new ElexisEvent(iFinding, IFinding.class, - ElexisEvent.EVENT_CREATE, ElexisEvent.PRIORITY_NORMAL)); - - return iFinding; - } else { - // if cancel delete the created finding - try { - FindingsUiUtil.deleteFinding(iFinding); - } catch (ElexisException e) { - MessageDialog.openError(UiDesk.getDisplay().getActiveShell(), "Fehler", e.getMessage()); - } + Boolean okPressed = (Boolean) FindingsUiUtil + .executeCommand("ch.elexis.core.findings.ui.commandEdit", iFinding); + if (okPressed) { + return iFinding; + } else { + // if cancel delete the created finding + try { + FindingsUiUtil.deleteFinding(iFinding); + } catch (ElexisException e) { + MessageDialog.openError(UiDesk.getDisplay().getActiveShell(), "Fehler", e.getMessage()); + } + } } } catch (ElexisException e) { MessageDialog.openWarning(Display.getDefault().getActiveShell(), "Befunde Vorlagen", diff --git a/bundles/ch.elexis.core.findings.templates/src/ch/elexis/core/findings/templates/service/IFindingsTemplateService.java b/bundles/ch.elexis.core.findings.templates/src/ch/elexis/core/findings/templates/service/IFindingsTemplateService.java index dd12f3bb0d..0ad851ecf9 100644 --- a/bundles/ch.elexis.core.findings.templates/src/ch/elexis/core/findings/templates/service/IFindingsTemplateService.java +++ b/bundles/ch.elexis.core.findings.templates/src/ch/elexis/core/findings/templates/service/IFindingsTemplateService.java @@ -10,6 +10,7 @@ import ch.elexis.core.findings.templates.model.FindingsTemplate; import ch.elexis.core.findings.templates.model.FindingsTemplates; import ch.elexis.core.findings.templates.model.Type; +import ch.elexis.core.model.IPatient; import ch.elexis.data.Patient; public interface IFindingsTemplateService { @@ -23,7 +24,7 @@ public interface IFindingsTemplateService { * @return * @throws ElexisException */ - public IFinding createFinding(Patient load, FindingsTemplate template) throws ElexisException; + public IFinding createFinding(IPatient load, FindingsTemplate template) throws ElexisException; /** * Get a findings templates model. diff --git a/bundles/ch.elexis.core.findings.ui/src/ch/elexis/core/findings/ui/handler/FindingEditHandler.java b/bundles/ch.elexis.core.findings.ui/src/ch/elexis/core/findings/ui/handler/FindingEditHandler.java index 574a6c885d..19d785e47a 100644 --- a/bundles/ch.elexis.core.findings.ui/src/ch/elexis/core/findings/ui/handler/FindingEditHandler.java +++ b/bundles/ch.elexis.core.findings.ui/src/ch/elexis/core/findings/ui/handler/FindingEditHandler.java @@ -12,11 +12,11 @@ import org.eclipse.ui.PlatformUI; import org.eclipse.ui.handlers.HandlerUtil; -import ch.elexis.core.data.events.ElexisEvent; -import ch.elexis.core.data.events.ElexisEventDispatcher; +import ch.elexis.core.common.ElexisEventTopics; import ch.elexis.core.findings.IFinding; import ch.elexis.core.findings.ui.dialogs.FindingsEditDialog; import ch.elexis.core.findings.ui.services.FindingsServiceComponent; +import ch.elexis.core.services.holder.ContextServiceHolder; import ch.elexis.core.ui.locks.AcquireLockBlockingUi; import ch.elexis.core.ui.locks.ILockHandler; @@ -62,8 +62,7 @@ public void lockAcquired() { // } // } FindingsServiceComponent.getService().saveFinding(iFinding); - ElexisEventDispatcher.getInstance() - .fire(new ElexisEvent(iFinding, IFinding.class, ElexisEvent.EVENT_RELOAD)); + ContextServiceHolder.get().postEvent(ElexisEventTopics.EVENT_RELOAD, IFinding.class); ret = Boolean.TRUE; } } diff --git a/bundles/ch.elexis.core.findings.ui/src/ch/elexis/core/findings/ui/handler/SelectVisibleCodesHandler.java b/bundles/ch.elexis.core.findings.ui/src/ch/elexis/core/findings/ui/handler/SelectVisibleCodesHandler.java index 10f92c26e3..afe594ded4 100644 --- a/bundles/ch.elexis.core.findings.ui/src/ch/elexis/core/findings/ui/handler/SelectVisibleCodesHandler.java +++ b/bundles/ch.elexis.core.findings.ui/src/ch/elexis/core/findings/ui/handler/SelectVisibleCodesHandler.java @@ -8,11 +8,11 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.handlers.HandlerUtil; -import ch.elexis.core.data.events.ElexisEvent; -import ch.elexis.core.data.events.ElexisEventDispatcher; +import ch.elexis.core.common.ElexisEventTopics; import ch.elexis.core.findings.ICoding; import ch.elexis.core.findings.ui.dialogs.VisibleCodingsSelectionDialog; import ch.elexis.core.findings.ui.util.FindingsUiUtil; +import ch.elexis.core.services.holder.ContextServiceHolder; public class SelectVisibleCodesHandler extends AbstractHandler implements IHandler { @@ -25,8 +25,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException { dialog.setSelected(FindingsUiUtil.loadVisibleCodings()); if (dialog.open() == Window.OK) { FindingsUiUtil.saveVisibleCodings(dialog.getSelected()); - ElexisEventDispatcher.getInstance() - .fire(new ElexisEvent(null, ICoding.class, ElexisEvent.EVENT_RELOAD, ElexisEvent.PRIORITY_NORMAL)); + ContextServiceHolder.get().postEvent(ElexisEventTopics.EVENT_RELOAD, ICoding.class); } return null; } diff --git a/bundles/ch.elexis.core.findings.ui/src/ch/elexis/core/findings/ui/views/FindingsViewDynamic.java b/bundles/ch.elexis.core.findings.ui/src/ch/elexis/core/findings/ui/views/FindingsViewDynamic.java index 0a386d6d8b..af1c659719 100644 --- a/bundles/ch.elexis.core.findings.ui/src/ch/elexis/core/findings/ui/views/FindingsViewDynamic.java +++ b/bundles/ch.elexis.core.findings.ui/src/ch/elexis/core/findings/ui/views/FindingsViewDynamic.java @@ -52,6 +52,7 @@ import ch.elexis.core.findings.ui.views.nattable.NatTableWrapper; import ch.elexis.core.findings.ui.views.nattable.NatTableWrapper.IDoubleClickListener; import ch.elexis.core.services.holder.ConfigServiceHolder; +import ch.elexis.core.services.holder.ContextServiceHolder; import ch.elexis.core.ui.actions.GlobalEventDispatcher; import ch.elexis.core.ui.actions.IActivationListener; import ch.elexis.core.ui.events.ElexisUiEventListenerImpl; @@ -255,7 +256,7 @@ private List expandGroups(List codings) { } public void refresh() { - dataProvider.reload(ElexisEventDispatcher.getSelectedPatient()); + dataProvider.reload(ContextServiceHolder.get().getActivePatient().orElse(null)); natTable.refresh(); } diff --git a/bundles/ch.elexis.core.findings.ui/src/ch/elexis/core/findings/ui/views/nattable/DynamicDataProvider.java b/bundles/ch.elexis.core.findings.ui/src/ch/elexis/core/findings/ui/views/nattable/DynamicDataProvider.java index ded315eb9c..c2a967d0c9 100644 --- a/bundles/ch.elexis.core.findings.ui/src/ch/elexis/core/findings/ui/views/nattable/DynamicDataProvider.java +++ b/bundles/ch.elexis.core.findings.ui/src/ch/elexis/core/findings/ui/views/nattable/DynamicDataProvider.java @@ -13,7 +13,7 @@ import ch.elexis.core.findings.IFinding; import ch.elexis.core.findings.IObservation; import ch.elexis.core.findings.ui.services.FindingsServiceComponent; -import ch.elexis.data.Patient; +import ch.elexis.core.model.IPatient; public class DynamicDataProvider implements IDataProvider { @@ -79,7 +79,7 @@ public int getColumnCount() { } } - public void reload(Patient selectedPatient) { + public void reload(IPatient selectedPatient) { if (selectedPatient == null) { currentFindings.clear(); } else { @@ -88,9 +88,9 @@ public void reload(Patient selectedPatient) { updateShownFindings(); } - public List getFindings(Patient patient) { + public List getFindings(IPatient patient) { List ret = new ArrayList<>(); - if (patient != null && patient.exists()) { + if (patient != null) { String patientId = patient.getId(); ret.addAll(getObservations(patientId)); /* diff --git a/bundles/ch.elexis.core.ui.e4/src/ch/elexis/core/ui/e4/util/CoreUiUtil.java b/bundles/ch.elexis.core.ui.e4/src/ch/elexis/core/ui/e4/util/CoreUiUtil.java index ac135c4b49..41402a7208 100644 --- a/bundles/ch.elexis.core.ui.e4/src/ch/elexis/core/ui/e4/util/CoreUiUtil.java +++ b/bundles/ch.elexis.core.ui.e4/src/ch/elexis/core/ui/e4/util/CoreUiUtil.java @@ -315,10 +315,7 @@ public static StructuredSelection getCommandSelection(IEclipseContext iEclipseCo * @param selection */ public static void setCommandSelection(String commandId, Object[] selection) { - if (serviceContext == null) { - CoreUiUtil.serviceContext = getServiceContext(); - } - serviceContext.set(commandId.concat(".selection"), //$NON-NLS-1$ + applicationContext.set(commandId.concat(".selection"), //$NON-NLS-1$ new StructuredSelection(selection)); }