This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Integracao\Ria;
|
||||
|
||||
use App\Enums\Intranet\Sistema;
|
||||
use App\Models\Integracao\Ria\DocumentoImunologicoRotina;
|
||||
use App\Models\Intranet\Cliente;
|
||||
use App\Services\Integracao\Ria\DocumentoImunologicoRotinaService;
|
||||
use App\Services\Integracao\RiaService;
|
||||
use App\Services\Telegram\TelegramService;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class EnviarDocumentoAlteradoCommand extends Command
|
||||
{
|
||||
protected $signature = 'integracao:ria-enviar-documento-alterado';
|
||||
protected $description = 'Comando para envio de documentos alterados ao RIA.';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
try {
|
||||
$currentDatabase = Config::get('database.default');
|
||||
|
||||
self::getClientes()->each(function($cliente) {
|
||||
try {
|
||||
$cliente = Cliente::where('link', $cliente)
|
||||
->where('sistema_id', Sistema::CONECTASUS)
|
||||
->firstOrFail();
|
||||
|
||||
Config::set('database.default', $cliente->link);
|
||||
|
||||
$parametrizacao = RiaService::getParametrizacao();
|
||||
|
||||
if (!is_null($parametrizacao)) {
|
||||
$token = RiaService::getToken($cliente, $parametrizacao, $parametrizacao->senha);
|
||||
$expiresAt = Carbon::now()->addMilliseconds($token['expires_in'])->subMinutes(2);
|
||||
|
||||
DocumentoImunologicoRotinaService::getDocumentosAlterados()
|
||||
->each(function($documentoAlterado) use ($cliente, $parametrizacao, &$token, $expiresAt) {
|
||||
if (Carbon::now() >= $expiresAt) {
|
||||
$token = RiaService::getToken($parametrizacao->senha);
|
||||
}
|
||||
|
||||
$headers = [
|
||||
'Authorization' => $parametrizacao->cns_solicitante,
|
||||
'Content-Type' => 'application/json',
|
||||
'X-Authorization-Server' => "Bearer " . $token['access_token'],
|
||||
];
|
||||
|
||||
$documentoAlterado->identificador_solicitante = $parametrizacao->identificador_solicitante;
|
||||
$documentoAlterado->cns_solicitante = $parametrizacao->cns_solicitante;
|
||||
$documentoAlterado->data_hora_envio = Carbon::now();
|
||||
|
||||
$response = RiaService::sendDocumentoImunologicoRotina($headers, $documentoAlterado, $cliente->municipio->estado->uf);
|
||||
|
||||
if ($response->status() === 201) {
|
||||
$documentoAlterado->identificador_rnds = $response->header('Location') ? $response->header('Location') : null;
|
||||
$documentoAlterado->response = $response->json();
|
||||
$documentoAlterado->alterar = false;
|
||||
$documentoAlterado->atualizado = true;
|
||||
|
||||
DocumentoImunologicoRotinaService::update($documentoAlterado->documento_imunologico_rotina_id, $documentoAlterado);
|
||||
}
|
||||
else {
|
||||
DocumentoImunologicoRotina::where('id', $documentoAlterado->documento_imunologico_rotina_id)->update([
|
||||
'tentou_substituir' => true,
|
||||
]);
|
||||
|
||||
DocumentoImunologicoRotinaService::updateInconsistencias($documentoAlterado->documento_imunologico_rotina_id, $response->json());
|
||||
}
|
||||
});
|
||||
|
||||
Log::channel('integracao-ria')->info('Comando executado com sucesso.', [
|
||||
'cliente' => $cliente->link,
|
||||
'origem' => 'EnviarDocumentoAlteradoCommand'
|
||||
]);
|
||||
}
|
||||
} catch (Exception $error) {
|
||||
Log::channel('integracao-ria')->error('Erro ao executar o comando', [
|
||||
'cliente' => $cliente->link ?? $cliente,
|
||||
'origem' => 'EnviarDocumentoAlteradoCommand',
|
||||
'erro' => $error->getMessage(),
|
||||
]);
|
||||
|
||||
if (env('APP_ENV') === 'production') {
|
||||
TelegramService::send('<strong>Integração RIA (' . ($cliente->link ?? $cliente) . '):</strong> (Erro ao executar o comando: EnviarDocumentoAlteradoCommand).');
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
Config::set('database.default', $currentDatabase);
|
||||
} catch (Exception $error) {
|
||||
Log::channel('integracao-ria')->error('Erro ao executar o comando', [
|
||||
'origem' => 'EnviarDocumentoAlteradoCommand',
|
||||
'erro' => $error->getMessage(),
|
||||
]);
|
||||
|
||||
if (env('APP_ENV') === 'production') {
|
||||
TelegramService::send('<strong>Integração RIA:</strong> (Erro ao executar o comando: EnviarDocumentoAlteradoCommand).');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getClientes()
|
||||
{
|
||||
return collect(json_decode(file_get_contents(base_path('connections.json')), true))
|
||||
->filter(fn ($config) => isset($config['database']) && Str::startsWith($config['database'], 'conectasus'))
|
||||
->reject(fn ($config) => empty(DB::connection('schema')->select("SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = ?", [$config['database']])))
|
||||
->map(fn ($config, $customer) => $customer)
|
||||
->sort()
|
||||
->values();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Integracao\Ria;
|
||||
|
||||
use App\Enums\Intranet\Sistema;
|
||||
use App\Models\Intranet\Cliente;
|
||||
use App\Services\Integracao\RiaService;
|
||||
use App\Services\Integracao\Ria\DocumentoImunologicoRotinaService;
|
||||
use App\Services\Telegram\TelegramService;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class EnviarDocumentoComInconsistenciaCommand extends Command
|
||||
{
|
||||
protected $signature = 'integracao:ria-enviar-documento-com-inconsistencia';
|
||||
protected $description = 'Comando para envio de documentos com inconsistencia ao RIA.';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
try {
|
||||
$currentDatabase = Config::get('database.default');
|
||||
|
||||
self::getClientes()->each(function($cliente) {
|
||||
try {
|
||||
$cliente = Cliente::where('link', $cliente)
|
||||
->where('sistema_id', Sistema::CONECTASUS)
|
||||
->firstOrFail();
|
||||
|
||||
Config::set('database.default', $cliente->link);
|
||||
|
||||
$parametrizacao = RiaService::getParametrizacao();
|
||||
|
||||
if (!is_null($parametrizacao)) {
|
||||
$token = RiaService::getToken($cliente, $parametrizacao, $parametrizacao->senha);
|
||||
$expiresAt = Carbon::now()->addMilliseconds($token['expires_in'])->subMinutes(2);
|
||||
|
||||
DocumentoImunologicoRotinaService::getDocumentosComInconsistencia()
|
||||
->each(function($documentoComInconsistencia) use ($cliente, $parametrizacao, &$token, $expiresAt) {
|
||||
if (Carbon::now() >= $expiresAt) {
|
||||
$token = RiaService::getToken($parametrizacao->senha);
|
||||
}
|
||||
|
||||
$headers = [
|
||||
'Authorization' => $parametrizacao->cns_solicitante,
|
||||
'Content-Type' => 'application/json',
|
||||
'X-Authorization-Server' => "Bearer " . $token['access_token'],
|
||||
];
|
||||
|
||||
$documentoComInconsistencia->identificador_solicitante = $parametrizacao->identificador_solicitante;
|
||||
$documentoComInconsistencia->cns_solicitante = $parametrizacao->cns_solicitante;
|
||||
$documentoComInconsistencia->data_hora_envio = Carbon::now();
|
||||
|
||||
$response = RiaService::sendDocumentoImunologicoRotina($headers, $documentoComInconsistencia, $cliente->municipio->estado->uf);
|
||||
|
||||
$documentoComInconsistencia->identificador_rnds = $response->header('Location') ? $response->header('Location') : null;
|
||||
$documentoComInconsistencia->response = $response->json();
|
||||
|
||||
DocumentoImunologicoRotinaService::update($documentoComInconsistencia->documento_imunologico_rotina_id, $documentoComInconsistencia);
|
||||
});
|
||||
|
||||
Log::channel('integracao-ria')->info('Comando executado com sucesso.', [
|
||||
'cliente' => $cliente->link,
|
||||
'origem' => 'EnviarDocumentoComInconsistenciaCommand'
|
||||
]);
|
||||
}
|
||||
} catch (Exception $error) {
|
||||
Log::channel('integracao-ria')->error('Erro ao executar o comando', [
|
||||
'cliente' => $cliente->link ?? $cliente,
|
||||
'origem' => 'EnviarDocumentoComInconsistenciaCommand',
|
||||
'erro' => $error->getMessage(),
|
||||
]);
|
||||
|
||||
if (env('APP_ENV') === 'production') {
|
||||
TelegramService::send('<strong>Integração RIA (' . ($cliente->link ?? $cliente) . '):</strong> (Erro ao executar o comando: EnviarDocumentoComInconsistenciaCommand).');
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
Config::set('database.default', $currentDatabase);
|
||||
} catch (Exception $error) {
|
||||
Log::channel('integracao-ria')->error('Erro ao executar o comando', [
|
||||
'origem' => 'EnviarDocumentoComInconsistenciaCommand',
|
||||
'erro' => $error->getMessage(),
|
||||
]);
|
||||
|
||||
if (env('APP_ENV') === 'production') {
|
||||
TelegramService::send('<strong>Integração RIA:</strong> (Erro ao executar o comando: EnviarDocumentoComInconsistenciaCommand).');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getClientes()
|
||||
{
|
||||
return collect(json_decode(file_get_contents(base_path('connections.json')), true))
|
||||
->filter(fn ($config) => isset($config['database']) && Str::startsWith($config['database'], 'conectasus'))
|
||||
->reject(fn ($config) => empty(DB::connection('schema')->select("SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = ?", [$config['database']])))
|
||||
->map(fn ($config, $customer) => $customer)
|
||||
->sort()
|
||||
->values();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Integracao\Ria;
|
||||
|
||||
use App\Enums\Intranet\Sistema;
|
||||
use App\Models\Intranet\Cliente;
|
||||
use App\Services\Integracao\RiaService;
|
||||
use App\Services\Integracao\Ria\DocumentoImunologicoRotinaService;
|
||||
use App\Services\Telegram\TelegramService;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class EnviarDocumentoComInconsistenciaRetroativoCommand extends Command
|
||||
{
|
||||
protected $signature = 'integracao:ria-enviar-documento-com-inconsistencia-retroativo';
|
||||
protected $description = 'Comando para envio de documentos com inconsistencia retroativos ao RIA.';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
try {
|
||||
$currentDatabase = Config::get('database.default');
|
||||
|
||||
self::getClientes()->each(function($cliente) {
|
||||
try {
|
||||
$cliente = Cliente::where('link', $cliente)
|
||||
->where('sistema_id', Sistema::CONECTASUS)
|
||||
->firstOrFail();
|
||||
|
||||
Config::set('database.default', $cliente->link);
|
||||
|
||||
$parametrizacao = RiaService::getParametrizacao();
|
||||
|
||||
if (!is_null($parametrizacao)) {
|
||||
$token = RiaService::getToken($parametrizacao->senha);
|
||||
$expiresAt = Carbon::now()->addMilliseconds($token['expires_in'])->subMinutes(2);
|
||||
|
||||
DocumentoImunologicoRotinaService::getDocumentosComInconsistenciaRetroativos()
|
||||
->each(function($documentoComInconsistenciaRetroativo) use ($cliente, $parametrizacao, &$token, $expiresAt) {
|
||||
if (Carbon::now() >= $expiresAt) {
|
||||
$token = RiaService::getToken($parametrizacao->senha);
|
||||
}
|
||||
|
||||
$headers = [
|
||||
'Authorization' => $parametrizacao->cns_solicitante,
|
||||
'Content-Type' => 'application/json',
|
||||
'X-Authorization-Server' => "Bearer " . $token['access_token'],
|
||||
];
|
||||
|
||||
$documentoComInconsistenciaRetroativo->identificador_solicitante = $parametrizacao->identificador_solicitante;
|
||||
$documentoComInconsistenciaRetroativo->cns_solicitante = $parametrizacao->cns_solicitante;
|
||||
$documentoComInconsistenciaRetroativo->data_hora_envio = Carbon::now();
|
||||
|
||||
$response = RiaService::sendDocumentoImunologicoRotina($headers, $documentoComInconsistenciaRetroativo, $cliente->municipio->estado->uf);
|
||||
|
||||
$documentoComInconsistenciaRetroativo->identificador_rnds = $response->header('Location') ? $response->header('Location') : null;
|
||||
$documentoComInconsistenciaRetroativo->response = $response->json();
|
||||
|
||||
DocumentoImunologicoRotinaService::update($documentoComInconsistenciaRetroativo->documento_imunologico_rotina_id, $documentoComInconsistenciaRetroativo);
|
||||
});
|
||||
|
||||
Log::channel('integracao-ria')->info('Comando executado com sucesso.', [
|
||||
'cliente' => $cliente->link,
|
||||
'origem' => 'EnviarDocumentoComInconsistenciaRetroativoCommand'
|
||||
]);
|
||||
}
|
||||
} catch (Exception $error) {
|
||||
Log::channel('integracao-ria')->error('Erro ao executar o comando', [
|
||||
'cliente' => $cliente->link ?? $cliente,
|
||||
'origem' => 'EnviarDocumentoComInconsistenciaRetroativoCommand',
|
||||
'erro' => $error->getMessage(),
|
||||
]);
|
||||
|
||||
if (env('APP_ENV') === 'production') {
|
||||
TelegramService::send('<strong>Integração RIA (' . ($cliente->link ?? $cliente) . '):</strong> (Erro ao executar o comando: EnviarDocumentoComInconsistenciaRetroativoCommand).');
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
Config::set('database.default', $currentDatabase);
|
||||
} catch (Exception $error) {
|
||||
Log::channel('integracao-ria')->error('Erro ao executar o comando', [
|
||||
'origem' => 'EnviarDocumentoComInconsistenciaRetroativoCommand',
|
||||
'erro' => $error->getMessage(),
|
||||
]);
|
||||
|
||||
if (env('APP_ENV') === 'production') {
|
||||
TelegramService::send('<strong>Integração RIA:</strong> (Erro ao executar o comando: EnviarDocumentoComInconsistenciaRetroativoCommand).');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getClientes()
|
||||
{
|
||||
return collect(json_decode(file_get_contents(base_path('connections.json')), true))
|
||||
->filter(fn ($config) => isset($config['database']) && Str::startsWith($config['database'], 'conectasus'))
|
||||
->reject(fn ($config) => empty(DB::connection('schema')->select("SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = ?", [$config['database']])))
|
||||
->map(fn ($config, $customer) => $customer)
|
||||
->sort()
|
||||
->values();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Integracao\Ria;
|
||||
|
||||
use App\Enums\Intranet\Sistema;
|
||||
use App\Models\Integracao\Ria\DocumentoImunologicoRotina;
|
||||
use App\Models\Intranet\Cliente;
|
||||
use App\Services\Integracao\RiaService;
|
||||
use App\Services\Integracao\Ria\DocumentoImunologicoRotinaService;
|
||||
use App\Services\Telegram\TelegramService;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class EnviarExclusaoDocumentoCommand extends Command
|
||||
{
|
||||
protected $signature = 'integracao:ria-enviar-exclusao-documento';
|
||||
protected $description = 'Comando para envio de exclusão de documentos ao RIA.';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
try {
|
||||
$currentDatabase = Config::get('database.default');
|
||||
|
||||
self::getClientes()->each(function($cliente) {
|
||||
try {
|
||||
$cliente = Cliente::where('link', $cliente)
|
||||
->where('sistema_id', Sistema::CONECTASUS)
|
||||
->firstOrFail();
|
||||
|
||||
Config::set('database.default', $cliente->link);
|
||||
|
||||
$parametrizacao = RiaService::getParametrizacao();
|
||||
|
||||
if (!is_null($parametrizacao)) {
|
||||
$token = RiaService::getToken($parametrizacao->senha);
|
||||
$expiresAt = Carbon::now()->addMilliseconds($token['expires_in'])->subMinutes(2);
|
||||
|
||||
DocumentoImunologicoRotinaService::getDocumentosParaExclusao()
|
||||
->each(function($documento) use ($parametrizacao, &$token, $expiresAt) {
|
||||
if (!app()->environment('production') && !str_contains($documento->identificador_rnds, 'ehr-services-hmg.saude.gov.br')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Carbon::now() >= $expiresAt) {
|
||||
$token = RiaService::getToken($parametrizacao->senha);
|
||||
}
|
||||
|
||||
$headers = [
|
||||
'Authorization' => $parametrizacao->cns_solicitante,
|
||||
'Content-Type' => 'application/json',
|
||||
'X-Authorization-Server' => "Bearer " . $token['access_token'],
|
||||
];
|
||||
|
||||
$documento->identificador_solicitante = $parametrizacao->identificador_solicitante;
|
||||
$documento->cns_solicitante = $parametrizacao->cns_solicitante;
|
||||
$documento->data_hora_envio = Carbon::now();
|
||||
|
||||
$response = RiaService::destroy($headers, $documento->identificador_rnds);
|
||||
|
||||
if ($response->status() === 204) {
|
||||
DocumentoImunologicoRotina::destroy($documento->id);
|
||||
}
|
||||
else {
|
||||
$documento->response = $response->json();
|
||||
|
||||
DocumentoImunologicoRotinaService::update($documento->id, $documento);
|
||||
}
|
||||
});
|
||||
|
||||
Log::channel('integracao-ria')->info('Comando executado com sucesso.', [
|
||||
'cliente' => $cliente->link,
|
||||
'origem' => 'EnviarExclusaoDocumentoCommand',
|
||||
]);
|
||||
}
|
||||
} catch (Exception $error) {
|
||||
Log::channel('integracao-ria')->error('Erro ao executar o comando', [
|
||||
'cliente' => $cliente->link ?? $cliente,
|
||||
'origem' => 'EnviarExclusaoDocumentoCommand',
|
||||
'erro' => $error->getMessage(),
|
||||
]);
|
||||
|
||||
if (env('APP_ENV') === 'production') {
|
||||
TelegramService::send('<strong>Integração RIA (' . ($cliente->link ?? $cliente) . '):</strong> (Erro ao executar o comando: EnviarExclusaoDocumentoCommand).');
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
Config::set('database.default', $currentDatabase);
|
||||
} catch (Exception $error) {
|
||||
Log::channel('integracao-ria')->error('Erro ao executar o comando', [
|
||||
'origem' => 'EnviarExclusaoDocumentoCommand',
|
||||
'erro' => $error->getMessage(),
|
||||
]);
|
||||
|
||||
if (env('APP_ENV') === 'production') {
|
||||
TelegramService::send('<strong>Integração RIA:</strong> (Erro ao executar o comando: EnviarExclusaoDocumentoCommand).');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getClientes()
|
||||
{
|
||||
return collect(json_decode(file_get_contents(base_path('connections.json')), true))
|
||||
->filter(fn ($config) => isset($config['database']) && Str::startsWith($config['database'], 'conectasus'))
|
||||
->reject(fn ($config) => empty(DB::connection('schema')->select("SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = ?", [$config['database']])))
|
||||
->map(fn ($config, $customer) => $customer)
|
||||
->sort()
|
||||
->values();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Integracao\Ria;
|
||||
|
||||
use App\Enums\Intranet\Sistema;
|
||||
use App\Models\Intranet\Cliente;
|
||||
use App\Services\Integracao\RiaService;
|
||||
use App\Services\Integracao\Ria\DocumentoImunologicoRotinaService;
|
||||
use App\Services\Telegram\TelegramService;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class EnviarRegistroAplicacaoCommand extends Command
|
||||
{
|
||||
protected $signature = 'integracao:ria-enviar-registro-aplicacao';
|
||||
protected $description = 'Comando para envio de novos registros de aplicação ao RIA.';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
try {
|
||||
$currentDatabase = Config::get('database.default');
|
||||
|
||||
self::getClientes()->each(function($cliente) {
|
||||
try {
|
||||
$cliente = Cliente::where('link', $cliente)
|
||||
->where('sistema_id', Sistema::CONECTASUS)
|
||||
->firstOrFail();
|
||||
|
||||
Config::set('database.default', $cliente->link);
|
||||
|
||||
$parametrizacao = RiaService::getParametrizacao();
|
||||
|
||||
if (!is_null($parametrizacao)) {
|
||||
$token = RiaService::getToken($parametrizacao->senha);
|
||||
$expiresAt = Carbon::now()->addMilliseconds($token['expires_in'])->subMinutes(2);
|
||||
|
||||
DocumentoImunologicoRotinaService::getRegistrosAplicacao()
|
||||
->each(function($registroAplicacao) use ($cliente, $parametrizacao, &$token, $expiresAt) {
|
||||
if (Carbon::now() >= $expiresAt) {
|
||||
$token = RiaService::getToken($parametrizacao->senha);
|
||||
}
|
||||
|
||||
$headers = [
|
||||
'Authorization' => $parametrizacao->cns_solicitante,
|
||||
'Content-Type' => 'application/json',
|
||||
'X-Authorization-Server' => "Bearer " . $token['access_token'],
|
||||
];
|
||||
|
||||
$registroAplicacao->identificador_solicitante = $parametrizacao->identificador_solicitante;
|
||||
$registroAplicacao->cns_solicitante = $parametrizacao->cns_solicitante;
|
||||
$registroAplicacao->data_hora_envio = Carbon::now();
|
||||
|
||||
$response = RiaService::sendDocumentoImunologicoRotina($headers, $registroAplicacao, $cliente->municipio->estado->uf);
|
||||
|
||||
$registroAplicacao->identificador_rnds = $response->header('Location') ? $response->header('Location') : null;
|
||||
$registroAplicacao->response = $response->json();
|
||||
|
||||
DocumentoImunologicoRotinaService::store($registroAplicacao);
|
||||
});
|
||||
|
||||
Log::channel('integracao-ria')->info('Comando executado com sucesso.', [
|
||||
'cliente' => $cliente->link,
|
||||
'origem' => 'EnviarRegistroAplicacaoCommand',
|
||||
]);
|
||||
}
|
||||
} catch (Exception $error) {
|
||||
Log::channel('integracao-ria')->error('Erro ao executar o comando', [
|
||||
'cliente' => $cliente->link ?? $cliente,
|
||||
'origem' => 'EnviarRegistroAplicacaoCommand',
|
||||
'erro' => $error->getMessage(),
|
||||
]);
|
||||
|
||||
if (env('APP_ENV') === 'production') {
|
||||
TelegramService::send('<strong>Integração RIA (' . ($cliente->link ?? $cliente) . '):</strong> (Erro ao executar o comando: EnviarRegistroAplicacaoCommand).');
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
Config::set('database.default', $currentDatabase);
|
||||
} catch (Exception $error) {
|
||||
Log::channel('integracao-ria')->error('Erro ao executar o comando', [
|
||||
'origem' => 'EnviarRegistroAplicacaoCommand',
|
||||
'erro' => $error->getMessage(),
|
||||
]);
|
||||
|
||||
if (env('APP_ENV') === 'production') {
|
||||
TelegramService::send('<strong>Integração RIA:</strong> (Erro ao executar o comando: EnviarRegistroAplicacaoCommand).');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getClientes()
|
||||
{
|
||||
return collect(json_decode(file_get_contents(base_path('connections.json')), true))
|
||||
->filter(fn ($config) => isset($config['database']) && Str::startsWith($config['database'], 'conectasus'))
|
||||
->reject(fn ($config) => empty(DB::connection('schema')->select("SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = ?", [$config['database']])))
|
||||
->map(fn ($config, $customer) => $customer)
|
||||
->sort()
|
||||
->values();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Integracao\Ria;
|
||||
|
||||
use App\Enums\Intranet\Sistema;
|
||||
use App\Models\Intranet\Cliente;
|
||||
use App\Services\Integracao\RiaService;
|
||||
use App\Services\Integracao\Ria\DocumentoImunologicoRotinaService;
|
||||
use App\Services\Telegram\TelegramService;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class EnviarRegistroAplicacaoRetroativoCommand extends Command
|
||||
{
|
||||
protected $signature = 'integracao:ria-enviar-registro-aplicacao-retroativo';
|
||||
protected $description = 'Comando para envio de registros de aplicação retroativos ao RIA.';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
try {
|
||||
$currentDatabase = Config::get('database.default');
|
||||
|
||||
self::getClientes()->each(function($cliente) {
|
||||
try {
|
||||
$cliente = Cliente::where('link', $cliente)
|
||||
->where('sistema_id', Sistema::CONECTASUS)
|
||||
->firstOrFail();
|
||||
|
||||
Config::set('database.default', $cliente->link);
|
||||
|
||||
$parametrizacao = RiaService::getParametrizacao();
|
||||
|
||||
if (!is_null($parametrizacao)) {
|
||||
$token = RiaService::getToken($parametrizacao->senha);
|
||||
$expiresAt = Carbon::now()->addMilliseconds($token['expires_in'])->subMinutes(2);
|
||||
|
||||
DocumentoImunologicoRotinaService::getRegistrosAplicacaoRetroativos()
|
||||
->each(function($registroAplicacaoRetroativo) use ($cliente, $parametrizacao, &$token, $expiresAt) {
|
||||
if (Carbon::now() >= $expiresAt) {
|
||||
$token = RiaService::getToken($parametrizacao->senha);
|
||||
}
|
||||
|
||||
$headers = [
|
||||
'Authorization' => $parametrizacao->cns_solicitante,
|
||||
'Content-Type' => 'application/json',
|
||||
'X-Authorization-Server' => "Bearer " . $token['access_token'],
|
||||
];
|
||||
|
||||
$registroAplicacaoRetroativo->identificador_solicitante = $parametrizacao->identificador_solicitante;
|
||||
$registroAplicacaoRetroativo->cns_solicitante = $parametrizacao->cns_solicitante;
|
||||
$registroAplicacaoRetroativo->data_hora_envio = Carbon::now();
|
||||
|
||||
$response = RiaService::sendDocumentoImunologicoRotina($headers, $registroAplicacaoRetroativo, $cliente->municipio->estado->uf);
|
||||
|
||||
$registroAplicacaoRetroativo->identificador_rnds = $response->header('Location') ? $response->header('Location') : null;
|
||||
$registroAplicacaoRetroativo->response = $response->json();
|
||||
|
||||
DocumentoImunologicoRotinaService::store($registroAplicacaoRetroativo);
|
||||
});
|
||||
|
||||
Log::channel('integracao-ria')->info('Comando executado com sucesso.', [
|
||||
'cliente' => $cliente->link,
|
||||
'origem' => 'EnviarRegistroAplicacaoRetroativoCommand'
|
||||
]);
|
||||
}
|
||||
} catch (Exception $error) {
|
||||
Log::channel('integracao-ria')->error('Erro ao executar o comando', [
|
||||
'cliente' => $cliente->link ?? $cliente,
|
||||
'origem' => 'EnviarRegistroAplicacaoRetroativoCommand',
|
||||
'erro' => $error->getMessage(),
|
||||
]);
|
||||
|
||||
if (env('APP_ENV') === 'production') {
|
||||
TelegramService::send('<strong>Integração RIA (' . ($cliente->link ?? $cliente) . '):</strong> (Erro ao executar o comando: EnviarRegistroAplicacaoRetroativoCommand).');
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
Config::set('database.default', $currentDatabase);
|
||||
} catch (Exception $error) {
|
||||
Log::channel('integracao-ria')->error('Erro ao executar o comando', [
|
||||
'origem' => 'EnviarRegistroAplicacaoRetroativoCommand',
|
||||
'erro' => $error->getMessage(),
|
||||
]);
|
||||
|
||||
if (env('APP_ENV') === 'production') {
|
||||
TelegramService::send('<strong>Integração RIA:</strong> (Erro ao executar o comando: EnviarRegistroAplicacaoRetroativoCommand).');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getClientes()
|
||||
{
|
||||
return collect(json_decode(file_get_contents(base_path('connections.json')), true))
|
||||
->filter(fn ($config) => isset($config['database']) && Str::startsWith($config['database'], 'conectasus'))
|
||||
->reject(fn ($config) => empty(DB::connection('schema')->select("SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = ?", [$config['database']])))
|
||||
->map(fn ($config, $customer) => $customer)
|
||||
->sort()
|
||||
->values();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Integracao\Ria;
|
||||
|
||||
use App\Enums\Intranet\Sistema;
|
||||
use App\Models\Intranet\Cliente;
|
||||
use App\Services\Integracao\RiaService;
|
||||
use App\Services\Integracao\Ria\DocumentoImunologicoRotinaService;
|
||||
use App\Services\Telegram\TelegramService;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class EnviarRegistroAtualizacaoCommand extends Command
|
||||
{
|
||||
protected $signature = 'integracao:ria-enviar-registro-atualizacao';
|
||||
protected $description = 'Comando para envio de novos registros de atulaização ao RIA.';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
try {
|
||||
$currentDatabase = Config::get('database.default');
|
||||
|
||||
self::getClientes()->each(function($cliente) {
|
||||
try {
|
||||
$cliente = Cliente::where('link', $cliente)
|
||||
->where('sistema_id', Sistema::CONECTASUS)
|
||||
->firstOrFail();
|
||||
|
||||
Config::set('database.default', $cliente->link);
|
||||
|
||||
$parametrizacao = RiaService::getParametrizacao();
|
||||
|
||||
if (!is_null($parametrizacao)) {
|
||||
$token = RiaService::getToken($parametrizacao->senha);
|
||||
$expiresAt = Carbon::now()->addMilliseconds($token['expires_in'])->subMinutes(2);
|
||||
|
||||
DocumentoImunologicoRotinaService::getRegistrosAtualizacao()
|
||||
->each(function($registroAtualizacao) use ($cliente, $parametrizacao, &$token, $expiresAt) {
|
||||
if (Carbon::now() >= $expiresAt) {
|
||||
$token = RiaService::getToken($parametrizacao->senha);
|
||||
}
|
||||
|
||||
$headers = [
|
||||
'Authorization' => $parametrizacao->cns_solicitante,
|
||||
'Content-Type' => 'application/json',
|
||||
'X-Authorization-Server' => "Bearer " . $token['access_token'],
|
||||
];
|
||||
|
||||
$registroAtualizacao->identificador_solicitante = $parametrizacao->identificador_solicitante;
|
||||
$registroAtualizacao->cns_solicitante = $parametrizacao->cns_solicitante;
|
||||
$registroAtualizacao->data_hora_envio = Carbon::now();
|
||||
|
||||
$response = RiaService::sendDocumentoImunologicoRotina($headers, $registroAtualizacao, $cliente->municipio->estado->uf);
|
||||
|
||||
$registroAtualizacao->identificador_rnds = $response->header('Location') ? $response->header('Location') : null;
|
||||
$registroAtualizacao->response = $response->json();
|
||||
|
||||
DocumentoImunologicoRotinaService::store($registroAtualizacao);
|
||||
});
|
||||
|
||||
Log::channel('integracao-ria')->info('Comando executado com sucesso.', [
|
||||
'cliente' => $cliente->link,
|
||||
'origem' => 'EnviarRegistroAtualizacaoCommand',
|
||||
]);
|
||||
}
|
||||
} catch (Exception $error) {
|
||||
Log::channel('integracao-ria')->error('Erro ao executar o comando', [
|
||||
'cliente' => $cliente->link ?? $cliente,
|
||||
'origem' => 'EnviarRegistroAtualizacaoCommand',
|
||||
'erro' => $error->getMessage(),
|
||||
]);
|
||||
|
||||
if (env('APP_ENV') === 'production') {
|
||||
TelegramService::send('<strong>Integração RIA (' . ($cliente->link ?? $cliente) . '):</strong> (Erro ao executar o comando: EnviarRegistroAtualizacaoCommand).');
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
Config::set('database.default', $currentDatabase);
|
||||
} catch (Exception $error) {
|
||||
Log::channel('integracao-ria')->error('Erro ao executar o comando', [
|
||||
'origem' => 'EnviarRegistroAtualizacaoCommand',
|
||||
'erro' => $error->getMessage(),
|
||||
]);
|
||||
|
||||
if (env('APP_ENV') === 'production') {
|
||||
TelegramService::send('<strong>Integração RIA:</strong> (Erro ao executar o comando: EnviarRegistroAtualizacaoCommand).');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getClientes()
|
||||
{
|
||||
return collect(json_decode(file_get_contents(base_path('connections.json')), true))
|
||||
->filter(fn ($config) => isset($config['database']) && Str::startsWith($config['database'], 'conectasus'))
|
||||
->reject(fn ($config) => empty(DB::connection('schema')->select("SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = ?", [$config['database']])))
|
||||
->map(fn ($config, $customer) => $customer)
|
||||
->sort()
|
||||
->values();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Integracao\Ria;
|
||||
|
||||
use App\Enums\Intranet\Sistema;
|
||||
use App\Models\Intranet\Cliente;
|
||||
use App\Services\Integracao\RiaService;
|
||||
use App\Services\Integracao\Ria\DocumentoImunologicoRotinaService;
|
||||
use App\Services\Telegram\TelegramService;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class EnviarRegistroAtualizacaoRetroativoCommand extends Command
|
||||
{
|
||||
protected $signature = 'integracao:ria-enviar-registro-atualizacao-retroativo';
|
||||
protected $description = 'Comando para envio de registros de atualização retroativos ao RIA.';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
try {
|
||||
$currentDatabase = Config::get('database.default');
|
||||
|
||||
self::getClientes()->each(function($cliente) {
|
||||
try {
|
||||
$cliente = Cliente::where('link', $cliente)
|
||||
->where('sistema_id', Sistema::CONECTASUS)
|
||||
->firstOrFail();
|
||||
|
||||
Config::set('database.default', $cliente->link);
|
||||
|
||||
$parametrizacao = RiaService::getParametrizacao();
|
||||
|
||||
if (!is_null($parametrizacao)) {
|
||||
$token = RiaService::getToken($parametrizacao->senha);
|
||||
$expiresAt = Carbon::now()->addMilliseconds($token['expires_in'])->subMinutes(2);
|
||||
|
||||
DocumentoImunologicoRotinaService::getRegistrosAtualizacaoRetroativos()
|
||||
->each(function($registroAtualizacaoRetroativo) use ($cliente, $parametrizacao, &$token, $expiresAt) {
|
||||
if (Carbon::now() >= $expiresAt) {
|
||||
$token = RiaService::getToken($parametrizacao->senha);
|
||||
}
|
||||
|
||||
$headers = [
|
||||
'Authorization' => $parametrizacao->cns_solicitante,
|
||||
'Content-Type' => 'application/json',
|
||||
'X-Authorization-Server' => "Bearer " . $token['access_token'],
|
||||
];
|
||||
|
||||
$registroAtualizacaoRetroativo->identificador_solicitante = $parametrizacao->identificador_solicitante;
|
||||
$registroAtualizacaoRetroativo->cns_solicitante = $parametrizacao->cns_solicitante;
|
||||
$registroAtualizacaoRetroativo->data_hora_envio = Carbon::now();
|
||||
|
||||
$response = RiaService::sendDocumentoImunologicoRotina($headers, $registroAtualizacaoRetroativo, $cliente->municipio->estado->uf);
|
||||
|
||||
$registroAtualizacaoRetroativo->identificador_rnds = $response->header('Location') ? $response->header('Location') : null;
|
||||
$registroAtualizacaoRetroativo->response = $response->json();
|
||||
|
||||
DocumentoImunologicoRotinaService::store($registroAtualizacaoRetroativo);
|
||||
});
|
||||
|
||||
Log::channel('integracao-ria')->info('Comando executado com sucesso.', [
|
||||
'cliente' => $cliente->link,
|
||||
'origem' => 'EnviarRegistroAtualizacaoRetroativoCommand'
|
||||
]);
|
||||
}
|
||||
} catch (Exception $error) {
|
||||
Log::channel('integracao-ria')->error('Erro ao executar o comando', [
|
||||
'cliente' => $cliente->link ?? $cliente,
|
||||
'origem' => 'EnviarRegistroAtualizacaoRetroativoCommand',
|
||||
'erro' => $error->getMessage(),
|
||||
]);
|
||||
|
||||
if (env('APP_ENV') === 'production') {
|
||||
TelegramService::send('<strong>Integração RIA (' . ($cliente->link ?? $cliente) . '):</strong> (Erro ao executar o comando: EnviarRegistroAtualizacaoRetroativoCommand).');
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
Config::set('database.default', $currentDatabase);
|
||||
} catch (Exception $error) {
|
||||
Log::channel('integracao-ria')->error('Erro ao executar o comando', [
|
||||
'origem' => 'EnviarRegistroAtualizacaoRetroativoCommand',
|
||||
'erro' => $error->getMessage(),
|
||||
]);
|
||||
|
||||
if (env('APP_ENV') === 'production') {
|
||||
TelegramService::send('<strong>Integração RIA:</strong> (Erro ao executar o comando: EnviarRegistroAtualizacaoRetroativoCommand).');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getClientes()
|
||||
{
|
||||
return collect(json_decode(file_get_contents(base_path('connections.json')), true))
|
||||
->filter(fn ($config) => isset($config['database']) && Str::startsWith($config['database'], 'conectasus'))
|
||||
->reject(fn ($config) => empty(DB::connection('schema')->select("SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = ?", [$config['database']])))
|
||||
->map(fn ($config, $customer) => $customer)
|
||||
->sort()
|
||||
->values();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user