466e3927 |
1 | /* |
2 | * To change this template, choose Tools | Templates |
3 | * and open the template in the editor. |
4 | */ |
5 | package org.ufcspa.simdecs.mediador; |
6 | |
25aea581 |
7 | import java.util.*; |
8 | import javax.persistence.EntityManager; |
56f36e0a |
9 | import javax.persistence.NoResultException; |
25aea581 |
10 | import org.ufcspa.simdecs.entities.*; |
11 | import org.ufcspa.simdecs.util.DbUtil; |
12 | import org.ufcspa.simdecs.util.NodoBean; |
13 | import org.ufcspa.simdecs.util.ProbabilisticBean; |
14 | import org.ufcspa.simdecs.util.UnBBayesUtil; |
15 | import unbbayes.prs.bn.ProbabilisticNode; |
16 | import unbbayes.prs.bn.TreeVariable; |
17 | import unbbayes.prs.id.DecisionNode; |
733f8ea6 |
18 | |
466e3927 |
19 | /** |
20 | * |
21 | * @author maroni |
22 | */ |
23 | public class NegociacaoPedagogica { |
24 | |
25aea581 |
25 | public static final String NAO_ABRIU_FICHA_PACIENTE = "NAO_ABRIU_FICHA_PACIENTE"; |
26 | |
27 | public static final String INVESTIGACAO_ADEQUADA = "INVESTIGACAO_ADEQUADA"; |
733f8ea6 |
28 | public static final String INVESTIGACAO_INSUFICIENTE = "INVESTIGACAO_INSUFICIENTE"; |
25aea581 |
29 | public static final String INVESTIGACAO_EXCESSIVA = "INVESTIGACAO_EXCESSIVA"; |
30 | public static final String INVESTIGACAO_BOGUS = "INVESTIGACAO_BOGUS"; |
31 | public static final String INVESTIGACAO_DISPENDIOSA = "INVESTIGACAO_DISPENDIOSA"; |
32 | public static final String INVESTIGACAO_DEMORADA = "INVESTIGACAO_DEMORADA"; |
733f8ea6 |
33 | |
25aea581 |
34 | public static final String DIAGNOSTICO_ADEQUADO = "DIAGNOSTICO_ADEQUADO"; |
35 | public static final String DIAGNOSTICO_INCORRETO_IMPLAUSIVEL= "DIAGNOSTICO_INCORRETO_IMPLAUSIVEL"; |
36 | public static final String DIAGNOSTICO_INCORRETO_PLAUSIVEL = "DIAGNOSTICO_INCORRETO_PLAUSIVEL"; |
733f8ea6 |
37 | |
25aea581 |
38 | public static final String CONDUTA_ADEQUADA = "CONDUTA_ADEQUADA"; |
39 | public static final String CONDUTA_INCORRETA_COERENTE = "CONDUTA_INCORRETA_COERENTE"; |
733f8ea6 |
40 | public static final String CONDUTA_INCORRETA_INCOERENTE = "CONDUTA_INCORRETA_INCOERENTE"; |
25aea581 |
41 | public static final String CONDUTA_INSUFICIENTE = "CONDUTA_INSUFICIENTE"; |
42 | public static final String CONDUTA_EXCESSIVA = "CONDUTA_EXCESSIVA"; |
43 | public static final String CONDUTA_DEMORADA = "CONDUTA_DEMORADA"; |
44 | public static final String CONDUTA_DISPENDIOSA = "CONDUTA_DISPENDIOSA"; |
45 | |
46 | |
47 | private LogExecucao logExecucao; |
48 | private EntityManager em; |
733f8ea6 |
49 | |
25aea581 |
50 | private String estrategia; |
51 | private List<String> resultadosSimulacao; |
52 | |
53 | |
54 | private boolean anamneseInsuficiente = false; |
55 | private boolean anamneseExcessiva = false; |
56 | private boolean exameFisicoInsuficiente = false; |
57 | private boolean exameFisicoExcessivo = false; |
58 | private boolean exameComplementarInsuficiente = false; |
59 | private boolean exameComplementarExcessivo = false; |
60 | private boolean perguntouBogus = false; |
733f8ea6 |
61 | |
56f36e0a |
62 | private Paciente paciente; |
63 | private SessaoUsuario sessaoUsuario; |
64 | |
733f8ea6 |
65 | |
25aea581 |
66 | private void populaEstrategia() throws Exception { |
67 | // Carrega o endereço do diagrama de influencia do banco e abre a rede no disco |
68 | Rede redeDI = em.find(Rede.class, 1000L); |
69 | UnBBayesUtil diagramaInfluencia = new UnBBayesUtil(redeDI); |
70 | |
71 | anamneseInsuficiente = false; |
72 | anamneseExcessiva = false; |
73 | exameFisicoInsuficiente = false; |
74 | exameFisicoExcessivo = false; |
75 | exameComplementarInsuficiente = false; |
76 | exameComplementarExcessivo = false; |
77 | perguntouBogus = false; |
78 | |
56f36e0a |
79 | if (logExecucao.isConcluiuInvestigacao()) { |
80 | // Define a probabilidade do nodo Anamnese |
81 | { |
82 | if (logExecucao.getPerguntasDisponiveis() > 0) { |
83 | ProbabilisticNode nodoAnamnese = (ProbabilisticNode) diagramaInfluencia.getNodeByName("Anamnese"); |
84 | float pcPerguntasAnamnese = logExecucao.getPerguntasRealizadas() / logExecucao.getPerguntasDisponiveis() * 100; |
85 | //System.out.println("PERCENTUAL ANAMNESE: " + pcPerguntasAnamnese); |
86 | if (pcPerguntasAnamnese <= 25) { |
87 | diagramaInfluencia.setNodeState(nodoAnamnese, "Insuficiente", 1, "Suficiente", 0, "Excessiva", 0); |
88 | anamneseInsuficiente = true; |
89 | } |
90 | else if (pcPerguntasAnamnese > 25 && pcPerguntasAnamnese <= 75) |
91 | diagramaInfluencia.setNodeState(nodoAnamnese, "Insuficiente", 0, "Suficiente", 1, "Excessiva", 0); |
92 | else { |
93 | diagramaInfluencia.setNodeState(nodoAnamnese, "Insuficiente", 0, "Suficiente", 0, "Excessiva", 1); |
94 | anamneseExcessiva = true; |
95 | } |
25aea581 |
96 | } |
97 | } |
56f36e0a |
98 | |
99 | // Define a probabilidade do nodo Exame Fisico |
100 | { |
101 | if (logExecucao.getExamesFisicosDisponiveis() > 0) { |
102 | ProbabilisticNode nodoExameFisico = (ProbabilisticNode) diagramaInfluencia.getNodeByName("ExameFisico"); |
103 | float pcExameFisico = logExecucao.getExamesFisicosRealizados() / logExecucao.getExamesFisicosDisponiveis() * 100; |
104 | //System.out.println("PERCENTUAL EXAME FISICO: " + pcExameFisico); |
105 | |
106 | if (pcExameFisico <= 25) { |
107 | diagramaInfluencia.setNodeState(nodoExameFisico, "Insuficiente", 1, "Suficiente", 0, "Excessiva", 0); |
108 | exameFisicoInsuficiente = true; |
109 | } |
110 | else if (pcExameFisico > 25 && pcExameFisico <= 75) |
111 | diagramaInfluencia.setNodeState(nodoExameFisico, "Insuficiente", 0, "Suficiente", 1, "Excessiva", 0); |
112 | else { |
113 | diagramaInfluencia.setNodeState(nodoExameFisico, "Insuficiente", 0, "Suficiente", 0, "Excessiva", 1); |
114 | exameFisicoExcessivo = true; |
115 | } |
25aea581 |
116 | } |
117 | } |
56f36e0a |
118 | |
119 | // Define a probabilidade do nodo Exame Complementar |
120 | { |
121 | if (logExecucao.getExamesComplementaresProfessor() > 0) { |
122 | ProbabilisticNode nodoExameComplementar = (ProbabilisticNode) diagramaInfluencia.getNodeByName("ExameComplementar"); |
123 | float pcExameComplementar = logExecucao.getExamesComplementaresRealizados() / logExecucao.getExamesComplementaresProfessor() * 100; |
124 | // System.out.println("PERCENTUAL EXAME COMPLEMENTAR: " + pcExameComplementar); |
125 | |
126 | if (pcExameComplementar <= 25) { |
127 | diagramaInfluencia.setNodeState(nodoExameComplementar, "Insuficiente", 1, "Suficiente", 0, "Excessiva", 0); |
128 | exameComplementarInsuficiente = true; |
129 | } |
130 | else if (pcExameComplementar > 25 && pcExameComplementar <= 7) |
131 | diagramaInfluencia.setNodeState(nodoExameComplementar, "Insuficiente", 0, "Suficiente", 1, "Excessiva", 0); |
132 | else { |
133 | diagramaInfluencia.setNodeState(nodoExameComplementar, "Insuficiente", 0, "Suficiente", 0, "Excessiva", 1); |
134 | exameFisicoExcessivo = true; |
135 | } |
25aea581 |
136 | } |
137 | } |
25aea581 |
138 | |
56f36e0a |
139 | // Define a probabilidade do nodo abriu ficha do paciente |
140 | { |
141 | ProbabilisticNode nodoAbriuFichaPaciente = (ProbabilisticNode) diagramaInfluencia.getNodeByName("AbriuFichaPaciente"); |
142 | |
143 | if (logExecucao.isAbriuFichaPaciente()) |
144 | diagramaInfluencia.setNodeState(nodoAbriuFichaPaciente, "Sim", 1, "Nao", 0); |
145 | else |
146 | diagramaInfluencia.setNodeState(nodoAbriuFichaPaciente, "Sim", 0, "Nao", 1); |
147 | } |
148 | |
149 | // Define a probabilidade do nodo Bogus |
150 | { |
151 | if (logExecucao.getPerguntasDisponiveis() > 0) { |
152 | ProbabilisticNode nodoBogus = (ProbabilisticNode) diagramaInfluencia.getNodeByName("Bogus"); |
153 | float pcNodoBogus = logExecucao.getPerguntasBogusRealizadas() / logExecucao.getPerguntasDisponiveis() * 100; |
154 | // System.out.println("PERCENTUAL BOGUS: " + pcNodoBogus); |
155 | |
156 | if (pcNodoBogus <= 10) |
157 | diagramaInfluencia.setNodeState(nodoBogus, "Presente", 0, "Ausente", 1); |
158 | else if (pcNodoBogus > 10 && pcNodoBogus <= 30) { |
159 | diagramaInfluencia.setNodeState(nodoBogus, "Presente", 0.4f, "Ausente", 0.6f); |
160 | perguntouBogus = true; |
161 | } |
162 | else { |
163 | diagramaInfluencia.setNodeState(nodoBogus, "Presente", 1, "Ausente", 0); |
164 | perguntouBogus = true; |
165 | } |
25aea581 |
166 | } |
167 | } |
168 | } |
169 | |
56f36e0a |
170 | |
171 | if (logExecucao.isConcluiuDiagnostico()) { |
172 | // Define a probabilidade de hesitação diagnostica |
173 | { |
174 | ProbabilisticNode nodoHestiacaoDiagnostico = (ProbabilisticNode) diagramaInfluencia.getNodeByName("HesitacaoDiagnostico"); |
175 | |
176 | if (logExecucao.getDesmarcacoesDiagnostico() == 0) |
177 | diagramaInfluencia.setNodeState(nodoHestiacaoDiagnostico, "Presente", 0, "Ausente", 1); |
178 | else if (logExecucao.getDesmarcacoesDiagnostico() == 1) |
179 | diagramaInfluencia.setNodeState(nodoHestiacaoDiagnostico, "Presente", 0.6f, "Ausente", 0.4f); |
180 | else |
181 | diagramaInfluencia.setNodeState(nodoHestiacaoDiagnostico, "Presente", 1, "Ausente", 0); |
182 | } |
25aea581 |
183 | } |
184 | |
56f36e0a |
185 | if (logExecucao.isConcluiuConduta()) { |
186 | // Define a probabilidade de hesitação na conduta |
187 | { |
188 | ProbabilisticNode nodoHestiacaoConduta = (ProbabilisticNode) diagramaInfluencia.getNodeByName("HesitacaoConduta"); |
189 | |
190 | if (logExecucao.getDesmarcacoesConduta() == 0) |
191 | diagramaInfluencia.setNodeState(nodoHestiacaoConduta, "Presente", 0, "Ausente", 1); |
192 | else if (logExecucao.getDesmarcacoesConduta() == 1) |
193 | diagramaInfluencia.setNodeState(nodoHestiacaoConduta, "Presente", 0.6f, "Ausente", 0.4f); |
194 | else |
195 | diagramaInfluencia.setNodeState(nodoHestiacaoConduta, "Presente", 1, "Ausente", 0); |
196 | } |
25aea581 |
197 | } |
198 | |
56f36e0a |
199 | // Define o nodo confianca |
25aea581 |
200 | { |
201 | ProbabilisticNode nodoConfianca = (ProbabilisticNode) diagramaInfluencia.getNodeByName("Confianca"); |
202 | |
203 | if (logExecucao.getConfiancaAtual().equals(Log.CONFIANCA_BAIXA)) |
204 | diagramaInfluencia.setNodeState(nodoConfianca, "Baixa", 1, "Media", 0, "Alta", 0); |
205 | else if (logExecucao.getConfiancaAtual().equals(Log.CONFIANCA_MEDIA)) |
206 | diagramaInfluencia.setNodeState(nodoConfianca, "Baixa", 0, "Media", 1, "Alta", 0); |
207 | else if (logExecucao.getConfiancaAtual().equals(Log.CONFIANCA_ALTA)) |
208 | diagramaInfluencia.setNodeState(nodoConfianca, "Baixa", 0, "Media", 0, "Alta", 1); |
209 | } |
56f36e0a |
210 | /* |
211 | // Debug das probabilidades do DI: |
212 | { |
213 | List<ProbabilisticBean> pd = diagramaInfluencia.getProbabilidadesDescOrder((TreeVariable) diagramaInfluencia.getNodeByName("ExameComplementar")); |
214 | System.out.println("NODO: EXAME COMPLEMENTAR"); |
215 | for (ProbabilisticBean p : pd) { |
216 | System.out.println(p.getState() + ": " + p.getProbability()); |
217 | } |
218 | } |
219 | |
220 | // Debug das probabilidades do DI: |
221 | { |
222 | List<ProbabilisticBean> pd = diagramaInfluencia.getProbabilidadesDescOrder((TreeVariable) diagramaInfluencia.getNodeByName("ExameFisico")); |
223 | System.out.println("NODO: EXAME FISICO"); |
224 | for (ProbabilisticBean p : pd) { |
225 | System.out.println(p.getState() + ": " + p.getProbability()); |
226 | } |
227 | } |
228 | |
229 | // Debug das probabilidades do DI: |
230 | { |
231 | List<ProbabilisticBean> pd = diagramaInfluencia.getProbabilidadesDescOrder((TreeVariable) diagramaInfluencia.getNodeByName("Anamnese")); |
232 | System.out.println("NODO: ANAMNESE"); |
233 | for (ProbabilisticBean p : pd) { |
234 | System.out.println(p.getState() + ": " + p.getProbability()); |
235 | } |
236 | } |
237 | |
238 | // Debug das probabilidades do DI: |
239 | { |
240 | List<ProbabilisticBean> pd = diagramaInfluencia.getProbabilidadesDescOrder((TreeVariable) diagramaInfluencia.getNodeByName("Investigacao")); |
241 | System.out.println("NODO: INVESTIGACAO"); |
242 | for (ProbabilisticBean p : pd) { |
243 | System.out.println(p.getState() + ": " + p.getProbability()); |
244 | } |
245 | } |
246 | |
247 | // Debug das probabilidades do DI: |
248 | { |
249 | List<ProbabilisticBean> pd = diagramaInfluencia.getProbabilidadesDescOrder((TreeVariable) diagramaInfluencia.getNodeByName("AbriuFichaPaciente")); |
250 | System.out.println("NODO: ABRIU FICHA PACIENTE"); |
251 | for (ProbabilisticBean p : pd) { |
252 | System.out.println(p.getState() + ": " + p.getProbability()); |
253 | } |
254 | } |
255 | |
256 | // Debug das probabilidades do DI: |
257 | { |
258 | List<ProbabilisticBean> pd = diagramaInfluencia.getProbabilidadesDescOrder((TreeVariable) diagramaInfluencia.getNodeByName("Bogus")); |
259 | System.out.println("NODO: Bogus"); |
260 | for (ProbabilisticBean p : pd) { |
261 | System.out.println(p.getState() + ": " + p.getProbability()); |
262 | } |
263 | } |
264 | |
265 | // Debug das probabilidades do DI: |
266 | { |
267 | List<ProbabilisticBean> pd = diagramaInfluencia.getProbabilidadesDescOrder((TreeVariable) diagramaInfluencia.getNodeByName("ResultadoInvestigacao")); |
268 | System.out.println("NODO: RESULTADO INVESTIGACAO"); |
269 | for (ProbabilisticBean p : pd) { |
270 | System.out.println(p.getState() + ": " + p.getProbability()); |
271 | } |
272 | } |
273 | |
274 | // Debug das probabilidades do DI: |
275 | { |
276 | List<ProbabilisticBean> pd = diagramaInfluencia.getProbabilidadesDescOrder((TreeVariable) diagramaInfluencia.getNodeByName("Credibilidade")); |
277 | System.out.println("NODO: CREDIBILIDADE"); |
278 | for (ProbabilisticBean p : pd) { |
279 | System.out.println(p.getState() + ": " + p.getProbability()); |
280 | } |
281 | } |
282 | |
283 | // Debug das probabilidades do DI: |
284 | { |
285 | List<ProbabilisticBean> pd = diagramaInfluencia.getProbabilidadesDescOrder((TreeVariable) diagramaInfluencia.getNodeByName("HesitacaoDiagnostico")); |
286 | System.out.println("NODO: HESITACAO DIAGNOSTICO"); |
287 | for (ProbabilisticBean p : pd) { |
288 | System.out.println(p.getState() + ": " + p.getProbability()); |
289 | } |
290 | } |
291 | |
292 | // Debug das probabilidades do DI: |
293 | { |
294 | List<ProbabilisticBean> pd = diagramaInfluencia.getProbabilidadesDescOrder((TreeVariable) diagramaInfluencia.getNodeByName("HesitacaoConduta")); |
295 | System.out.println("NODO: HESITACAO CONDUTA"); |
296 | for (ProbabilisticBean p : pd) { |
297 | System.out.println(p.getState() + ": " + p.getProbability()); |
298 | } |
299 | } |
300 | |
301 | // Debug das probabilidades do DI: |
302 | { |
303 | List<ProbabilisticBean> pd = diagramaInfluencia.getProbabilidadesDescOrder((TreeVariable) diagramaInfluencia.getNodeByName("Confianca")); |
304 | System.out.println("NODO: CONFIANCA"); |
305 | for (ProbabilisticBean p : pd) { |
306 | System.out.println(p.getState() + ": " + p.getProbability()); |
307 | } |
308 | } |
309 | |
310 | // Debug das probabilidades do DI: |
311 | { |
312 | List<ProbabilisticBean> pd = diagramaInfluencia.getProbabilidadesDescOrder((TreeVariable) diagramaInfluencia.getNodeByName("Estrategia")); |
313 | System.out.println("NODO: ESTRATEGIA"); |
314 | for (ProbabilisticBean p : pd) { |
315 | System.out.println(p.getState() + ": " + p.getProbability()); |
316 | } |
317 | } |
318 | */ |
25aea581 |
319 | // Mostra o resultado do diagrama de influencia |
56f36e0a |
320 | DecisionNode nodoTatica = (DecisionNode) diagramaInfluencia.getNodeByName("Estrategia"); |
25aea581 |
321 | List<ProbabilisticBean> probs = diagramaInfluencia.getProbabilidadesDescOrder(nodoTatica); |
322 | |
323 | for (ProbabilisticBean prob : probs) { |
324 | estrategia = prob.getState().toUpperCase(); |
325 | break; |
326 | } |
327 | } |
328 | |
56f36e0a |
329 | private String getResultadoDiagnostico() throws Exception { |
330 | // Nao selecionou o primeiro diagnostico |
331 | if (logExecucao.getPrimeiroDiagnosticoCaso() != null && !logExecucao.getDiagnostico().equals(logExecucao.getPrimeiroDiagnosticoCaso())) |
332 | if (logExecucao.getSegundoDiagnosticoCaso() != null && logExecucao.getDiagnostico().equals(logExecucao.getSegundoDiagnosticoCaso())) |
333 | return DIAGNOSTICO_INCORRETO_PLAUSIVEL; |
334 | else |
335 | return DIAGNOSTICO_INCORRETO_IMPLAUSIVEL; |
25aea581 |
336 | |
56f36e0a |
337 | return DIAGNOSTICO_ADEQUADO; |
338 | } |
25aea581 |
339 | |
56f36e0a |
340 | private String getResultadoConduta() throws Exception { |
341 | |
342 | // Caso o diagnóstico esteja adequado verifica se a conduta foi excessiva, insuficiente ou adequada! |
343 | if (getResultadoDiagnostico().equals(DIAGNOSTICO_ADEQUADO)) { |
344 | |
345 | // Verifica se a conduta está certa ou errada! |
346 | boolean diferente=false; |
347 | for(Nodo conduta : logExecucao.getCondutas().values()) { |
348 | if (!logExecucao.getCondutasIdeaisDiagnostico().contains(conduta)) { |
349 | diferente=true; |
350 | break; |
351 | } |
352 | } |
353 | |
354 | // Esta errada |
355 | if (diferente) |
356 | return CONDUTA_INCORRETA_INCOERENTE; |
357 | |
358 | // Esta certa, agora verifica se é excessiva ou adequada! |
359 | if (logExecucao.getCondutas().size() > logExecucao.getCondutasIdeaisDiagnostico().size()) |
360 | return CONDUTA_EXCESSIVA; |
361 | else if (logExecucao.getCondutas().size() < logExecucao.getCondutasIdeaisDiagnostico().size()) |
362 | return CONDUTA_INSUFICIENTE; |
363 | else |
364 | return CONDUTA_ADEQUADA; |
365 | } |
366 | // Caso o diagnóstico esteja errado |
367 | else { |
368 | // Verifica se a conduta está certa ou errada (avalia somente a primeira) |
369 | for(Nodo conduta : logExecucao.getCondutas().values()) { |
370 | if (logExecucao.getCondutasIdeaisDiagnostico().contains(conduta)) |
371 | return CONDUTA_INCORRETA_COERENTE; |
372 | else |
373 | return CONDUTA_INCORRETA_INCOERENTE; |
374 | } |
25aea581 |
375 | } |
376 | |
56f36e0a |
377 | return null; |
378 | } |
379 | |
380 | private String getResultadoCustoConduta() { |
381 | float custoRealizado=0; |
382 | float custoPrevisto=0; |
383 | |
384 | for(Nodo conduta : logExecucao.getCondutas().values()) |
385 | custoRealizado+=conduta.getCusto(); |
386 | |
387 | for(Nodo conduta : logExecucao.getCondutasIdeaisDiagnostico()) |
388 | custoPrevisto+=conduta.getCusto(); |
25aea581 |
389 | |
56f36e0a |
390 | if (custoPrevisto > 0) { |
391 | float pcCusto = custoRealizado / custoPrevisto * 100; |
392 | |
393 | if (pcCusto >= 150) |
394 | return CONDUTA_DISPENDIOSA; |
395 | } |
396 | |
397 | return null; |
25aea581 |
398 | } |
399 | |
56f36e0a |
400 | private String getResultadoTempoConduta() { |
401 | float tempoRealizado=0; |
402 | float tempoPrevisto=0; |
25aea581 |
403 | |
56f36e0a |
404 | for(Nodo conduta : logExecucao.getCondutas().values()) |
405 | tempoRealizado+=conduta.getTempo(); |
25aea581 |
406 | |
56f36e0a |
407 | for(Nodo conduta : logExecucao.getCondutasIdeaisDiagnostico()) |
408 | tempoPrevisto+=conduta.getTempo(); |
25aea581 |
409 | |
56f36e0a |
410 | if (tempoPrevisto > 0) { |
411 | float pcTempo = tempoRealizado / tempoPrevisto * 100; |
412 | |
413 | if (pcTempo >= 150) |
414 | return CONDUTA_DEMORADA; |
415 | } |
416 | |
417 | return null; |
418 | } |
419 | |
420 | private String getResultadoCustoInvestigacao() { |
421 | // Verifica se a anamnese teve alto custo! |
422 | if (logExecucao.getExamesComplementaresCustoProfessor() > 0) { |
423 | float pcCusto = logExecucao.getExamesComplementaresCustoRealizado() / logExecucao.getExamesComplementaresCustoProfessor() * 100; |
424 | if (pcCusto > 150) |
425 | return INVESTIGACAO_DISPENDIOSA; |
426 | } |
25aea581 |
427 | |
56f36e0a |
428 | return null; |
25aea581 |
429 | } |
733f8ea6 |
430 | |
56f36e0a |
431 | private String getResultadoTempoInvestigacao() { |
432 | if (logExecucao.getExamesComplementaresTempoProfessor() > 0 || logExecucao.getExamesFisicosTempoProfessor() > 0) { |
433 | float pcTempo = (logExecucao.getExamesComplementaresTempoRealizado() + logExecucao.getExamesFisicosTempoRealizado()) / |
434 | (logExecucao.getExamesComplementaresTempoProfessor() + logExecucao.getExamesFisicosTempoProfessor()) * 100; |
435 | |
436 | if (pcTempo > 150) |
437 | return INVESTIGACAO_DEMORADA; |
438 | } |
439 | |
440 | return null; |
441 | } |
733f8ea6 |
442 | |
443 | |
56f36e0a |
444 | private void populaResultadoSimulacao() throws Exception { |
445 | |
446 | populaEstrategia(); |
447 | |
25aea581 |
448 | resultadosSimulacao = new ArrayList<String>(); |
449 | |
450 | if (logExecucao.isConcluiuInvestigacao()) { |
451 | // Verifica se abriu a ficha do paciente |
452 | if (!logExecucao.isAbriuFichaPaciente()) |
453 | resultadosSimulacao.add(NAO_ABRIU_FICHA_PACIENTE); |
454 | |
455 | // Verifica se a investigação é insuficiente ou excessiva |
456 | int fatorInsuficiente = 0; |
457 | if (anamneseInsuficiente) |
458 | fatorInsuficiente++; |
459 | if (exameComplementarInsuficiente) |
460 | fatorInsuficiente++; |
461 | if (exameFisicoInsuficiente) |
462 | fatorInsuficiente++; |
463 | |
464 | int fatorExcessivo = 0; |
465 | if (anamneseExcessiva) |
466 | fatorExcessivo++; |
467 | if (exameComplementarExcessivo) |
468 | fatorExcessivo++; |
469 | if (exameFisicoExcessivo) |
470 | fatorExcessivo++; |
471 | |
472 | if (fatorExcessivo != 0 || fatorInsuficiente != 0) { |
473 | if (fatorInsuficiente > fatorExcessivo) |
474 | resultadosSimulacao.add(INVESTIGACAO_INSUFICIENTE); |
475 | else |
476 | resultadosSimulacao.add(INVESTIGACAO_EXCESSIVA); |
477 | } |
478 | |
479 | // Verifica se é bogus |
480 | if (perguntouBogus) |
481 | resultadosSimulacao.add(INVESTIGACAO_BOGUS); |
482 | |
483 | // Verifica se a anamnese teve alto custo! |
56f36e0a |
484 | String resultadoCustoInvestigacao = getResultadoCustoInvestigacao(); |
485 | if (resultadoCustoInvestigacao != null) |
486 | resultadosSimulacao.add(resultadoCustoInvestigacao); |
25aea581 |
487 | |
56f36e0a |
488 | String resultadoTempoInvestigacao = getResultadoTempoInvestigacao(); |
489 | if (resultadoTempoInvestigacao != null) |
490 | resultadosSimulacao.add(resultadoTempoInvestigacao); |
25aea581 |
491 | } |
492 | |
25aea581 |
493 | // Verifica se o diagnóstico foi adequado |
494 | if (logExecucao.isConcluiuDiagnostico()) { |
56f36e0a |
495 | String resultadoDiagnostico = getResultadoDiagnostico(); |
496 | resultadosSimulacao.add(resultadoDiagnostico); |
25aea581 |
497 | } |
498 | |
499 | |
56f36e0a |
500 | // Verifica as condutas |
25aea581 |
501 | if (logExecucao.isConcluiuConduta()) { |
56f36e0a |
502 | // Verifica a adequacao da conduta |
503 | String resultadoConduta = getResultadoConduta(); |
504 | resultadosSimulacao.add(resultadoConduta); |
25aea581 |
505 | |
506 | |
56f36e0a |
507 | // Verifica o custo |
508 | String resultadoCondutaCusto = getResultadoCustoConduta(); |
509 | if (resultadoCondutaCusto != null) |
510 | resultadosSimulacao.add(resultadoCondutaCusto); |
511 | |
512 | // Verifica o tempo |
513 | String resultadoCondutaTempo = getResultadoTempoConduta(); |
514 | if (resultadoCondutaTempo != null) |
515 | resultadosSimulacao.add(resultadoCondutaTempo); |
516 | } |
25aea581 |
517 | |
56f36e0a |
518 | // Após a execução da procura das falhas. Caso não haja problema da a simulação como correta |
519 | if (logExecucao.isConcluiuInvestigacao()) { |
520 | if (!resultadosSimulacao.contains(INVESTIGACAO_BOGUS) && !resultadosSimulacao.contains(INVESTIGACAO_DEMORADA) && |
521 | !resultadosSimulacao.contains(INVESTIGACAO_DISPENDIOSA) && !resultadosSimulacao.contains(INVESTIGACAO_EXCESSIVA) && |
522 | !resultadosSimulacao.contains(INVESTIGACAO_INSUFICIENTE) ) { |
523 | |
524 | resultadosSimulacao.add(INVESTIGACAO_ADEQUADA); |
25aea581 |
525 | } |
25aea581 |
526 | } |
527 | } |
56f36e0a |
528 | |
529 | public NegociacaoPedagogica(long idSessao, Paciente paciente) throws Exception { |
530 | em = DbUtil.getInstance().getEntityManager(); |
531 | SessaoUsuario sessaoUsuario = em.find(SessaoUsuario.class, idSessao); |
532 | this.sessaoUsuario = sessaoUsuario; |
533 | this.paciente = paciente; |
25aea581 |
534 | |
25aea581 |
535 | // Busca o log de execução |
56f36e0a |
536 | logExecucao = new LogExecucao(sessaoUsuario, paciente); |
537 | } |
538 | |
539 | public String getIntervencao(String etapa) throws Exception { |
733f8ea6 |
540 | System.out.println(logExecucao); |
25aea581 |
541 | |
56f36e0a |
542 | populaResultadoSimulacao(); |
543 | |
25aea581 |
544 | System.out.println("ESTRATÉGIA: " + estrategia); |
545 | System.out.println("RESULTADOS:"); |
546 | |
547 | for(String resultado : resultadosSimulacao) { |
56f36e0a |
548 | System.out.println(resultado + " - " + etapa); |
549 | |
550 | // Registra somente resultados referentes a posicao atual do simulador |
551 | if (etapa.equals(Log.ETAPA_INVESTIGACAO) && !resultado.startsWith("INVESTIGACAO") && !resultado.equals(NAO_ABRIU_FICHA_PACIENTE)) |
552 | continue; |
25aea581 |
553 | |
56f36e0a |
554 | // Registra somente resultados referentes a posicao atual do simulador |
555 | if (etapa.equals(Log.ETAPA_DIAGNOSTICO) && !resultado.startsWith("DIAGNOSTICO")) |
556 | continue; |
557 | |
558 | // Registra somente resultados referentes a posicao atual do simulador |
559 | if (etapa.equals(Log.ETAPA_CONDUTA) && !resultado.startsWith("CONDUTA")) |
560 | continue; |
561 | |
562 | |
563 | |
564 | try { |
565 | IntervencaoPedagogica testarExistencia = (IntervencaoPedagogica) em.createQuery("From IntervencaoPedagogica where sessaoUsuario.id=:pSessao and estrategia=:pEstrategia and resultado=:pResultado") |
566 | .setParameter("pSessao", sessaoUsuario.getId()) |
567 | .setParameter("pEstrategia", estrategia) |
568 | .setParameter("pResultado", resultado) |
569 | .getSingleResult(); |
570 | continue; |
571 | } catch(NoResultException e) { } |
572 | |
25aea581 |
573 | if (!em.getTransaction().isActive()) |
574 | em.getTransaction().begin(); |
575 | |
56f36e0a |
576 | IntervencaoPedagogica intervencao = new IntervencaoPedagogica(); |
25aea581 |
577 | intervencao.setAplicada(false); |
578 | intervencao.setDataGeracao(new Date()); |
579 | intervencao.setEstrategia(estrategia); |
580 | intervencao.setResultado(resultado); |
56f36e0a |
581 | intervencao.setSessaoUsuario(sessaoUsuario); |
25aea581 |
582 | |
583 | TaticaPedagogica tatica = (TaticaPedagogica) em.createQuery("From TaticaPedagogica where resultado=:pResultado and estrategia=:pEstrategia") |
584 | .setParameter("pResultado", resultado) |
585 | .setParameter("pEstrategia", estrategia) |
586 | .getSingleResult(); |
587 | intervencao.setTatica(tatica); |
588 | |
589 | em.persist(intervencao); |
56f36e0a |
590 | |
25aea581 |
591 | em.getTransaction().commit(); |
56f36e0a |
592 | } |
593 | |
594 | // Busca as intervencoes a serem mostradas agora! |
595 | { |
596 | StringBuilder retorno = new StringBuilder(); |
597 | |
598 | Iterator<IntervencaoPedagogica> itIntervencoes = em.createQuery("From IntervencaoPedagogica where sessaoUsuario.id=:pSessao and aplicada=false order by dataGeracao desc") |
599 | .setParameter("pSessao", sessaoUsuario.getId()) |
600 | .getResultList() |
601 | .iterator(); |
602 | |
603 | if (!itIntervencoes.hasNext()) |
604 | return " <resposta_acao_mediador acao=\"nao\" />"; |
605 | |
606 | retorno.append(" <resposta_acao_mediador acao=\"sim\" mensagem=\"Atenção\" problema=\""); |
25aea581 |
607 | |
56f36e0a |
608 | while(itIntervencoes.hasNext()) { |
609 | IntervencaoPedagogica intervencao = itIntervencoes.next(); |
610 | retorno.append(intervencao.getTatica().getMensagem()); |
611 | retorno.append("\n\n"); |
612 | |
613 | if (!em.getTransaction().isActive()) |
614 | em.getTransaction().begin(); |
615 | |
616 | |
617 | intervencao.setAplicada(true); |
618 | em.merge(intervencao); |
619 | |
620 | em.getTransaction().commit(); |
621 | |
622 | } |
623 | |
624 | retorno.append("\" />"); |
625 | return retorno.toString(); |
25aea581 |
626 | } |
56f36e0a |
627 | } |
628 | |
629 | public String getMensagemFinal() throws Exception { |
630 | StringBuilder retorno = new StringBuilder(); |
631 | |
632 | retorno.append("PACIENTE: " + paciente.getNome() + "\n\n"); |
633 | |
634 | retorno.append("RESUMO:\n"); |
635 | |
636 | |
637 | // Diagnostico |
4e89c95d |
638 | if (logExecucao.isConcluiuDiagnostico()) { |
639 | String resultadoDiagnostico = getResultadoDiagnostico(); |
640 | if (resultadoDiagnostico.equals(DIAGNOSTICO_ADEQUADO)) |
641 | retorno.append("-Você chegou ao diagnóstico previsto para esta simulação!\n"); |
642 | else if (resultadoDiagnostico.equals(DIAGNOSTICO_INCORRETO_PLAUSIVEL)) |
643 | retorno.append("-Você não chegou ao diagnóstico previsto para esta simulação! Porém, seu diagnóstico é plausível!\n"); |
644 | else |
645 | retorno.append("-Você não chegou ao diagnóstico previsto para esta simulação! Seu diagnóstico não é plausível!\n"); |
646 | } else |
647 | retorno.append("-Você finalizou o atendimento sem selecionar um diagnóstico!\n"); |
648 | |
56f36e0a |
649 | |
650 | // Conduta |
4e89c95d |
651 | if (logExecucao.isConcluiuConduta()) { |
652 | String resultadoConduta = getResultadoConduta(); |
653 | if (resultadoConduta.equals(CONDUTA_ADEQUADA)) |
654 | retorno.append("-A conduta selecionada esta adequada ao previsto pela simulação!\n"); |
655 | else if (resultadoConduta.equals(CONDUTA_EXCESSIVA)) |
656 | retorno.append("-A conduta selecionada esta adequada ao previsto pela simulação, porém existem procedimentos em excesso!\n"); |
657 | else if (resultadoConduta.equals(CONDUTA_INSUFICIENTE)) |
658 | retorno.append("-A conduta selecionada esta adequada ao previsto pela simulação, porém a quantidade de procedimentos é insuficiente em relação ao previsto!\n"); |
659 | else if (resultadoConduta.equals(CONDUTA_INCORRETA_COERENTE)) |
660 | retorno.append("-A conduta selecionada esta inadequada ao previsto pela simulação, porém é coerente com o diagnóstico selecionado!\n"); |
661 | else if (resultadoConduta.equals(CONDUTA_INCORRETA_INCOERENTE)) |
662 | retorno.append("-A conduta selecionada esta inadequada e incoerente com o diagnóstico selecionado!\n"); |
663 | |
664 | String resultadoTempoConduta = getResultadoTempoConduta(); |
665 | String resultadoTempoInvestigacao = getResultadoTempoInvestigacao(); |
666 | if (resultadoTempoConduta != null || resultadoTempoInvestigacao != null) { |
667 | retorno.append("-Quanto a utilização do tempo "); |
668 | if (resultadoTempoInvestigacao != null && resultadoTempoConduta != null) |
669 | retorno.append("sua investigação e conduta foram demoradas"); |
670 | else if (resultadoTempoInvestigacao != null) |
671 | retorno.append("sua investigação foi demorada"); |
672 | else if (resultadoTempoConduta != null) |
673 | retorno.append("sua conduta foi demorada"); |
674 | retorno.append("!\n"); |
675 | } |
56f36e0a |
676 | |
4e89c95d |
677 | String resultadoCustoConduta = getResultadoCustoConduta(); |
678 | String resultadoCustoInvestigacao = getResultadoCustoInvestigacao(); |
679 | if (resultadoCustoConduta != null || resultadoCustoInvestigacao != null) { |
680 | retorno.append("-Quanto a utilização de recursos "); |
681 | if (resultadoCustoInvestigacao != null && resultadoCustoConduta != null) |
682 | retorno.append("sua investigação e conduta foram dispendiosas"); |
683 | else if (resultadoCustoInvestigacao != null) |
684 | retorno.append("sua investigação foi dispendiosa"); |
685 | else if (resultadoCustoConduta != null) |
686 | retorno.append("sua conduta foi dispendiosa"); |
687 | retorno.append("!\n"); |
688 | } |
689 | } else |
690 | retorno.append("-Você finalizou o atendimento sem selecionar uma conduta!\n"); |
56f36e0a |
691 | |
25aea581 |
692 | |
56f36e0a |
693 | // Log de execução |
694 | List<LogPerguntas> logPerguntas = em.createQuery("From LogPerguntas where sessaoUsuario.id=:pIdSessao and paciente.id=:pIdPaciente") |
695 | .setParameter("pIdSessao", sessaoUsuario.getId()) |
696 | .setParameter("pIdPaciente", paciente.getId()) |
697 | .getResultList(); |
698 | |
699 | // Mostra os sintomas esperados: |
700 | retorno.append("\n\nSINAIS / SINTOMAS:\nAS PERGUNTAS QUE PODERIAM FORTALECER O DIAGNÓSTICO SÃO:\n"); |
701 | for(LogPerguntas logPergunta : logPerguntas) { |
702 | if (logPergunta.getTipoNodo().equals(Nodo.SINAL_SINTOMA) && logPergunta.isAtivo()) |
703 | retorno.append(logPergunta.getPergunta() + "\n"); |
704 | } |
705 | |
706 | // Mostra os sintomas selecionados: |
707 | retorno.append("\n\nAS PERGUNTAS SELECIONADAS NO DECORRER DA SUA SIMULAÇÃO FORAM:\n"); |
708 | List<Nodo> nodosInvestigacao = logExecucao.getNodosInvestigacao(); |
709 | for(Nodo nodoInvestigacao : nodosInvestigacao) { |
710 | if (nodoInvestigacao.getTipo().equals(Nodo.SINAL_SINTOMA)) { |
711 | for(LogPerguntas logPergunta : logPerguntas) { |
712 | if (logPergunta.getNodo().getId() == nodoInvestigacao.getId()) { |
713 | retorno.append(logPergunta.getPergunta() + "\n"); |
714 | break; |
715 | } |
716 | } |
717 | } |
718 | } |
25aea581 |
719 | |
56f36e0a |
720 | |
721 | return retorno.toString(); |
733f8ea6 |
722 | } |
466e3927 |
723 | |
724 | } |