This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\TransportePaciente;
|
||||
|
||||
use App\Enums\TransportePaciente\Status;
|
||||
use App\Models\Intranet\Cliente;
|
||||
use App\Models\TransportePaciente\Parametrizacao\Parametrizacao;
|
||||
use App\Models\TransportePaciente\Ponto\Ponto;
|
||||
use App\Services\Service;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ReimpressaoProtocoloService extends Service
|
||||
{
|
||||
public static function index()
|
||||
{
|
||||
$parametrizacao = Parametrizacao::first();
|
||||
$cliente = Cliente::where('link', app('config')->get('database.default'))->firstOrFail();
|
||||
$currentLotacao = self::getCurrentLotacao();
|
||||
|
||||
return [
|
||||
'model' => [
|
||||
'prontuario' => null,
|
||||
'nome' => null,
|
||||
'nascimento' => null,
|
||||
],
|
||||
'form' => [
|
||||
'mensagem_protocolo' => $parametrizacao->mensagem_protocolo ?? null,
|
||||
'cliente' => [
|
||||
'sistema' => [
|
||||
'ramo_atividade' => [
|
||||
'nome' => $cliente->sistema->ramoAtividade->nome ?? null,
|
||||
],
|
||||
'nome' => $cliente->sistema->nome ?? null,
|
||||
'versao' => $cliente->sistema->versao ?? null,
|
||||
],
|
||||
'municipio' => [
|
||||
'estado' => [
|
||||
'uf' => $cliente->municipio->estado->uf ?? null,
|
||||
],
|
||||
'nome' => $cliente->municipio->nome ?? null,
|
||||
],
|
||||
'nome' => $cliente->nome ?? null,
|
||||
'email' => $cliente->email ?? null,
|
||||
'site' => $cliente->site ?? null,
|
||||
'logotipo' => $cliente->logotipo ?? null,
|
||||
],
|
||||
'usuario' => $currentLotacao->usuario->cidadao->nome,
|
||||
'pontos' => self::getPontos(),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public static function search()
|
||||
{
|
||||
return DB::table('transporte_paciente_agendar_transporte as agenda')
|
||||
->select(
|
||||
'agenda.id',
|
||||
'agenda.data as data_consulta',
|
||||
'cidadao.nome as nome',
|
||||
'cidadao.nome_social',
|
||||
'cidadao.data_nascimento',
|
||||
DB::raw('LPAD(paciente.prontuario, 6, 0) as prontuario'),
|
||||
'municipio.nome as municipio',
|
||||
'destino.descricao_destino as destino',
|
||||
'agenda.acompanhante',
|
||||
'agenda.data_saida',
|
||||
'agenda.horario_saida',
|
||||
'agenda.ponto_id',
|
||||
'agenda.observacao',
|
||||
'motivo.descricao as motivo',
|
||||
'ponto.descricao as ponto',
|
||||
'infraestrutura.telefone as infraestrutura_telefone',
|
||||
DB::raw('CONCAT(veiculo.numero_placa, " - ", veiculo.descricao_modelo) as veiculo'),
|
||||
DB::raw("
|
||||
(
|
||||
SELECT GROUP_CONCAT(cadastro_cidadao_telefone.numero SEPARATOR ', ')
|
||||
FROM cadastro_cidadao_telefone
|
||||
WHERE cadastro_cidadao_telefone.cidadao_id = cidadao.id
|
||||
AND cadastro_cidadao_telefone.deleted_at IS NULL
|
||||
) AS telefone_paciente
|
||||
"),
|
||||
)
|
||||
->leftJoin('cadastro_paciente as paciente', 'agenda.paciente_id', 'paciente.id')
|
||||
->leftJoin('cadastro_cidadao as cidadao', 'paciente.cidadao_id', 'cidadao.id')
|
||||
->leftJoin('transporte_paciente_motivo_viagem_procedimento as motivo', 'agenda.motivo_id', 'motivo.id')
|
||||
->leftJoin('transporte_paciente_ponto as ponto','agenda.ponto_id', 'ponto.id')
|
||||
->leftJoin('transporte_paciente_veiculo as veiculo', 'agenda.veiculo_id', 'veiculo.id')
|
||||
->leftJoin('transporte_paciente_destino as destino', 'agenda.destino_id', 'destino.id')
|
||||
->leftJoin('intranet.cadastro_municipio as municipio', 'destino.municipio_id', 'municipio.id')
|
||||
->leftJoin('cadastro_lotacao as lotacao', 'agenda.created_lotacao_id', 'lotacao.id')
|
||||
->leftJoin('cadastro_infraestrutura as infraestrutura', 'lotacao.infraestrutura_id', 'infraestrutura.id')
|
||||
->when(request()->prontuario, function($query){
|
||||
$query->where('paciente.prontuario', request()->prontuario);
|
||||
})
|
||||
->when(request()->nome, function($query){
|
||||
$query->where('cidadao.nome', 'like', request()->nome . '%');
|
||||
})
|
||||
->when(request()->nascimento, function($query){
|
||||
$query->where('cidadao.data_nascimento', request()->nascimento);
|
||||
})
|
||||
->whereIn('agenda.status_id', [Status::AGENDADO, Status::MODIFICADO])
|
||||
->orderBy('agenda.data')
|
||||
->get();
|
||||
}
|
||||
|
||||
public static function getPontos()
|
||||
{
|
||||
return Ponto::select([
|
||||
'id',
|
||||
DB::raw('COALESCE(descricao, "CASA DO PACIENTE") AS descricao'),
|
||||
])
|
||||
->orderBy('descricao')
|
||||
->get();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user