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