This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Impressao\Ambulatorio;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Paciente;
|
||||
use App\Services\Ambulatorio\AgendamentoService;
|
||||
use App\Utils\Exports\Pdf1;
|
||||
use App\Utils\MaskUtil;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class AgendamentoDemandaEspontaneaController extends Controller
|
||||
{
|
||||
private const TITLE = 'AGENDAMENTOS E DEMANDAS';
|
||||
private const TEMPLATE = 'ambulatorio.agendamento-demanda-espontanea';
|
||||
|
||||
public static function getTemplate()
|
||||
{
|
||||
$params = (object) request()->all();
|
||||
|
||||
$paciente = Paciente::findOrFail($params->paciente_id);
|
||||
$municipioResidencia = $paciente->cidadao->domicilio->endereco->logradouro->municipio ?? null;
|
||||
|
||||
$agendamentosDemandas = AgendamentoService::getAgendamentosDemandasEspontaneas($params);
|
||||
$itens = $agendamentosDemandas['itens'];
|
||||
|
||||
$itens->each(function ($item) {
|
||||
$item->data = Carbon::create($item->data)->format('d/m/Y');
|
||||
});
|
||||
|
||||
return [
|
||||
'paciente' => [
|
||||
'nome' => $paciente->cidadao->nome,
|
||||
'nome_social' => $paciente->cidadao->nome_social,
|
||||
'data_nascimento' => is_null($paciente->cidadao->data_nascimento)
|
||||
? null
|
||||
: (new Carbon($paciente->cidadao->data_nascimento))->format('d/m/Y'),
|
||||
'idade' => $paciente->cidadao->idade_formatada,
|
||||
'nome_mae' => $paciente->cidadao->nome_mae,
|
||||
'prontuario' => $paciente->prontuario,
|
||||
'cpf' => MaskUtil::getCpfMasked($paciente->cidadao->cpf),
|
||||
'cns' => MaskUtil::getCnsMasked($paciente->cidadao->cns),
|
||||
'municipio_uf' => is_null($municipioResidencia)
|
||||
? null
|
||||
: "{$municipioResidencia->nome} / {$municipioResidencia->estado->uf}",
|
||||
'telefone' => MaskUtil::getPhoneMasked($paciente->cidadao->telefone_principal->numero ?? null),
|
||||
'unidade_referencia' => $paciente->unidade->nome_fantasia ?? null,
|
||||
'classificacao' => $paciente->classificacao->descricao ?? null,
|
||||
'validade_fim' => is_null($paciente->validade_fim)
|
||||
? 'INDETERMINADO'
|
||||
: (new Carbon($paciente->validade_fim))->format('d/m/Y')
|
||||
],
|
||||
'inicio' => request()->periodo['start'],
|
||||
'fim' => request()->periodo['end'],
|
||||
'origem' => request()->origem === 'consulta-agendada'
|
||||
? 'Consulta agendada'
|
||||
: (request()->origem === 'demanda-espontanea' ? 'Demanda espontânea' : 'Todas'),
|
||||
'colunas' => request()->columns,
|
||||
'itens' => $itens,
|
||||
'totalizadores' => $agendamentosDemandas['totalizadores'],
|
||||
];
|
||||
}
|
||||
|
||||
public function __invoke()
|
||||
{
|
||||
return Pdf1::generate(self::TITLE, self::TEMPLATE, self::getTemplate());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user