01e7dc8b |
1 | /* |
2 | * To change this template, choose Tools | Templates |
3 | * and open the template in the editor. |
4 | */ |
5 | package org.ufcspa.simdecs.comunicacao; |
6 | |
01e7dc8b |
7 | import java.io.PrintWriter; |
2f5d1c39 |
8 | import java.util.Date; |
01e7dc8b |
9 | import javax.persistence.EntityManager; |
01e7dc8b |
10 | import javax.servlet.http.HttpServletRequest; |
11 | import javax.servlet.http.HttpServletResponse; |
2f5d1c39 |
12 | import org.ufcspa.simdecs.entities.Log; |
13 | import org.ufcspa.simdecs.entities.Paciente; |
14 | import org.ufcspa.simdecs.entities.SessaoUsuario; |
15 | import org.ufcspa.simdecs.entities.TipoEventoLog; |
4e89c95d |
16 | import org.ufcspa.simdecs.mediador.NegociacaoPedagogica; |
01e7dc8b |
17 | |
18 | /** |
19 | * |
20 | * @author maroni |
21 | */ |
cff9bc95 |
22 | public class MetodoConfiancaEtapa extends BaseComunicacao { |
23 | |
24 | @Override |
25 | protected void executaServico(EntityManager em, HttpServletRequest request, HttpServletResponse response, PrintWriter out) throws Exception |
26 | { |
01e7dc8b |
27 | response.setContentType("text/html;charset=UTF-8"); |
cff9bc95 |
28 | |
29 | response.setContentType("text/xml"); |
30 | response.setHeader("Cache-Control", "no-cache"); |
31 | |
32 | long pIdSessao = Long.parseLong(request.getParameter("idsessao")); |
33 | String pNivel = request.getParameter("nivelconfianca"); |
34 | String pEtapa = request.getParameter("etapa"); |
35 | long pIdPaciente = Long.parseLong(request.getParameter("idpaciente")); |
36 | String nivelConfianca; |
37 | String etapa; |
38 | |
39 | if (pNivel.toLowerCase().equals("baixo")) { |
40 | nivelConfianca = Log.CONFIANCA_BAIXA; |
41 | } else if (pNivel.toLowerCase().equals("medio")) { |
42 | nivelConfianca = Log.CONFIANCA_MEDIA; |
43 | } else if (pNivel.toLowerCase().equals("alto")) { |
44 | nivelConfianca = Log.CONFIANCA_ALTA; |
45 | } else { |
46 | return; |
01e7dc8b |
47 | } |
01e7dc8b |
48 | |
cff9bc95 |
49 | if (pEtapa.toLowerCase().equals("diagnostico")) { |
50 | etapa = Log.ETAPA_DIAGNOSTICO; |
51 | } else if (pEtapa.toLowerCase().equals("investigacao")) { |
52 | etapa = Log.ETAPA_INVESTIGACAO; |
53 | } else if (pEtapa.toLowerCase().equals("conduta")) { |
54 | etapa = Log.ETAPA_CONDUTA; |
55 | } else { |
56 | return; |
57 | } |
01e7dc8b |
58 | |
cff9bc95 |
59 | // Registra Log |
60 | SessaoUsuario sessaoUsuario = em.find(SessaoUsuario.class, pIdSessao); |
61 | if (sessaoUsuario == null) { |
62 | return; |
63 | } |
01e7dc8b |
64 | |
cff9bc95 |
65 | Paciente paciente = em.find(Paciente.class, pIdPaciente); |
66 | if (paciente == null) { |
67 | return; |
68 | } |
69 | |
70 | if (!em.getTransaction().isActive()) { |
71 | em.getTransaction().begin(); |
72 | } |
73 | |
74 | Log log = new Log(); |
75 | |
76 | |
77 | log.setTipo(em.find(TipoEventoLog.class, TipoEventoLog.CONFIANCA_ETAPA)); |
78 | log.setData(new Date()); |
79 | log.setSessaoUsuario(sessaoUsuario); |
80 | |
81 | log.setRede(paciente.getRede()); |
82 | log.setConfianca(nivelConfianca); |
83 | log.setEtapa(etapa); |
84 | log.setPaciente(paciente); |
85 | log.setCaso(sessaoUsuario.getCaso()); |
86 | |
87 | em.persist(log); |
88 | em.getTransaction().commit(); |
4e89c95d |
89 | |
90 | NegociacaoPedagogica negociacaoPedagogica = new NegociacaoPedagogica(pIdSessao, paciente); |
cff9bc95 |
91 | out.println("<xml>"); |
cff9bc95 |
92 | out.println(" <nivel_confianca registrado=\"sim\" />"); |
4e89c95d |
93 | out.println(negociacaoPedagogica.getIntervencao(etapa)); |
28042ed9 |
94 | out.println(" <execucao sucesso=\"sim\" />" ); |
cff9bc95 |
95 | out.println("</xml>"); |
96 | } |
01e7dc8b |
97 | } |