92 lines
3.8 KiB
PHP
92 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Impressao\ProntoAtendimento\AtendimentoMedico;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\ProntoAtendimento\Atendimento\Atendimento;
|
|
use App\Models\ProntoAtendimento\Atendimento\ServicoEnfermagem;
|
|
use App\Utils\Exports\Pdf;
|
|
use App\Utils\Exports\Template;
|
|
use App\Utils\MaskUtil;
|
|
|
|
|
|
class ServicoEnfermagemController extends Controller
|
|
{
|
|
private const TITLE = 'Solicitação de Serviços de Enfermagem';
|
|
private const TEMPLATE = 'pronto-atendimento.atendimento-medico.servicos-enfermagem';
|
|
|
|
public function __invoke(int $atendimentoId)
|
|
{
|
|
return (new Pdf)->stream(self::getTemplate($atendimentoId), 'servicos-enfermagem');
|
|
}
|
|
|
|
public static function getTemplate(int $atendimentoId)
|
|
{
|
|
$servicosEnfermagem = ServicoEnfermagem::whereHas('atendimentoMedico', function ($query) use ($atendimentoId) {
|
|
|
|
$query->where('atendimento_id', $atendimentoId);
|
|
})
|
|
->orWhereHas('atendimentoEnfermagem', function ($query) use ($atendimentoId) {
|
|
|
|
$query->where('atendimento_id', $atendimentoId);
|
|
})
|
|
->orWhereHas('pacienteObservacao', function ($query) use ($atendimentoId) {
|
|
|
|
$query->where('atendimento_id', $atendimentoId);
|
|
})
|
|
->get();
|
|
|
|
$data['paciente'] = self::getPacienteData(Atendimento::findOrFail($atendimentoId));
|
|
$data['servicosEnfermagem'] = [];
|
|
|
|
foreach ($servicosEnfermagem as $servicoEnfermagem) {
|
|
$data['servicosEnfermagem'][] = [
|
|
'data' => $servicoEnfermagem->created_at->format('d/m/Y H:i:s'),
|
|
'medico' => [
|
|
'nome' => $servicoEnfermagem->updatedLotacao->usuario->cidadao->nome,
|
|
'cbo' => $servicoEnfermagem->updatedLotacao->ocupacao->nome,
|
|
],
|
|
'procedimentos' => [
|
|
'nome' => $servicoEnfermagem->procedimento->nome,
|
|
'codigo' => MaskUtil::getProcedimentoMasked($servicoEnfermagem->procedimento->codigo),
|
|
],
|
|
];
|
|
}
|
|
|
|
return Template::make(self::TITLE, self::TEMPLATE)->withData($data)->getHtml();
|
|
}
|
|
|
|
private static function getPacienteData($atendimento)
|
|
{
|
|
$paciente = $atendimento->faa->paciente;
|
|
$cidadao = $paciente->cidadao;
|
|
$gestacao = $atendimento->gestacoes->sortByDesc('created_at')->first();
|
|
|
|
return [
|
|
'nome' => $cidadao->nome,
|
|
'nome_social' => $cidadao->nome_social,
|
|
'prontuario' => $paciente->prontuario,
|
|
'cns' => $cidadao->cns ? MaskUtil::getCnsMasked($cidadao->cns) : 'NÃO INFORMADO',
|
|
'cpf' => $cidadao->cpf ? MaskUtil::getCpfMasked($cidadao->cpf) : 'NÃO INFORMADO',
|
|
'sexo' => $cidadao->sexo->descricao,
|
|
'data_nascimento' => $cidadao->data_nascimento
|
|
? $cidadao->data_nascimento->format('d/m/Y')
|
|
: 'NÃO INFORMADA',
|
|
'idade' => $cidadao->data_nascimento
|
|
? "{$cidadao->idade['anos']} ano(s), "
|
|
. "{$cidadao->idade['meses']} mês(es) e "
|
|
. "{$cidadao->idade['dias']} dia(s) "
|
|
: 'NÃO INFORMADA',
|
|
'idade_gestacional' => $gestacao && $gestacao->idade_gestacional
|
|
? "{$gestacao->idade_gestacional['semanas']} semana(s) e {$gestacao->idade_gestacional['dias']} dia(s)"
|
|
: null,
|
|
'nome_mae' => $cidadao->nome_mae ?? 'NÃO INFORMADO',
|
|
'endereco' => $cidadao->domicilio
|
|
? "{$cidadao->domicilio->endereco->completo}, "
|
|
. MaskUtil::getCepMasked($cidadao->domicilio->endereco->logradouro->cep)
|
|
: 'NÃO INFORMADO',
|
|
'telefones' => $cidadao->telefones->map(fn ($t) => MaskUtil::getPhoneMasked($t->numero))->all(),
|
|
];
|
|
}
|
|
}
|