mirror of
https://github.com/pcvolkmer/onkostar-plugin-dnpm.git
synced 2025-07-04 18:12:55 +00:00
Merge pull request #12 from CCC-MF/issue_11
Übernahme des MTB-Protokolls in DNPM-Therapieplan - Protokollauszug
This commit is contained in:
6
pom.xml
6
pom.xml
@ -47,6 +47,12 @@
|
||||
<version>${spring-version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-jpa</artifactId>
|
||||
<version>1.2.0.RELEASE</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
|
@ -3,6 +3,7 @@ package DNPM.analyzer;
|
||||
import DNPM.services.Studie;
|
||||
import DNPM.services.StudienService;
|
||||
import DNPM.services.TherapieplanServiceFactory;
|
||||
import DNPM.services.mtb.MtbService;
|
||||
import de.itc.onkostar.api.Disease;
|
||||
import de.itc.onkostar.api.Procedure;
|
||||
import de.itc.onkostar.api.analysis.AnalyseTriggerEvent;
|
||||
@ -27,12 +28,16 @@ public class TherapieplanAnalyzer implements IProcedureAnalyzer {
|
||||
|
||||
private final TherapieplanServiceFactory therapieplanServiceFactory;
|
||||
|
||||
private final MtbService mtbService;
|
||||
|
||||
public TherapieplanAnalyzer(
|
||||
final StudienService studienService,
|
||||
final TherapieplanServiceFactory therapieplanServiceFactory
|
||||
final TherapieplanServiceFactory therapieplanServiceFactory,
|
||||
final MtbService mtbService
|
||||
) {
|
||||
this.studienService = studienService;
|
||||
this.therapieplanServiceFactory = therapieplanServiceFactory;
|
||||
this.mtbService = mtbService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -110,6 +115,7 @@ public class TherapieplanAnalyzer implements IProcedureAnalyzer {
|
||||
* </pre>
|
||||
*
|
||||
* @param input Map mit Eingabewerten
|
||||
* @return Liste mit Studien
|
||||
*/
|
||||
public List<Studie> getStudien(Map<String, Object> input) {
|
||||
var query = input.get("q");
|
||||
@ -120,4 +126,38 @@ public class TherapieplanAnalyzer implements IProcedureAnalyzer {
|
||||
return studienService.findByQuery(query.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Übergibt den Text der referenzierten MTBs für den Protokollauszug
|
||||
*
|
||||
* <p>Wurde der Eingabewert <code>id</code> nicht übergeben, wird ein leerer String zurück gegeben.
|
||||
*
|
||||
* <p>Beispiel zur Nutzung in einem Formularscript
|
||||
* <pre>
|
||||
* executePluginMethod(
|
||||
* 'TherapieplanAnalyzer',
|
||||
* 'getProtokollauszug',
|
||||
* { id: 12345 },
|
||||
* (response) => console.log(response),
|
||||
* false
|
||||
* );
|
||||
* </pre>
|
||||
*
|
||||
* @param input Map mit Eingabewerten
|
||||
* @return Zeichenkette mit Protokollauszug
|
||||
*/
|
||||
public String getProtokollauszug(Map<String, Object> input) {
|
||||
var id = input.get("id");
|
||||
|
||||
if (null == id || 0 == Integer.parseInt(id.toString())) {
|
||||
return "";
|
||||
}
|
||||
|
||||
var procedureId = Integer.parseInt(id.toString());
|
||||
return mtbService.getProtocol(
|
||||
therapieplanServiceFactory
|
||||
.currentUsableInstance()
|
||||
.findReferencedMtbs(procedureId)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,10 +1,14 @@
|
||||
package DNPM.config;
|
||||
|
||||
import DNPM.database.SettingsRepository;
|
||||
import DNPM.services.*;
|
||||
import DNPM.services.mtb.DefaultMtbService;
|
||||
import DNPM.services.mtb.MtbService;
|
||||
import de.itc.onkostar.api.IOnkostarApi;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
@ -15,6 +19,7 @@ import javax.sql.DataSource;
|
||||
*/
|
||||
@Configuration
|
||||
@ComponentScan(basePackages = "DNPM.analyzer")
|
||||
@EnableJpaRepositories(basePackages = "DNPM.database")
|
||||
public class PluginConfiguration {
|
||||
|
||||
@Bean
|
||||
@ -28,8 +33,22 @@ public class PluginConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TherapieplanServiceFactory therapieplanServiceFactory(final IOnkostarApi onkostarApi, final FormService formService) {
|
||||
return new TherapieplanServiceFactory(onkostarApi, formService);
|
||||
public SettingsService settingsService(final SettingsRepository settingsRepository) {
|
||||
return new SettingsService(settingsRepository);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MtbService mtbService(final SettingsService settingsService) {
|
||||
return new DefaultMtbService(settingsService);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TherapieplanServiceFactory therapieplanServiceFactory(
|
||||
final IOnkostarApi onkostarApi,
|
||||
final SettingsService settingsService,
|
||||
final FormService formService
|
||||
) {
|
||||
return new TherapieplanServiceFactory(onkostarApi, settingsService, formService);
|
||||
}
|
||||
|
||||
}
|
||||
|
20
src/main/java/DNPM/database/ReadOnlyRepository.java
Normal file
20
src/main/java/DNPM/database/ReadOnlyRepository.java
Normal file
@ -0,0 +1,20 @@
|
||||
package DNPM.database;
|
||||
|
||||
import org.springframework.data.repository.NoRepositoryBean;
|
||||
import org.springframework.data.repository.Repository;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Basis-Repository for ReadOnly Spring-Data-JPA Repositories
|
||||
* <p>Entity-Klassen müssen in Package <code>de.itc.db.dnpm</code> liegen
|
||||
* @param <T> Typ des Entities
|
||||
* @param <ID> Typ der ID
|
||||
*/
|
||||
@NoRepositoryBean
|
||||
public interface ReadOnlyRepository<T, ID extends Serializable> extends Repository<T, ID> {
|
||||
|
||||
List<T> findAll();
|
||||
|
||||
}
|
14
src/main/java/DNPM/database/SettingsRepository.java
Normal file
14
src/main/java/DNPM/database/SettingsRepository.java
Normal file
@ -0,0 +1,14 @@
|
||||
package DNPM.database;
|
||||
|
||||
import de.itc.db.dnpm.Setting;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* Spring Data JPA Repository zum Lesen von Einstellungen
|
||||
*/
|
||||
@Repository("dnpmSettingRepository")
|
||||
public interface SettingsRepository extends ReadOnlyRepository<Setting, Long> {
|
||||
|
||||
Setting findByName(String name);
|
||||
|
||||
}
|
@ -6,6 +6,7 @@ import de.itc.onkostar.api.Procedure;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static DNPM.services.FormService.hasValue;
|
||||
@ -36,6 +37,40 @@ public class DefaultTherapieplanService implements TherapieplanService {
|
||||
this.updateMtbInSubforms(procedure);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finde verlinkte MTBs in Hauptformular und Unterformularen
|
||||
*
|
||||
* @param procedure Die Prozedur mit Hauptformular
|
||||
* @return Liste mit verlinkten MTBs
|
||||
*/
|
||||
@Override
|
||||
public List<Procedure> findReferencedMtbs(Procedure procedure) {
|
||||
if (!hasValue(procedure, "referstemtb")) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
var mtbProcedure = this.onkostarApi.getProcedure(procedure.getValue("referstemtb").getInt());
|
||||
if (null == mtbProcedure) {
|
||||
return List.of();
|
||||
}
|
||||
return List.of(mtbProcedure);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finde verlinkte MTBs in Hauptformular und Unterformularen
|
||||
*
|
||||
* @param procedureId ID der Prozedur mit Hauptformular
|
||||
* @return Liste mit verlinkten MTBs
|
||||
*/
|
||||
@Override
|
||||
public List<Procedure> findReferencedMtbs(int procedureId) {
|
||||
var procedure = this.onkostarApi.getProcedure(procedureId);
|
||||
if (null == procedure) {
|
||||
return List.of();
|
||||
}
|
||||
return findReferencedMtbs(procedure);
|
||||
}
|
||||
|
||||
private void updateMtbInSections(Procedure procedure) {
|
||||
if (!isYes(procedure, "humangenberatung") && !isYes(procedure, "reevaluation")) {
|
||||
return;
|
||||
|
@ -1,12 +1,75 @@
|
||||
package DNPM.services;
|
||||
|
||||
import de.itc.onkostar.api.IOnkostarApi;
|
||||
import de.itc.onkostar.api.Procedure;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static DNPM.services.FormService.hasValue;
|
||||
import static DNPM.services.FormService.isYes;
|
||||
|
||||
public class MultipleMtbTherapieplanService implements TherapieplanService {
|
||||
|
||||
private final IOnkostarApi onkostarApi;
|
||||
|
||||
private final FormService formService;
|
||||
|
||||
public MultipleMtbTherapieplanService(final IOnkostarApi onkostarApi, final FormService formService) {
|
||||
this.onkostarApi = onkostarApi;
|
||||
this.formService = formService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateRequiredMtbEntries(Procedure procedure) {
|
||||
// No action required
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Procedure> findReferencedMtbs(Procedure procedure) {
|
||||
var procedureIds = new ArrayList<Integer>();
|
||||
|
||||
var mtbReference = procedure.getValue("referstemtb").getInt();
|
||||
procedureIds.add(mtbReference);
|
||||
|
||||
if (isYes(procedure, "humangenberatung") && hasValue(procedure, "reftkhumangenber")) {
|
||||
procedureIds.add(procedure.getValue("reftkhumangenber").getInt());
|
||||
}
|
||||
|
||||
if (isYes(procedure, "reevaluation") && hasValue(procedure, "reftkreevaluation")) {
|
||||
procedureIds.add(procedure.getValue("reftkreevaluation").getInt());
|
||||
}
|
||||
|
||||
formService.getSubFormProcedureIds(procedure.getId()).stream()
|
||||
.map(onkostarApi::getProcedure)
|
||||
.filter(Objects::nonNull)
|
||||
.forEach(subform -> {
|
||||
if (subform.getFormName().equals("DNPM UF Einzelempfehlung")) {
|
||||
procedureIds.add(subform.getValue("mtb").getInt());
|
||||
}
|
||||
|
||||
if (subform.getFormName().equals("DNPM UF Rebiopsie")) {
|
||||
procedureIds.add(subform.getValue("reftumorkonferenz").getInt());
|
||||
}
|
||||
});
|
||||
|
||||
return procedureIds.stream()
|
||||
.distinct()
|
||||
.map(onkostarApi::getProcedure)
|
||||
.filter(Objects::nonNull)
|
||||
.sorted(Comparator.comparing(Procedure::getStartDate))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Procedure> findReferencedMtbs(int procedureId) {
|
||||
var procedure = this.onkostarApi.getProcedure(procedureId);
|
||||
if (null == procedure) {
|
||||
return List.of();
|
||||
}
|
||||
return findReferencedMtbs(procedure);
|
||||
}
|
||||
}
|
||||
|
47
src/main/java/DNPM/services/SettingsService.java
Normal file
47
src/main/java/DNPM/services/SettingsService.java
Normal file
@ -0,0 +1,47 @@
|
||||
package DNPM.services;
|
||||
|
||||
import DNPM.database.SettingsRepository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Implementiert den Dienst zur Ermittlung von Systemeinstellungen
|
||||
*/
|
||||
public class SettingsService {
|
||||
|
||||
private final SettingsRepository settingsRepository;
|
||||
|
||||
public SettingsService(final SettingsRepository settingsRepository) {
|
||||
this.settingsRepository = settingsRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Übergibt ein <code>Optional</code> für die Einstellung mit angegebenen Namen
|
||||
* @param name Name der Einstellung
|
||||
* @return Optional mit Wert der Einstellung oder ein leeres Optional, wenn Einstellung nicht gefunden
|
||||
*/
|
||||
public Optional<String> getSetting(String name) {
|
||||
var sid = settingsRepository.findByName(name);
|
||||
if (null == sid) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(sid.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Übergibt die SID als <code>Optional</code>
|
||||
* @return Optional mit Wert der SID
|
||||
*/
|
||||
public Optional<String> getSID() {
|
||||
return getSetting("SID");
|
||||
}
|
||||
|
||||
/**
|
||||
* Übergibt die Einstellung für <code>mehrere_mtb_in_mtbepisode</code>
|
||||
* @return Übergibt <code>true</code>, wenn <code>mehrere_mtb_in_mtbepisode</code> auf "Ja" gesetzt ist.
|
||||
*/
|
||||
public boolean multipleMtbsInMtbEpisode() {
|
||||
var setting = getSetting("mehrere_mtb_in_mtbepisode");
|
||||
return setting.isPresent() && setting.get().equals("true");
|
||||
}
|
||||
}
|
@ -2,6 +2,8 @@ package DNPM.services;
|
||||
|
||||
import de.itc.onkostar.api.Procedure;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface TherapieplanService {
|
||||
|
||||
/**
|
||||
@ -12,4 +14,20 @@ public interface TherapieplanService {
|
||||
*/
|
||||
void updateRequiredMtbEntries(Procedure procedure);
|
||||
|
||||
/**
|
||||
* Finde verlinkte MTBs in Hauptformular und Unterformularen
|
||||
*
|
||||
* @param procedure Die Prozedur mit Hauptformular
|
||||
* @return Liste mit verlinkten MTBs
|
||||
*/
|
||||
List<Procedure> findReferencedMtbs(Procedure procedure);
|
||||
|
||||
/**
|
||||
* Finde verlinkte MTBs in Hauptformular und Unterformularen
|
||||
*
|
||||
* @param procedureId ID der Prozedur mit Hauptformular
|
||||
* @return Liste mit verlinkten MTBs
|
||||
*/
|
||||
List<Procedure> findReferencedMtbs(int procedureId);
|
||||
|
||||
}
|
||||
|
@ -6,19 +6,23 @@ public class TherapieplanServiceFactory {
|
||||
|
||||
private final IOnkostarApi onkostarApi;
|
||||
|
||||
private final SettingsService settingsService;
|
||||
|
||||
private final FormService formService;
|
||||
|
||||
public TherapieplanServiceFactory(IOnkostarApi onkostarApi, FormService formService) {
|
||||
public TherapieplanServiceFactory(
|
||||
final IOnkostarApi onkostarApi,
|
||||
final SettingsService settingsService,
|
||||
final FormService formService
|
||||
) {
|
||||
this.onkostarApi = onkostarApi;
|
||||
this.settingsService = settingsService;
|
||||
this.formService = formService;
|
||||
}
|
||||
|
||||
public TherapieplanService currentUsableInstance() {
|
||||
if (
|
||||
null != onkostarApi.getGlobalSetting("mehrere_mtb_in_mtbepisode")
|
||||
&& onkostarApi.getGlobalSetting("mehrere_mtb_in_mtbepisode").equals("true")
|
||||
) {
|
||||
return new MultipleMtbTherapieplanService();
|
||||
if (settingsService.multipleMtbsInMtbEpisode()) {
|
||||
return new MultipleMtbTherapieplanService(onkostarApi, formService);
|
||||
}
|
||||
|
||||
return new DefaultTherapieplanService(onkostarApi, formService);
|
||||
|
39
src/main/java/DNPM/services/mtb/DefaultMtbService.java
Normal file
39
src/main/java/DNPM/services/mtb/DefaultMtbService.java
Normal file
@ -0,0 +1,39 @@
|
||||
package DNPM.services.mtb;
|
||||
|
||||
import DNPM.services.SettingsService;
|
||||
import de.itc.onkostar.api.Procedure;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DefaultMtbService implements MtbService {
|
||||
|
||||
private final SettingsService settingsService;
|
||||
|
||||
public DefaultMtbService(final SettingsService settingsService) {
|
||||
this.settingsService = settingsService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProtocol(List<Procedure> procedures) {
|
||||
ProcedureToProtocolMapper mapper = null;
|
||||
var sid = settingsService.getSID();
|
||||
|
||||
if (sid.isPresent()) {
|
||||
switch (sid.get()) {
|
||||
case "20119":
|
||||
mapper = new OsTumorkonferenzVarianteUkwToProtocolMapper();
|
||||
default:
|
||||
if (!settingsService.multipleMtbsInMtbEpisode()) {
|
||||
mapper = new OsTumorkonferenzToProtocolMapper();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (null == mapper) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return mapper.apply(procedures).orElse("");
|
||||
}
|
||||
|
||||
}
|
9
src/main/java/DNPM/services/mtb/MtbService.java
Normal file
9
src/main/java/DNPM/services/mtb/MtbService.java
Normal file
@ -0,0 +1,9 @@
|
||||
package DNPM.services.mtb;
|
||||
|
||||
import de.itc.onkostar.api.Procedure;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface MtbService {
|
||||
String getProtocol(List<Procedure> procedures);
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package DNPM.services.mtb;
|
||||
|
||||
import de.itc.onkostar.api.Procedure;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class OsTumorkonferenzToProtocolMapper implements ProcedureToProtocolMapper {
|
||||
@Override
|
||||
public Optional<String> apply(List<Procedure> procedures) {
|
||||
assert(procedures.size() == 1);
|
||||
|
||||
var procedure = procedures.get(0);
|
||||
|
||||
assert(procedure.getFormName().equals("OS.Tumorkonferenz"));
|
||||
|
||||
var fragestellung = procedure.getValue("Fragestellung");
|
||||
var empfehlung = procedure.getValue("Empfehlung");
|
||||
|
||||
if (
|
||||
null != fragestellung && !fragestellung.getString().isBlank()
|
||||
&& null != empfehlung && !empfehlung.getString().isBlank()
|
||||
) {
|
||||
return Optional.of(String.format("Fragestellung:\n%s\n\nEmpfehlung:\n%s", fragestellung.getString(), empfehlung.getString()));
|
||||
} else if (null != fragestellung && !fragestellung.getString().isBlank()) {
|
||||
return Optional.of(fragestellung.getString());
|
||||
} else if (null != empfehlung && !empfehlung.getString().isBlank()) {
|
||||
return Optional.of(empfehlung.getString());
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package DNPM.services.mtb;
|
||||
|
||||
import de.itc.onkostar.api.Procedure;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class OsTumorkonferenzVarianteUkwToProtocolMapper implements ProcedureToProtocolMapper {
|
||||
@Override
|
||||
public Optional<String> apply(List<Procedure> procedures) {
|
||||
procedures.forEach(procedure -> {
|
||||
assert (procedure.getFormName().equals("OS.Tumorkonferenz.VarianteUKW"));
|
||||
});
|
||||
|
||||
procedures.sort(Comparator.comparing(Procedure::getStartDate));
|
||||
|
||||
var result = procedures.stream().map(procedure -> {
|
||||
var fragestellung = procedure.getValue("Fragestellung");
|
||||
var empfehlung = procedure.getValue("Empfehlung");
|
||||
|
||||
if (
|
||||
null != fragestellung && !fragestellung.getString().isBlank()
|
||||
&& null != empfehlung && !empfehlung.getString().isBlank()
|
||||
) {
|
||||
return String.format("Fragestellung:\n%s\n\nEmpfehlung:\n%s", fragestellung.getString().trim(), empfehlung.getString().trim());
|
||||
} else if (null != fragestellung && !fragestellung.getString().isBlank()) {
|
||||
return fragestellung.getString().trim();
|
||||
} else if (null != empfehlung && !empfehlung.getString().isBlank()) {
|
||||
return empfehlung.getString().trim();
|
||||
}
|
||||
return "";
|
||||
}).collect(Collectors.joining("\n\n"));
|
||||
|
||||
if (!result.isBlank()) {
|
||||
return Optional.of(result);
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package DNPM.services.mtb;
|
||||
|
||||
import de.itc.onkostar.api.Procedure;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ProcedureToProtocolMapper extends Function<List<Procedure>, Optional<String>> {}
|
43
src/main/java/de/itc/db/dnpm/Setting.java
Normal file
43
src/main/java/de/itc/db/dnpm/Setting.java
Normal file
@ -0,0 +1,43 @@
|
||||
package de.itc.db.dnpm;
|
||||
|
||||
import org.hibernate.annotations.Immutable;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Immutable
|
||||
@Table(name = "einstellung")
|
||||
public class Setting {
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
@Column(name = "wert")
|
||||
private String value;
|
||||
|
||||
protected Setting() {
|
||||
// No content
|
||||
}
|
||||
|
||||
public Setting(Long id, String name, String value) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
package DNPM.analyzer;
|
||||
|
||||
import DNPM.services.MultipleMtbTherapieplanService;
|
||||
import DNPM.services.StudienService;
|
||||
import DNPM.services.TherapieplanServiceFactory;
|
||||
import DNPM.services.*;
|
||||
import DNPM.services.mtb.MtbService;
|
||||
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;
|
||||
@ -13,6 +13,7 @@ import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@ -24,22 +25,32 @@ public class TherapieplanAnalyzerTest {
|
||||
@Mock
|
||||
private IOnkostarApi onkostarApi;
|
||||
|
||||
@Mock
|
||||
private FormService formService;
|
||||
|
||||
@Mock
|
||||
private StudienService studienService;
|
||||
|
||||
@Mock
|
||||
private TherapieplanServiceFactory therapieplanServiceFactory;
|
||||
|
||||
@Mock
|
||||
private TherapieplanService therapieplanService;
|
||||
|
||||
@Mock
|
||||
private MtbService mtbService;
|
||||
|
||||
private TherapieplanAnalyzer therapieplanAnalyzer;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
this.therapieplanAnalyzer = new TherapieplanAnalyzer(studienService, therapieplanServiceFactory);
|
||||
this.therapieplanAnalyzer = new TherapieplanAnalyzer(studienService, therapieplanServiceFactory, mtbService);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRunServiceMethodsOnAnalyzeCalled() {
|
||||
when(this.therapieplanServiceFactory.currentUsableInstance()).thenReturn(new MultipleMtbTherapieplanService());
|
||||
when(this.therapieplanServiceFactory.currentUsableInstance())
|
||||
.thenReturn(new MultipleMtbTherapieplanService(onkostarApi, formService));
|
||||
|
||||
this.therapieplanAnalyzer.analyze(new Procedure(onkostarApi), null);
|
||||
|
||||
@ -72,4 +83,23 @@ public class TherapieplanAnalyzerTest {
|
||||
assertThat(captor.getValue()).isEqualTo("NCT-123");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRequestProtokollauszug() {
|
||||
doAnswer(invocationOnMock -> {
|
||||
var procedure = new Procedure(onkostarApi);
|
||||
procedure.setValue("referstemtb", new Item("referstemtb", 2345));
|
||||
return List.of(procedure);
|
||||
}).when(this.therapieplanService).findReferencedMtbs(anyInt());
|
||||
|
||||
when(this.therapieplanServiceFactory.currentUsableInstance())
|
||||
.thenReturn(therapieplanService);
|
||||
|
||||
var input = Map.of("id", (Object) 1234);
|
||||
this.therapieplanAnalyzer.getProtokollauszug(input);
|
||||
|
||||
var captor = ArgumentCaptor.forClass(List.class);
|
||||
verify(mtbService, times(1)).getProtocol(captor.capture());
|
||||
assertThat(captor.getValue()).hasSize(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package DNPM.config;
|
||||
|
||||
import DNPM.services.FormService;
|
||||
import DNPM.services.SettingsService;
|
||||
import DNPM.services.TherapieplanServiceFactory;
|
||||
import de.itc.onkostar.api.IOnkostarApi;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@ -17,6 +18,9 @@ public class PluginConfigurationTest {
|
||||
@Mock
|
||||
private IOnkostarApi onkostarApi;
|
||||
|
||||
@Mock
|
||||
private SettingsService settingsService;
|
||||
|
||||
@Mock
|
||||
private FormService formService;
|
||||
|
||||
@ -29,7 +33,7 @@ public class PluginConfigurationTest {
|
||||
|
||||
@Test
|
||||
void testShouldReturnTherapieplanServiceFactory() {
|
||||
var actual = this.configuration.therapieplanServiceFactory(onkostarApi, formService);
|
||||
var actual = this.configuration.therapieplanServiceFactory(onkostarApi, settingsService, formService);
|
||||
assertThat(actual).isInstanceOf(TherapieplanServiceFactory.class);
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,6 @@
|
||||
package DNPM.config;
|
||||
|
||||
import DNPM.services.DefaultTherapieplanService;
|
||||
import DNPM.services.FormService;
|
||||
import DNPM.services.MultipleMtbTherapieplanService;
|
||||
import DNPM.services.TherapieplanServiceFactory;
|
||||
import DNPM.services.*;
|
||||
import de.itc.onkostar.api.IOnkostarApi;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@ -12,8 +9,6 @@ import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@ -25,31 +20,19 @@ public class TherapieplanServiceFactoryTest {
|
||||
@Mock
|
||||
private FormService formService;
|
||||
|
||||
@Mock
|
||||
private SettingsService settingsService;
|
||||
|
||||
private TherapieplanServiceFactory therapieplanServiceFactory;
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
this.therapieplanServiceFactory = new TherapieplanServiceFactory(onkostarApi, formService);
|
||||
this.therapieplanServiceFactory = new TherapieplanServiceFactory(onkostarApi, settingsService, formService);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testShouldReturnDefaultTherapieplanServiceIfSettingIsFalse() {
|
||||
doAnswer(invocationOnMock -> {
|
||||
var settingName = invocationOnMock.getArgument(0, String.class);
|
||||
if (settingName.equals("mehrere_mtb_in_mtbepisode")) {
|
||||
return "false";
|
||||
}
|
||||
return null;
|
||||
}).when(onkostarApi).getGlobalSetting(anyString());
|
||||
|
||||
var actual = this.therapieplanServiceFactory.currentUsableInstance();
|
||||
|
||||
assertThat(actual).isInstanceOf(DefaultTherapieplanService.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testShouldReturnDefaultTherapieplanServiceIfNoSetting() {
|
||||
when(onkostarApi.getGlobalSetting(anyString())).thenReturn(null);
|
||||
when(settingsService.multipleMtbsInMtbEpisode()).thenReturn(false);
|
||||
|
||||
var actual = this.therapieplanServiceFactory.currentUsableInstance();
|
||||
|
||||
@ -58,13 +41,7 @@ public class TherapieplanServiceFactoryTest {
|
||||
|
||||
@Test
|
||||
void testShouldReturnMultipleMtbTherapieplanServiceIfSettingIsTrue() {
|
||||
doAnswer(invocationOnMock -> {
|
||||
var settingName = invocationOnMock.getArgument(0, String.class);
|
||||
if (settingName.equals("mehrere_mtb_in_mtbepisode")) {
|
||||
return "true";
|
||||
}
|
||||
return null;
|
||||
}).when(onkostarApi).getGlobalSetting(anyString());
|
||||
when(settingsService.multipleMtbsInMtbEpisode()).thenReturn(true);
|
||||
|
||||
var actual = this.therapieplanServiceFactory.currentUsableInstance();
|
||||
|
||||
|
58
src/test/java/DNPM/services/SettingsServiceTest.java
Normal file
58
src/test/java/DNPM/services/SettingsServiceTest.java
Normal file
@ -0,0 +1,58 @@
|
||||
package DNPM.services;
|
||||
|
||||
import DNPM.database.SettingsRepository;
|
||||
import de.itc.db.dnpm.Setting;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.anyString;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class SettingsServiceTest {
|
||||
|
||||
@Mock
|
||||
private SettingsRepository settingsRepository;
|
||||
|
||||
private SettingsService service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
this.service = new SettingsService(settingsRepository);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnSID() {
|
||||
doAnswer(invocationOnMock -> {
|
||||
var name = invocationOnMock.getArgument(0, String.class);
|
||||
if (null != name && name.equals("SID")) {
|
||||
return new Setting(1L, "SID", "12345");
|
||||
}
|
||||
return null;
|
||||
}).when(settingsRepository).findByName(anyString());
|
||||
|
||||
var actual = service.getSID();
|
||||
assertThat(actual).isPresent();
|
||||
assertThat(actual.get()).isEqualTo("12345");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnSIDByName() {
|
||||
doAnswer(invocationOnMock -> {
|
||||
var name = invocationOnMock.getArgument(0, String.class);
|
||||
if (null != name && name.equals("SID")) {
|
||||
return new Setting(1L, "SID", "12345");
|
||||
}
|
||||
return null;
|
||||
}).when(settingsRepository).findByName(anyString());
|
||||
|
||||
var actual = service.getSetting("SID");
|
||||
assertThat(actual).isPresent();
|
||||
assertThat(actual.get()).isEqualTo("12345");
|
||||
}
|
||||
|
||||
}
|
112
src/test/java/DNPM/services/mtb/DefaultMtbServiceTest.java
Normal file
112
src/test/java/DNPM/services/mtb/DefaultMtbServiceTest.java
Normal file
@ -0,0 +1,112 @@
|
||||
package DNPM.services.mtb;
|
||||
|
||||
import DNPM.services.SettingsService;
|
||||
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.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class DefaultMtbServiceTest {
|
||||
|
||||
private IOnkostarApi onkostarApi;
|
||||
|
||||
private SettingsService settingsService;
|
||||
|
||||
private DefaultMtbService service;
|
||||
|
||||
@BeforeEach
|
||||
void setup(
|
||||
@Mock IOnkostarApi onkostarApi,
|
||||
@Mock SettingsService settingsService
|
||||
) {
|
||||
this.onkostarApi = onkostarApi;
|
||||
this.settingsService = settingsService;
|
||||
this.service = new DefaultMtbService(settingsService);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testShouldReturnMtbProtocolForDefaultImplementation() {
|
||||
when(settingsService.getSID()).thenReturn(Optional.of("12345"));
|
||||
when(settingsService.multipleMtbsInMtbEpisode()).thenReturn(false);
|
||||
|
||||
var procedure1 = new Procedure(onkostarApi);
|
||||
procedure1.setFormName("OS.Tumorkonferenz");
|
||||
procedure1.setStartDate(Date.from(Instant.parse("2023-01-01T00:00:00Z")));
|
||||
procedure1.setValue("Fragestellung", new Item("Fragestellung", "Test ok?"));
|
||||
procedure1.setValue("Empfehlung", new Item("Empfehlung", "Rerun Test if not ok!"));
|
||||
|
||||
var procedures = List.of(
|
||||
procedure1
|
||||
);
|
||||
|
||||
var actual = service.getProtocol(procedures);
|
||||
|
||||
assertThat(actual).isEqualTo("Fragestellung:\nTest ok?\n\nEmpfehlung:\nRerun Test if not ok!");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testShouldReturnEmptyMtbProtocolForMultipleMtb() {
|
||||
when(settingsService.getSID()).thenReturn(Optional.of("12345"));
|
||||
when(settingsService.multipleMtbsInMtbEpisode()).thenReturn(true);
|
||||
|
||||
var procedure1 = new Procedure(onkostarApi);
|
||||
procedure1.setFormName("OS.Tumorkonferenz");
|
||||
procedure1.setStartDate(Date.from(Instant.parse("2023-01-01T00:00:00Z")));
|
||||
procedure1.setValue("Fragestellung", new Item("Fragestellung", "Test ok?"));
|
||||
procedure1.setValue("Empfehlung", new Item("Empfehlung", "Rerun Test if not ok!"));
|
||||
|
||||
var procedures = List.of(
|
||||
procedure1
|
||||
);
|
||||
|
||||
var actual = service.getProtocol(procedures);
|
||||
|
||||
assertThat(actual).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testShouldReturnMtbProtocolForSID20119() {
|
||||
when(settingsService.getSID()).thenReturn(Optional.of("20119"));
|
||||
when(settingsService.multipleMtbsInMtbEpisode()).thenReturn(true);
|
||||
|
||||
var procedure1 = new Procedure(onkostarApi);
|
||||
procedure1.setFormName("OS.Tumorkonferenz.VarianteUKW");
|
||||
procedure1.setStartDate(Date.from(Instant.parse("2023-02-01T00:00:00Z")));
|
||||
procedure1.setValue("Fragestellung", new Item("Fragestellung", "Test immer noch ok?"));
|
||||
procedure1.setValue("Empfehlung", new Item("Empfehlung", "Do not rerun Test if ok!"));
|
||||
|
||||
var procedure2 = new Procedure(onkostarApi);
|
||||
procedure2.setFormName("OS.Tumorkonferenz.VarianteUKW");
|
||||
procedure2.setStartDate(Date.from(Instant.parse("2023-01-01T00:00:00Z")));
|
||||
procedure2.setValue("Fragestellung", new Item("Fragestellung", "Test ok?"));
|
||||
procedure2.setValue("Empfehlung", new Item("Empfehlung", "Rerun Test if not ok!"));
|
||||
|
||||
|
||||
var procedures = Arrays.asList(
|
||||
procedure1,
|
||||
procedure2
|
||||
);
|
||||
|
||||
var actual = service.getProtocol(procedures);
|
||||
|
||||
assertThat(actual).isEqualTo(
|
||||
"Fragestellung:\nTest ok?\n\nEmpfehlung:\nRerun Test if not ok!\n\n" +
|
||||
"Fragestellung:\nTest immer noch ok?\n\nEmpfehlung:\nDo not rerun Test if ok!"
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user