Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[26903] handleArticleBillingDialog Methode angepasst #779

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
import java.util.stream.Collectors;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PlatformUI;

import ch.elexis.core.constants.Preferences;
import ch.elexis.core.common.ElexisEventTopics;
import ch.elexis.core.constants.Preferences;
import ch.elexis.core.model.IArticle;
import ch.elexis.core.model.IArticleDefaultSignature;
import ch.elexis.core.model.IBillable;
Expand All @@ -38,7 +37,6 @@
import ch.elexis.core.ui.Messages;
import ch.elexis.core.ui.dialogs.PrescriptionSignatureTitleAreaDialog;
import ch.elexis.core.ui.dialogs.ResultDialog;
import ch.elexis.core.ui.util.CreatePrescriptionHelper;
import ch.rgw.tools.Result;

public class BillingProcessor {
Expand Down Expand Up @@ -97,37 +95,26 @@ private void handleArticleBillingDialog(IArticle selectedArticle) {
if (medicationExists) {
return;
}
EntryType disposalType = signature.getDisposalType();
IPrescription prescription = null;
if (disposalType != EntryType.SELF_DISPENSED) {
Result<IBilled> billResult = BillingServiceHolder.get().bill(selectedArticle, actEncounter, 1.0);
if (billResult.isOK()) {
IBilled billed = billResult.get();
CreatePrescriptionHelper prescriptionHelper = new CreatePrescriptionHelper(selectedArticle,
Display.getDefault().getActiveShell());
prescription = prescriptionHelper.createPrescriptionFromSignature(signature);
if (prescription != null) {
prescription.setExtInfo(ch.elexis.core.model.prescription.Constants.FLD_EXT_VERRECHNET_ID,
billed.getId().toString());
prescription.setDosageInstruction(signature.getSignatureAsDosisString());
prescription.setRemark(signature.getComment());
CoreModelServiceHolder.get().save(prescription);
updatePrescriptionWithBilledId(billed, signature);
}
} else {
ResultDialog.show(billResult);
return;
}
} else {
CreatePrescriptionHelper prescriptionHelper = new CreatePrescriptionHelper(selectedArticle,
Display.getDefault().getActiveShell());
prescription = prescriptionHelper.createPrescriptionFromSignature(signature);
if (prescription != null) {
Result<IBilled> billResult = BillingServiceHolder.get().bill(selectedArticle, actEncounter, 1.0);
if (!billResult.isOK()) {
ResultDialog.show(billResult);
return;
}
IBilled billed = billResult.get();
String prescId = billed.getExtInfo(ch.elexis.core.model.verrechnet.Constants.FLD_EXT_PRESC_ID).toString();
if (prescId != null) {
Optional<IPrescription> prescriptionOpt = CoreModelServiceHolder.get().load(prescId, IPrescription.class);
if (prescriptionOpt.isPresent()) {
IPrescription prescription = prescriptionOpt.get();
prescription.setDosageInstruction(signature.getSignatureAsDosisString());
prescription.setRemark(signature.getComment());
prescription.setExtInfo(ch.elexis.core.model.prescription.Constants.FLD_EXT_VERRECHNET_ID,
billed.getId());
prescription.setEntryType(signature.getDisposalType());
prescription.setDateFrom(actEncounter.getDate().atStartOfDay());
CoreModelServiceHolder.get().save(prescription);
}
}
}
}
CoreModelServiceHolder.get().save(actEncounter);
postRefreshMedicationEvent();
}
Expand All @@ -144,21 +131,6 @@ private boolean checkIfMedicationExists(List<IPrescription> prescriptions, IArti
});
}

private void updatePrescriptionWithBilledId(IBilled billed, IArticleDefaultSignature signature) {
getRecentPatientPrescriptions(actEncounter.getPatient(), actEncounter.getDate().atStartOfDay()).stream()
.filter(prescription -> {
Object extInfo = prescription.getExtInfo(ch.elexis.core.model.prescription.Constants.FLD_EXT_VERRECHNET_ID);
return extInfo != null && billed.getId().equals(extInfo.toString());
}).findFirst().ifPresent(prescription -> {
prescription.setDosageInstruction(signature.getSignatureAsDosisString());
prescription.setRemark(signature.getComment());
prescription.setDateFrom(billed.getEncounter().getDate().atStartOfDay());
prescription.setExtInfo(ch.elexis.core.model.prescription.Constants.FLD_EXT_VERRECHNET_ID,
billed.getId().toString());
CoreModelServiceHolder.get().save(prescription);
});
}

private boolean fixOrReserveWithArticleExists(List<IPrescription> prescriptions, IArticle selectedArticle) {
return prescriptions.stream()
.anyMatch(prescription -> prescription.getArticle().getId().equals(selectedArticle.getId())
Expand Down