Class: Gerint::Comunicacao
- Inherits:
-
Object
- Object
- Gerint::Comunicacao
- Defined in:
- lib/gerint/comunicacao/comunicacao.rb
Instance Attribute Summary collapse
-
#ambiente ⇒ Object
Returns the value of attribute ambiente.
-
#apikey ⇒ Object
Returns the value of attribute apikey.
-
#cnes ⇒ Object
Returns the value of attribute cnes.
-
#senha ⇒ Object
Returns the value of attribute senha.
-
#usuario ⇒ Object
Returns the value of attribute usuario.
Instance Method Summary collapse
- #alta(alta) ⇒ Object
- #busca_situacao_solicitacoes ⇒ Object
- #busca_solicitacoes_executante(filtros = "") ⇒ Object
-
#credenciais ⇒ Object
Consulta as credenciais instanciadas.
- #endereco_url ⇒ Object
- #executa_get(endereco) ⇒ Object
- #executa_post(endereco, body) ⇒ Object
-
#initialize(ambiente, apikey, usuario, senha, cnes) ⇒ Comunicacao
constructor
A new instance of Comunicacao.
- #internacao(internacao) ⇒ Object
- #solicitacao_internacao(solicitacao_internacao) ⇒ Object
- #solicitacao_internacao_psiquiatria(solicitacao_internacao_psiquiatria) ⇒ Object
- #transferir_leito(transf) ⇒ Object
Constructor Details
#initialize(ambiente, apikey, usuario, senha, cnes) ⇒ Comunicacao
Returns a new instance of Comunicacao.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/gerint/comunicacao/comunicacao.rb', line 9 def initialize(ambiente, apikey, usuario, senha, cnes) @ambiente = ambiente @apikey = apikey @usuario = usuario @senha = senha @cnes = cnes if ambiente == 'H' && apikey == '' # Se não informar a apikey, pega os dados de teste do HEPA @apikey = "0ecc120b-c3bf-4e71-a5f9-cbaf0e394e34" @usuario = "integracao.2237180" @senha = "integracao.2237180" @cnes = "2237180" end end |
Instance Attribute Details
#ambiente ⇒ Object
Returns the value of attribute ambiente.
7 8 9 |
# File 'lib/gerint/comunicacao/comunicacao.rb', line 7 def ambiente @ambiente end |
#apikey ⇒ Object
Returns the value of attribute apikey.
7 8 9 |
# File 'lib/gerint/comunicacao/comunicacao.rb', line 7 def apikey @apikey end |
#cnes ⇒ Object
Returns the value of attribute cnes.
7 8 9 |
# File 'lib/gerint/comunicacao/comunicacao.rb', line 7 def cnes @cnes end |
#senha ⇒ Object
Returns the value of attribute senha.
7 8 9 |
# File 'lib/gerint/comunicacao/comunicacao.rb', line 7 def senha @senha end |
#usuario ⇒ Object
Returns the value of attribute usuario.
7 8 9 |
# File 'lib/gerint/comunicacao/comunicacao.rb', line 7 def usuario @usuario end |
Instance Method Details
#alta(alta) ⇒ Object
115 116 117 118 119 |
# File 'lib/gerint/comunicacao/comunicacao.rb', line 115 def alta(alta) ender = "/internacoes/liberar" # No GERINT o serviço é chamado de Liberação de Internação body = alta.to_json retorno = self.executa_post(ender, body) end |
#busca_situacao_solicitacoes ⇒ Object
87 88 89 90 |
# File 'lib/gerint/comunicacao/comunicacao.rb', line 87 def busca_situacao_solicitacoes ender = "/solicitacoes/buscaSituacaoSolicitacoes" retorno = self.executa_get(ender) end |
#busca_solicitacoes_executante(filtros = "") ⇒ Object
92 93 94 95 |
# File 'lib/gerint/comunicacao/comunicacao.rb', line 92 def busca_solicitacoes_executante(filtros="") ender = "/solicitacoes/buscaSolicitacoesExecutante#{filtros}" retorno = self.executa_get(ender) end |
#credenciais ⇒ Object
Consulta as credenciais instanciadas
24 25 26 27 28 29 30 |
# File 'lib/gerint/comunicacao/comunicacao.rb', line 24 def credenciais # Consulta as credenciais instanciadas x = "ambiente = #{@ambiente} \n" x += "apikey = #{@apikey} \n" x += "usuario = #{@usuario} \n" x += "senha = #{@senha} \n" x += "cnes = #{@cnes}" end |
#endereco_url ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/gerint/comunicacao/comunicacao.rb', line 32 def endereco_url if @ambiente == 'P' "https://api.procempa.com.br/apiman-gateway/saude/api/1.0/gerint" elsif @ambiente == 'H' "https://api-hom.procempa.com.br/apiman-gateway/saude/api/1.1/gerint" else "ERRO: Ambiente inválido, informa P para produção ou H para Homologação" end end |
#executa_get(endereco) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/gerint/comunicacao/comunicacao.rb', line 42 def executa_get(endereco) ender = endereco_url + endereco url = URI("#{ender}") https = Net::HTTP.new(url.host, url.port); https.use_ssl = true request = Net::HTTP::Get.new(url) request["X-API-Key"] = @apikey request["usuario"] = @usuario request["senha"] = @senha request["cnes"] = @cnes request["Cookie"] = "SERVERID=WS4CH" response = https.request(request) response.read_body end |
#executa_post(endereco, body) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/gerint/comunicacao/comunicacao.rb', line 61 def executa_post(endereco, body) ender = endereco_url + endereco url = URI("#{ender}") https = Net::HTTP.new(url.host, url.port); https.use_ssl = true request = Net::HTTP::Post.new(url) request["X-API-Key"] = @apikey request["usuario"] = @usuario request["senha"] = @senha request["cnes"] = @cnes request["Content-Type"] = "application/json" request["Cookie"] = "SERVERID=WS4CH" request.body = body puts "***************************" puts request.body puts "***************************" response = https.request(request) response.read_body end |
#internacao(internacao) ⇒ Object
109 110 111 112 113 |
# File 'lib/gerint/comunicacao/comunicacao.rb', line 109 def internacao(internacao) ender = "/internacoes" # Usado para internações e internações psiquiatricas body = internacao.to_json retorno = self.executa_post(ender, body) end |
#solicitacao_internacao(solicitacao_internacao) ⇒ Object
97 98 99 100 101 |
# File 'lib/gerint/comunicacao/comunicacao.rb', line 97 def solicitacao_internacao(solicitacao_internacao) ender = "/solicitacoes" body = solicitacao_internacao.to_json retorno = self.executa_post(ender, body) end |
#solicitacao_internacao_psiquiatria(solicitacao_internacao_psiquiatria) ⇒ Object
103 104 105 106 107 |
# File 'lib/gerint/comunicacao/comunicacao.rb', line 103 def solicitacao_internacao_psiquiatria(solicitacao_internacao_psiquiatria) ender = "/solicitacoes/psiquiatria" body = solicitacao_internacao_psiquiatria.to_json retorno = self.executa_post(ender, body) end |
#transferir_leito(transf) ⇒ Object
121 122 123 124 125 |
# File 'lib/gerint/comunicacao/comunicacao.rb', line 121 def transferir_leito(transf) ender = "/internacoes/transferir" body = transf.to_json retorno = self.executa_post(ender, body) end |