mirror of
https://github.com/pcvolkmer/onkostar-plugin-dnpm.git
synced 2025-07-05 02:22:54 +00:00
Merge branch 'master' into issue_37
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user