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