From a97d76e5bbe42cde2a5729efedcdcdcd7c26bbe9 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Mon, 3 Apr 2023 14:34:32 +0200 Subject: Issue #20: Detailimplementierungen für Consent Management --- .../consent/MrConsentManagerServiceTest.java | 61 ++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/test/java/DNPM/services/consent/MrConsentManagerServiceTest.java (limited to 'src/test/java/DNPM/services') diff --git a/src/test/java/DNPM/services/consent/MrConsentManagerServiceTest.java b/src/test/java/DNPM/services/consent/MrConsentManagerServiceTest.java new file mode 100644 index 0000000..2c8448e --- /dev/null +++ b/src/test/java/DNPM/services/consent/MrConsentManagerServiceTest.java @@ -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"); + } + +} -- cgit v1.2.3 From 783dfedd60a80ab4eeca720e7c5644a1a1042698 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Mon, 3 Apr 2023 17:35:40 +0200 Subject: Issue #20: Detailimplementierung für UKW mit Formular "Excel-Formular" --- .../consent/UkwConsentManagerServiceTest.java | 87 ++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 src/test/java/DNPM/services/consent/UkwConsentManagerServiceTest.java (limited to 'src/test/java/DNPM/services') diff --git a/src/test/java/DNPM/services/consent/UkwConsentManagerServiceTest.java b/src/test/java/DNPM/services/consent/UkwConsentManagerServiceTest.java new file mode 100644 index 0000000..824b4ff --- /dev/null +++ b/src/test/java/DNPM/services/consent/UkwConsentManagerServiceTest.java @@ -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"); + } + +} -- cgit v1.2.3 From 0914dd21d26eaa83bb057d0bc0af74f9cd3df20c Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Mon, 3 Apr 2023 17:41:50 +0200 Subject: Issue #20: Kein Consent-Update, wenn kein Datum oder Wert angegeben closes #20 --- .../consent/UkwConsentManagerServiceTest.java | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'src/test/java/DNPM/services') diff --git a/src/test/java/DNPM/services/consent/UkwConsentManagerServiceTest.java b/src/test/java/DNPM/services/consent/UkwConsentManagerServiceTest.java index 824b4ff..fdcd6e3 100644 --- a/src/test/java/DNPM/services/consent/UkwConsentManagerServiceTest.java +++ b/src/test/java/DNPM/services/consent/UkwConsentManagerServiceTest.java @@ -51,6 +51,58 @@ public class UkwConsentManagerServiceTest { 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 { -- cgit v1.2.3