mirror of
https://github.com/pcvolkmer/onkostar-plugin-dnpm.git
synced 2025-07-05 02:22:54 +00:00
Issue #54: Service zum Ermitteln des ECOG-Status aus Strahlentherapie-Formularen hinzugefügt
This commit is contained in:
@ -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<String> 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<EcogStatusWithDate> 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");
|
||||
}
|
||||
}
|
@ -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<String> 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<EcogStatusWithDate> 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user