24d46eb2 |
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 | |
24d46eb2 |
7 | import java.io.PrintWriter; |
2f5d1c39 |
8 | import java.util.Date; |
24d46eb2 |
9 | import javax.persistence.EntityManager; |
24d46eb2 |
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; |
24d46eb2 |
16 | |
17 | /** |
18 | * |
19 | * @author maroni |
20 | */ |
cff9bc95 |
21 | public class MetodoRegistraAcao extends BaseComunicacao { |
24d46eb2 |
22 | |
cff9bc95 |
23 | @Override |
24 | protected void executaServico(EntityManager em, HttpServletRequest request, HttpServletResponse response, PrintWriter out) throws Exception |
25 | { |
24d46eb2 |
26 | response.setContentType("text/html;charset=UTF-8"); |
cff9bc95 |
27 | response.setContentType("text/xml"); |
28 | response.setHeader("Cache-Control", "no-cache"); |
24d46eb2 |
29 | |
cff9bc95 |
30 | long pIdSessao = Long.parseLong(request.getParameter("idsessao")); |
31 | long pIdPaciente = Long.parseLong(request.getParameter("idpaciente")); |
32 | String pAcao = request.getParameter("acao"); //Acoes: abre_investigacao, fecha_investigacao, abre_diagnostico, fecha_diagnostico, abre_conduta, fecha_conduta |
33 | String acao; |
34 | String etapa; |
2f5d1c39 |
35 | |
cff9bc95 |
36 | if (pAcao.toLowerCase().equals("abre_investigacao")) { |
37 | acao = Log.ACAO_ABERTURA; |
38 | etapa = Log.ETAPA_INVESTIGACAO; |
39 | } else if (pAcao.toLowerCase().equals("fecha_investigacao")) { |
40 | acao = Log.ACAO_FECHAMENTO; |
41 | etapa = Log.ETAPA_INVESTIGACAO; |
42 | } else if (pAcao.toLowerCase().equals("abre_diagnostico")) { |
43 | acao = Log.ACAO_ABERTURA; |
44 | etapa = Log.ETAPA_DIAGNOSTICO; |
45 | } else if (pAcao.toLowerCase().equals("fecha_diagnostico")) { |
46 | acao = Log.ACAO_FECHAMENTO; |
47 | etapa = Log.ETAPA_DIAGNOSTICO; |
48 | } else if (pAcao.toLowerCase().equals("abre_conduta")) { |
49 | acao = Log.ACAO_ABERTURA; |
50 | etapa = Log.ETAPA_CONDUTA; |
51 | } else if (pAcao.toLowerCase().equals("fecha_conduta")) { |
52 | acao = Log.ACAO_FECHAMENTO; |
53 | etapa = Log.ETAPA_CONDUTA; |
54 | } else { |
55 | return; |
56 | } |
2f5d1c39 |
57 | |
24d46eb2 |
58 | |
cff9bc95 |
59 | // Registra Log |
60 | SessaoUsuario sessaoUsuario = em.find(SessaoUsuario.class, pIdSessao); |
61 | if (sessaoUsuario == null) { |
62 | return; |
24d46eb2 |
63 | } |
24d46eb2 |
64 | |
cff9bc95 |
65 | Paciente paciente = em.find(Paciente.class, pIdPaciente); |
66 | if (paciente == null) { |
67 | return; |
68 | } |
24d46eb2 |
69 | |
cff9bc95 |
70 | if (!em.getTransaction().isActive()) { |
71 | em.getTransaction().begin(); |
72 | } |
73 | |
74 | Log log = new Log(); |
75 | log.setTipo(em.find(TipoEventoLog.class, TipoEventoLog.REGISTRO_ACAO)); |
76 | log.setAcao(acao); |
77 | log.setEtapa(etapa); |
78 | log.setPaciente(paciente); |
79 | log.setRede(paciente.getRede()); |
80 | log.setCaso(sessaoUsuario.getCaso()); |
81 | log.setData(new Date()); |
82 | log.setSessaoUsuario(sessaoUsuario); |
83 | |
84 | em.persist(log); |
85 | em.getTransaction().commit(); |
86 | |
87 | |
88 | out.println("<xml>"); |
89 | out.println(" <resposta_acao_mediador acao=\"sim\" problema=\"PROBLEMA: " + this.getClass() + "\" mensagem=\"MENSAGEM:" + this.getClass() + "\" />"); |
90 | // out.println(" <resposta_acao_mediador acao=\"nao\" />"); |
91 | |
92 | out.println("</xml>"); |
24d46eb2 |
93 | } |
94 | |
24d46eb2 |
95 | } |