1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
|
package DNPM;
import DNPM.services.systemtherapie.SystemtherapieService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
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.AnalyzerRequirement;
import de.itc.onkostar.api.analysis.IProcedureAnalyzer;
import de.itc.onkostar.api.analysis.OnkostarPluginType;
import org.hibernate.SQLQuery;
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.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class DNPMHelper implements IProcedureAnalyzer {
private static final Logger logger = LoggerFactory.getLogger(DNPMHelper.class);
private final IOnkostarApi onkostarApi;
private final SystemtherapieService systemtherapieService;
public DNPMHelper(final IOnkostarApi onkostarApi, final SystemtherapieService systemtherapieService) {
this.onkostarApi = onkostarApi;
this.systemtherapieService = systemtherapieService;
}
@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 getVersion() {
return "1";
}
@Override
public String getName() {
return "UMR DNPM";
}
@Override
public String getDescription() {
return "Methoden für DNPM-Formulare";
}
@Override
public boolean isRelevantForDeletedProcedure() {
return false;
}
@Override
public boolean isSynchronous() {
return true;
}
@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 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";
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;
}
} catch (Exception e) {
return null;
}
return VerbundeneFormulare;
}
public List<Map<String, String>> getSystemischeTherapienFromDiagnose(final Map<String, Object> input) {
var diagnoseId = input.get("DiagnoseId");
if (null == diagnoseId || Integer.parseInt(diagnoseId.toString()) == 0) {
logger.error("Kein Parameter 'DiagnoseId' angegeben, gebe 'null' zurück");
return null;
}
return systemtherapieService.getSystemischeTherapienFromDiagnose(Integer.parseInt(diagnoseId.toString()));
}
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);
}
}
ObjectMapper Obj = new ObjectMapper();
try {
jsonStr = Obj.writeValueAsString(Formulare);
} catch (JsonProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return jsonStr;
}
public Object getEmpfehlung(final Map<String, Object> input) {
var procedureID = input.get("ProcedureID");
if (null == procedureID || Integer.parseInt(procedureID.toString()) == 0) {
logger.error("Kein Parameter 'ProcedureID' angegeben, gebe 'null' zurück");
return null;
}
try {
SessionFactory sessionFactory = onkostarApi.getSessionFactory();
Session session = sessionFactory.getCurrentSession();
var sql = "SELECT * FROM prozedur "
+ "LEFT JOIN dk_mtb_einzelempfehlung em ON em.id = prozedur.id "
// TODO data_form_id immer 489?
+ "WHERE prozedur.hauptprozedur_id = " + Integer.parseInt(procedureID.toString()) + " 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) {
logger.error("Fehler bei Abfrage von Empfehlungen", 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;
//String strD = strDate.toString();
//String CompareDate = strD.substring(1, 11);
//DateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd");
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;
}
}
}
|