summaryrefslogtreecommitdiff
path: root/src/main/java/dev/dnpm/oshelper/services/consent
diff options
context:
space:
mode:
authorPaul-Christian Volkmer2025-10-23 11:08:10 +0200
committerPaul-Christian Volkmer2025-10-23 11:09:54 +0200
commit84fb0d829832bf1628112376bba729422b169402 (patch)
tree4828674b77105877dccfcccb380da3f7c0f75987 /src/main/java/dev/dnpm/oshelper/services/consent
parent61e7dfcbe637f401f81ff853e9bd10c90b325acb (diff)
refactor: change package name
Diffstat (limited to 'src/main/java/dev/dnpm/oshelper/services/consent')
-rw-r--r--src/main/java/dev/dnpm/oshelper/services/consent/ConsentManagerService.java51
-rw-r--r--src/main/java/dev/dnpm/oshelper/services/consent/ConsentManagerServiceFactory.java52
-rw-r--r--src/main/java/dev/dnpm/oshelper/services/consent/MrConsentManagerService.java150
-rw-r--r--src/main/java/dev/dnpm/oshelper/services/consent/UkwConsentManagerService.java96
4 files changed, 349 insertions, 0 deletions
diff --git a/src/main/java/dev/dnpm/oshelper/services/consent/ConsentManagerService.java b/src/main/java/dev/dnpm/oshelper/services/consent/ConsentManagerService.java
new file mode 100644
index 0000000..10a265c
--- /dev/null
+++ b/src/main/java/dev/dnpm/oshelper/services/consent/ConsentManagerService.java
@@ -0,0 +1,51 @@
+/*
+ * This file is part of onkostar-plugin-dnpm
+ *
+ * Copyright (c) 2025 the original author or authors.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package dev.dnpm.oshelper.services.consent;
+
+import de.itc.onkostar.api.Procedure;
+
+/**
+ * Schnittstelle für die Anwendung von Consent-Änderungen
+ *
+ * @since 0.2.0
+ */
+public interface ConsentManagerService {
+
+ /**
+ * Wende Consent an, wenn dieses Consent-Formular gespeichert wird
+ * @param procedure Prozedur des Consent-Formulars
+ */
+ void applyConsent(Procedure procedure);
+
+ /**
+ * Optionale Prüfung, ob die angegebene Prozedur angewendet werden kann.
+ * @param procedure Anzuwendende Prozedur
+ * @return Gibt <code>true</code> zurück, wenn die Prozedur angewendet werden kann.
+ */
+ default boolean canApply(Procedure procedure) {
+ return null != procedure;
+ }
+
+}
diff --git a/src/main/java/dev/dnpm/oshelper/services/consent/ConsentManagerServiceFactory.java b/src/main/java/dev/dnpm/oshelper/services/consent/ConsentManagerServiceFactory.java
new file mode 100644
index 0000000..45207f8
--- /dev/null
+++ b/src/main/java/dev/dnpm/oshelper/services/consent/ConsentManagerServiceFactory.java
@@ -0,0 +1,52 @@
+/*
+ * This file is part of onkostar-plugin-dnpm
+ *
+ * Copyright (c) 2025 the original author or authors.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package dev.dnpm.oshelper.services.consent;
+
+import de.itc.onkostar.api.IOnkostarApi;
+
+public class ConsentManagerServiceFactory {
+
+ private final IOnkostarApi onkostarApi;
+
+ public ConsentManagerServiceFactory(
+ final IOnkostarApi onkostarApi
+ ) {
+ this.onkostarApi = onkostarApi;
+ }
+
+ public ConsentManagerService currentUsableInstance() {
+ var consentFormName = onkostarApi.getGlobalSetting("consentform");
+
+ switch (consentFormName) {
+ case "Excel-Formular":
+ return new UkwConsentManagerService(this.onkostarApi);
+ case "MR.Consent":
+ return new MrConsentManagerService(this.onkostarApi);
+ default:
+ return procedure -> {};
+ }
+ }
+
+}
diff --git a/src/main/java/dev/dnpm/oshelper/services/consent/MrConsentManagerService.java b/src/main/java/dev/dnpm/oshelper/services/consent/MrConsentManagerService.java
new file mode 100644
index 0000000..fcb3509
--- /dev/null
+++ b/src/main/java/dev/dnpm/oshelper/services/consent/MrConsentManagerService.java
@@ -0,0 +1,150 @@
+/*
+ * This file is part of onkostar-plugin-dnpm
+ *
+ * Copyright (c) 2025 the original author or authors.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package dev.dnpm.oshelper.services.consent;
+
+import dev.dnpm.oshelper.VerweisVon;
+import de.itc.onkostar.api.IOnkostarApi;
+import de.itc.onkostar.api.Item;
+import de.itc.onkostar.api.Procedure;
+import org.hibernate.SQLQuery;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.transform.Transformers;
+import org.hibernate.type.StandardBasicTypes;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Detailimplementierung für das Formular `MR.Consent`
+ *
+ * @since 0.2.0
+ */
+public class MrConsentManagerService implements ConsentManagerService {
+
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
+
+ private final IOnkostarApi onkostarApi;
+
+ public MrConsentManagerService(final IOnkostarApi onkostarApi) {
+ this.onkostarApi = onkostarApi;
+ }
+
+ @Override
+ public boolean canApply(Procedure procedure) {
+ return null != procedure && procedure.getFormName().equals("MR.Consent");
+ }
+
+ /**
+ * Wende Consent an, wenn dieses Consent-Formular gespeichert wird
+ *
+ * @param procedure Prozedur des Consent-Formulars
+ */
+ @Override
+ public void applyConsent(Procedure procedure) {
+ int value = 0;
+ try {
+ SessionFactory sessionFactory = onkostarApi.getSessionFactory();
+ Session session = sessionFactory.getCurrentSession();
+ // geänderte Werte checken
+ String sql1 = "select id, max(timestamp) AS datum from aenderungsprotokoll where entity_id = '" + procedure.getId() + "'";
+ SQLQuery query1 = session.createSQLQuery(sql1)
+ .addScalar("id", StandardBasicTypes.INTEGER)
+ .addScalar("datum", StandardBasicTypes.TIMESTAMP);
+ logger.info("Wert-Check: {}", query1.uniqueResult());
+
+ String sql = "SELECT prozedur.id AS procedure_id, prozedur.data_form_id, data_catalogue.name AS data_catalogue, data_catalogue_entry.name AS data_catalogue_entry, data_form.description AS formname, prozedur.beginndatum AS datum " +
+ "FROM prozedur " +
+ "LEFT JOIN data_form_data_catalogue ON data_form_data_catalogue.data_form_id = prozedur.data_form_id " +
+ "LEFT JOIN data_catalogue_entry ON data_catalogue_entry.data_catalogue_id = data_form_data_catalogue.data_catalogue_id " +
+ "LEFT JOIN data_catalogue ON data_catalogue.id = data_catalogue_entry.data_catalogue_id " +
+ "LEFT JOIN data_form ON data_form.id = prozedur.data_form_id " +
+ "WHERE patient_id = " + procedure.getPatientId() + " " +
+ "AND geloescht = 0 " +
+ "AND data_catalogue_entry.type = 'formReference' " +
+ "GROUP BY prozedur.id, prozedur.data_form_id, data_catalogue.name, data_catalogue_entry.name";
+
+ SQLQuery query = session.createSQLQuery(sql)
+ .addScalar("procedure_id", StandardBasicTypes.INTEGER)
+ .addScalar("data_form_id", StandardBasicTypes.INTEGER)
+ .addScalar("data_catalogue", StandardBasicTypes.STRING)
+ .addScalar("data_catalogue_entry", StandardBasicTypes.STRING)
+ .addScalar("formname", StandardBasicTypes.STRING)
+ .addScalar("datum", StandardBasicTypes.DATE);
+
+ query.setResultTransformer(Transformers.aliasToBean(VerweisVon.class));
+
+ @SuppressWarnings("unchecked")
+ List<VerweisVon> result = query.list();
+
+ for (VerweisVon verweisVon : result) {
+ sql = verweisVon.getSQL();
+ query = session.createSQLQuery(sql)
+ .addScalar("value", StandardBasicTypes.INTEGER);
+ if (query.uniqueResult() != null) {
+ value = (Integer) query.uniqueResult();
+ }
+ if (value == procedure.getId()) {
+ saveReferencedProcedure(procedure, verweisVon);
+ value = 0;
+ }
+ }
+ } catch (RuntimeException e) {
+ logger.error("Sonstiger Fehler bei der Ausführung von analyze()", e);
+ }
+ }
+
+ private void saveReferencedProcedure(Procedure prozedur, VerweisVon verweisVon) {
+ Procedure andereprozedur = onkostarApi.getProcedure(verweisVon.getProcedure_id());
+ try {
+ Map<String, Item> felder = prozedur.getAllValues();
+ for (Map.Entry<String, Item> feld : felder.entrySet()) {
+ if (feld.getKey().startsWith("Consent")) {
+ if (feld.getKey().equals("ConsentStatusEinwilligungDNPM")) {
+ switch (feld.getValue().getValue().toString()) {
+ case "z":
+ andereprozedur.setValue(feld.getKey(), new Item(feld.getKey(), "active"));
+ break;
+ case "a":
+ case "w":
+ andereprozedur.setValue(feld.getKey(), new Item(feld.getKey(), "rejected"));
+ break;
+ default:
+ break;
+ }
+ } else {
+ andereprozedur.setValue(feld.getKey(), prozedur.getValue(feld.getKey()));
+ }
+ }
+ }
+ onkostarApi.saveProcedure(andereprozedur);
+ } catch (Exception e) {
+ logger.error("Kann Prozedur nicht speichern", e);
+ }
+ }
+
+}
diff --git a/src/main/java/dev/dnpm/oshelper/services/consent/UkwConsentManagerService.java b/src/main/java/dev/dnpm/oshelper/services/consent/UkwConsentManagerService.java
new file mode 100644
index 0000000..1aede17
--- /dev/null
+++ b/src/main/java/dev/dnpm/oshelper/services/consent/UkwConsentManagerService.java
@@ -0,0 +1,96 @@
+/*
+ * This file is part of onkostar-plugin-dnpm
+ *
+ * Copyright (c) 2025 the original author or authors.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package dev.dnpm.oshelper.services.consent;
+
+import de.itc.onkostar.api.IOnkostarApi;
+import de.itc.onkostar.api.Item;
+import de.itc.onkostar.api.Procedure;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Comparator;
+
+/**
+ * Detailimplementierung für das Formular `Excel-Formular`
+ *
+ * @since 0.2.0
+ */
+public class UkwConsentManagerService implements ConsentManagerService {
+
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
+
+ private final IOnkostarApi onkostarApi;
+
+ public UkwConsentManagerService(final IOnkostarApi onkostarApi) {
+ this.onkostarApi = onkostarApi;
+ }
+
+ @Override
+ public boolean canApply(Procedure procedure) {
+ return null != procedure && procedure.getFormName().equals("Excel-Formular");
+ }
+
+ /**
+ * Wende Consent an, wenn dieses Consent-Formular gespeichert wird
+ *
+ * @param procedure Prozedur des Consent-Formulars
+ */
+ @Override
+ public void applyConsent(Procedure procedure) {
+ var refdnpmklinikanamnese = procedure.getValue("refdnpmklinikanamnese").getInt();
+ var dnpmKlinikAnamnese = this.onkostarApi.getProcedure(refdnpmklinikanamnese);
+
+ if (null == dnpmKlinikAnamnese) {
+ return;
+ }
+
+ var consents = procedure.getSubProceduresMap().get("ufdnpmconsent");
+
+ if (null == consents) {
+ return;
+ }
+
+ consents.stream()
+ .max(Comparator.comparing(Procedure::getStartDate))
+ .ifPresent(lastConsent -> {
+ var date = lastConsent.getStartDate();
+ var status = lastConsent.getValue("status");
+ if (null == date || null == status || status.getString().isBlank()) {
+ logger.warn("Kein DNPM-Einwilligungstatus angegeben");
+ return;
+ }
+
+ dnpmKlinikAnamnese.setValue("ConsentStatusEinwilligungDNPM", new Item("Einwilligung", status.getString()));
+ dnpmKlinikAnamnese.setValue("ConsentDatumEinwilligungDNPM", new Item("DatumEinwilligung", date));
+
+ try {
+ onkostarApi.saveProcedure(dnpmKlinikAnamnese, false);
+ } catch (Exception e) {
+ logger.error("Kann DNPM-Einwilligungstatus nicht aktualisieren", e);
+ }
+ });
+ }
+
+}