mirror of
https://github.com/pcvolkmer/onkostar-plugin-dnpm.git
synced 2025-07-02 01:02:55 +00:00
Merge branch 'master' into issue_37
This commit is contained in:
@ -0,0 +1,27 @@
|
||||
// To be included in Script "Beim Neuanlegen" of form "DNPM Klink/Anamnese"
|
||||
|
||||
executePluginMethod('DNPMHelper', 'getEcogStatus', {PatientId: getPatient().id}, (resp) => {
|
||||
if (resp.status.code === 1) {
|
||||
// Hack: Get version id of ECOG status as stored in Database
|
||||
// by using initial empty entry and its version.
|
||||
// Since OS always creates an initial empty entry for subforms
|
||||
// this can be used to get required version id from within a form script.
|
||||
let version = getFieldValue('ECOGVerlauf')[0].ECOG.version;
|
||||
|
||||
// Abort if no version available.
|
||||
if (version == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
let uf = resp.result.map(item => {
|
||||
let date = new Date(item.date).toISOString().split('T')[0];
|
||||
let ecog = [];
|
||||
ecog.val = item.status;
|
||||
ecog.version = version;
|
||||
return {
|
||||
Datum: [date, 'exact'], ECOG: ecog
|
||||
};
|
||||
});
|
||||
setFieldValue('ECOGVerlauf', uf);
|
||||
}
|
||||
}, false);
|
6
pom.xml
6
pom.xml
@ -155,6 +155,12 @@
|
||||
<version>2.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.17</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -1,6 +1,9 @@
|
||||
package DNPM;
|
||||
|
||||
import DNPM.analyzer.AnalyzerUtils;
|
||||
import DNPM.security.IllegalSecuredObjectAccessException;
|
||||
import DNPM.security.PermissionType;
|
||||
import DNPM.security.PersonPoolBasedPermissionEvaluator;
|
||||
import DNPM.services.systemtherapie.SystemtherapieService;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
@ -17,6 +20,7 @@ import org.hibernate.transform.Transformers;
|
||||
import org.hibernate.type.StandardBasicTypes;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@ -31,9 +35,16 @@ public class DNPMHelper implements IProcedureAnalyzer {
|
||||
|
||||
private final SystemtherapieService systemtherapieService;
|
||||
|
||||
public DNPMHelper(final IOnkostarApi onkostarApi, final SystemtherapieService systemtherapieService) {
|
||||
private final PersonPoolBasedPermissionEvaluator personPoolBasedPermissionEvaluator;
|
||||
|
||||
public DNPMHelper(
|
||||
final IOnkostarApi onkostarApi,
|
||||
final SystemtherapieService systemtherapieService,
|
||||
final PersonPoolBasedPermissionEvaluator permissionEvaluator
|
||||
) {
|
||||
this.onkostarApi = onkostarApi;
|
||||
this.systemtherapieService = systemtherapieService;
|
||||
this.personPoolBasedPermissionEvaluator = permissionEvaluator;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -45,7 +56,7 @@ public class DNPMHelper implements IProcedureAnalyzer {
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return "0.3.0";
|
||||
return "0.4.0";
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -249,4 +260,25 @@ public class DNPMHelper implements IProcedureAnalyzer {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// TODO Achtung, keine Sicherheitsprüfung, darüber kann für jeden Patienten die Liste mit ECOG-Status abgerufen werden!
|
||||
public List<SystemtherapieService.EcogStatusWithDate> getEcogStatus(final Map<String, Object> input) {
|
||||
var pid = AnalyzerUtils.getRequiredId(input, "PatientId");
|
||||
if (pid.isEmpty()) {
|
||||
logger.error("Kein Parameter 'PatientId' angegeben, gebe leere Liste zurück");
|
||||
return List.of();
|
||||
}
|
||||
|
||||
var patient = onkostarApi.getPatient(pid.get());
|
||||
if (null == patient) {
|
||||
logger.error("Patient nicht gefunden, gebe leere Liste zurück");
|
||||
return List.of();
|
||||
}
|
||||
|
||||
if (personPoolBasedPermissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), patient, PermissionType.READ)) {
|
||||
return systemtherapieService.ecogSatus(patient);
|
||||
}
|
||||
|
||||
throw new IllegalSecuredObjectAccessException("Kein Zugriff auf diesen Patienten");
|
||||
}
|
||||
}
|
172
src/main/java/DNPM/analyzer/SystemtherapieAnalyzer.java
Normal file
172
src/main/java/DNPM/analyzer/SystemtherapieAnalyzer.java
Normal file
@ -0,0 +1,172 @@
|
||||
package DNPM.analyzer;
|
||||
|
||||
import DNPM.services.systemtherapie.SystemtherapieService;
|
||||
import de.itc.onkostar.api.Disease;
|
||||
import de.itc.onkostar.api.IOnkostarApi;
|
||||
import de.itc.onkostar.api.Item;
|
||||
import de.itc.onkostar.api.Procedure;
|
||||
import de.itc.onkostar.api.analysis.AnalyseTriggerEvent;
|
||||
import de.itc.onkostar.api.analysis.AnalyzerRequirement;
|
||||
import de.itc.onkostar.api.analysis.IProcedureAnalyzer;
|
||||
import de.itc.onkostar.api.analysis.OnkostarPluginType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Diese Klasse implementiert ein Plugin, welches Aktionen nach Bearbeitung eines Formulars zur Systemtherapie durchführt.
|
||||
*
|
||||
* @since 0.4.0
|
||||
*/
|
||||
@Component
|
||||
public class SystemtherapieAnalyzer implements IProcedureAnalyzer {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
private final IOnkostarApi onkostarApi;
|
||||
|
||||
private final SystemtherapieService systemtherapieService;
|
||||
|
||||
public SystemtherapieAnalyzer(
|
||||
final IOnkostarApi onkostarApi,
|
||||
final SystemtherapieService systemtherapieService
|
||||
) {
|
||||
this.onkostarApi = onkostarApi;
|
||||
this.systemtherapieService = systemtherapieService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OnkostarPluginType getType() {
|
||||
return OnkostarPluginType.ANALYZER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return "0.4.0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "DNPM Systemtherapie Analyzer";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Aktualisiert verknüpfte Formulare nach Änderungen im Formularen vom Typ Systemtherapie";
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
@Override
|
||||
public boolean isRelevantForDeletedProcedure() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRelevantForAnalyzer(Procedure procedure, Disease disease) {
|
||||
return null != procedure && null != disease && (
|
||||
procedure.getFormName().equals("OS.Systemische Therapie")
|
||||
|| procedure.getFormName().equals("OS.Systemische Therapie.VarianteUKW")
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSynchronous() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnalyzerRequirement getRequirement() {
|
||||
return AnalyzerRequirement.PROCEDURE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<AnalyseTriggerEvent> getTriggerEvents() {
|
||||
return Set.of(
|
||||
AnalyseTriggerEvent.EDIT_SAVE,
|
||||
AnalyseTriggerEvent.EDIT_LOCK,
|
||||
AnalyseTriggerEvent.REORG
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void analyze(Procedure procedure, Disease disease) {
|
||||
var date = procedure.getStartDate();
|
||||
var status = procedure.getValue("ECOGvorTherapie");
|
||||
|
||||
if (null == date || null == status) {
|
||||
// Ignore
|
||||
return;
|
||||
}
|
||||
|
||||
var ecogFromCompleted = systemtherapieService.ecogSatus(procedure.getPatient())
|
||||
.stream()
|
||||
.filter(ecogStatusWithDate -> ecogStatusWithDate.getDate().after(disease.getDiagnosisDate()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (ecogFromCompleted.isEmpty()) {
|
||||
// Nothing to do
|
||||
return;
|
||||
}
|
||||
|
||||
procedure.getPatient().getDiseases().stream()
|
||||
.flatMap(d -> onkostarApi.getProceduresForDiseaseByForm(d.getId(), "DNPM Klinik/Anamnese").stream())
|
||||
.forEach(p -> {
|
||||
var ufEcog = p.getValue("ECOGVerlauf");
|
||||
if (null != ufEcog && ufEcog.getValue() instanceof List) {
|
||||
updateExistingEcogVerlauf(p, ecogFromCompleted, ufEcog);
|
||||
} else {
|
||||
newEcogverlauf(p, ecogFromCompleted);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void updateExistingEcogVerlauf(Procedure p, List<SystemtherapieService.EcogStatusWithDate> ecogFromCompleted, Item ufEcog) {
|
||||
var shouldSave = false;
|
||||
var existingDates = ufEcog.<List<Map<String, String>>>getValue().stream()
|
||||
.map(v -> v.get("Datum"))
|
||||
.collect(Collectors.toList());
|
||||
for (var ecog : ecogFromCompleted) {
|
||||
var formattedDate = new SimpleDateFormat("yyyy-MM-dd").format(ecog.getDate());
|
||||
if (!existingDates.contains(formattedDate)) {
|
||||
var newSubProcedure = new Procedure(onkostarApi);
|
||||
newSubProcedure.setStartDate(ecog.getDate());
|
||||
newSubProcedure.setValue("Datum", new Item("Datum", ecog.getDate()));
|
||||
newSubProcedure.setValue("ECOG", new Item("ECOG", ecog.getStatus()));
|
||||
p.addSubProcedure("ECOGVerlauf", newSubProcedure);
|
||||
shouldSave = true;
|
||||
}
|
||||
}
|
||||
if (shouldSave) {
|
||||
try {
|
||||
onkostarApi.saveProcedure(p, true);
|
||||
} catch (Exception e) {
|
||||
logger.error("Cannot update ECOG for procedure '{}'", p.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void newEcogverlauf(Procedure p, List<SystemtherapieService.EcogStatusWithDate> ecogFromCompleted) {
|
||||
p.setValue("ECOGVerlauf", new Item("ECOGVerlauf", List.of()));
|
||||
for (var ecog : ecogFromCompleted) {
|
||||
var newSubProcedure = new Procedure(onkostarApi);
|
||||
newSubProcedure.setStartDate(ecog.getDate());
|
||||
newSubProcedure.setValue("Datum", new Item("Datum", ecog.getDate()));
|
||||
newSubProcedure.setValue("ECOG", new Item("ECOG", ecog.getStatus()));
|
||||
p.addSubProcedure("ECOGVerlauf", newSubProcedure);
|
||||
}
|
||||
try {
|
||||
onkostarApi.saveProcedure(p, true);
|
||||
} catch (Exception e) {
|
||||
logger.error("Create update ECOG for procedure '{}'", p.getId());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -2,11 +2,12 @@ package DNPM.services.systemtherapie;
|
||||
|
||||
import DNPM.services.SettingsService;
|
||||
import de.itc.onkostar.api.IOnkostarApi;
|
||||
import de.itc.onkostar.api.Patient;
|
||||
import de.itc.onkostar.api.Procedure;
|
||||
import de.itc.onkostar.api.ProcedureEditStateType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Standardimplementierung des Systemtherapieservices
|
||||
@ -15,6 +16,8 @@ import java.util.Map;
|
||||
*/
|
||||
public class DefaultSystemtherapieService implements SystemtherapieService {
|
||||
|
||||
private static final String ECOG_FIELD = "ECOGvorTherapie";
|
||||
|
||||
private final IOnkostarApi onkostarApi;
|
||||
|
||||
private final SettingsService settingsService;
|
||||
@ -51,6 +54,43 @@ public class DefaultSystemtherapieService implements SystemtherapieService {
|
||||
return new OsSystemischeTherapieToProzedurwerteMapper();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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<String> latestEcogStatus(Patient patient) {
|
||||
return ecogSatus(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<EcogStatusWithDate> ecogSatus(Patient patient) {
|
||||
return patient.getDiseases().stream()
|
||||
.flatMap(disease -> onkostarApi.getProceduresForDiseaseByForm(disease.getId(), getFormName()).stream())
|
||||
.filter(procedure -> procedure.getEditState() == ProcedureEditStateType.COMPLETED)
|
||||
.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("systemtherapieform")
|
||||
|
@ -1,9 +1,13 @@
|
||||
package DNPM.services.systemtherapie;
|
||||
|
||||
import de.itc.onkostar.api.Patient;
|
||||
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
|
||||
@ -25,4 +29,57 @@ 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<String> 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<EcogStatusWithDate> ecogSatus(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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,12 @@
|
||||
package DNPM;
|
||||
|
||||
import DNPM.security.IllegalSecuredObjectAccessException;
|
||||
import DNPM.security.PermissionType;
|
||||
import DNPM.security.PersonPoolBasedPermissionEvaluator;
|
||||
import DNPM.services.systemtherapie.SystemtherapieService;
|
||||
import de.itc.onkostar.api.IOnkostarApi;
|
||||
import de.itc.onkostar.api.Item;
|
||||
import de.itc.onkostar.api.Patient;
|
||||
import de.itc.onkostar.api.Procedure;
|
||||
import org.hibernate.SQLQuery;
|
||||
import org.hibernate.Session;
|
||||
@ -21,6 +25,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@ -30,16 +35,20 @@ class DNPMHelperTest {
|
||||
|
||||
private SystemtherapieService systemtherapieService;
|
||||
|
||||
private PersonPoolBasedPermissionEvaluator personPoolBasedPermissionEvaluator;
|
||||
|
||||
private DNPMHelper dnpmHelper;
|
||||
|
||||
@BeforeEach
|
||||
void setup(
|
||||
@Mock IOnkostarApi onkostarApi,
|
||||
@Mock SystemtherapieService systemtherapieService
|
||||
@Mock SystemtherapieService systemtherapieService,
|
||||
@Mock PersonPoolBasedPermissionEvaluator personPoolBasedPermissionEvaluator
|
||||
) {
|
||||
this.onkostarApi = onkostarApi;
|
||||
this.systemtherapieService = systemtherapieService;
|
||||
this.dnpmHelper = new DNPMHelper(onkostarApi, systemtherapieService);
|
||||
this.personPoolBasedPermissionEvaluator = personPoolBasedPermissionEvaluator;
|
||||
this.dnpmHelper = new DNPMHelper(onkostarApi, systemtherapieService, personPoolBasedPermissionEvaluator);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -245,6 +254,41 @@ class DNPMHelperTest {
|
||||
assertThat(argumentCaptor.getValue()).contains("WHERE patient_id = 2 AND geloescht = 0");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testShouldReturnEcogStatusList() {
|
||||
when(personPoolBasedPermissionEvaluator.hasPermission(any(), any(Patient.class), any(PermissionType.class)))
|
||||
.thenReturn(true);
|
||||
|
||||
doAnswer(invocationOnMock -> {
|
||||
var id = invocationOnMock.getArgument(0, Integer.class);
|
||||
var patient = new Patient(onkostarApi);
|
||||
patient.setId(id);
|
||||
return patient;
|
||||
}).when(onkostarApi).getPatient(anyInt());
|
||||
|
||||
dnpmHelper.getEcogStatus(Map.of("PatientId", 42));
|
||||
|
||||
var argumentCaptor = ArgumentCaptor.forClass(Patient.class);
|
||||
verify(systemtherapieService, times(1)).ecogSatus(argumentCaptor.capture());
|
||||
assertThat(argumentCaptor.getValue()).isNotNull();
|
||||
assertThat(argumentCaptor.getValue().getId()).isEqualTo(42);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testShouldNotReturnEcogStatusListIfNoPermissionGranted() {
|
||||
when(personPoolBasedPermissionEvaluator.hasPermission(any(), any(Patient.class), any(PermissionType.class)))
|
||||
.thenReturn(false);
|
||||
|
||||
doAnswer(invocationOnMock -> {
|
||||
var id = invocationOnMock.getArgument(0, Integer.class);
|
||||
var patient = new Patient(onkostarApi);
|
||||
patient.setId(id);
|
||||
return patient;
|
||||
}).when(onkostarApi).getPatient(anyInt());
|
||||
|
||||
assertThrows(IllegalSecuredObjectAccessException.class, () -> dnpmHelper.getEcogStatus(Map.of("PatientId", 42)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
137
src/test/java/DNPM/analyzer/SystemtherapieAnalyzerTest.java
Normal file
137
src/test/java/DNPM/analyzer/SystemtherapieAnalyzerTest.java
Normal file
@ -0,0 +1,137 @@
|
||||
package DNPM.analyzer;
|
||||
|
||||
import DNPM.services.systemtherapie.SystemtherapieService;
|
||||
import de.itc.onkostar.api.*;
|
||||
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.time.temporal.ChronoUnit;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class SystemtherapieAnalyzerTest {
|
||||
|
||||
private IOnkostarApi onkostarApi;
|
||||
|
||||
private SystemtherapieService systemtherapieService;
|
||||
|
||||
private SystemtherapieAnalyzer systemtherapieAnalyzer;
|
||||
|
||||
private Disease dummyDisease(int id, Date diagnosisDate) {
|
||||
var disease = new Disease(onkostarApi);
|
||||
disease.setId(id);
|
||||
disease.setDiagnosisDate(diagnosisDate);
|
||||
return disease;
|
||||
}
|
||||
|
||||
private Date daysPassed(int days) {
|
||||
return Date.from(Instant.now().minus(days, ChronoUnit.DAYS));
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void setUp(
|
||||
@Mock IOnkostarApi onkostarApi,
|
||||
@Mock SystemtherapieService systemtherapieService
|
||||
) {
|
||||
this.onkostarApi = onkostarApi;
|
||||
this.systemtherapieService = systemtherapieService;
|
||||
this.systemtherapieAnalyzer = new SystemtherapieAnalyzer(onkostarApi, systemtherapieService);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldInsertNewEcogStatus() throws Exception {
|
||||
final var diagnosisDate = daysPassed(7);
|
||||
final var ecogDate = daysPassed(1);
|
||||
final var procedureDate = daysPassed(1);
|
||||
|
||||
doAnswer(invocationOnMock -> List.of(new SystemtherapieService.EcogStatusWithDate(ecogDate, "0")))
|
||||
.when(systemtherapieService).ecogSatus(any(Patient.class));
|
||||
|
||||
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));
|
||||
|
||||
doAnswer(invocationOnMock -> List.of(dummyDisease(42, diagnosisDate))).when(this.onkostarApi).getDiseasesByPatientId(anyInt());
|
||||
|
||||
doAnswer(invocationOnMock -> List.of(procedure)).when(onkostarApi).getProceduresForDiseaseByForm(anyInt(), anyString());
|
||||
|
||||
systemtherapieAnalyzer.analyze(procedure, dummyDisease(10, diagnosisDate));
|
||||
|
||||
var idCaptor = ArgumentCaptor.forClass(Integer.class);
|
||||
var formNameCaptor = ArgumentCaptor.forClass(String.class);
|
||||
verify(onkostarApi, times(1)).getProceduresForDiseaseByForm(idCaptor.capture(), formNameCaptor.capture());
|
||||
assertThat(idCaptor.getValue()).isEqualTo(42);
|
||||
assertThat(formNameCaptor.getValue()).isEqualTo("DNPM Klinik/Anamnese");
|
||||
|
||||
verify(onkostarApi, times(1)).saveProcedure(any(Procedure.class), anyBoolean());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotModifyEcogStatusIfNoCompletedSystemTherapy() throws Exception {
|
||||
final var diagnosisDate = daysPassed(7);
|
||||
final var procedureDate = daysPassed(1);
|
||||
|
||||
doAnswer(invocationOnMock -> List.of())
|
||||
.when(systemtherapieService).ecogSatus(any(Patient.class));
|
||||
|
||||
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));
|
||||
|
||||
systemtherapieAnalyzer.analyze(procedure, dummyDisease(10, diagnosisDate));
|
||||
|
||||
verify(onkostarApi, times(0)).getProceduresForDiseaseByForm(anyInt(), anyString());
|
||||
verify(onkostarApi, times(0)).saveProcedure(any(Procedure.class), anyBoolean());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotIncludeEcogStatusBeforeDiagnosisDate() throws Exception {
|
||||
final var diagnosisDate = daysPassed(7);
|
||||
final var ecogDate = daysPassed(28);
|
||||
final var procedureDate = daysPassed(1);
|
||||
|
||||
doAnswer(invocationOnMock -> List.of(new SystemtherapieService.EcogStatusWithDate(ecogDate, "0")))
|
||||
.when(systemtherapieService).ecogSatus(any(Patient.class));
|
||||
|
||||
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));
|
||||
|
||||
systemtherapieAnalyzer.analyze(procedure, dummyDisease(10, diagnosisDate));
|
||||
|
||||
verify(onkostarApi, times(0)).getProceduresForDiseaseByForm(anyInt(), anyString());
|
||||
verify(onkostarApi, times(0)).saveProcedure(any(Procedure.class), anyBoolean());
|
||||
}
|
||||
|
||||
}
|
@ -1,8 +1,7 @@
|
||||
package DNPM.services.systemtherapie;
|
||||
|
||||
import DNPM.services.SettingsService;
|
||||
import de.itc.onkostar.api.IOnkostarApi;
|
||||
import de.itc.onkostar.api.Procedure;
|
||||
import de.itc.onkostar.api.*;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@ -12,6 +11,7 @@ import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@ -94,4 +94,40 @@ class DefaultSystemtherapieServiceTest {
|
||||
.isExactlyInstanceOf(ArrayList.class)
|
||||
.hasSize(1);
|
||||
}
|
||||
|
||||
@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.Systemische Therapie");
|
||||
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.Systemische Therapie");
|
||||
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.ecogSatus(patient);
|
||||
|
||||
assertThat(actual)
|
||||
.isNotNull()
|
||||
.isExactlyInstanceOf(ArrayList.class)
|
||||
.hasSize(2);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user