From f0f09d43a319f6facde3e774dd0f90a9b3c79815 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Tue, 10 Oct 2023 12:13:51 +0200 Subject: [PATCH 1/3] =?UTF-8?q?Issue=20#54:=20Service=20zum=20Ermitteln=20?= =?UTF-8?q?des=20ECOG-Status=20aus=20Strahlentherapie-Formularen=20hinzuge?= =?UTF-8?q?f=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DefaultStrahlentherapieService.java | 73 ++++++++++++ .../StrahlentherapieService.java | 70 ++++++++++++ .../DefaultStrahlentherapieServiceTest.java | 106 ++++++++++++++++++ 3 files changed, 249 insertions(+) create mode 100644 src/main/java/DNPM/services/strahlentherapie/DefaultStrahlentherapieService.java create mode 100644 src/main/java/DNPM/services/strahlentherapie/StrahlentherapieService.java create mode 100644 src/test/java/DNPM/services/strahlentherapie/DefaultStrahlentherapieServiceTest.java diff --git a/src/main/java/DNPM/services/strahlentherapie/DefaultStrahlentherapieService.java b/src/main/java/DNPM/services/strahlentherapie/DefaultStrahlentherapieService.java new file mode 100644 index 0000000..b899d56 --- /dev/null +++ b/src/main/java/DNPM/services/strahlentherapie/DefaultStrahlentherapieService.java @@ -0,0 +1,73 @@ +package DNPM.services.strahlentherapie; + +import DNPM.services.SettingsService; +import de.itc.onkostar.api.IOnkostarApi; +import de.itc.onkostar.api.Patient; +import de.itc.onkostar.api.Procedure; + +import java.util.Comparator; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Collectors; + +/** + * Standardimplementierung des StrahlentherapieServices + * + * @since 0.6.0 + */ +public class DefaultStrahlentherapieService implements StrahlentherapieService { + + private static final String ECOG_FIELD = "ECOGvorTherapie"; + + private final IOnkostarApi onkostarApi; + + private final SettingsService settingsService; + + public DefaultStrahlentherapieService(final IOnkostarApi onkostarApi, final SettingsService settingsService) { + this.onkostarApi = onkostarApi; + this.settingsService = settingsService; + } + + /** + * Ermittelt den letzten bekannten ECOG-Status aus allen Systemtherapieformularen des Patienten + * + * @param patient Der zu verwendende Patient + * @return Der ECOG-Status als String oder leeres Optional + */ + @Override + public Optional latestEcogStatus(Patient patient) { + return ecogStatus(patient).stream() + .max(Comparator.comparing(EcogStatusWithDate::getDate)) + .map(EcogStatusWithDate::getStatus); + } + + /** + * Ermittelt jeden bekannten ECOG-Status aus allen Systemtherapieformularen des Patienten + * + * @param patient Der zu verwendende Patient + * @return Eine Liste mit Datum und ECOG-Status als String + */ + @Override + public List ecogStatus(Patient patient) { + return patient.getDiseases().stream() + .flatMap(disease -> onkostarApi.getProceduresForDiseaseByForm(disease.getId(), getFormName()).stream()) + .filter(procedure -> null != procedure.getStartDate()) + .sorted(Comparator.comparing(Procedure::getStartDate)) + .map(procedure -> { + try { + return new EcogStatusWithDate(procedure.getStartDate(), procedure.getValue(ECOG_FIELD).getString()); + } catch (IllegalArgumentException e) { + return null; + } + }) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + } + + private String getFormName() { + return settingsService + .getSetting("strahlentherapieform") + .orElse("OS.Strahlentherapie"); + } +} diff --git a/src/main/java/DNPM/services/strahlentherapie/StrahlentherapieService.java b/src/main/java/DNPM/services/strahlentherapie/StrahlentherapieService.java new file mode 100644 index 0000000..f5cef46 --- /dev/null +++ b/src/main/java/DNPM/services/strahlentherapie/StrahlentherapieService.java @@ -0,0 +1,70 @@ +package DNPM.services.strahlentherapie; + +import de.itc.onkostar.api.Patient; +import org.springframework.util.Assert; + +import java.util.Date; +import java.util.List; +import java.util.Optional; + +/** + * Service für Systemtherapieformulare + * + * @since 0.6.0 + */ +public interface StrahlentherapieService { + + /** + * Ermittelt den letzten bekannten ECOG-Status aus allen Systemtherapieformularen des Patienten + * @param patient Der zu verwendende Patient + * @return Der ECOG-Status als String oder leeres Optional + */ + Optional latestEcogStatus(Patient patient); + + /** + * Ermittelt jeden bekannten ECOG-Status aus allen Strahlentherapieformularen des Patienten + * @param patient Der zu verwendende Patient + * @return Eine Liste mit Datum und ECOG-Status als String + */ + List ecogStatus(Patient patient); + + /** + * Datenklasse zum Abbilden des ECOG-Status und Datum + */ + class EcogStatusWithDate { + private Date date; + private String status; + + public EcogStatusWithDate(Date date, String status) { + Assert.notNull(date, "Date cannot be null"); + Assert.hasText(status, "Status cannot be empty String"); + Assert.isTrue(isValidEcogCode(status), "Not a valid ADT.LeistungszustandECOG code"); + this.date = date; + this.status = status; + } + + private boolean isValidEcogCode(String status) { + switch (status) { + case "0": + case "1": + case "2": + case "3": + case "4": + case "5": + case "U": + return true; + default: + return false; + } + } + + public Date getDate() { + return date; + } + + public String getStatus() { + return status; + } + } + +} diff --git a/src/test/java/DNPM/services/strahlentherapie/DefaultStrahlentherapieServiceTest.java b/src/test/java/DNPM/services/strahlentherapie/DefaultStrahlentherapieServiceTest.java new file mode 100644 index 0000000..652aa16 --- /dev/null +++ b/src/test/java/DNPM/services/strahlentherapie/DefaultStrahlentherapieServiceTest.java @@ -0,0 +1,106 @@ +package DNPM.services.strahlentherapie; + +import DNPM.services.SettingsService; +import de.itc.onkostar.api.*; +import org.assertj.core.util.Lists; +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.time.Instant; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Optional; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.*; + +@ExtendWith(MockitoExtension.class) +class DefaultStrahlentherapieServiceTest { + + private IOnkostarApi onkostarApi; + + private SettingsService settingsService; + + private DefaultStrahlentherapieService service; + + @BeforeEach + void setup(@Mock IOnkostarApi onkostarApi, @Mock SettingsService settingsService) { + this.onkostarApi = onkostarApi; + this.settingsService = settingsService; + this.service = new DefaultStrahlentherapieService(onkostarApi, settingsService); + } + + @Test + void testShouldRequestProceduresWithDefaultFormName() { + when(this.settingsService.getSetting(anyString())).thenReturn(Optional.empty()); + + doAnswer(invocationOnMock -> { + var procedure = new Procedure(onkostarApi); + procedure.setId(1); + procedure.setFormName("OS.Strahlentherapie"); + procedure.setStartDate(Date.from(Instant.parse("2023-07-01T06:00:00Z"))); + procedure.setEditState(ProcedureEditStateType.COMPLETED); + procedure.setValue("ECOGvorTherapie", new Item("ECOGvorTherapie", 1)); + return Lists.list(procedure); + }).when(this.onkostarApi).getProceduresForDiseaseByForm(anyInt(), anyString()); + + doAnswer(invocationOnMock -> { + var disease = new Disease(onkostarApi); + disease.setId(1); + disease.setPatientId(123); + return Lists.list(disease); + }).when(this.onkostarApi).getDiseasesByPatientId(anyInt()); + + var patient = new Patient(onkostarApi); + patient.setId(123); + + service.ecogStatus(patient); + + var argumentCaptor = ArgumentCaptor.forClass(String.class); + verify(onkostarApi, times(1)).getProceduresForDiseaseByForm(anyInt(), argumentCaptor.capture()); + assertThat(argumentCaptor.getValue()).isEqualTo("OS.Strahlentherapie"); + } + + @Test + void testShouldReturnListOfEcogStatusWithDate() { + doAnswer(invocationOnMock -> { + var disease = new Disease(onkostarApi); + disease.setId(1); + return List.of(disease); + }).when(this.onkostarApi).getDiseasesByPatientId(anyInt()); + + doAnswer(invocationOnMock -> { + var procedure1 = new Procedure(onkostarApi); + procedure1.setId(1); + procedure1.setFormName("OS.Strahlentherapie"); + procedure1.setStartDate(Date.from(Instant.parse("2023-07-01T06:00:00Z"))); + procedure1.setEditState(ProcedureEditStateType.COMPLETED); + procedure1.setValue("ECOGvorTherapie", new Item("ECOGvorTherapie", 1)); + + var procedure2 = new Procedure(onkostarApi); + procedure2.setId(2); + procedure2.setFormName("OS.Strahlentherapie"); + procedure2.setStartDate(Date.from(Instant.parse("2023-07-12T06:00:00Z"))); + procedure2.setEditState(ProcedureEditStateType.COMPLETED); + procedure2.setValue("ECOGvorTherapie", new Item("ECOGvorTherapie", 2)); + return List.of(procedure1, procedure2); + }).when(this.onkostarApi).getProceduresForDiseaseByForm(anyInt(), anyString()); + + var patient = new Patient(onkostarApi); + patient.setId(1); + + var actual = service.ecogStatus(patient); + + assertThat(actual) + .isNotNull() + .isExactlyInstanceOf(ArrayList.class) + .hasSize(2); + } +} From 14e9fcab1a400d04b21c2ea5cf3a3e02dd30f043 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Tue, 10 Oct 2023 12:21:27 +0200 Subject: [PATCH 2/3] Issue #54: Add common EcogService interface --- src/main/java/DNPM/analyzer/DNPMHelper.java | 3 +- .../DNPM/analyzer/SystemtherapieAnalyzer.java | 5 +- .../java/DNPM/dto/EcogStatusWithDate.java | 68 +++++++++++++++++++ .../DNPM/services/TherapieMitEcogService.java | 30 ++++++++ .../DefaultStrahlentherapieService.java | 1 + .../StrahlentherapieService.java | 64 +---------------- .../DefaultSystemtherapieService.java | 1 + .../systemtherapie/SystemtherapieService.java | 60 +--------------- .../analyzer/SystemtherapieAnalyzerTest.java | 5 +- 9 files changed, 112 insertions(+), 125 deletions(-) create mode 100644 src/main/java/DNPM/dto/EcogStatusWithDate.java create mode 100644 src/main/java/DNPM/services/TherapieMitEcogService.java diff --git a/src/main/java/DNPM/analyzer/DNPMHelper.java b/src/main/java/DNPM/analyzer/DNPMHelper.java index 376333e..bb21fa0 100644 --- a/src/main/java/DNPM/analyzer/DNPMHelper.java +++ b/src/main/java/DNPM/analyzer/DNPMHelper.java @@ -1,5 +1,6 @@ package DNPM.analyzer; +import DNPM.dto.EcogStatusWithDate; import DNPM.VerweisVon; import DNPM.security.DelegatingDataBasedPermissionEvaluator; import DNPM.security.IllegalSecuredObjectAccessException; @@ -237,7 +238,7 @@ public class DNPMHelper extends BackendService { } - public List getEcogStatus(final Map input) { + public List getEcogStatus(final Map input) { var pid = AnalyzerUtils.getRequiredId(input, "PatientId"); if (pid.isEmpty()) { logger.error("Kein Parameter 'PatientId' angegeben, gebe leere Liste zurück"); diff --git a/src/main/java/DNPM/analyzer/SystemtherapieAnalyzer.java b/src/main/java/DNPM/analyzer/SystemtherapieAnalyzer.java index f886f3d..e8936cf 100644 --- a/src/main/java/DNPM/analyzer/SystemtherapieAnalyzer.java +++ b/src/main/java/DNPM/analyzer/SystemtherapieAnalyzer.java @@ -1,5 +1,6 @@ package DNPM.analyzer; +import DNPM.dto.EcogStatusWithDate; import DNPM.services.systemtherapie.SystemtherapieService; import de.itc.onkostar.api.Disease; import de.itc.onkostar.api.IOnkostarApi; @@ -111,7 +112,7 @@ public class SystemtherapieAnalyzer extends Analyzer { }); } - private void updateExistingEcogVerlauf(Procedure p, List ecogFromCompleted, Item ufEcog) { + private void updateExistingEcogVerlauf(Procedure p, List ecogFromCompleted, Item ufEcog) { var shouldSave = false; var existingDates = ufEcog.>>getValue().stream() .map(v -> v.get("Datum")) @@ -136,7 +137,7 @@ public class SystemtherapieAnalyzer extends Analyzer { } } - private void newEcogverlauf(Procedure p, List ecogFromCompleted) { + private void newEcogverlauf(Procedure p, List ecogFromCompleted) { p.setValue("ECOGVerlauf", new Item("ECOGVerlauf", List.of())); for (var ecog : ecogFromCompleted) { var newSubProcedure = new Procedure(onkostarApi); diff --git a/src/main/java/DNPM/dto/EcogStatusWithDate.java b/src/main/java/DNPM/dto/EcogStatusWithDate.java new file mode 100644 index 0000000..d48a3ff --- /dev/null +++ b/src/main/java/DNPM/dto/EcogStatusWithDate.java @@ -0,0 +1,68 @@ +/* + * MIT License + * + * 2023 Comprehensive Cancer Center Mainfranken + * + * 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 DNPM.dto; + +import org.springframework.util.Assert; + +import java.util.Date; + +/** + * Datenklasse zum Abbilden des ECOG-Status und Datum + */ +public class EcogStatusWithDate { + private Date date; + private String status; + + public EcogStatusWithDate(Date date, String status) { + Assert.notNull(date, "Date cannot be null"); + Assert.hasText(status, "Status cannot be empty String"); + Assert.isTrue(isValidEcogCode(status), "Not a valid ADT.LeistungszustandECOG code"); + this.date = date; + this.status = status; + } + + private boolean isValidEcogCode(String status) { + switch (status) { + case "0": + case "1": + case "2": + case "3": + case "4": + case "5": + case "U": + return true; + default: + return false; + } + } + + public Date getDate() { + return date; + } + + public String getStatus() { + return status; + } +} diff --git a/src/main/java/DNPM/services/TherapieMitEcogService.java b/src/main/java/DNPM/services/TherapieMitEcogService.java new file mode 100644 index 0000000..e8cbae4 --- /dev/null +++ b/src/main/java/DNPM/services/TherapieMitEcogService.java @@ -0,0 +1,30 @@ +package DNPM.services; + +import DNPM.dto.EcogStatusWithDate; +import de.itc.onkostar.api.Patient; + +import java.util.List; +import java.util.Optional; + +/** + * Schnittstelle zum Ermitteln von ECOG-Statusinformationen + * + * @since 0.6.0 + */ +public interface TherapieMitEcogService { + + /** + * Ermittelt den letzten bekannten ECOG-Status aus allen Therapieformularen des Patienten + * @param patient Der zu verwendende Patient + * @return Der ECOG-Status als String oder leeres Optional + */ + Optional latestEcogStatus(Patient patient); + + /** + * Ermittelt jeden bekannten ECOG-Status aus allen Therapieformularen des Patienten + * @param patient Der zu verwendende Patient + * @return Eine Liste mit Datum und ECOG-Status als String + */ + List ecogStatus(Patient patient); + +} diff --git a/src/main/java/DNPM/services/strahlentherapie/DefaultStrahlentherapieService.java b/src/main/java/DNPM/services/strahlentherapie/DefaultStrahlentherapieService.java index b899d56..a318a81 100644 --- a/src/main/java/DNPM/services/strahlentherapie/DefaultStrahlentherapieService.java +++ b/src/main/java/DNPM/services/strahlentherapie/DefaultStrahlentherapieService.java @@ -1,5 +1,6 @@ package DNPM.services.strahlentherapie; +import DNPM.dto.EcogStatusWithDate; import DNPM.services.SettingsService; import de.itc.onkostar.api.IOnkostarApi; import de.itc.onkostar.api.Patient; diff --git a/src/main/java/DNPM/services/strahlentherapie/StrahlentherapieService.java b/src/main/java/DNPM/services/strahlentherapie/StrahlentherapieService.java index f5cef46..a8de923 100644 --- a/src/main/java/DNPM/services/strahlentherapie/StrahlentherapieService.java +++ b/src/main/java/DNPM/services/strahlentherapie/StrahlentherapieService.java @@ -1,70 +1,10 @@ package DNPM.services.strahlentherapie; -import de.itc.onkostar.api.Patient; -import org.springframework.util.Assert; - -import java.util.Date; -import java.util.List; -import java.util.Optional; +import DNPM.services.TherapieMitEcogService; /** * Service für Systemtherapieformulare * * @since 0.6.0 */ -public interface StrahlentherapieService { - - /** - * Ermittelt den letzten bekannten ECOG-Status aus allen Systemtherapieformularen des Patienten - * @param patient Der zu verwendende Patient - * @return Der ECOG-Status als String oder leeres Optional - */ - Optional latestEcogStatus(Patient patient); - - /** - * Ermittelt jeden bekannten ECOG-Status aus allen Strahlentherapieformularen des Patienten - * @param patient Der zu verwendende Patient - * @return Eine Liste mit Datum und ECOG-Status als String - */ - List ecogStatus(Patient patient); - - /** - * Datenklasse zum Abbilden des ECOG-Status und Datum - */ - class EcogStatusWithDate { - private Date date; - private String status; - - public EcogStatusWithDate(Date date, String status) { - Assert.notNull(date, "Date cannot be null"); - Assert.hasText(status, "Status cannot be empty String"); - Assert.isTrue(isValidEcogCode(status), "Not a valid ADT.LeistungszustandECOG code"); - this.date = date; - this.status = status; - } - - private boolean isValidEcogCode(String status) { - switch (status) { - case "0": - case "1": - case "2": - case "3": - case "4": - case "5": - case "U": - return true; - default: - return false; - } - } - - public Date getDate() { - return date; - } - - public String getStatus() { - return status; - } - } - -} +public interface StrahlentherapieService extends TherapieMitEcogService {} diff --git a/src/main/java/DNPM/services/systemtherapie/DefaultSystemtherapieService.java b/src/main/java/DNPM/services/systemtherapie/DefaultSystemtherapieService.java index 4b9c1a2..578613f 100644 --- a/src/main/java/DNPM/services/systemtherapie/DefaultSystemtherapieService.java +++ b/src/main/java/DNPM/services/systemtherapie/DefaultSystemtherapieService.java @@ -1,5 +1,6 @@ package DNPM.services.systemtherapie; +import DNPM.dto.EcogStatusWithDate; import DNPM.services.SettingsService; import de.itc.onkostar.api.IOnkostarApi; import de.itc.onkostar.api.Patient; diff --git a/src/main/java/DNPM/services/systemtherapie/SystemtherapieService.java b/src/main/java/DNPM/services/systemtherapie/SystemtherapieService.java index ea26c0c..a7ac1bd 100644 --- a/src/main/java/DNPM/services/systemtherapie/SystemtherapieService.java +++ b/src/main/java/DNPM/services/systemtherapie/SystemtherapieService.java @@ -1,20 +1,17 @@ package DNPM.services.systemtherapie; -import de.itc.onkostar.api.Patient; +import DNPM.services.TherapieMitEcogService; import de.itc.onkostar.api.Procedure; -import org.springframework.util.Assert; -import java.util.Date; import java.util.List; import java.util.Map; -import java.util.Optional; /** * Service für Systemtherapieformulare * * @since 0.2.0 */ -public interface SystemtherapieService { +public interface SystemtherapieService extends TherapieMitEcogService { /** * Ermittelt eine Zusammenfassung der systemischen Therapien für eine Erkrankung * @param diseaseId Die ID der Erkrankung @@ -29,57 +26,4 @@ public interface SystemtherapieService { */ ProzedurToProzedurwerteMapper prozedurToProzedurwerteMapper(Procedure procedure); - /** - * Ermittelt den letzten bekannten ECOG-Status aus allen Systemtherapieformularen des Patienten - * @param patient Der zu verwendende Patient - * @return Der ECOG-Status als String oder leeres Optional - */ - Optional latestEcogStatus(Patient patient); - - /** - * Ermittelt jeden bekannten ECOG-Status aus allen Systemtherapieformularen des Patienten - * @param patient Der zu verwendende Patient - * @return Eine Liste mit Datum und ECOG-Status als String - */ - List ecogStatus(Patient patient); - - /** - * Datenklasse zum Abbilden des ECOG-Status und Datum - */ - class EcogStatusWithDate { - private Date date; - private String status; - - public EcogStatusWithDate(Date date, String status) { - Assert.notNull(date, "Date cannot be null"); - Assert.hasText(status, "Status cannot be empty String"); - Assert.isTrue(isValidEcogCode(status), "Not a valid ADT.LeistungszustandECOG code"); - this.date = date; - this.status = status; - } - - private boolean isValidEcogCode(String status) { - switch (status) { - case "0": - case "1": - case "2": - case "3": - case "4": - case "5": - case "U": - return true; - default: - return false; - } - } - - public Date getDate() { - return date; - } - - public String getStatus() { - return status; - } - } - } diff --git a/src/test/java/DNPM/analyzer/SystemtherapieAnalyzerTest.java b/src/test/java/DNPM/analyzer/SystemtherapieAnalyzerTest.java index 1fa57c0..d500059 100644 --- a/src/test/java/DNPM/analyzer/SystemtherapieAnalyzerTest.java +++ b/src/test/java/DNPM/analyzer/SystemtherapieAnalyzerTest.java @@ -1,5 +1,6 @@ package DNPM.analyzer; +import DNPM.dto.EcogStatusWithDate; import DNPM.services.systemtherapie.SystemtherapieService; import de.itc.onkostar.api.*; import org.junit.jupiter.api.BeforeEach; @@ -54,7 +55,7 @@ class SystemtherapieAnalyzerTest { final var ecogDate = daysPassed(1); final var procedureDate = daysPassed(1); - doAnswer(invocationOnMock -> List.of(new SystemtherapieService.EcogStatusWithDate(ecogDate, "0"))) + doAnswer(invocationOnMock -> List.of(new EcogStatusWithDate(ecogDate, "0"))) .when(systemtherapieService).ecogStatus(any(Patient.class)); var patient = new Patient(onkostarApi); @@ -114,7 +115,7 @@ class SystemtherapieAnalyzerTest { final var ecogDate = daysPassed(28); final var procedureDate = daysPassed(1); - doAnswer(invocationOnMock -> List.of(new SystemtherapieService.EcogStatusWithDate(ecogDate, "0"))) + doAnswer(invocationOnMock -> List.of(new EcogStatusWithDate(ecogDate, "0"))) .when(systemtherapieService).ecogStatus(any(Patient.class)); var patient = new Patient(onkostarApi); From 9c503d2244f61221fdf9716ded30f86aa758f957 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Tue, 10 Oct 2023 13:02:21 +0200 Subject: [PATCH 3/3] Issue #54: Verwende ECOG nach Update von Strahlen- und Systemtherapieformular --- ...yzer.java => TherapieMitEcogAnalyzer.java} | 30 +++++++++----- ....java => TherapieMitEcogAnalyzerTest.java} | 39 ++++++++++++++++--- 2 files changed, 54 insertions(+), 15 deletions(-) rename src/main/java/DNPM/analyzer/{SystemtherapieAnalyzer.java => TherapieMitEcogAnalyzer.java} (81%) rename src/test/java/DNPM/analyzer/{SystemtherapieAnalyzerTest.java => TherapieMitEcogAnalyzerTest.java} (75%) diff --git a/src/main/java/DNPM/analyzer/SystemtherapieAnalyzer.java b/src/main/java/DNPM/analyzer/TherapieMitEcogAnalyzer.java similarity index 81% rename from src/main/java/DNPM/analyzer/SystemtherapieAnalyzer.java rename to src/main/java/DNPM/analyzer/TherapieMitEcogAnalyzer.java index e8936cf..46841e1 100644 --- a/src/main/java/DNPM/analyzer/SystemtherapieAnalyzer.java +++ b/src/main/java/DNPM/analyzer/TherapieMitEcogAnalyzer.java @@ -1,6 +1,7 @@ package DNPM.analyzer; import DNPM.dto.EcogStatusWithDate; +import DNPM.services.strahlentherapie.StrahlentherapieService; import DNPM.services.systemtherapie.SystemtherapieService; import de.itc.onkostar.api.Disease; import de.itc.onkostar.api.IOnkostarApi; @@ -21,28 +22,31 @@ import java.util.stream.Collectors; /** * Diese Klasse implementiert ein Plugin, welches Aktionen nach Bearbeitung eines Formulars zur Systemtherapie durchführt. * - * @since 0.4.0 + * @since 0.6.0 */ @Component -public class SystemtherapieAnalyzer extends Analyzer { +public class TherapieMitEcogAnalyzer extends Analyzer { private final Logger logger = LoggerFactory.getLogger(this.getClass()); private final IOnkostarApi onkostarApi; + private final StrahlentherapieService strahlentherapieService; private final SystemtherapieService systemtherapieService; - public SystemtherapieAnalyzer( + public TherapieMitEcogAnalyzer( final IOnkostarApi onkostarApi, + final StrahlentherapieService strahlentherapieService, final SystemtherapieService systemtherapieService ) { this.onkostarApi = onkostarApi; + this.strahlentherapieService = strahlentherapieService; this.systemtherapieService = systemtherapieService; } @Override public String getDescription() { - return "Aktualisiert verknüpfte Formulare nach Änderungen im Formularen vom Typ Systemtherapie"; + return "Aktualisiert verknüpfte Formulare nach Änderungen in Formularen vom Typ Strahlen-/Systemtherapie mit ECOG-Status"; } /** @@ -56,7 +60,9 @@ public class SystemtherapieAnalyzer extends Analyzer { @Override public boolean isRelevantForAnalyzer(Procedure procedure, Disease disease) { return null != procedure && null != disease && ( - procedure.getFormName().equals("OS.Systemische Therapie") + procedure.getFormName().equals("OS.Strahlentherapie") + || procedure.getFormName().equals("OS.Strahlentherapie.VarianteUKW") + || procedure.getFormName().equals("OS.Systemische Therapie") || procedure.getFormName().equals("OS.Systemische Therapie.VarianteUKW") ); } @@ -90,12 +96,18 @@ public class SystemtherapieAnalyzer extends Analyzer { return; } - var ecogFromCompleted = systemtherapieService.ecogStatus(procedure.getPatient()) + var ecog = strahlentherapieService.ecogStatus(procedure.getPatient()) .stream() .filter(ecogStatusWithDate -> ecogStatusWithDate.getDate().after(disease.getDiagnosisDate())) .collect(Collectors.toList()); - if (ecogFromCompleted.isEmpty()) { + ecog.addAll(systemtherapieService.ecogStatus(procedure.getPatient()) + .stream() + .filter(ecogStatusWithDate -> ecogStatusWithDate.getDate().after(disease.getDiagnosisDate())) + .collect(Collectors.toList())); + + + if (ecog.isEmpty()) { // Nothing to do return; } @@ -105,9 +117,9 @@ public class SystemtherapieAnalyzer extends Analyzer { .forEach(p -> { var ufEcog = p.getValue("ECOGVerlauf"); if (null != ufEcog && ufEcog.getValue() instanceof List) { - updateExistingEcogVerlauf(p, ecogFromCompleted, ufEcog); + updateExistingEcogVerlauf(p, ecog, ufEcog); } else { - newEcogverlauf(p, ecogFromCompleted); + newEcogverlauf(p, ecog); } }); } diff --git a/src/test/java/DNPM/analyzer/SystemtherapieAnalyzerTest.java b/src/test/java/DNPM/analyzer/TherapieMitEcogAnalyzerTest.java similarity index 75% rename from src/test/java/DNPM/analyzer/SystemtherapieAnalyzerTest.java rename to src/test/java/DNPM/analyzer/TherapieMitEcogAnalyzerTest.java index d500059..aab0759 100644 --- a/src/test/java/DNPM/analyzer/SystemtherapieAnalyzerTest.java +++ b/src/test/java/DNPM/analyzer/TherapieMitEcogAnalyzerTest.java @@ -1,6 +1,7 @@ package DNPM.analyzer; import DNPM.dto.EcogStatusWithDate; +import DNPM.services.strahlentherapie.StrahlentherapieService; import DNPM.services.systemtherapie.SystemtherapieService; import de.itc.onkostar.api.*; import org.junit.jupiter.api.BeforeEach; @@ -20,13 +21,15 @@ import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) -class SystemtherapieAnalyzerTest { +class TherapieMitEcogAnalyzerTest { private IOnkostarApi onkostarApi; + private StrahlentherapieService strahlentherapieService; + private SystemtherapieService systemtherapieService; - private SystemtherapieAnalyzer systemtherapieAnalyzer; + private TherapieMitEcogAnalyzer therapieMitEcogAnalyzer; private Disease dummyDisease(int id, Date diagnosisDate) { var disease = new Disease(onkostarApi); @@ -42,11 +45,13 @@ class SystemtherapieAnalyzerTest { @BeforeEach void setUp( @Mock IOnkostarApi onkostarApi, + @Mock StrahlentherapieService strahlentherapieService, @Mock SystemtherapieService systemtherapieService ) { this.onkostarApi = onkostarApi; + this.strahlentherapieService = strahlentherapieService; this.systemtherapieService = systemtherapieService; - this.systemtherapieAnalyzer = new SystemtherapieAnalyzer(onkostarApi, systemtherapieService); + this.therapieMitEcogAnalyzer = new TherapieMitEcogAnalyzer(onkostarApi, strahlentherapieService, systemtherapieService); } @Test @@ -73,7 +78,7 @@ class SystemtherapieAnalyzerTest { doAnswer(invocationOnMock -> List.of(procedure)).when(onkostarApi).getProceduresForDiseaseByForm(anyInt(), anyString()); - systemtherapieAnalyzer.analyze(procedure, dummyDisease(10, diagnosisDate)); + therapieMitEcogAnalyzer.analyze(procedure, dummyDisease(10, diagnosisDate)); var idCaptor = ArgumentCaptor.forClass(Integer.class); var formNameCaptor = ArgumentCaptor.forClass(String.class); @@ -103,7 +108,7 @@ class SystemtherapieAnalyzerTest { procedure.setPatient(patient); procedure.setValue("ECOGvorTherapie", new Item("ECOGvorTherapie", 1)); - systemtherapieAnalyzer.analyze(procedure, dummyDisease(10, diagnosisDate)); + therapieMitEcogAnalyzer.analyze(procedure, dummyDisease(10, diagnosisDate)); verify(onkostarApi, times(0)).getProceduresForDiseaseByForm(anyInt(), anyString()); verify(onkostarApi, times(0)).saveProcedure(any(Procedure.class), anyBoolean()); @@ -129,10 +134,32 @@ class SystemtherapieAnalyzerTest { procedure.setPatient(patient); procedure.setValue("ECOGvorTherapie", new Item("ECOGvorTherapie", 1)); - systemtherapieAnalyzer.analyze(procedure, dummyDisease(10, diagnosisDate)); + therapieMitEcogAnalyzer.analyze(procedure, dummyDisease(10, diagnosisDate)); verify(onkostarApi, times(0)).getProceduresForDiseaseByForm(anyInt(), anyString()); verify(onkostarApi, times(0)).saveProcedure(any(Procedure.class), anyBoolean()); } + @Test + void shouldRequestEcogFromStrahlentherapieAndSystemtherapie() { + final var diagnosisDate = daysPassed(7); + final var procedureDate = daysPassed(1); + + var patient = new Patient(onkostarApi); + patient.setId(1); + + var procedure = new Procedure(onkostarApi); + procedure.setId(1000); + procedure.setStartDate(procedureDate); + procedure.setEditState(ProcedureEditStateType.COMPLETED); + procedure.setPatientId(1); + procedure.setPatient(patient); + procedure.setValue("ECOGvorTherapie", new Item("ECOGvorTherapie", 1)); + + therapieMitEcogAnalyzer.analyze(procedure, dummyDisease(10, diagnosisDate)); + + verify(strahlentherapieService, times(1)).ecogStatus(any()); + verify(systemtherapieService, times(1)).ecogStatus(any()); + } + }