From caff22b6d9f37b57fde3142ee3dad4266c6ef83e Mon Sep 17 00:00:00 2001 From: Marco Descher Date: Wed, 16 Aug 2023 13:26:21 +0200 Subject: [PATCH] [25492] PatientErfassenDialog - switch to NoPo --- .../dialogs/PatientErfassenDialog.java | 77 +++++++------------ .../ui/contacts/views/PatientenListeView.java | 12 +-- 2 files changed, 35 insertions(+), 54 deletions(-) diff --git a/bundles/ch.elexis.core.ui.contacts/src/ch/elexis/core/ui/contacts/dialogs/PatientErfassenDialog.java b/bundles/ch.elexis.core.ui.contacts/src/ch/elexis/core/ui/contacts/dialogs/PatientErfassenDialog.java index e3f57bdf8a..83df4c436a 100644 --- a/bundles/ch.elexis.core.ui.contacts/src/ch/elexis/core/ui/contacts/dialogs/PatientErfassenDialog.java +++ b/bundles/ch.elexis.core.ui.contacts/src/ch/elexis/core/ui/contacts/dialogs/PatientErfassenDialog.java @@ -31,19 +31,19 @@ import org.eclipse.swt.widgets.Text; import ch.elexis.core.constants.StringConstants; -import ch.elexis.core.data.events.ElexisEventDispatcher; import ch.elexis.core.l10n.Messages; +import ch.elexis.core.model.IPatient; +import ch.elexis.core.model.builder.IContactBuilder; +import ch.elexis.core.services.holder.CoreModelServiceHolder; +import ch.elexis.core.types.Gender; import ch.elexis.core.ui.UiDesk; import ch.elexis.core.ui.icons.ImageSize; import ch.elexis.core.ui.icons.Images; -import ch.elexis.core.ui.locks.AcquireLockUi; -import ch.elexis.core.ui.locks.ILockHandler; import ch.elexis.core.ui.util.FormatValidator; import ch.elexis.core.ui.util.SWTHelper; import ch.elexis.data.Kontakt; import ch.elexis.data.Patient; import ch.elexis.data.Person; -import ch.elexis.data.Person.PersonDataException; import ch.elexis.data.Query; import ch.rgw.tools.ExHandler; import ch.rgw.tools.StringTool; @@ -54,11 +54,11 @@ public class PatientErfassenDialog extends TitleAreaDialog { HashMap fld; Text tName, tVorname, tGebDat, tStrasse, tPlz, tOrt, tTel, tMail, tAHV; Combo cbSex; - Patient result; + private IPatient patient; Object po; - public Patient getResult() { - return result; + public IPatient getResult() { + return patient; } public PatientErfassenDialog(final Shell parent, final HashMap fields) { @@ -138,7 +138,7 @@ protected Control createDialogArea(final Composite parent) { tMail.setForeground(red); setEnableOKButton(false); return; - } + } tMail.setForeground(defaultMailColor); setEnableOKButton(true); @@ -182,7 +182,6 @@ protected Control createDialogArea(final Composite parent) { return ret; } - private void setEnableOKButton(boolean enabled) { getButton(IDialogConstants.OK_ID).setEnabled(enabled); } @@ -198,35 +197,30 @@ public void create() { @Override protected void okPressed() { - final String[] ret = new String[9]; - ret[0] = tName.getText(); - ret[1] = tVorname.getText(); + Gender gender = null; int idx = cbSex.getSelectionIndex(); if (idx == 1 || cbSex.getText().contentEquals(Messages.Patient_female_short)) { - ret[2] = Patient.FEMALE; // German w for weiblich = female + gender = Gender.FEMALE; // German w for weiblich = female } else if (idx == 0 || cbSex.getText().contentEquals(Messages.Patient_male_short)) { - ret[2] = Patient.MALE; + gender = Gender.MALE; } else if (idx == -1) { SWTHelper.showError(Messages.PatientErfassenDialog_Error_Sex, Messages.PatientErfassenDialog_Sex_must_be_specified); return; } - ret[3] = tGebDat.getText(); try { TimeTool check = null; - if (!StringTool.isNothing(ret[3])) { - check = new TimeTool(ret[3], true); + if (!StringTool.isNothing(tGebDat.getText())) { + check = new TimeTool(tGebDat.getText(), true); + } else { + check = new TimeTool(); } - ret[4] = tStrasse.getText(); - ret[5] = tPlz.getText(); - ret[6] = tOrt.getText(); - ret[7] = tTel.getText(); - ret[8] = tMail.getText(); Query qbe = new Query(Kontakt.class); - qbe.add("Bezeichnung1", Query.EQUALS, ret[0], true); //$NON-NLS-1$ - qbe.add("Bezeichnung2", Query.EQUALS, ret[1], true); //$NON-NLS-1$ - if (check != null) + qbe.add("Bezeichnung1", Query.EQUALS, tName.getText(), true); //$NON-NLS-1$ + qbe.add("Bezeichnung2", Query.EQUALS, tVorname.getText(), true); //$NON-NLS-1$ + if (check != null) { qbe.add(Person.BIRTHDATE, Query.EQUALS, check.toDBString(false), true); + } List list = qbe.execute(); if ((list != null) && (!list.isEmpty())) { Kontakt k = list.get(0); @@ -240,40 +234,27 @@ protected void okPressed() { } } } - result = new Patient(ret[0], ret[1], check, ret[2]); - String formattedAHV = tAHV.getText(); + patient = new IContactBuilder.PatientBuilder(CoreModelServiceHolder.get(), tVorname.getText(), + tName.getText(), check.toLocalDate(), gender).build(); + patient.setStreet(tStrasse.getText()); + patient.setZip(tPlz.getText()); + patient.setCity(tOrt.getText()); + patient.setPhone1(tTel.getText()); + patient.setEmail(tMail.getText()); + CoreModelServiceHolder.get().save(patient); + String formattedAHV = tAHV.getText(); if (!formattedAHV.isEmpty()) { formattedAHV = FormatValidator.getFormattedAHVNum(formattedAHV); - result.addXid(DOMAIN_AHV, formattedAHV, true); + patient.addXid(DOMAIN_AHV, formattedAHV, true); } - AcquireLockUi.aquireAndRun(result, new ILockHandler() { - - @Override - public void lockFailed() { - result.delete(); - } - - @Override - public void lockAcquired() { - result.set( - new String[] { Kontakt.FLD_STREET, Kontakt.FLD_ZIP, Kontakt.FLD_PLACE, Kontakt.FLD_PHONE1, - Kontakt.FLD_E_MAIL }, - new String[] { ret[4], ret[5], ret[6], ret[7], ret[8] }); - - ElexisEventDispatcher.fireSelectionEvent(result); - } - }); super.okPressed(); } catch (TimeFormatException e) { ExHandler.handle(e); SWTHelper.showError("Falsches Datumsformat", "Das Geburtsdatum kann nicht interpretiert werden"); return; - } catch (PersonDataException pe) { - ExHandler.handle(pe); - SWTHelper.showError("Unplausible Angaben", "Bitte überprüfen Sie die Eingabe nochmals: " + pe.getMessage()); } } diff --git a/bundles/ch.elexis.core.ui.contacts/src/ch/elexis/core/ui/contacts/views/PatientenListeView.java b/bundles/ch.elexis.core.ui.contacts/src/ch/elexis/core/ui/contacts/views/PatientenListeView.java index 7c586a1afb..8a702f76a8 100644 --- a/bundles/ch.elexis.core.ui.contacts/src/ch/elexis/core/ui/contacts/views/PatientenListeView.java +++ b/bundles/ch.elexis.core.ui.contacts/src/ch/elexis/core/ui/contacts/views/PatientenListeView.java @@ -385,15 +385,15 @@ public void doRun() { PatientErfassenDialog ped = new PatientErfassenDialog(getViewSite().getShell(), ctlFields); if (ped.open() == Dialog.OK) { plcp.temporaryAddObject(ped.getResult()); - Patient pat = ped.getResult(); + IPatient pat = ped.getResult(); for (int j = 0; j < currentUserFields.length; j++) { String current = currentUserFields[j]; if (current.startsWith(Patient.FLD_PATID)) { - dcfp.setValue(j, pat.getPatCode()); - } else if (current.startsWith(Patient.FLD_NAME) && pat.getName() != null) { - dcfp.setValue(j, pat.getName()); - } else if (current.startsWith(Patient.FLD_FIRSTNAME) && pat.getVorname() != null) { - dcfp.setValue(j, pat.getVorname()); + dcfp.setValue(j, pat.getPatientNr()); + } else if (current.startsWith(Patient.FLD_NAME) && pat.getLastName() != null) { + dcfp.setValue(j, pat.getLastName()); + } else if (current.startsWith(Patient.FLD_FIRSTNAME) && pat.getFirstName() != null) { + dcfp.setValue(j, pat.getFirstName()); } } plcp.syncRefresh();