1
0
mirror of https://github.com/pcvolkmer/onkostar-plugin-dnpm.git synced 2025-07-03 01:32:55 +00:00

Issue #20: Detailimplementierung für UKW mit Formular "Excel-Formular"

This commit is contained in:
2023-04-03 17:35:40 +02:00
parent a97d76e5bb
commit 783dfedd60
4 changed files with 161 additions and 2 deletions

View File

@ -16,6 +16,8 @@ public class ConsentManagerServiceFactory {
var consentFormName = onkostarApi.getGlobalSetting("consentform"); var consentFormName = onkostarApi.getGlobalSetting("consentform");
switch (consentFormName) { switch (consentFormName) {
case "Excel-Formular":
return new UkwConsentManagerService(this.onkostarApi);
case "MR.Consent": case "MR.Consent":
default: default:
return new MrConsentManagerService(this.onkostarApi); return new MrConsentManagerService(this.onkostarApi);

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 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 == status) {
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

@ -1,7 +1,9 @@
package DNPM.config; package DNPM.config;
import DNPM.services.consent.ConsentManagerService;
import DNPM.services.consent.ConsentManagerServiceFactory; import DNPM.services.consent.ConsentManagerServiceFactory;
import DNPM.services.consent.MrConsentManagerService; import DNPM.services.consent.MrConsentManagerService;
import DNPM.services.consent.UkwConsentManagerService;
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.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
@ -32,9 +34,10 @@ class ConsentManagerServiceFactoryTest {
this.consentManagerServiceFactory = new ConsentManagerServiceFactory(onkostarApi); this.consentManagerServiceFactory = new ConsentManagerServiceFactory(onkostarApi);
} }
private static Set<Map.Entry<String, Class<MrConsentManagerService>>> expectedMappings() { private static Set<Map.Entry<String, Class<? extends ConsentManagerService>>> expectedMappings() {
return Map.ofEntries( return Map.ofEntries(
Map.entry("MR.Consent", MrConsentManagerService.class) Map.entry("MR.Consent", MrConsentManagerService.class),
Map.entry("Excel-Formular", UkwConsentManagerService.class)
).entrySet(); ).entrySet();
} }

View File

@ -0,0 +1,87 @@
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 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");
}
}