1
0
mirror of https://github.com/pcvolkmer/onkostar-plugin-dnpm.git synced 2025-07-02 01:02:55 +00:00

Aufteilung der Methode getSystemischeTherapienFromDiagnose() und Prüfung auf DiagnoseId

This commit is contained in:
2023-03-22 10:18:32 +01:00
parent 0d536f7ed7
commit 3f3a23ccd2
2 changed files with 268 additions and 267 deletions

View File

@ -15,297 +15,293 @@ import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.transform.Transformers;
import org.hibernate.type.StandardBasicTypes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
public class DNPMHelper implements IProcedureAnalyzer{
public class DNPMHelper implements IProcedureAnalyzer {
private final IOnkostarApi onkostarApi;
private static final Logger logger = LoggerFactory.getLogger(DNPMHelper.class);
public DNPMHelper(final IOnkostarApi onkostarApi) {
this.onkostarApi = onkostarApi;
}
private final IOnkostarApi onkostarApi;
@Override
public OnkostarPluginType getType() {
// Typ des Plugins
// Für das Interface IProcedureAnalyzer gültig sind ANALYZER und BACKEND_SERVICE
return OnkostarPluginType.BACKEND_SERVICE;
}
public DNPMHelper(final IOnkostarApi onkostarApi) {
this.onkostarApi = onkostarApi;
}
@Override
public String getVersion() {
return "1";
}
@Override
public OnkostarPluginType getType() {
// Typ des Plugins
// Für das Interface IProcedureAnalyzer gültig sind ANALYZER und BACKEND_SERVICE
return OnkostarPluginType.BACKEND_SERVICE;
}
@Override
public String getName() {
return "UMR DNPM";
}
@Override
public String getVersion() {
return "1";
}
@Override
public String getDescription() {
return "Methoden für DNPM-Formulare";
}
@Override
public String getName() {
return "UMR DNPM";
}
@Override
public boolean isRelevantForDeletedProcedure() {
return false;
}
@Override
public String getDescription() {
return "Methoden für DNPM-Formulare";
}
@Override
public boolean isSynchronous() {
return true;
}
@Override
public boolean isRelevantForDeletedProcedure() {
return false;
}
@Override
public AnalyzerRequirement getRequirement() {
return AnalyzerRequirement.PROCEDURE;
}
@Override
public boolean isRelevantForAnalyzer(Procedure entry, Disease currentDisease) {
// Plugin enthält nur Methoden für Formulare und soll nicht ausgeführt werden
return false;
}
@Override
public boolean isSynchronous() {
return true;
}
@Override
public void analyze(Procedure entry, Disease currentDisease) {
// wird nicht benötigt, da dass Plugin nicht ausgeführt wird
}
@SuppressWarnings("unchecked")
public Object getVerweise(final Map<String, Object> input) {
int ProcedureId = (int) input.get("ProcedureId");
int PatientId = (int) input.get("PatientId");
int value = 0;
List<Map<String, String>> VerbundeneFormulare = new ArrayList<Map<String, String>>();
try {
SessionFactory sessionFactory = onkostarApi.getSessionFactory();
Session session = sessionFactory.getCurrentSession();
try {
String sql = "SELECT prozedur.id AS procedure_id, prozedur.data_form_id, data_catalogue.name AS data_catalogue, data_catalogue_entry.name AS data_catalogue_entry, data_form.description AS formname, prozedur.beginndatum AS datum " +
"FROM prozedur " +
"LEFT JOIN data_form_data_catalogue ON data_form_data_catalogue.data_form_id = prozedur.data_form_id " +
"LEFT JOIN data_catalogue_entry ON data_catalogue_entry.data_catalogue_id = data_form_data_catalogue.data_catalogue_id " +
"LEFT JOIN data_catalogue ON data_catalogue.id = data_catalogue_entry.data_catalogue_id " +
"LEFT JOIN data_form ON data_form.id = prozedur.data_form_id " +
"WHERE patient_id = " + PatientId + " " +
"AND geloescht = 0 " +
"AND data_catalogue_entry.type = 'formReference' " +
"GROUP BY prozedur.id, prozedur.data_form_id, data_catalogue.name, data_catalogue_entry.name";
@Override
public AnalyzerRequirement getRequirement() {
return AnalyzerRequirement.PROCEDURE;
}
SQLQuery query = session.createSQLQuery(sql)
.addScalar("procedure_id", StandardBasicTypes.INTEGER)
.addScalar("data_form_id", StandardBasicTypes.INTEGER)
.addScalar("data_catalogue", StandardBasicTypes.STRING)
.addScalar("data_catalogue_entry", StandardBasicTypes.STRING)
.addScalar("formname", StandardBasicTypes.STRING)
.addScalar("datum", StandardBasicTypes.DATE);
@Override
public boolean isRelevantForAnalyzer(Procedure entry, Disease currentDisease) {
// Plugin enthält nur Methoden für Formulare und soll nicht ausgeführt werden
return false;
}
@Override
public void analyze(Procedure entry, Disease currentDisease) {
// wird nicht benötigt, da dass Plugin nicht ausgeführt wird
}
@SuppressWarnings("unchecked")
public Object getVerweise(final Map<String, Object> input) {
int ProcedureId = (int) input.get("ProcedureId");
int PatientId = (int) input.get("PatientId");
int value = 0;
List<Map<String, String>> VerbundeneFormulare = new ArrayList<Map<String, String>>();
query.setResultTransformer(Transformers.aliasToBean(VerweisVon.class));
List<VerweisVon> result = query.list();
try {
for (VerweisVon var : result) {
sql = var.getSQL();
query = session.createSQLQuery(sql)
.addScalar("value", StandardBasicTypes.INTEGER);
if (query.uniqueResult() != null) {
value = (Integer)query.uniqueResult();
SessionFactory sessionFactory = onkostarApi.getSessionFactory();
Session session = sessionFactory.getCurrentSession();
try {
String sql = "SELECT prozedur.id AS procedure_id, prozedur.data_form_id, data_catalogue.name AS data_catalogue, data_catalogue_entry.name AS data_catalogue_entry, data_form.description AS formname, prozedur.beginndatum AS datum " +
"FROM prozedur " +
"LEFT JOIN data_form_data_catalogue ON data_form_data_catalogue.data_form_id = prozedur.data_form_id " +
"LEFT JOIN data_catalogue_entry ON data_catalogue_entry.data_catalogue_id = data_form_data_catalogue.data_catalogue_id " +
"LEFT JOIN data_catalogue ON data_catalogue.id = data_catalogue_entry.data_catalogue_id " +
"LEFT JOIN data_form ON data_form.id = prozedur.data_form_id " +
"WHERE patient_id = " + PatientId + " " +
"AND geloescht = 0 " +
"AND data_catalogue_entry.type = 'formReference' " +
"GROUP BY prozedur.id, prozedur.data_form_id, data_catalogue.name, data_catalogue_entry.name";
SQLQuery query = session.createSQLQuery(sql)
.addScalar("procedure_id", StandardBasicTypes.INTEGER)
.addScalar("data_form_id", StandardBasicTypes.INTEGER)
.addScalar("data_catalogue", StandardBasicTypes.STRING)
.addScalar("data_catalogue_entry", StandardBasicTypes.STRING)
.addScalar("formname", StandardBasicTypes.STRING)
.addScalar("datum", StandardBasicTypes.DATE);
query.setResultTransformer(Transformers.aliasToBean(VerweisVon.class));
List<VerweisVon> result = query.list();
try {
for (VerweisVon var : result) {
sql = var.getSQL();
query = session.createSQLQuery(sql)
.addScalar("value", StandardBasicTypes.INTEGER);
if (query.uniqueResult() != null) {
value = (Integer) query.uniqueResult();
}
if (value == ProcedureId) {
VerbundeneFormulare.add(Map.of("formular", var.getVerbundenesFormular()));
value = 0;
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (Exception e) {
return null;
}
if (value == ProcedureId) {
VerbundeneFormulare.add(Map.of("formular", var.getVerbundenesFormular()));
value = 0;
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
} catch (Exception e) {
return null;
}
} catch (Exception e) {
return null;
return VerbundeneFormulare;
}
return VerbundeneFormulare;
}
public Object getSystemischeTherapienFromDiagnose(final Map<String, Object> input) {
int DiagnoseId = (int) input.get("DiagnoseId");
public List<Map<String, String>> getSystemischeTherapienFromDiagnose(final Map<String, Object> input) {
var diagnoseId = input.get("DiagnoseId");
String jsonStr = "";
List<Object> Rueckgabewerte = new ArrayList<Object>();
List<Procedure> Prozeduren = onkostarApi.getProceduresForDiseaseByForm(DiagnoseId, "OS.Systemische Therapie");
// für jede Prozedur
for (Procedure Prozedur : Prozeduren) {
String Beginn = new String();
String Ende = new String();
String Wirkstoffe = new String();
String Beendigung = new String();
String Ergebnis = new String();
if (null == diagnoseId || Integer.parseInt(diagnoseId.toString()) == 0) {
logger.error("Kein Parameter 'DiagnoseId' angegeben, gebe 'null' zurück");
return null;
}
// SubstanzenCodesListe enthält die Liste der SubstanzenCodes
List<Map<String, String>> SubstanzenCodesListe = new ArrayList<Map<String, String>>();
// alle Werte der Prozedur auslesen
Map<String, Item> alleWerte = Prozedur.getAllValues();
// Prozedurwerte enthält nur die interessanten Werte
Map<String, Object> Prozedurwerte = new HashMap<>();
// alle Werte durchgehen und die interessanten übernehmen
for (Map.Entry<String, Item> WerteListe : alleWerte.entrySet()) {
// Datum des Hauptformulars merken
if (WerteListe.getKey().equals("Beendigung")) {
Beendigung = WerteListe.getValue().getValue();
List<Map<String, String>> result = new ArrayList<>();
for (Procedure Prozedur : onkostarApi.getProceduresForDiseaseByForm(Integer.parseInt(diagnoseId.toString()), "OS.Systemische Therapie")) {
result.add(getProzedurwerte(Prozedur));
}
if (WerteListe.getKey().equals("Ergebnis")) {
Ergebnis = WerteListe.getValue().getValue();
}
if (WerteListe.getKey().equals("Beginn")) {
Beginn = WerteListe.getValue().getString();// + "," + WerteListe.getValue().getDateAccuracy();
}
if (WerteListe.getKey().equals("Ende")) {
Ende = WerteListe.getValue().getString();// + "," + WerteListe.getValue().getDateAccuracy();
}
// im Subformular (SubstanzenList) Substanzen auslesen
if (WerteListe.getKey().equals("SubstanzenList")) {
int Index = -1;
// SubstanzenCodesListe enthält die Liste der SubstanzenCodes eines Subformulars
ArrayList<Map<String, Map<String, String>>> Subformular = new ArrayList<>();
Subformular = WerteListe.getValue().getValue();
// Werte aus Subformular verarbeiten
for (Map<String, Map<String, String>> SubformularWerte: Subformular) {
return result;
}
// SubstanzenCodes enthält den Code und den Namen einer Substanz
Map<String, String> SubstanzenCodes = new HashMap<String, String>();
// Index des Codes (Substanz)
Index = Arrays.asList((SubformularWerte.keySet().toArray())).indexOf("Substanz");
if (AtcCode.isAtcCode(SubformularWerte.values().toArray()[Index].toString())) {
SubstanzenCodes.put("system", "ATC");
} else {
SubstanzenCodes.put("system", "other");
private static Map<String, String> getProzedurwerte(Procedure Prozedur) {
List<String> wirkstoffListe = new ArrayList<>();
// SubstanzenCodesListe enthält die Liste der SubstanzenCodes
List<Map<String, String>> substanzenCodesListe = new ArrayList<>();
// alle Werte der Prozedur auslesen
Map<String, Item> alleWerte = Prozedur.getAllValues();
// Prozedurwerte enthält nur die interessanten Werte
Map<String, String> prozedurwerte = new HashMap<>();
// alle Werte durchgehen und die interessanten übernehmen
if (alleWerte.containsKey("Beendigung")) {
prozedurwerte.put("Beendigung", alleWerte.get("Beendigung").getValue());
}
if (alleWerte.containsKey("Ergebnis")) {
prozedurwerte.put("Ergebnis", alleWerte.get("Ergebnis").getValue());
}
if (alleWerte.containsKey("Beginn")) {
prozedurwerte.put("Beginn", alleWerte.get("Beginn").getString());
}
if (alleWerte.containsKey("Ende")) {
prozedurwerte.put("Ende", alleWerte.get("Ende").getString());
}
if (alleWerte.containsKey("SubstanzenList")) {
List<Map<String, String>> substanzList = alleWerte.get("SubstanzenList").getValue();
for (var substanz : substanzList) {
var substanzCodes = getSubstanzCode(substanz);
substanzenCodesListe.add(substanzCodes);
wirkstoffListe.add(substanzCodes.get("substance"));
}
SubstanzenCodes.put("code", (String) SubformularWerte.values().toArray()[Index]);
// Index der Substanz (Substanz_shortDescription)
Index = Arrays.asList((SubformularWerte.keySet().toArray())).indexOf("Substanz_shortDescription");
SubstanzenCodes.put("substance", (String) SubformularWerte.values().toArray()[Index]);
SubstanzenCodesListe.add(SubstanzenCodes);
Wirkstoffe = Wirkstoffe + (String) SubformularWerte.values().toArray()[Index] + ", ";
}
}
}
ObjectMapper Obj = new ObjectMapper();
try {
jsonStr = Obj.writeValueAsString(SubstanzenCodesListe);
} catch (JsonProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Prozedurwerte.put("Beginn", Beginn);
Prozedurwerte.put("Ende", Ende);
Prozedurwerte.put("Beendigung", Beendigung);
Prozedurwerte.put("Ergebnis", Ergebnis);
Prozedurwerte.put("Wirkstoffe", Wirkstoffe.substring(0, Wirkstoffe.length()-2));
Prozedurwerte.put("WirkstoffCodes", jsonStr);
Rueckgabewerte.add(Prozedurwerte);
}
return Rueckgabewerte;
}
public Object getProzedurenFromDiagnose(final Map<String, Object> input) {
String dataForm = (String) input.get("dataForm");
int DiagnoseId = (int) input.get("DiagnoseId");
int PatientId = (int) input.get("PatientId");
// Prozedur, Feldname, Wert
List<Object> Formulare = new ArrayList<Object>();
String jsonStr = "";
List<Procedure> Prozeduren = onkostarApi.getProceduresByPatientId(PatientId);
for (Procedure Prozedur: Prozeduren ) {
// Formular gehört zur aktuellen Diagnose und hat den angegebenen Namen
if (Prozedur.getDiseaseIds().contains(DiagnoseId) && Prozedur.getFormName().contains(dataForm)) {
// alle Werte auslesen
Map<String, Item> Werte = Prozedur.getAllValues();
Map<String, Object> Values = new HashMap<>();
for (Map.Entry<String, Item> WerteListe: Werte.entrySet()) {
Values.put(WerteListe.getKey(), WerteListe.getValue());
prozedurwerte.put("Wirkstoffe", String.join(", ", wirkstoffListe));
try {
ObjectMapper mapper = new ObjectMapper();
prozedurwerte.put("WirkstoffCodes", mapper.writeValueAsString(substanzenCodesListe));
} catch (JsonProcessingException e) {
logger.error("Kann 'WirkstoffCodes' nicht in JSON-String mappen", e);
}
return prozedurwerte;
}
private static Map<String, String> getSubstanzCode(Map<String, String> substanz) {
Map<String, String> substanzCode = new HashMap<>();
if (substanz.containsKey("Substanz")) {
if (AtcCode.isAtcCode(substanz.get("Substanz"))) {
substanzCode.put("system", "ATC");
} else {
substanzCode.put("system", "other");
}
substanzCode.put("code", substanz.get("Substanz"));
}
if (substanz.containsKey("Substanz_shortDescription")) {
substanzCode.put("substance", substanz.get("Substanz_shortDescription"));
}
return substanzCode;
}
public Object getProzedurenFromDiagnose(final Map<String, Object> input) {
String dataForm = (String) input.get("dataForm");
int DiagnoseId = (int) input.get("DiagnoseId");
int PatientId = (int) input.get("PatientId");
// Prozedur, Feldname, Wert
List<Object> Formulare = new ArrayList<Object>();
String jsonStr = "";
List<Procedure> Prozeduren = onkostarApi.getProceduresByPatientId(PatientId);
for (Procedure Prozedur : Prozeduren) {
// Formular gehört zur aktuellen Diagnose und hat den angegebenen Namen
if (Prozedur.getDiseaseIds().contains(DiagnoseId) && Prozedur.getFormName().contains(dataForm)) {
// alle Werte auslesen
Map<String, Item> Werte = Prozedur.getAllValues();
Map<String, Object> Values = new HashMap<>();
for (Map.Entry<String, Item> WerteListe : Werte.entrySet()) {
Values.put(WerteListe.getKey(), WerteListe.getValue());
// System.out.println(WerteListe.getKey() + ": " + WerteListe.getValue());
}
Map<String, Object> Formular = new HashMap<>();
Formular.put("Formular", Prozedur.getFormName());
Formular.put("Felder", Values);
Formulare.add(Formular);
}
}
Map<String, Object> Formular = new HashMap<>();
Formular.put("Formular", Prozedur.getFormName());
Formular.put("Felder", Values);
Formulare.add(Formular);
}
ObjectMapper Obj = new ObjectMapper();
try {
jsonStr = Obj.writeValueAsString(Formulare);
} catch (JsonProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return jsonStr;
}
ObjectMapper Obj = new ObjectMapper();
try {
jsonStr = Obj.writeValueAsString(Formulare);
} catch (JsonProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
public Object getEmpfehlung(final Map<String, Object> input) {
// Auslesen der Parameter aus 'input'
int ProcedureID = (int) input.get("ProcedureID");
String sql;
try {
SessionFactory sessionFactory = onkostarApi.getSessionFactory();
Session session = sessionFactory.getCurrentSession();
try {
sql = "SELECT * FROM prozedur "
+ "LEFT JOIN dk_mtb_einzelempfehlung em ON em.id = prozedur.id "
+ "WHERE prozedur.hauptprozedur_id = " + ProcedureID + " AND prozedur.geloescht = 0 AND prozedur.data_form_id = 489 "
+ "ORDER BY beginndatum";
SQLQuery query = session.createSQLQuery(sql)
.addScalar("id", StandardBasicTypes.STRING)
.addScalar("genname", StandardBasicTypes.STRING)
.addScalar("geneid", StandardBasicTypes.STRING)
.addScalar("geneidlink", StandardBasicTypes.STRING)
.addScalar("empfehlung", StandardBasicTypes.STRING)
.addScalar("beginndatum", StandardBasicTypes.STRING);
@SuppressWarnings("unchecked")
List<String[]> rows = query.list();
return rows;
} catch (Exception e) {
return null;
}
} catch (Exception e) {
return null;
}
}
return jsonStr;
}
public Object getEmpfehlung(final Map<String, Object> input) {
// Auslesen der Parameter aus 'input'
int ProcedureID = (int) input.get("ProcedureID");
String sql;
try {
SessionFactory sessionFactory = onkostarApi.getSessionFactory();
Session session = sessionFactory.getCurrentSession();
try {
sql = "SELECT * FROM prozedur "
+ "LEFT JOIN dk_mtb_einzelempfehlung em ON em.id = prozedur.id "
+ "WHERE prozedur.hauptprozedur_id = " + ProcedureID + " AND prozedur.geloescht = 0 AND prozedur.data_form_id = 489 "
+ "ORDER BY beginndatum";
SQLQuery query = session.createSQLQuery(sql)
.addScalar("id", StandardBasicTypes.STRING)
.addScalar("genname", StandardBasicTypes.STRING)
.addScalar("geneid", StandardBasicTypes.STRING)
.addScalar("geneidlink", StandardBasicTypes.STRING)
.addScalar("empfehlung", StandardBasicTypes.STRING)
.addScalar("beginndatum", StandardBasicTypes.STRING);
@SuppressWarnings("unchecked")
List<String[]> rows = query.list();
return rows;
} catch (Exception e) {
return null;
}
} catch (Exception e) {
return null;
}
}
public Object updateEmpfehlungPrio(final Map<String, Object> input) {
// Auslesen der Parameter aus 'input'
//int rid = (int) input.get("rid");
Object rid = input.get("rid");
Object strDate = input.get("bd");
SQLQuery result = null;
public Object updateEmpfehlungPrio(final Map<String, Object> input) {
// Auslesen der Parameter aus 'input'
//int rid = (int) input.get("rid");
Object rid = input.get("rid");
Object strDate = input.get("bd");
SQLQuery result = null;
//String strD = strDate.toString();
//String CompareDate = strD.substring(1, 11);
//DateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd");
//String strD = strDate.toString();
//String CompareDate = strD.substring(1, 11);
String sql;
//DateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd");
try {
sql = "UPDATE prozedur SET beginndatum = '"+ strDate +"' WHERE id = '"+ rid +"' ";
result = onkostarApi.getSessionFactory().getCurrentSession().createSQLQuery(sql);
result.executeUpdate();
return true;
} catch (Exception e) {
return "Achtung: Ein Fehler ist aufgetreten, Änderung konnte nicht gespeichert werden!";
//return null;
}
}
String sql;
try {
sql = "UPDATE prozedur SET beginndatum = '" + strDate + "' WHERE id = '" + rid + "' ";
result = onkostarApi.getSessionFactory().getCurrentSession().createSQLQuery(sql);
result.executeUpdate();
return true;
} catch (Exception e) {
return "Achtung: Ein Fehler ist aufgetreten, Änderung konnte nicht gespeichert werden!";
//return null;
}
}
}

View File

@ -12,6 +12,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
import java.sql.Date;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -64,22 +65,19 @@ public class DNPMHelperTest {
assertThat(actual).isNotNull();
assertThat(actual).isExactlyInstanceOf(ArrayList.class);
assertThat(actual).hasSize(1);
@SuppressWarnings("unchecked")
var actualList = (ArrayList<Map<String, Object>>) actual;
assertThat(actualList).hasSize(1);
assertThat(actualList.get(0).get("Beginn"))
assertThat(actual.get(0).get("Beginn"))
.isEqualTo(Date.from(Instant.parse("2023-01-01T00:00:00Z")).toString());
assertThat(actualList.get(0).get("Ende"))
assertThat(actual.get(0).get("Ende"))
.isEqualTo(Date.from(Instant.parse("2023-01-31T00:00:00Z")).toString());
assertThat(actualList.get(0).get("Beendigung"))
assertThat(actual.get(0).get("Beendigung"))
.isEqualTo("E");
assertThat(actualList.get(0).get("Ergebnis"))
assertThat(actual.get(0).get("Ergebnis"))
.isEqualTo("T");
assertThat(actualList.get(0).get("Wirkstoffe"))
assertThat(actual.get(0).get("Wirkstoffe"))
.isEqualTo("Testsubstanz, cyclophosphamide");
assertThat(actualList.get(0).get("WirkstoffCodes"))
assertThat(actual.get(0).get("WirkstoffCodes"))
.isEqualTo(
"[" +
"{\"system\":\"other\",\"code\":\"Testsubstanz\",\"substance\":\"Testsubstanz\"}," +
@ -88,4 +86,11 @@ public class DNPMHelperTest {
);
}
@Test
void testShouldReturnNullIfNoDiagnoseId() {
var actual = dnpmHelper.getSystemischeTherapienFromDiagnose(new HashMap<>());
assertThat(actual).isNull();
}
}