1
0
mirror of https://github.com/pcvolkmer/onkostar-plugin-dnpm.git synced 2025-07-05 02:22:54 +00:00

Merge pull request #21 from CCC-MF/issue_20

Anpassung des ConsentManagements an verschiedene Standorte
This commit is contained in:
2023-04-03 17:44:38 +02:00
committed by GitHub
12 changed files with 524 additions and 117 deletions

View File

@ -1,31 +1,29 @@
package DNPM; package DNPM;
import DNPM.services.consent.ConsentManagerServiceFactory;
import de.itc.onkostar.api.Disease; import de.itc.onkostar.api.Disease;
import de.itc.onkostar.api.IOnkostarApi; import de.itc.onkostar.api.IOnkostarApi;
import de.itc.onkostar.api.Item;
import de.itc.onkostar.api.Procedure; import de.itc.onkostar.api.Procedure;
import de.itc.onkostar.api.analysis.AnalyzerRequirement; import de.itc.onkostar.api.analysis.AnalyzerRequirement;
import de.itc.onkostar.api.analysis.IProcedureAnalyzer; import de.itc.onkostar.api.analysis.IProcedureAnalyzer;
import de.itc.onkostar.api.analysis.OnkostarPluginType; import de.itc.onkostar.api.analysis.OnkostarPluginType;
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.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Map;
public class ConsentManager implements IProcedureAnalyzer { public class ConsentManager implements IProcedureAnalyzer {
private final Logger logger = LoggerFactory.getLogger(this.getClass()); private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final IOnkostarApi onkostarApi; private final IOnkostarApi onkostarApi;
public ConsentManager(final IOnkostarApi onkostarApi) { private final ConsentManagerServiceFactory consentManagerServiceFactory;
public ConsentManager(
final IOnkostarApi onkostarApi,
final ConsentManagerServiceFactory consentManagerServiceFactory
) {
this.onkostarApi = onkostarApi; this.onkostarApi = onkostarApi;
this.consentManagerServiceFactory = consentManagerServiceFactory;
} }
@Override @Override
@ -71,85 +69,7 @@ public class ConsentManager implements IProcedureAnalyzer {
@Override @Override
public void analyze(Procedure prozedur, Disease erkrankung) { public void analyze(Procedure prozedur, Disease erkrankung) {
int value = 0; consentManagerServiceFactory.currentUsableInstance().applyConsent(prozedur);
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 = '" + prozedur.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 = " + prozedur.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 == prozedur.getId()) {
saveReferencedProcedure(prozedur, 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);
}
} }
} }

View File

@ -2,6 +2,7 @@ package DNPM.config;
import DNPM.database.SettingsRepository; import DNPM.database.SettingsRepository;
import DNPM.services.*; import DNPM.services.*;
import DNPM.services.consent.ConsentManagerServiceFactory;
import DNPM.services.mtb.DefaultMtbService; import DNPM.services.mtb.DefaultMtbService;
import DNPM.services.mtb.MtbService; import DNPM.services.mtb.MtbService;
import DNPM.services.systemtherapie.DefaultSystemtherapieService; import DNPM.services.systemtherapie.DefaultSystemtherapieService;
@ -52,6 +53,11 @@ public class PluginConfiguration {
return new DefaultSystemtherapieService(onkostarApi, settingsService); return new DefaultSystemtherapieService(onkostarApi, settingsService);
} }
@Bean
public ConsentManagerServiceFactory consentManagerServiceFactory(final IOnkostarApi onkostarApi) {
return new ConsentManagerServiceFactory(onkostarApi);
}
@Bean @Bean
public TherapieplanServiceFactory therapieplanServiceFactory( public TherapieplanServiceFactory therapieplanServiceFactory(
final IOnkostarApi onkostarApi, final IOnkostarApi onkostarApi,

View File

@ -0,0 +1,18 @@
package DNPM.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);
}

View File

@ -0,0 +1,27 @@
package DNPM.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":
default:
return new MrConsentManagerService(this.onkostarApi);
}
}
}

View File

@ -0,0 +1,121 @@
package DNPM.services.consent;
import DNPM.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 Logger logger = LoggerFactory.getLogger(this.getClass());
private final IOnkostarApi onkostarApi;
public MrConsentManagerService(final IOnkostarApi onkostarApi) {
this.onkostarApi = onkostarApi;
}
/**
* 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);
}
}
}

View File

@ -0,0 +1,67 @@
package DNPM.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;
}
/**
* 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);
}
});
}
}

View File

@ -19,6 +19,7 @@
</bean> </bean>
<bean id="ConsentManager" class="DNPM.ConsentManager"> <bean id="ConsentManager" class="DNPM.ConsentManager">
<constructor-arg ref="localOnkostarApi" /> <constructor-arg ref="localOnkostarApi" />
<constructor-arg ref="consentManagerServiceFactory" />
</bean> </bean>
<context:component-scan base-package="ATCCodes" /> <context:component-scan base-package="ATCCodes" />

View File

@ -1,20 +1,15 @@
package DNPM; package DNPM;
import DNPM.services.consent.ConsentManagerServiceFactory;
import DNPM.services.consent.MrConsentManagerService;
import de.itc.onkostar.api.IOnkostarApi; import de.itc.onkostar.api.IOnkostarApi;
import de.itc.onkostar.api.Procedure; import de.itc.onkostar.api.Procedure;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.type.Type;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
@ExtendWith(MockitoExtension.class) @ExtendWith(MockitoExtension.class)
@ -22,39 +17,30 @@ class ConsentManagerTest {
private IOnkostarApi onkostarApi; private IOnkostarApi onkostarApi;
private ConsentManagerServiceFactory consentManagerServiceFactory;
private ConsentManager consentManager; private ConsentManager consentManager;
@BeforeEach @BeforeEach
void setup( void setup(
@Mock IOnkostarApi onkostarApi @Mock IOnkostarApi onkostarApi,
@Mock ConsentManagerServiceFactory consentManagerServiceFactory
) { ) {
this.onkostarApi = onkostarApi; this.onkostarApi = onkostarApi;
this.consentManager = new ConsentManager(onkostarApi); this.consentManagerServiceFactory = consentManagerServiceFactory;
this.consentManager = new ConsentManager(onkostarApi, consentManagerServiceFactory);
} }
@Test @Test
void testShouldCreateSqlQueriesWithRelatedEntityIds() { void shouldRunServiceMethodsOnAnalyzeCalled() {
var sessionFactory = mock(SessionFactory.class); var consentManagerServiceMock = mock(MrConsentManagerService.class);
var session = mock(Session.class);
var query = mock(SQLQuery.class);
when(onkostarApi.getSessionFactory()).thenReturn(sessionFactory); when(this.consentManagerServiceFactory.currentUsableInstance())
when(sessionFactory.getCurrentSession()).thenReturn(session); .thenReturn(consentManagerServiceMock);
when(session.createSQLQuery(anyString())).thenReturn(query);
when(query.addScalar(anyString(), any(Type.class))).thenReturn(query);
when(query.uniqueResult()).thenReturn("");
var dummyProzedur = new Procedure(this.onkostarApi); this.consentManager.analyze(new Procedure(onkostarApi), null);
dummyProzedur.setId(111);
dummyProzedur.setPatientId(123);
consentManager.analyze(dummyProzedur, null); verify(consentManagerServiceMock, times(1)).applyConsent(any(Procedure.class));
var argumentCaptor = ArgumentCaptor.forClass(String.class);
verify(session, times(2)).createSQLQuery(argumentCaptor.capture());
assertThat(argumentCaptor.getAllValues()).hasSize(2);
assertThat(argumentCaptor.getAllValues().get(0)).contains("where entity_id = '111'");
assertThat(argumentCaptor.getAllValues().get(1)).contains("WHERE patient_id = 123 AND geloescht = 0");
} }
} }

View File

@ -0,0 +1,54 @@
package DNPM.config;
import DNPM.services.consent.ConsentManagerService;
import DNPM.services.consent.ConsentManagerServiceFactory;
import DNPM.services.consent.MrConsentManagerService;
import DNPM.services.consent.UkwConsentManagerService;
import de.itc.onkostar.api.IOnkostarApi;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import java.util.Map;
import java.util.Set;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
class ConsentManagerServiceFactoryTest {
private IOnkostarApi onkostarApi;
private ConsentManagerServiceFactory consentManagerServiceFactory;
@BeforeEach
void setup(
@Mock IOnkostarApi onkostarApi
) {
this.onkostarApi = onkostarApi;
this.consentManagerServiceFactory = new ConsentManagerServiceFactory(onkostarApi);
}
private static Set<Map.Entry<String, Class<? extends ConsentManagerService>>> expectedMappings() {
return Map.ofEntries(
Map.entry("MR.Consent", MrConsentManagerService.class),
Map.entry("Excel-Formular", UkwConsentManagerService.class)
).entrySet();
}
@ParameterizedTest
@MethodSource("expectedMappings")
void testShouldMapFormNameToService(Map.Entry<String, Class<?>> expectedMapping) {
when(onkostarApi.getGlobalSetting(anyString())).thenReturn(expectedMapping.getKey());
var actual = consentManagerServiceFactory.currentUsableInstance();
assertThat(actual).isExactlyInstanceOf(expectedMapping.getValue());
}
}

View File

@ -3,6 +3,7 @@ package DNPM.config;
import DNPM.services.FormService; import DNPM.services.FormService;
import DNPM.services.SettingsService; import DNPM.services.SettingsService;
import DNPM.services.TherapieplanServiceFactory; import DNPM.services.TherapieplanServiceFactory;
import DNPM.services.consent.ConsentManagerServiceFactory;
import de.itc.onkostar.api.IOnkostarApi; import de.itc.onkostar.api.IOnkostarApi;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -31,6 +32,12 @@ class PluginConfigurationTest {
this.configuration = new PluginConfiguration(); this.configuration = new PluginConfiguration();
} }
@Test
void testShouldReturnConsentManagerServiceFactory() {
var actual = this.configuration.consentManagerServiceFactory(onkostarApi);
assertThat(actual).isInstanceOf(ConsentManagerServiceFactory.class);
}
@Test @Test
void testShouldReturnTherapieplanServiceFactory() { void testShouldReturnTherapieplanServiceFactory() {
var actual = this.configuration.therapieplanServiceFactory(onkostarApi, settingsService, formService); var actual = this.configuration.therapieplanServiceFactory(onkostarApi, settingsService, formService);

View File

@ -0,0 +1,61 @@
package DNPM.services.consent;
import de.itc.onkostar.api.IOnkostarApi;
import de.itc.onkostar.api.Procedure;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.type.Type;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.*;
@ExtendWith(MockitoExtension.class)
public class MrConsentManagerServiceTest {
private IOnkostarApi onkostarApi;
private MrConsentManagerService service;
@BeforeEach
void setup(
@Mock IOnkostarApi onkostarApi
) {
this.onkostarApi = onkostarApi;
this.service = new MrConsentManagerService(onkostarApi);
}
@Test
void testShouldCreateSqlQueriesWithRelatedEntityIds() {
var sessionFactory = mock(SessionFactory.class);
var session = mock(Session.class);
var query = mock(SQLQuery.class);
when(onkostarApi.getSessionFactory()).thenReturn(sessionFactory);
when(sessionFactory.getCurrentSession()).thenReturn(session);
when(session.createSQLQuery(anyString())).thenReturn(query);
when(query.addScalar(anyString(), any(Type.class))).thenReturn(query);
when(query.uniqueResult()).thenReturn("");
var dummyProzedur = new Procedure(this.onkostarApi);
dummyProzedur.setId(111);
dummyProzedur.setPatientId(123);
this.service.applyConsent(dummyProzedur);
var argumentCaptor = ArgumentCaptor.forClass(String.class);
verify(session, times(2)).createSQLQuery(argumentCaptor.capture());
assertThat(argumentCaptor.getAllValues()).hasSize(2);
assertThat(argumentCaptor.getAllValues().get(0)).contains("where entity_id = '111'");
assertThat(argumentCaptor.getAllValues().get(1)).contains("WHERE patient_id = 123 AND geloescht = 0");
}
}

View File

@ -0,0 +1,139 @@
package DNPM.services.consent;
import de.itc.onkostar.api.IOnkostarApi;
import de.itc.onkostar.api.Item;
import de.itc.onkostar.api.Procedure;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import java.sql.Date;
import java.time.Instant;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
@ExtendWith(MockitoExtension.class)
public class UkwConsentManagerServiceTest {
private IOnkostarApi onkostarApi;
private UkwConsentManagerService service;
@BeforeEach
void setup(
@Mock IOnkostarApi onkostarApi
) {
this.onkostarApi = onkostarApi;
this.service = new UkwConsentManagerService(onkostarApi);
}
@Test
void testShouldSkipUpdateRelatedDnpmKlinikAnamneseFormIfNoConsentAvailable() throws Exception {
var excelForm = new Procedure(this.onkostarApi);
excelForm.setId(111);
excelForm.setPatientId(123);
excelForm.setValue("refdnpmklinikanamnese", new Item("refdnpmklinikanamnese", 2));
var dnpmKlinikAnamneseForm = new Procedure(this.onkostarApi);
dnpmKlinikAnamneseForm.setId(2);
dnpmKlinikAnamneseForm.setPatientId(123);
when(onkostarApi.getProcedure(anyInt())).thenReturn(dnpmKlinikAnamneseForm);
this.service.applyConsent(excelForm);
verify(onkostarApi, times(0)).saveProcedure(any(Procedure.class), anyBoolean());
}
@Test
void testShouldSkipUpdateRelatedDnpmKlinikAnamneseFormIfNoConsentDateAvailable() throws Exception {
var consentSubForm = new Procedure(this.onkostarApi);
consentSubForm.setId(1);
consentSubForm.setPatientId(123);
consentSubForm.setValue("status", new Item("status", "accepted"));
var excelForm = new Procedure(this.onkostarApi);
excelForm.setId(111);
excelForm.setPatientId(123);
excelForm.setValue("refdnpmklinikanamnese", new Item("refdnpmklinikanamnese", 2));
excelForm.addSubProcedure("ufdnpmconsent", consentSubForm);
var dnpmKlinikAnamneseForm = new Procedure(this.onkostarApi);
dnpmKlinikAnamneseForm.setId(2);
dnpmKlinikAnamneseForm.setPatientId(123);
when(onkostarApi.getProcedure(anyInt())).thenReturn(dnpmKlinikAnamneseForm);
this.service.applyConsent(excelForm);
verify(onkostarApi, times(0)).saveProcedure(any(Procedure.class), anyBoolean());
}
@Test
void testShouldSkipUpdateRelatedDnpmKlinikAnamneseFormIfNoConsentValueAvailable() throws Exception {
var consentSubForm = new Procedure(this.onkostarApi);
consentSubForm.setId(1);
consentSubForm.setPatientId(123);
consentSubForm.setStartDate(Date.from(Instant.parse("2023-04-03T12:00:00Z")));
consentSubForm.setValue("datum", new Item("datum", Date.from(Instant.parse("2023-04-03T12:00:00Z"))));
var excelForm = new Procedure(this.onkostarApi);
excelForm.setId(111);
excelForm.setPatientId(123);
excelForm.setValue("refdnpmklinikanamnese", new Item("refdnpmklinikanamnese", 2));
excelForm.addSubProcedure("ufdnpmconsent", consentSubForm);
var dnpmKlinikAnamneseForm = new Procedure(this.onkostarApi);
dnpmKlinikAnamneseForm.setId(2);
dnpmKlinikAnamneseForm.setPatientId(123);
when(onkostarApi.getProcedure(anyInt())).thenReturn(dnpmKlinikAnamneseForm);
this.service.applyConsent(excelForm);
verify(onkostarApi, times(0)).saveProcedure(any(Procedure.class), anyBoolean());
}
@Test
void testShouldUpdateRelatedDnpmKlinikAnamneseFormOnFormSave() throws Exception {
var consentSubForm = new Procedure(this.onkostarApi);
consentSubForm.setId(1);
consentSubForm.setPatientId(123);
consentSubForm.setStartDate(Date.from(Instant.parse("2023-04-03T12:00:00Z")));
consentSubForm.setValue("datum", new Item("datum", Date.from(Instant.parse("2023-04-03T12:00:00Z"))));
consentSubForm.setValue("status", new Item("status", "accepted"));
var excelForm = new Procedure(this.onkostarApi);
excelForm.setId(111);
excelForm.setPatientId(123);
excelForm.setValue("refdnpmklinikanamnese", new Item("refdnpmklinikanamnese", 2));
excelForm.addSubProcedure("ufdnpmconsent", consentSubForm);
var dnpmKlinikAnamneseForm = new Procedure(this.onkostarApi);
dnpmKlinikAnamneseForm.setId(2);
dnpmKlinikAnamneseForm.setPatientId(123);
when(onkostarApi.getProcedure(anyInt())).thenReturn(dnpmKlinikAnamneseForm);
this.service.applyConsent(excelForm);
var argumentCaptor = ArgumentCaptor.forClass(Procedure.class);
verify(onkostarApi, times(1)).saveProcedure(argumentCaptor.capture(), anyBoolean());
var savedForm = argumentCaptor.getValue();
assertThat(savedForm).isExactlyInstanceOf(Procedure.class);
assertThat(savedForm.getValue("ConsentStatusEinwilligungDNPM").getString()).isEqualTo("accepted");
assertThat(savedForm.getValue("ConsentDatumEinwilligungDNPM").getDate()).isEqualTo("2023-04-03T12:00:00Z");
}
}