Skip to content

Commit

Permalink
[25356] fix findings dynamic view create, edit, reload
Browse files Browse the repository at this point in the history
  • Loading branch information
huthomas committed Aug 23, 2023
1 parent b10a87e commit ecfec06
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -310,7 +311,7 @@ public Optional<ICoding> findOneCode(List<ICoding> 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();
Expand Down Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -255,7 +256,7 @@ private List<ICoding> expandGroups(List<ICoding> codings) {
}

public void refresh() {
dataProvider.reload(ElexisEventDispatcher.getSelectedPatient());
dataProvider.reload(ContextServiceHolder.get().getActivePatient().orElse(null));
natTable.refresh();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -79,7 +79,7 @@ public int getColumnCount() {
}
}

public void reload(Patient selectedPatient) {
public void reload(IPatient selectedPatient) {
if (selectedPatient == null) {
currentFindings.clear();
} else {
Expand All @@ -88,9 +88,9 @@ public void reload(Patient selectedPatient) {
updateShownFindings();
}

public List<IFinding> getFindings(Patient patient) {
public List<IFinding> getFindings(IPatient patient) {
List<IFinding> ret = new ArrayList<>();
if (patient != null && patient.exists()) {
if (patient != null) {
String patientId = patient.getId();
ret.addAll(getObservations(patientId));
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down

0 comments on commit ecfec06

Please sign in to comment.