Skip to content

Commit

Permalink
[26187] add old hl7 medics order, make new web order optional via pref
Browse files Browse the repository at this point in the history
  • Loading branch information
huthomas committed Feb 21, 2024
1 parent d16cd1b commit e6faab8
Show file tree
Hide file tree
Showing 4 changed files with 536 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;

Expand All @@ -30,24 +31,30 @@
public class MedicsPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {

public static final String DOWNLOAD_DIR = "medics/download"; //$NON-NLS-1$
public static final String UPLOAD_DIR = "medics/upload"; //$NON-NLS-1$
public static final String IMED_DIR = "medics/uploadimed"; //$NON-NLS-1$
public static final String ARCHIV_DIR = "medics/archiv"; //$NON-NLS-1$
public static final String ERROR_DIR = "medics/error"; //$NON-NLS-1$
public static final String DOKUMENT_CATEGORY = "medics/extern"; //$NON-NLS-1$
public static final String DELETE_ARCHIV_DAYS = "medics/del_archiv/days"; //$NON-NLS-1$

private static final String DEFAULT_DOWNLOAD = StringUtils.EMPTY;
private static final String DEFAULT_UPLOAD = StringUtils.EMPTY;
private static final String DEFAULT_IMED = StringUtils.EMPTY;
private static final String DEFAULT_ARCHIV = StringUtils.EMPTY;
private static final String DEFAULT_DOKUMENT_CATEGORY = Messages.MedicsPreferencePage_documentCategoryName;
private static final int DEFAULT_DELETE_ARCHIV_DAYS = 30;

public static final String CFG_MEDICS_ORDER_API = "medics/order_api"; //$NON-NLS-1$

private List<WebAisMandatorComposite> webaisMandators;
private Composite mandatorsContainer;

public MedicsPreferencePage() {
super(GRID);
setPreferenceStore(new SettingsPreferenceStore(CoreHub.localCfg));
getPreferenceStore().setDefault(DOWNLOAD_DIR, DEFAULT_DOWNLOAD);
getPreferenceStore().setDefault(UPLOAD_DIR, DEFAULT_UPLOAD);
getPreferenceStore().setDefault(IMED_DIR, DEFAULT_IMED);
getPreferenceStore().setDefault(ARCHIV_DIR, DEFAULT_ARCHIV);
getPreferenceStore().setDefault(DOKUMENT_CATEGORY, DEFAULT_DOKUMENT_CATEGORY);
Expand All @@ -68,13 +75,35 @@ protected Control createContents(Composite parent) {
super.createContents(fieldEditorContainer);
getFieldEditorParent().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

Label separator = new Label(container, SWT.HORIZONTAL | SWT.SEPARATOR);
separator.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
Button btnChangeApi = new Button(container, SWT.PUSH);
btnChangeApi.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (StringUtils.isEmpty(ConfigServiceHolder.get().get(CFG_MEDICS_ORDER_API, ""))) {
ConfigServiceHolder.get().set(CFG_MEDICS_ORDER_API, "web");
btnChangeApi.setText("Wechsel auf HL7 API");

mandatorsContainer.setVisible(true);
((GridData) mandatorsContainer.getLayoutData()).exclude = false;
} else {
ConfigServiceHolder.get().set(CFG_MEDICS_ORDER_API, "");
btnChangeApi.setText("Wechsel auf Web API (neu)");

mandatorsContainer.setVisible(false);
((GridData) mandatorsContainer.getLayoutData()).exclude = true;
}
layoutParentShell(container);
}
});
btnChangeApi.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false));

Composite mandatorsContainer = new Composite(container, SWT.NONE);
mandatorsContainer = new Composite(container, SWT.NONE);
mandatorsContainer.setLayout(new GridLayout());
mandatorsContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

Label separator = new Label(mandatorsContainer, SWT.HORIZONTAL | SWT.SEPARATOR);
separator.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

if (ContextServiceHolder.get().getActiveUser().isPresent()
&& ContextServiceHolder.get().getActiveUser().get().isAdministrator()) {
Button useTestBtn = new Button(mandatorsContainer, SWT.CHECK);
Expand All @@ -101,6 +130,16 @@ public void widgetSelected(SelectionEvent e) {
webaisMandators.add(composite);
}

if (StringUtils.isEmpty(ConfigServiceHolder.get().get(CFG_MEDICS_ORDER_API, ""))) {
btnChangeApi.setText("Wechsel auf Web API (neu)");
mandatorsContainer.setVisible(false);
((GridData) mandatorsContainer.getLayoutData()).exclude = true;
} else {
btnChangeApi.setText("Wechsel auf HL7 API");
mandatorsContainer.setVisible(true);
((GridData) mandatorsContainer.getLayoutData()).exclude = false;
}

return container;
}

Expand All @@ -112,6 +151,8 @@ public void updateMandatorComposites() {
protected void createFieldEditors() {
addField(new DirectoryFieldEditor(DOWNLOAD_DIR, Messages.MedicsPreferencePage_labelDownloadDir,
getFieldEditorParent()));
addField(new DirectoryFieldEditor(UPLOAD_DIR, Messages.MedicsPreferencePage_labelUploadDir,
getFieldEditorParent()));
addField(new DirectoryFieldEditor(IMED_DIR, Messages.MedicsPreferencePage_labelUploadDirimed,
getFieldEditorParent()));
addField(new DirectoryFieldEditor(ARCHIV_DIR, Messages.MedicsPreferencePage_labelArchivDir,
Expand Down Expand Up @@ -139,7 +180,21 @@ public static String getUploadDirimed() {
return CoreHub.localCfg.get(IMED_DIR, DEFAULT_IMED);
}

public static String getUploadDir() {
return CoreHub.localCfg.get(UPLOAD_DIR, DEFAULT_UPLOAD);
}

@Override
public void init(IWorkbench workbench) {
}

public static void layoutParentShell(Composite composite) {
Composite parent = composite.getParent();
while (parent != null && !(parent instanceof Shell)) {
parent = parent.getParent();
}
if (parent instanceof Shell) {
parent.layout(true, true);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package ch.elexis.labor.medics.v2.data;

import java.io.File;
import java.io.FileInputStream;
import java.text.MessageFormat;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ch.elexis.core.data.util.PlatformHelper;
import ch.elexis.core.ui.util.SWTHelper;
import ch.elexis.data.Kontakt;
import ch.elexis.data.PersistentObject;
import ch.elexis.labor.medics.v2.Messages;
import ch.rgw.tools.ExHandler;
import ch.rgw.tools.JdbcLink;
import ch.rgw.tools.JdbcLink.Stm;

public class KontaktOrderManagement extends PersistentObject {
public static final String TABLENAME = "KONTAKT_ORDER_MANAGEMENT"; //$NON-NLS-1$

public static final String FLD_KONTAKT_ID = "KONTAKT_ID"; //$NON-NLS-1$
public static final String FLD_ORDER_NR = "ORDER_NR"; //$NON-NLS-1$

public static long FIRST_ORDER_NR = 100000;

private static final JdbcLink j = getConnection();
protected static Logger log = LoggerFactory.getLogger(KontaktOrderManagement.class.getName());

static {
if (!tableExists(TABLENAME)) {
String filepath = PlatformHelper.getBasePath("ch.elexis.laborimport.medics.v2") //$NON-NLS-1$
+ File.separator + "createTable.script"; //$NON-NLS-1$
Stm stm = j.getStatement();
try {
FileInputStream fis = new FileInputStream(filepath);
stm.execScript(fis, true, true);
} catch (Exception e) {
ExHandler.handle(e);
SWTHelper.showError(Messages.KontaktOrderManagement_titleErrorCreateDB,
MessageFormat.format(Messages.KontaktOrderManagement_messageErrorCreateDB, filepath));
} finally {
j.releaseStatement(stm);
}

}
addMapping(TABLENAME, FLD_KONTAKT_ID, FLD_ORDER_NR);
}

public KontaktOrderManagement() {
super();
}

private KontaktOrderManagement(String id) {
super(id);
}

public KontaktOrderManagement(final Kontakt kontakt) {
create(null);
setKontakt(kontakt);
setOrderNr(FIRST_ORDER_NR);
}

/** Eine KontaktOrderManagement anhand der ID aus der Datenbank laden */
public static KontaktOrderManagement load(String id) {
return new KontaktOrderManagement(id);
}

public Kontakt getKontakt() {
return Kontakt.load(get(FLD_KONTAKT_ID));
}

public void setKontakt(final Kontakt kontakt) {
if (kontakt != null) {
set(FLD_KONTAKT_ID, kontakt.getId());
}
}

/**
* Transforms text into int value.
*
* @param doubleStr
* @return
*/
private static Long getLong(final String longStr) {
Long value = null;
if (longStr != null && longStr.length() > 0) {
try {
value = Long.parseLong(longStr);
} catch (NumberFormatException e) {
log.warn(MessageFormat.format("Could not parse long {0}!", longStr), e);
}
}
return value;
}

public Long getOrderNr() {
String intStr = get(FLD_ORDER_NR);
return getLong(intStr);
}

public void setOrderNr(final Long orderNr) {
if (orderNr != null) {
set(FLD_ORDER_NR, orderNr.toString());
}
}

@Override
public String getLabel() {
Kontakt kontakt = getKontakt();
if (kontakt != null) {
return kontakt.getLabel() + " (" + getOrderNr() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
}
return "-"; //$NON-NLS-1$
}

@Override
protected String getTableName() {
return TABLENAME;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,49 @@

import java.util.Optional;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.program.Program;
import org.eclipse.swt.widgets.Shell;

import ch.elexis.core.model.IPatient;
import ch.elexis.core.services.holder.ConfigServiceHolder;
import ch.elexis.core.services.holder.ContextServiceHolder;
import ch.elexis.labor.medics.v2.MedicsActivator;
import ch.elexis.labor.medics.v2.MedicsPreferencePage;
import ch.elexis.labor.medics.v2.Messages;

public class LabOrderAction extends Action {

private LabOrderActionHl7 labOrderHl7;

public LabOrderAction() {
setId("laborder"); //$NON-NLS-1$
setImageDescriptor(MedicsActivator.getImageDescriptor("rsc/medics16.png")); //$NON-NLS-1$
setText(Messages.LabOrderAction_nameAction);

labOrderHl7 = new LabOrderActionHl7();
}

@Override
public void run() {
Optional<IPatient> patient = ContextServiceHolder.get().getActivePatient();
if (patient.isPresent()) {
WebAis webAis = new WebAis();
String response = webAis.createPatientAndOrder(patient.get());
if (isUrl(response)) {
Program.launch(response);
if (StringUtils.isEmpty(ConfigServiceHolder.get().get(MedicsPreferencePage.CFG_MEDICS_ORDER_API, ""))) {
labOrderHl7.run();
} else {
Optional<IPatient> patient = ContextServiceHolder.get().getActivePatient();
if (patient.isPresent()) {
WebAis webAis = new WebAis();
String response = webAis.createPatientAndOrder(patient.get());
if (isUrl(response)) {
Program.launch(response);
} else {
MessageDialog.openError(new Shell(), Messages.LabOrderAction_errorTitleCannotShowURL, response);
}
} else {
MessageDialog.openError(new Shell(), Messages.LabOrderAction_errorTitleCannotShowURL, response);
MessageDialog.openError(new Shell(), Messages.LabOrderAction_errorTitleNoPatientSelected,
Messages.LabOrderAction_errorMessageNoPatientSelected);
}
} else {
MessageDialog.openError(new Shell(), Messages.LabOrderAction_errorTitleNoPatientSelected,
Messages.LabOrderAction_errorMessageNoPatientSelected);
}
}

Expand Down
Loading

0 comments on commit e6faab8

Please sign in to comment.