This commit is contained in:
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Impressao\ProntoAtendimento\AtendimentoMedico;
|
||||
|
||||
use App\Enums\Cadastro\SujeitoAtencao\PreferenciaNome;
|
||||
use App\Enums\ProntoAtendimento\Atendimento\Medico\AtestadoModelo;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Lotacao;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Paciente;
|
||||
use App\Models\Geral\DocumentoTipo;
|
||||
use App\Models\ProntoAtendimento\Atendimento\Medico\AtendimentoMedico;
|
||||
use App\Models\ProntoAtendimento\Atendimento\Recepcao;
|
||||
use App\Models\Sigtap\Cid;
|
||||
use App\Utils\DataUtil;
|
||||
use App\Utils\Exports\Pdf;
|
||||
use App\Utils\Exports\Template;
|
||||
use App\Utils\MaskUtil;
|
||||
use App\Utils\NumericUtil;
|
||||
use DateTime;
|
||||
|
||||
class AtestadoAcompanhanteController extends Controller
|
||||
{
|
||||
private const TITLE = 'Atestado Acompanhante';
|
||||
private const TEMPLATE = 'pronto-atendimento.atendimento-medico.atestado-acompanhante';
|
||||
|
||||
public static function getTemplate($atendimentoId = null)
|
||||
{
|
||||
if ($atendimentoId) {
|
||||
|
||||
$atendimentoMedico = AtendimentoMedico::orderByDesc('created_at')
|
||||
->where('atendimento_id', $atendimentoId)
|
||||
->has('atestado')
|
||||
->firstOrFail();
|
||||
|
||||
$recepcao = Recepcao::orderByDesc('atendido_em')
|
||||
->where('atendimento_id', $atendimentoId)
|
||||
->firstOrFail();
|
||||
|
||||
$atestado = $atendimentoMedico->atestado;
|
||||
$paciente = $atendimentoMedico->atendimento->faa->paciente;
|
||||
$atendido_em = new DateTime($recepcao->atendido_em);
|
||||
|
||||
$data = [
|
||||
'paciente' => [
|
||||
'nome' => $paciente->cidadao->nome,
|
||||
'cpf' => MaskUtil::getDocumentMasked(1, $paciente->cidadao->cpf),
|
||||
'nomeSocial' => $paciente->cidadao->nome_social,
|
||||
'prefereNomeSocial' => $paciente->cidadao->preferencia_nome_id === PreferenciaNome::NOME_SOCIAL,
|
||||
],
|
||||
'nomeAcompanhante' => $atestado->nome_acompanhante,
|
||||
'documento' => [
|
||||
'tipo' => $atestado->documentoTipo->nome,
|
||||
'numero' => MaskUtil::getDocumentMasked($atestado->documento_tipo_id, $atestado->documento_numero),
|
||||
],
|
||||
'unidade' => [
|
||||
'nome' => $atestado->updatedLotacao->infraestrutura->unidade->nome_fantasia,
|
||||
],
|
||||
'data' => $atendido_em->format('d/m/Y'),
|
||||
'hora' => $atendido_em->format('H:i:s'),
|
||||
'cid' => $atestado->imprime_cid ? $atendimentoMedico->cid->cid->codigo : '',
|
||||
'afastamento_texto' => self::getAfastamentoTexto(
|
||||
$atestado->modelo_id ?? AtestadoModelo::PADRAO,
|
||||
$atestado->dias,
|
||||
$atestado->quantidade_horas,
|
||||
$atestado->horario_inicial,
|
||||
),
|
||||
'profissional' => [
|
||||
'nome' => $atestado->updatedLotacao->usuario->cidadao->nome,
|
||||
'cbo' => $atestado->updatedLotacao->ocupacao->nome,
|
||||
]
|
||||
];
|
||||
}
|
||||
else {
|
||||
|
||||
$paciente = Paciente::findOrFail(request()->paciente_id);
|
||||
$documentoTipo = DocumentoTipo::findOrFail(request()->documento_tipo_id);
|
||||
$lotacao = Lotacao::findOrFail(auth()->payload()->get('lotacao_id'));
|
||||
$atendido_em = new DateTime(request()->atendido_em);
|
||||
|
||||
$data = [
|
||||
'paciente' => [
|
||||
'nome' => $paciente->cidadao->nome,
|
||||
'cpf' => MaskUtil::getDocumentMasked(1, $paciente->cidadao->cpf),
|
||||
'nomeSocial' => $paciente->cidadao->nome_social,
|
||||
'prefereNomeSocial' => $paciente->cidadao->preferencia_nome_id === PreferenciaNome::NOME_SOCIAL,
|
||||
],
|
||||
'nomeAcompanhante' => request()->nome,
|
||||
'documento' => [
|
||||
'tipo' => $documentoTipo->nome,
|
||||
'numero' => MaskUtil::getDocumentMasked($documentoTipo->id, request()->documento_numero),
|
||||
],
|
||||
'unidade' => [
|
||||
'nome' => $lotacao->infraestrutura->unidade->nome_fantasia,
|
||||
],
|
||||
'data' => $atendido_em->format('d/m/Y'),
|
||||
'hora' => $atendido_em->format('H:i:s'),
|
||||
'cid' => DataUtil::isStringTrue(request()->imprime_cid) && request()->cid_id
|
||||
? Cid::findOrFail(request()->cid_id)->codigo : '',
|
||||
'afastamento_texto' => self::getAfastamentoTexto(
|
||||
request()->modelo_id ?? AtestadoModelo::PADRAO,
|
||||
request()->dias,
|
||||
request()->quantidade_horas,
|
||||
request()->horario_inicial,
|
||||
),
|
||||
'profissional' => [
|
||||
'nome' => $lotacao->usuario->cidadao->nome,
|
||||
'cbo' => $lotacao->ocupacao->nome,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
return Template::make(self::TITLE, self::TEMPLATE)->withData($data)->getHtml();
|
||||
}
|
||||
|
||||
private static function getAfastamentoTexto($modeloId, $dias, $quantidadeHoras, $horarioInicial)
|
||||
{
|
||||
switch ((int) $modeloId) {
|
||||
case AtestadoModelo::PERIODO_MANHA:
|
||||
return 'Em decorrencia, devera permanecer em afastamento de suas atividades laborativas no periodo da manha.';
|
||||
case AtestadoModelo::PERIODO_TARDE:
|
||||
return 'Em decorrencia, devera permanecer em afastamento de suas atividades laborativas no periodo da tarde.';
|
||||
case AtestadoModelo::PERIODO_NOITE:
|
||||
return 'Em decorrencia, devera permanecer em afastamento de suas atividades laborativas no periodo da noite.';
|
||||
case AtestadoModelo::QUANTIDADE_HORAS:
|
||||
if (is_null($quantidadeHoras) || is_null($horarioInicial)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$horario = (new DateTime($horarioInicial))->format('H:i');
|
||||
$horasPorExtenso = NumericUtil::getPorExtenso($quantidadeHoras);
|
||||
|
||||
return "Em decorrencia, devera permanecer em afastamento de suas atividades laborativas por um periodo de {$quantidadeHoras} ({$horasPorExtenso}) hora(s), a partir das {$horario} hora(s).";
|
||||
default:
|
||||
if (is_null($dias)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$diasPorExtenso = NumericUtil::getPorExtenso($dias);
|
||||
$sufixoDia = (int) $dias > 1 ? 's' : '';
|
||||
|
||||
return "Em decorrencia, devera permanecer em afastamento de suas atividades laborativas por um periodo de {$dias} ({$diasPorExtenso}) dia{$sufixoDia} a partir desta data.";
|
||||
}
|
||||
}
|
||||
|
||||
public function __invoke($atendimentoId = null)
|
||||
{
|
||||
return (new Pdf)->stream(self::getTemplate($atendimentoId), 'atestado');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Impressao\ProntoAtendimento\AtendimentoMedico;
|
||||
|
||||
use App\Enums\Cadastro\SujeitoAtencao\PreferenciaNome;
|
||||
use App\Enums\ProntoAtendimento\Atendimento\Medico\AtestadoModelo;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Lotacao;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Paciente;
|
||||
use App\Models\Geral\DocumentoTipo;
|
||||
use App\Models\ProntoAtendimento\Atendimento\Medico\AtendimentoMedico;
|
||||
use App\Models\ProntoAtendimento\Atendimento\Recepcao;
|
||||
use App\Models\Sigtap\Cid;
|
||||
use App\Utils\DataUtil;
|
||||
use App\Utils\Exports\Pdf;
|
||||
use App\Utils\Exports\Template;
|
||||
use App\Utils\MaskUtil;
|
||||
use App\Utils\NumericUtil;
|
||||
use DateTime;
|
||||
|
||||
class AtestadoController extends Controller
|
||||
{
|
||||
private const TITLE = 'Atestado';
|
||||
private const TEMPLATE = 'pronto-atendimento.atendimento-medico.atestado';
|
||||
|
||||
public static function getTemplate($atendimentoId = null)
|
||||
{
|
||||
if ($atendimentoId) {
|
||||
|
||||
$atendimentoMedico = AtendimentoMedico::orderByDesc('created_at')
|
||||
->where('atendimento_id', $atendimentoId)
|
||||
->has('atestado')
|
||||
->firstOrFail();
|
||||
|
||||
$recepcao = Recepcao::orderByDesc('atendido_em')
|
||||
->where('atendimento_id', $atendimentoId)
|
||||
->firstOrFail();
|
||||
|
||||
$atestado = $atendimentoMedico->atestado;
|
||||
$paciente = $atendimentoMedico->atendimento->faa->paciente;
|
||||
$atendido_em = new DateTime($recepcao->atendido_em);
|
||||
|
||||
$data = [
|
||||
'paciente' => [
|
||||
'nome' => $paciente->cidadao->nome,
|
||||
'nomeSocial' => $paciente->cidadao->nome_social,
|
||||
'prefereNomeSocial' => $paciente->cidadao->preferencia_nome_id === PreferenciaNome::NOME_SOCIAL,
|
||||
],
|
||||
'documento' => [
|
||||
'tipo' => $atestado->documentoTipo->nome,
|
||||
'numero' => MaskUtil::getDocumentMasked($atestado->documento_tipo_id, $atestado->documento_numero),
|
||||
],
|
||||
'unidade' => [
|
||||
'nome' => $atestado->updatedLotacao->infraestrutura->unidade->nome_fantasia,
|
||||
],
|
||||
'data' => $atendido_em->format('d/m/Y'),
|
||||
'hora' => $atendido_em->format('H:i:s'),
|
||||
'cid' => $atestado->imprime_cid ? $atendimentoMedico->cid->cid->codigo : '',
|
||||
'afastamento_texto' => self::getAfastamentoTexto(
|
||||
$atestado->modelo_id ?? AtestadoModelo::PADRAO,
|
||||
$atestado->dias,
|
||||
$atestado->quantidade_horas,
|
||||
$atestado->horario_inicial,
|
||||
),
|
||||
'profissional' => [
|
||||
'nome' => $atestado->updatedLotacao->usuario->cidadao->nome,
|
||||
'cbo' => $atestado->updatedLotacao->ocupacao->nome,
|
||||
]
|
||||
];
|
||||
}
|
||||
else {
|
||||
|
||||
$paciente = Paciente::findOrFail(request()->paciente_id);
|
||||
$documentoTipo = DocumentoTipo::findOrFail(request()->documento_tipo_id);
|
||||
$lotacao = Lotacao::findOrFail(auth()->payload()->get('lotacao_id'));
|
||||
$atendido_em = new DateTime(request()->atendido_em);
|
||||
|
||||
$data = [
|
||||
'paciente' => [
|
||||
'nome' => $paciente->cidadao->nome,
|
||||
'nomeSocial' => $paciente->cidadao->nome_social,
|
||||
'prefereNomeSocial' => $paciente->cidadao->preferencia_nome_id === PreferenciaNome::NOME_SOCIAL,
|
||||
],
|
||||
'documento' => [
|
||||
'tipo' => $documentoTipo->nome,
|
||||
'numero' => MaskUtil::getDocumentMasked($documentoTipo->id, request()->documento_numero),
|
||||
],
|
||||
'unidade' => [
|
||||
'nome' => $lotacao->infraestrutura->unidade->nome_fantasia,
|
||||
],
|
||||
'data' => $atendido_em->format('d/m/Y'),
|
||||
'hora' => $atendido_em->format('H:i:s'),
|
||||
'cid' => DataUtil::isStringTrue(request()->imprime_cid) && request()->cid_id
|
||||
? Cid::findOrFail(request()->cid_id)->codigo : '',
|
||||
'afastamento_texto' => self::getAfastamentoTexto(
|
||||
request()->modelo_id ?? AtestadoModelo::PADRAO,
|
||||
request()->dias,
|
||||
request()->quantidade_horas,
|
||||
request()->horario_inicial,
|
||||
),
|
||||
'profissional' => [
|
||||
'nome' => $lotacao->usuario->cidadao->nome,
|
||||
'cbo' => $lotacao->ocupacao->nome,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
return Template::make(self::TITLE, self::TEMPLATE)->withData($data)->getHtml();
|
||||
}
|
||||
|
||||
private static function getAfastamentoTexto($modeloId, $dias, $quantidadeHoras, $horarioInicial)
|
||||
{
|
||||
switch ((int) $modeloId) {
|
||||
case AtestadoModelo::PERIODO_MANHA:
|
||||
return 'Em decorrencia, devera permanecer em afastamento de suas atividades laborativas no periodo da manha.';
|
||||
case AtestadoModelo::PERIODO_TARDE:
|
||||
return 'Em decorrencia, devera permanecer em afastamento de suas atividades laborativas no periodo da tarde.';
|
||||
case AtestadoModelo::PERIODO_NOITE:
|
||||
return 'Em decorrencia, devera permanecer em afastamento de suas atividades laborativas no periodo da noite.';
|
||||
case AtestadoModelo::QUANTIDADE_HORAS:
|
||||
if (is_null($quantidadeHoras) || is_null($horarioInicial)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$horario = (new DateTime($horarioInicial))->format('H:i');
|
||||
$horasPorExtenso = NumericUtil::getPorExtenso($quantidadeHoras);
|
||||
|
||||
return "Em decorrencia, devera permanecer em afastamento de suas atividades laborativas por um periodo de {$quantidadeHoras} ({$horasPorExtenso}) hora(s), a partir das {$horario} hora(s).";
|
||||
default:
|
||||
if (is_null($dias)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$diasPorExtenso = NumericUtil::getPorExtenso($dias);
|
||||
$sufixoDia = (int) $dias > 1 ? 's' : '';
|
||||
|
||||
return "Em decorrencia, devera permanecer em afastamento de suas atividades laborativas por um periodo de {$dias} ({$diasPorExtenso}) dia{$sufixoDia} a partir desta data.";
|
||||
}
|
||||
}
|
||||
|
||||
public function __invoke($atendimentoId = null)
|
||||
{
|
||||
return (new Pdf)->stream(self::getTemplate($atendimentoId), 'atestado');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,235 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Impressao\ProntoAtendimento\AtendimentoMedico;
|
||||
|
||||
use App\Enums\Cadastro\SujeitoAtencao\PreferenciaNome;
|
||||
use App\Enums\Cadastro\SujeitoAtencao\Sexo;
|
||||
use App\Enums\ProntoAtendimento\Atendimento\Medico\DeclaracaoComparecimentoTipo;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Lotacao;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Paciente;
|
||||
use App\Models\Geral\DocumentoTipo;
|
||||
use App\Models\ProntoAtendimento\Atendimento\Medico\DeclaracaoComparecimento;
|
||||
use App\Utils\Exports\Pdf;
|
||||
use App\Utils\Exports\Template;
|
||||
use App\Utils\MaskUtil;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class DeclaracaoComparecimentoAcompanhanteController extends Controller
|
||||
{
|
||||
private const TITLE = 'Declaração de comparecimento do acompanhante';
|
||||
private const TEMPLATE = 'pronto-atendimento.atendimento-medico.declaracao-comparecimento-acompanhante';
|
||||
|
||||
public static function getTemplate($atendimentoId = null)
|
||||
{
|
||||
$declaracoes = $atendimentoId
|
||||
? DeclaracaoComparecimento::orderByDesc('created_at')
|
||||
->where(function($query) use ($atendimentoId) {
|
||||
$query
|
||||
->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);
|
||||
})
|
||||
->orWhereHas('atendimentoTriagem', function($query) use ($atendimentoId) {
|
||||
$query->where('atendimento_id', $atendimentoId);
|
||||
})
|
||||
->orWhereHas('atendimentoExameImagem', function($query) use ($atendimentoId) {
|
||||
$query->where('atendimento_id', $atendimentoId);
|
||||
})
|
||||
->orWhereHas('recepcao', function($query) use ($atendimentoId) {
|
||||
$query->where('atendimento_id', $atendimentoId);
|
||||
});
|
||||
})
|
||||
->where('tipo_id', DeclaracaoComparecimentoTipo::ACOMPANHANTE)
|
||||
->get()
|
||||
: request()->declaracoes;
|
||||
|
||||
$now = new \DateTime;
|
||||
|
||||
$data['declaracoes'] = [];
|
||||
|
||||
foreach ($declaracoes as $declaracao) {
|
||||
|
||||
if ((is_array($declaracao) && is_numeric($declaracao['id'] ?? null))
|
||||
|| $declaracao instanceof DeclaracaoComparecimento
|
||||
) {
|
||||
|
||||
if (!($declaracao instanceof DeclaracaoComparecimento)) {
|
||||
|
||||
$declaracao = DeclaracaoComparecimento::findOrFail($declaracao['id']);
|
||||
}
|
||||
|
||||
$paciente = self::getPaciente($declaracao);
|
||||
$profissioanal = self::getProfissional($declaracao);
|
||||
|
||||
$data['declaracoes'][] = [
|
||||
'acompanhante' => [
|
||||
'nome' => $declaracao->nome,
|
||||
],
|
||||
'paciente' => [
|
||||
'nome' => $paciente->cidadao->nome,
|
||||
'nomeSocial' => $paciente->cidadao->nome_social,
|
||||
'prefereNomeSocial' => $paciente->cidadao->preferencia_nome_id === PreferenciaNome::NOME_SOCIAL,
|
||||
'sexoMasculino' => $paciente->cidadao->sexo->id === Sexo::MASCULINO
|
||||
|| $paciente->cidadao->sexo->base_id === Sexo::MASCULINO,
|
||||
],
|
||||
'documento' => [
|
||||
'tipo' => $declaracao->documentoTipo->nome,
|
||||
'numero' => MaskUtil::getDocumentMasked($declaracao->documento_tipo_id, $declaracao->documento_numero),
|
||||
],
|
||||
'unidade' => [
|
||||
'nome' => $declaracao->updatedLotacao->infraestrutura->unidade->nome_fantasia,
|
||||
],
|
||||
'de' => $declaracao->de->format('H:i (d/m/Y)'),
|
||||
'ate' => $declaracao->ate->format('H:i (d/m/Y)'),
|
||||
'motivo' => $declaracao->motivo,
|
||||
'profissional' => [
|
||||
'nome' => $profissioanal->updatedLotacao->usuario->cidadao->nome,
|
||||
'cbo' => $profissioanal->updatedLotacao->ocupacao->nome,
|
||||
],
|
||||
];
|
||||
}
|
||||
else {
|
||||
|
||||
$paciente = Paciente::findOrFail(request()->paciente_id);
|
||||
$lotacao = Lotacao::findOrFail(auth()->payload()->get('lotacao_id'));
|
||||
$documentoTipo = DocumentoTipo::findOrFail($declaracao['documento_tipo_id']);
|
||||
|
||||
$data['declaracoes'][] = [
|
||||
'acompanhante' => [
|
||||
'nome' => $declaracao['nome'],
|
||||
],
|
||||
'paciente' => [
|
||||
'nome' => $paciente->cidadao->nome,
|
||||
'nomeSocial' => $paciente->cidadao->nome_social,
|
||||
'prefereNomeSocial' => $paciente->cidadao->preferencia_nome_id === PreferenciaNome::NOME_SOCIAL,
|
||||
'sexoMasculino' => $paciente->cidadao->sexo->id === Sexo::MASCULINO
|
||||
|| $paciente->cidadao->sexo->base_id === Sexo::MASCULINO,
|
||||
],
|
||||
'documento' => [
|
||||
'tipo' => $documentoTipo->nome,
|
||||
'numero' => MaskUtil::getDocumentMasked($documentoTipo->id, $declaracao['documento_numero']),
|
||||
],
|
||||
'unidade' => [
|
||||
'nome' => $lotacao->infraestrutura->unidade->nome_fantasia,
|
||||
],
|
||||
'de' => Carbon::createFromFormat('Y-m-d H:i', $declaracao['de'])->format('H:i (d/m/Y)'),
|
||||
'ate' => Carbon::createFromFormat('Y-m-d H:i', $declaracao['ate'])->format('H:i (d/m/Y)'),
|
||||
'motivo' => $declaracao['motivo'],
|
||||
'profissional' => [
|
||||
'nome' => $lotacao->usuario->cidadao->nome,
|
||||
'cbo' => $lotacao->ocupacao->nome,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return Template::make(self::TITLE, self::TEMPLATE)->withData($data)->getHtml();
|
||||
}
|
||||
|
||||
|
||||
public static function getPaciente($declaracao) {
|
||||
|
||||
$paciente = $declaracao->atendimentoMedico
|
||||
? $declaracao->atendimentoMedico->atendimento->faa->paciente
|
||||
: null;
|
||||
|
||||
if (!$paciente) {
|
||||
|
||||
$paciente = $declaracao->atendimentoEnfermagem
|
||||
? $declaracao->atendimentoEnfermagem->atendimento->faa->paciente
|
||||
: null;
|
||||
}
|
||||
|
||||
if (!$paciente) {
|
||||
|
||||
$paciente = $declaracao->atendimentoTriagem
|
||||
? $declaracao->atendimentoTriagem->atendimento->faa->paciente
|
||||
: null;
|
||||
}
|
||||
|
||||
if (!$paciente) {
|
||||
|
||||
$paciente = $declaracao->pacienteObservacao
|
||||
? $declaracao->pacienteObservacao->atendimento->faa->paciente
|
||||
: null;
|
||||
}
|
||||
|
||||
if (!$paciente) {
|
||||
|
||||
$paciente = $declaracao->pacienteObservacao
|
||||
? $declaracao->pacienteObservacao->atendimento->faa->paciente
|
||||
: null;
|
||||
}
|
||||
|
||||
if (!$paciente) {
|
||||
|
||||
$paciente = $declaracao->atendimentoExameImagem
|
||||
? $declaracao->atendimentoExameImagem->atendimento->faa->paciente
|
||||
: null;
|
||||
}
|
||||
|
||||
if (!$paciente) {
|
||||
|
||||
$paciente = $declaracao->recepcao
|
||||
? $declaracao->recepcao->atendimento->faa->paciente
|
||||
: null;
|
||||
}
|
||||
|
||||
return $paciente;
|
||||
}
|
||||
|
||||
public static function getProfissional($declaracao) {
|
||||
|
||||
$profissional = $declaracao->atendimentoMedico
|
||||
? $declaracao->atendimentoMedico
|
||||
: null;
|
||||
|
||||
if (!$profissional) {
|
||||
|
||||
$profissional = $declaracao->atendimentoEnfermagem
|
||||
? $declaracao->atendimentoEnfermagem
|
||||
: null;
|
||||
}
|
||||
|
||||
if (!$profissional) {
|
||||
|
||||
$profissional = $declaracao->atendimentoTriagem
|
||||
? $declaracao->atendimentoTriagem
|
||||
: null;
|
||||
}
|
||||
|
||||
if (!$profissional) {
|
||||
|
||||
$profissional = $declaracao->pacienteObservacao
|
||||
? $declaracao->pacienteObservacao
|
||||
: null;
|
||||
}
|
||||
|
||||
if (!$profissional) {
|
||||
|
||||
$profissional = $declaracao->atendimentoExameImagem
|
||||
? $declaracao->atendimentoExameImagem
|
||||
: null;
|
||||
}
|
||||
|
||||
if (!$profissional) {
|
||||
|
||||
$profissional = $declaracao->recepcao
|
||||
? $declaracao->recepcao
|
||||
: null;
|
||||
}
|
||||
|
||||
return $profissional;
|
||||
}
|
||||
|
||||
public function __invoke($atendimentoId = null)
|
||||
{
|
||||
return (new Pdf)->stream(self::getTemplate($atendimentoId), 'declaracao-comparecimento-acompanhante');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,235 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Impressao\ProntoAtendimento\AtendimentoMedico;
|
||||
|
||||
use App\Enums\Cadastro\SujeitoAtencao\PreferenciaNome;
|
||||
use App\Enums\Cadastro\SujeitoAtencao\Sexo;
|
||||
use App\Enums\ProntoAtendimento\Atendimento\Medico\DeclaracaoComparecimentoTipo;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Lotacao;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Paciente;
|
||||
use App\Models\Geral\DocumentoTipo;
|
||||
use App\Models\ProntoAtendimento\Atendimento\Medico\DeclaracaoComparecimento;
|
||||
use App\Utils\Exports\Pdf;
|
||||
use App\Utils\Exports\Template;
|
||||
use App\Utils\MaskUtil;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class DeclaracaoComparecimentoPacienteController extends Controller
|
||||
{
|
||||
private const TITLE = 'Declaração de comparecimento do paciente';
|
||||
private const TEMPLATE = 'pronto-atendimento.atendimento-medico.declaracao-comparecimento';
|
||||
|
||||
public static function getTemplate($atendimentoId = null)
|
||||
{
|
||||
$declaracoes = $atendimentoId
|
||||
? DeclaracaoComparecimento::orderByDesc('created_at')
|
||||
->where(function($query) use ($atendimentoId) {
|
||||
$query
|
||||
->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);
|
||||
})
|
||||
->orWhereHas('atendimentoTriagem', function($query) use ($atendimentoId) {
|
||||
$query->where('atendimento_id', $atendimentoId);
|
||||
})
|
||||
->orWhereHas('atendimentoExameImagem', function($query) use ($atendimentoId) {
|
||||
$query->where('atendimento_id', $atendimentoId);
|
||||
})
|
||||
->orWhereHas('recepcao', function($query) use ($atendimentoId) {
|
||||
$query->where('atendimento_id', $atendimentoId);
|
||||
});
|
||||
})
|
||||
->where('tipo_id', DeclaracaoComparecimentoTipo::PACIENTE)
|
||||
->get()
|
||||
: request()->declaracoes;
|
||||
|
||||
$now = new \DateTime;
|
||||
|
||||
$data['declaracoes'] = [];
|
||||
|
||||
foreach ($declaracoes as $declaracao) {
|
||||
|
||||
if ((is_array($declaracao) && is_numeric($declaracao['id'] ?? null))
|
||||
|| $declaracao instanceof DeclaracaoComparecimento
|
||||
) {
|
||||
|
||||
if (!($declaracao instanceof DeclaracaoComparecimento)) {
|
||||
|
||||
$declaracao = DeclaracaoComparecimento::findOrFail($declaracao['id']);
|
||||
}
|
||||
|
||||
$paciente = self::getPaciente($declaracao);
|
||||
$profissioanal = self::getProfissional($declaracao);
|
||||
|
||||
$data['declaracoes'][] = [
|
||||
'acompanhante' => [
|
||||
'nome' => $declaracao->nome,
|
||||
],
|
||||
'paciente' => [
|
||||
'nome' => $paciente->cidadao->nome,
|
||||
'nomeSocial' => $paciente->cidadao->nome_social,
|
||||
'prefereNomeSocial' => $paciente->cidadao->preferencia_nome_id === PreferenciaNome::NOME_SOCIAL,
|
||||
'sexoMasculino' => $paciente->cidadao->sexo->id === Sexo::MASCULINO
|
||||
|| $paciente->cidadao->sexo->base_id === Sexo::MASCULINO,
|
||||
],
|
||||
'documento' => [
|
||||
'tipo' => $declaracao->documentoTipo->nome,
|
||||
'numero' => MaskUtil::getDocumentMasked($declaracao->documento_tipo_id, $declaracao->documento_numero),
|
||||
],
|
||||
'unidade' => [
|
||||
'nome' => $declaracao->updatedLotacao->infraestrutura->unidade->nome_fantasia,
|
||||
],
|
||||
'de' => $declaracao->de->format('H:i (d/m/Y)'),
|
||||
'ate' => $declaracao->ate->format('H:i (d/m/Y)'),
|
||||
'motivo' => $declaracao->motivo,
|
||||
'profissional' => [
|
||||
'nome' => $profissioanal->updatedLotacao->usuario->cidadao->nome,
|
||||
'cbo' => $profissioanal->updatedLotacao->ocupacao->nome,
|
||||
],
|
||||
];
|
||||
}
|
||||
else {
|
||||
|
||||
$paciente = Paciente::findOrFail(request()->paciente_id);
|
||||
$lotacao = Lotacao::findOrFail(auth()->payload()->get('lotacao_id'));
|
||||
$documentoTipo = DocumentoTipo::findOrFail($declaracao['documento_tipo_id']);
|
||||
|
||||
$data['declaracoes'][] = [
|
||||
'acompanhante' => [
|
||||
'nome' => $declaracao['nome'],
|
||||
],
|
||||
'paciente' => [
|
||||
'nome' => $paciente->cidadao->nome,
|
||||
'nomeSocial' => $paciente->cidadao->nome_social,
|
||||
'prefereNomeSocial' => $paciente->cidadao->preferencia_nome_id === PreferenciaNome::NOME_SOCIAL,
|
||||
'sexoMasculino' => $paciente->cidadao->sexo->id === Sexo::MASCULINO
|
||||
|| $paciente->cidadao->sexo->base_id === Sexo::MASCULINO,
|
||||
],
|
||||
'documento' => [
|
||||
'tipo' => $documentoTipo->nome,
|
||||
'numero' => MaskUtil::getDocumentMasked($documentoTipo->id, $declaracao['documento_numero']),
|
||||
],
|
||||
'unidade' => [
|
||||
'nome' => $lotacao->infraestrutura->unidade->nome_fantasia,
|
||||
],
|
||||
'de' => Carbon::createFromFormat('Y-m-d H:i', $declaracao['de'])->format('H:i (d/m/Y)'),
|
||||
'ate' => Carbon::createFromFormat('Y-m-d H:i', $declaracao['ate'])->format('H:i (d/m/Y)'),
|
||||
'motivo' => $declaracao['motivo'],
|
||||
'profissional' => [
|
||||
'nome' => $lotacao->usuario->cidadao->nome,
|
||||
'cbo' => $lotacao->ocupacao->nome,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return Template::make(self::TITLE, self::TEMPLATE)->withData($data)->getHtml();
|
||||
}
|
||||
|
||||
|
||||
public static function getPaciente($declaracao) {
|
||||
|
||||
$paciente = $declaracao->atendimentoMedico
|
||||
? $declaracao->atendimentoMedico->atendimento->faa->paciente
|
||||
: null;
|
||||
|
||||
if (!$paciente) {
|
||||
|
||||
$paciente = $declaracao->atendimentoEnfermagem
|
||||
? $declaracao->atendimentoEnfermagem->atendimento->faa->paciente
|
||||
: null;
|
||||
}
|
||||
|
||||
if (!$paciente) {
|
||||
|
||||
$paciente = $declaracao->atendimentoTriagem
|
||||
? $declaracao->atendimentoTriagem->atendimento->faa->paciente
|
||||
: null;
|
||||
}
|
||||
|
||||
if (!$paciente) {
|
||||
|
||||
$paciente = $declaracao->pacienteObservacao
|
||||
? $declaracao->pacienteObservacao->atendimento->faa->paciente
|
||||
: null;
|
||||
}
|
||||
|
||||
if (!$paciente) {
|
||||
|
||||
$paciente = $declaracao->pacienteObservacao
|
||||
? $declaracao->pacienteObservacao->atendimento->faa->paciente
|
||||
: null;
|
||||
}
|
||||
|
||||
if (!$paciente) {
|
||||
|
||||
$paciente = $declaracao->atendimentoExameImagem
|
||||
? $declaracao->atendimentoExameImagem->atendimento->faa->paciente
|
||||
: null;
|
||||
}
|
||||
|
||||
if (!$paciente) {
|
||||
|
||||
$paciente = $declaracao->recepcao
|
||||
? $declaracao->recepcao->atendimento->faa->paciente
|
||||
: null;
|
||||
}
|
||||
|
||||
return $paciente;
|
||||
}
|
||||
|
||||
public static function getProfissional($declaracao) {
|
||||
|
||||
$profissional = $declaracao->atendimentoMedico
|
||||
? $declaracao->atendimentoMedico
|
||||
: null;
|
||||
|
||||
if (!$profissional) {
|
||||
|
||||
$profissional = $declaracao->atendimentoEnfermagem
|
||||
? $declaracao->atendimentoEnfermagem
|
||||
: null;
|
||||
}
|
||||
|
||||
if (!$profissional) {
|
||||
|
||||
$profissional = $declaracao->atendimentoTriagem
|
||||
? $declaracao->atendimentoTriagem
|
||||
: null;
|
||||
}
|
||||
|
||||
if (!$profissional) {
|
||||
|
||||
$profissional = $declaracao->pacienteObservacao
|
||||
? $declaracao->pacienteObservacao
|
||||
: null;
|
||||
}
|
||||
|
||||
if (!$profissional) {
|
||||
|
||||
$profissional = $declaracao->atendimentoExameImagem
|
||||
? $declaracao->atendimentoExameImagem
|
||||
: null;
|
||||
}
|
||||
|
||||
if (!$profissional) {
|
||||
|
||||
$profissional = $declaracao->recepcao
|
||||
? $declaracao->recepcao
|
||||
: null;
|
||||
}
|
||||
|
||||
return $profissional;
|
||||
}
|
||||
|
||||
public function __invoke($atendimentoId = null)
|
||||
{
|
||||
return (new Pdf)->stream(self::getTemplate($atendimentoId), 'declaracao-comparecimento-paciente');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,242 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Impressao\ProntoAtendimento\AtendimentoMedico;
|
||||
|
||||
use App\Enums\Cadastro\SujeitoAtencao\PreferenciaNome;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ProntoAtendimento\Atendimento\Atendimento;
|
||||
use App\Utils\DataUtil;
|
||||
use App\Utils\Exports\Pdf;
|
||||
use App\Utils\Exports\Template;
|
||||
use App\Utils\MaskUtil;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class EncaminhamentoHospitalarController extends Controller
|
||||
{
|
||||
private const TITLE = 'Encaminhamento hospitalar';
|
||||
private const TEMPLATE = 'pronto-atendimento.atendimento-medico.encaminhamento-hospitalar';
|
||||
|
||||
public static function getTemplate(int $atendimentoId)
|
||||
{
|
||||
$atendimento = Atendimento::findOrFail($atendimentoId);
|
||||
|
||||
$atendimentoMedico = $atendimento->atendimentosMedico->last();
|
||||
$paciente = $atendimento->faa->paciente;
|
||||
$encaminhamentoHospitalar = $atendimentoMedico->encaminhamentoHospitalar;
|
||||
|
||||
$data = [
|
||||
'unidade' => [
|
||||
'nome' => $encaminhamentoHospitalar->updatedLotacao->infraestrutura->unidade->nome_fantasia ?? null,
|
||||
],
|
||||
'paciente' => [
|
||||
'nome' => $paciente->cidadao->nome,
|
||||
'nomeSocial' => $paciente->cidadao->nome_social,
|
||||
'prefereNomeSocial' => $paciente->cidadao->preferencia_nome_id === PreferenciaNome::NOME_SOCIAL,
|
||||
'idadeCompleta' => $paciente->cidadao->idade_formatada,
|
||||
'sexo' => $paciente->cidadao->sexo->descricao,
|
||||
'dataNascimento' => (new \DateTime($paciente->cidadao->data_nascimento))->format('d/m/Y'),
|
||||
'telefone' => $paciente->cidadao->telefone_principal
|
||||
? MaskUtil::getPhoneMasked($paciente->cidadao->telefone_principal->numero)
|
||||
: null,
|
||||
'municipioNascimento' => $paciente->cidadao->municipioNascimento
|
||||
? "{$paciente->cidadao->municipioNascimento->nome} / "
|
||||
. $paciente->cidadao->municipioNascimento->estado->uf
|
||||
: '',
|
||||
'nomeMae' => $paciente->cidadao->nome_mae ?? '',
|
||||
],
|
||||
'encaminhamentoHospitalar' => [
|
||||
'dataCadastro' => [
|
||||
'porExtenso' => $encaminhamentoHospitalar->created_at->format('d \d\e F \d\e Y'),
|
||||
],
|
||||
'unidade' => $encaminhamentoHospitalar->unidade->nome_fantasia,
|
||||
'quarto' => $encaminhamentoHospitalar->quarto ?? '',
|
||||
'leito' => $encaminhamentoHospitalar->leito ?? '',
|
||||
'medico_hospitalar' => $encaminhamentoHospitalar->medico_hospitalar ?? '',
|
||||
'observacoes' => $encaminhamentoHospitalar->observacoes ?? '',
|
||||
'profissional' => [
|
||||
'nome' => $encaminhamentoHospitalar->updatedLotacao->usuario->cidadao->nome,
|
||||
'cbo' => $encaminhamentoHospitalar->updatedLotacao->ocupacao->nome,
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
self::setEvolucoesMedicas($data, $atendimento);
|
||||
self::setEvolucoesEnfermagem($data, $atendimento);
|
||||
|
||||
if (DataUtil::isStringTrue(request()->atendimento_geral)) {
|
||||
|
||||
self::setAtendimentosGerais($data, $atendimento);
|
||||
}
|
||||
else if (is_array(request()->anamnese)) {
|
||||
|
||||
self::setAnamneses($data, $atendimento);
|
||||
}
|
||||
|
||||
if (DataUtil::isStringTrue(request()->imprime_cid)) {
|
||||
|
||||
$data['encaminhamentoHospitalar']['cid'] = $encaminhamentoHospitalar->cid
|
||||
? "{$encaminhamentoHospitalar->cid->codigo} - {$encaminhamentoHospitalar->cid->nome}" : '';
|
||||
}
|
||||
|
||||
self::setPrescricoesInternas($data, $atendimento);
|
||||
|
||||
$data['data_impressao'] = Carbon::now()->format('d/m/Y H:i:s');
|
||||
|
||||
return Template::make(self::TITLE, self::TEMPLATE)->withData($data)->getHtml();
|
||||
}
|
||||
|
||||
private static function setEvolucoesMedicas(&$data, $atendimento)
|
||||
{
|
||||
if (request()->evolucao_medica !== 'ultima' && request()->evolucao_medica !== 'todas') {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$atendimentosMedico = $atendimento->atendimentosMedico()
|
||||
->whereNotNull('evolucao')
|
||||
->orderByDesc('created_at');
|
||||
|
||||
if (request()->evolucao_medica === 'ultima') {
|
||||
|
||||
$atendimentosMedico->take(1);
|
||||
}
|
||||
|
||||
$data['evolucoesMedicas'] = $atendimentosMedico->get()->map(fn ($atendimentoMedico) => [
|
||||
'dataHora' => $atendimentoMedico->created_at->format('d/m/Y H:i:s'),
|
||||
'profissional' => [
|
||||
'nome' => $atendimentoMedico->createdLotacao->usuario->cidadao->nome,
|
||||
'cbo' => $atendimentoMedico->createdLotacao->ocupacao->nome,
|
||||
],
|
||||
'evolucao' => $atendimentoMedico->evolucao
|
||||
]);
|
||||
}
|
||||
|
||||
private static function setEvolucoesEnfermagem(&$data, $atendimento)
|
||||
{
|
||||
if (request()->evolucao_enfermagem !== 'ultima' && request()->evolucao_enfermagem !== 'todas') {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$data['evolucoesEnfermagem'] = [];
|
||||
|
||||
// TODO: Adicionar as evoluções de enfermagem.
|
||||
}
|
||||
|
||||
private static function setAtendimentosGerais(&$data, $atendimento)
|
||||
{
|
||||
$atendimentosMedico = $atendimento->atendimentosMedico()->orderBy('created_at');
|
||||
|
||||
$data['atendimentosGerais'] = $atendimentosMedico->pluck('atendimento_geral');
|
||||
}
|
||||
|
||||
private static function setAnamneses(&$data, $atendimento)
|
||||
{
|
||||
$atendimentosMedico = $atendimento->atendimentosMedico()->orderBy('created_at');
|
||||
|
||||
$plurais = [
|
||||
'queixa_principal_duracao' => 'queixasPrincipaisDuracoes',
|
||||
'historia' => 'historias',
|
||||
'exame_fisico' => 'examesFisicos',
|
||||
'diagnostico' => 'diagnosticos',
|
||||
'conduta' => 'condutas',
|
||||
];
|
||||
|
||||
$anamnese = [
|
||||
'queixa_principal_duracao',
|
||||
'historia',
|
||||
'exame_fisico',
|
||||
'diagnostico',
|
||||
'conduta',
|
||||
];
|
||||
|
||||
foreach ($anamnese as $i => $item) {
|
||||
|
||||
if (!in_array($item, request()->anamnese)) {
|
||||
|
||||
unset($anamnese[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
$atendimentosMedico->get()->each(function ($atendimentoMedico) use (&$data, $plurais, $anamnese) {
|
||||
|
||||
foreach ($anamnese as $item) {
|
||||
|
||||
if (empty($atendimentoMedico->{$item})) {
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$data[$plurais[$item]][] = $atendimentoMedico->{$item};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static function setPrescricoesInternas(&$data, $atendimento)
|
||||
{
|
||||
if (request()->prescricao_interna !== 'ultima' && request()->prescricao_interna !== 'todas') {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$prescricoesInternas = new Collection;
|
||||
|
||||
$atendimento->atendimentosMedico()->get()->each(function ($atendimentoMedico) use ($prescricoesInternas) {
|
||||
|
||||
$atendimentoMedico->prescricoesInternas->each(function ($prescricaoInterna) use ($prescricoesInternas) {
|
||||
|
||||
$prescricoesInternas->push($prescricaoInterna);
|
||||
});
|
||||
});
|
||||
|
||||
if (request()->prescricao_interna === 'ultima') {
|
||||
|
||||
$prescricoesInternas = $prescricoesInternas->sortByDesc('created_at')->take(1);
|
||||
}
|
||||
else {
|
||||
|
||||
$prescricoesInternas = $prescricoesInternas->sortBy('created_at');
|
||||
}
|
||||
|
||||
$data['prescricoesInternas'] = $prescricoesInternas->map(function ($prescricaoInterna) {
|
||||
|
||||
$data = [
|
||||
'dataHora' => $prescricaoInterna->updated_at->format('d/m/Y H:i:s'),
|
||||
'profissional' => [
|
||||
'nome' => $prescricaoInterna->updatedLotacao->usuario->cidadao->nome,
|
||||
'cbo' => $prescricaoInterna->updatedLotacao->ocupacao->nome,
|
||||
],
|
||||
'viaAdministracao' => $prescricaoInterna->viaAdministracao->nome,
|
||||
'doseUnica' => $prescricaoInterna->dose_unica,
|
||||
'frequencia' => $prescricaoInterna->frequencia,
|
||||
'observacoes' => $prescricaoInterna->observacoes ?? '',
|
||||
'medicamentos' => [],
|
||||
];
|
||||
|
||||
foreach ($prescricaoInterna->medicamentos as $medicamento) {
|
||||
|
||||
$data['medicamentos'][] = [
|
||||
'nome' => $medicamento->medicamento->nome,
|
||||
'quantidade' => $medicamento->quantidade,
|
||||
'formaFarmaceutica' => $medicamento->medicamento->formaFarmaceutica->nome,
|
||||
'administracao' => $medicamento->administracao,
|
||||
'aplicacoes' => $medicamento->aplicacoes->map(function ($aplicacao, $index) {
|
||||
|
||||
return [
|
||||
'aplicacao' => $index + 1,
|
||||
'status' => $aplicacao->status->nome ?? null
|
||||
];
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
return $data;
|
||||
});
|
||||
}
|
||||
|
||||
public function __invoke(int $atendimentoMedicoId)
|
||||
{
|
||||
return (new Pdf)->stream(self::getTemplate($atendimentoMedicoId), self::TITLE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Impressao\ProntoAtendimento\AtendimentoMedico;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Utils\Exports\Pdf;
|
||||
use App\Utils\Exports\Template;
|
||||
|
||||
class EvolucaoAndPrescricaoInternaController extends Controller
|
||||
{
|
||||
private const TITLE = 'Evolução médica/prescrição interna';
|
||||
private const FILE_NAME = 'Evolução médica + prescrição interna';
|
||||
private const TEMPLATE = 'pronto-atendimento.atendimento-medico.evolucao-prescricao';
|
||||
|
||||
public static function getTemplate(int $atendimentoMedicoId, int $prescricaoInternaId)
|
||||
{
|
||||
$templateEvolucaoMedica = EvolucaoController::getTemplate($atendimentoMedicoId, true);
|
||||
$templatePrescricaoInterna = PrescricaoInternaController::getTemplate($prescricaoInternaId, true);
|
||||
|
||||
return Template::make(self::TITLE, self::TEMPLATE)
|
||||
->withData(['conteudo' => $templateEvolucaoMedica . $templatePrescricaoInterna])
|
||||
->getHtml();
|
||||
}
|
||||
|
||||
public function __invoke(int $atendimentoMedicoId, int $prescricaoInternaId)
|
||||
{
|
||||
return (new Pdf)->stream(self::getTemplate($atendimentoMedicoId, $prescricaoInternaId), self::FILE_NAME);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Impressao\ProntoAtendimento\AtendimentoMedico;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ProntoAtendimento\Atendimento\Medico\AtendimentoMedico;
|
||||
use App\Utils\Exports\Pdf;
|
||||
use App\Utils\Exports\Template;
|
||||
|
||||
class EvolucaoController extends Controller
|
||||
{
|
||||
private const TITLE = 'Evolução médica';
|
||||
private const TEMPLATE = 'pronto-atendimento.atendimento-medico.evolucao-medica';
|
||||
|
||||
public static function getTemplate(int $atendimentoMedicoId, bool $onlyContent = false)
|
||||
{
|
||||
$atendimentoMedico = AtendimentoMedico::findOrFail($atendimentoMedicoId);
|
||||
|
||||
$evolucoes = [];
|
||||
|
||||
$atendimentoMedico->atendimento->atendimentosMedico()
|
||||
->whereNotNull('evolucao')
|
||||
->orderByDesc('created_at')
|
||||
->get()
|
||||
->each(function ($atendimentoMedico) use (&$evolucoes) {
|
||||
|
||||
$evolucoes[] = [
|
||||
'dataHora' => $atendimentoMedico->created_at->format('d/m/Y H:i:s'),
|
||||
'profissional' => [
|
||||
'nome' => $atendimentoMedico->createdLotacao->usuario->cidadao->nome,
|
||||
'cbo' => $atendimentoMedico->createdLotacao->ocupacao->nome,
|
||||
],
|
||||
'evolucao' => $atendimentoMedico->evolucao
|
||||
];
|
||||
});
|
||||
|
||||
$template = $onlyContent ? self::TEMPLATE . '-conteudo' : self::TEMPLATE;
|
||||
|
||||
return Template::make(self::TITLE, $template)->withData(compact('evolucoes'))->getHtml();
|
||||
}
|
||||
|
||||
public function __invoke(int $atendimentoMedicoId)
|
||||
{
|
||||
return (new Pdf)->stream(self::getTemplate($atendimentoMedicoId), self::TITLE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Impressao\ProntoAtendimento\AtendimentoMedico;
|
||||
|
||||
use App\Enums\Cadastro\SujeitoAtencao\PreferenciaNome;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Lotacao;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Paciente;
|
||||
use App\Models\ProntoAtendimento\Atendimento\Medico\Encaminhamento;
|
||||
use App\Models\Sigtap\Cid;
|
||||
use App\Models\Sigtap\Ocupacao;
|
||||
use App\Utils\DataUtil;
|
||||
use App\Utils\Exports\Pdf;
|
||||
use App\Utils\Exports\Template;
|
||||
use App\Utils\MaskUtil;
|
||||
|
||||
class GuiaEncaminhamentoController extends Controller
|
||||
{
|
||||
private const TITLE = 'Guia de encaminhamento';
|
||||
private const SUBTITLE = 'Referência';
|
||||
private const TEMPLATE = 'pronto-atendimento.atendimento-medico.guia-encaminhamento';
|
||||
|
||||
public static function getTemplate($atendimentoId = null)
|
||||
{
|
||||
$encaminhamentos = $atendimentoId
|
||||
? Encaminhamento::orderByDesc('created_at')
|
||||
->whereHas('atendimentoMedico', function($query) use ($atendimentoId) {
|
||||
$query->where('atendimento_id', $atendimentoId);
|
||||
})
|
||||
->get()
|
||||
: request()->encaminhamentos;
|
||||
|
||||
$data['encaminhamentos'] = [];
|
||||
|
||||
foreach ($encaminhamentos as $encaminhamento) {
|
||||
|
||||
if ((is_array($encaminhamento) && is_numeric($encaminhamento['id'] ?? null))
|
||||
|| $encaminhamento instanceof Encaminhamento
|
||||
) {
|
||||
|
||||
if (!($encaminhamento instanceof Encaminhamento)) {
|
||||
|
||||
$encaminhamento = Encaminhamento::findOrFail($encaminhamento['id']);
|
||||
}
|
||||
|
||||
$paciente = $encaminhamento->atendimentoMedico->atendimento->faa->paciente;
|
||||
|
||||
$cid = "{$encaminhamento->atendimentoMedico->cid->cid->codigo} - "
|
||||
. $encaminhamento->atendimentoMedico->cid->cid->nome;
|
||||
|
||||
$data['encaminhamentos'][] = [
|
||||
'paciente' => [
|
||||
'nome' => $paciente->cidadao->nome,
|
||||
'nomeSocial' => $paciente->cidadao->nome_social,
|
||||
'prefereNomeSocial' => $paciente->cidadao->preferencia_nome_id === PreferenciaNome::NOME_SOCIAL,
|
||||
'cns' => $paciente->cidadao->cns,
|
||||
'sexo' => $paciente->cidadao->sexo->descricao,
|
||||
'idadeCompleta' => $paciente->cidadao->idade_formatada,
|
||||
'dataNascimento' => $paciente->cidadao->data_nascimento
|
||||
? (new \DateTime($paciente->cidadao->data_nascimento))->format('d/m/Y')
|
||||
: null,
|
||||
'telefone' => $paciente->cidadao->telefone_principal
|
||||
? MaskUtil::getPhoneMasked($paciente->cidadao->telefone_principal->numero)
|
||||
: null,
|
||||
'prontuarioUnidade' => $paciente->prontuario_unidade,
|
||||
'nomeMae' => $paciente->cidadao->nome_mae,
|
||||
'municipioNascimento' => $paciente->cidadao->municipioNascimento
|
||||
? "{$paciente->cidadao->municipioNascimento->nome} / "
|
||||
. $paciente->cidadao->municipioNascimento->estado->uf
|
||||
: '',
|
||||
],
|
||||
'unidade' => [
|
||||
'nome' => $encaminhamento->updatedLotacao->infraestrutura->unidade->nome_fantasia,
|
||||
'cnes' => $encaminhamento->updatedLotacao->infraestrutura->unidade->cnes,
|
||||
],
|
||||
'profissional' => [
|
||||
'nome' => $encaminhamento->updatedLotacao->usuario->cidadao->nome,
|
||||
'cbo' => $encaminhamento->updatedLotacao->ocupacao->nome,
|
||||
'cns' => $encaminhamento->updatedLotacao->usuario->cidadao->cns,
|
||||
],
|
||||
'cbo' => $encaminhamento->ocupacao->nome,
|
||||
'cid' => $cid,
|
||||
'urgente' => $encaminhamento->urgente,
|
||||
'motivo' => $encaminhamento->motivo,
|
||||
'observacoes' => $encaminhamento->observacoes ?? ''
|
||||
];
|
||||
}
|
||||
else {
|
||||
|
||||
$paciente = Paciente::findOrFail(request()->paciente_id);
|
||||
$cid = request()->cid_id ? Cid::findOrFail(request()->cid_id) : null;
|
||||
$lotacao = Lotacao::findOrFail(auth()->payload()->get('lotacao_id'));
|
||||
|
||||
$data['encaminhamentos'][] = [
|
||||
'paciente' => [
|
||||
'nome' => $paciente->cidadao->nome,
|
||||
'nomeSocial' => $paciente->cidadao->nome_social,
|
||||
'prefereNomeSocial' => $paciente->cidadao->preferencia_nome_id === PreferenciaNome::NOME_SOCIAL,
|
||||
'cns' => $paciente->cidadao->cns,
|
||||
'sexo' => $paciente->cidadao->sexo->descricao,
|
||||
'idadeCompleta' => $paciente->cidadao->idade_formatada,
|
||||
'dataNascimento' => $paciente->cidadao->data_nascimento
|
||||
? (new \DateTime($paciente->cidadao->data_nascimento))->format('d/m/Y')
|
||||
: null,
|
||||
'telefone' => $paciente->cidadao->telefone_principal
|
||||
? MaskUtil::getPhoneMasked($paciente->cidadao->telefone_principal->numero)
|
||||
: null,
|
||||
'prontuarioUnidade' => $paciente->prontuario_unidade,
|
||||
'nomeMae' => $paciente->cidadao->nome_mae,
|
||||
'municipioNascimento' => $paciente->cidadao->municipioNascimento
|
||||
? "{$paciente->cidadao->municipioNascimento->nome} / "
|
||||
. $paciente->cidadao->municipioNascimento->estado->uf
|
||||
: '',
|
||||
],
|
||||
'unidade' => [
|
||||
'nome' => $lotacao->infraestrutura->unidade->nome_fantasia,
|
||||
'cnes' => $lotacao->infraestrutura->unidade->cnes,
|
||||
],
|
||||
'profissional' => [
|
||||
'nome' => $lotacao->usuario->cidadao->nome,
|
||||
'cbo' => $lotacao->ocupacao->nome,
|
||||
'cns' => $lotacao->usuario->cidadao->cns,
|
||||
],
|
||||
'cbo' => Ocupacao::findOrFail($encaminhamento['ocupacao_id'])->nome,
|
||||
'cid' => $cid ? "{$cid->codigo} - {$cid->nome}" : '',
|
||||
'urgente' => DataUtil::getBooleanValueFromStringBoolean($encaminhamento['urgente']),
|
||||
'motivo' => $encaminhamento['motivo'],
|
||||
'observacoes' => $encaminhamento['observacoes'] ?? ''
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return Template::make(self::TITLE, self::TEMPLATE)
|
||||
->withSubtitle(self::SUBTITLE)
|
||||
->withData($data)
|
||||
->getHtml();
|
||||
}
|
||||
|
||||
public function __invoke($atendimentoId = null)
|
||||
{
|
||||
return (new Pdf)->stream(self::getTemplate($atendimentoId), 'guia-encaminhamento');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Impressao\ProntoAtendimento\AtendimentoMedico;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Lotacao;
|
||||
use App\Models\ProntoAtendimento\Atendimento\Medico\AtendimentoMedico;
|
||||
use App\Utils\Exports\Pdf;
|
||||
use App\Utils\Exports\Template;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class OrientacoesController extends Controller
|
||||
{
|
||||
private const TITLE = 'Orientações ao paciente';
|
||||
private const TEMPLATE = 'pronto-atendimento.atendimento-medico.orientacoes-medicas';
|
||||
|
||||
public static function getTemplate($atendimentoId = null)
|
||||
{
|
||||
if ($atendimentoId) {
|
||||
|
||||
$atendimentoMedico = AtendimentoMedico::orderByDesc('created_at')
|
||||
->where('atendimento_id', $atendimentoId)
|
||||
->whereNotNull('orientacoes')
|
||||
->firstOrFail();
|
||||
|
||||
$data = [
|
||||
'orientacoes' => $atendimentoMedico->orientacoes,
|
||||
'dataHora' => $atendimentoMedico->updated_at->format('d/m/Y H:i:s'),
|
||||
'profissional' => [
|
||||
'nome' => $atendimentoMedico->updatedLotacao->usuario->cidadao->nome,
|
||||
'cbo' => $atendimentoMedico->updatedLotacao->ocupacao->nome,
|
||||
]
|
||||
];
|
||||
}
|
||||
else {
|
||||
|
||||
$lotacao = Lotacao::findOrFail(auth()->payload()->get('lotacao_id'));
|
||||
|
||||
$data = [
|
||||
'orientacoes' => request()->orientacoes,
|
||||
'dataHora' => Carbon::now()->format('d/m/Y H:i:s'),
|
||||
'profissional' => [
|
||||
'nome' => $lotacao->usuario->cidadao->nome,
|
||||
'cbo' => $lotacao->ocupacao->nome,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
return Template::make(self::TITLE, self::TEMPLATE)->withData($data)->getHtml();
|
||||
}
|
||||
|
||||
public function __invoke($atendimentoId = null)
|
||||
{
|
||||
return (new Pdf)->stream(self::getTemplate($atendimentoId), 'orientacoes');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Impressao\ProntoAtendimento\AtendimentoMedico;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ProntoAtendimento\Atendimento\Atendimento;
|
||||
use App\Models\ProntoAtendimento\Atendimento\AvaliacaoAntropometrica;
|
||||
use App\Models\ProntoAtendimento\Atendimento\PrescricaoInterna;
|
||||
use App\Utils\Exports\Pdf;
|
||||
use App\Utils\Exports\Template;
|
||||
use App\Utils\MaskUtil;
|
||||
|
||||
class PrescricaoInternaController extends Controller
|
||||
{
|
||||
private const TITLE = 'Prescrição interna';
|
||||
private const TEMPLATE = 'pronto-atendimento.atendimento-medico.prescricao-interna';
|
||||
|
||||
public static function getTemplate($atendimentoId, bool $onlyContent = false)
|
||||
{
|
||||
|
||||
$prescricao = [];
|
||||
|
||||
$prescricao = array_map(function ($atendimento){
|
||||
return $atendimento['id'];
|
||||
}, request()->atendimentos);
|
||||
|
||||
$prescricoesInternas = PrescricaoInterna::orderByDesc('created_at')
|
||||
->whereHas('atendimentoMedico', function ($query) use ($atendimentoId) {
|
||||
$query->where('atendimento_id', $atendimentoId);
|
||||
})
|
||||
->whereIn('atendimento_medico_id', $prescricao)
|
||||
->get();
|
||||
|
||||
$avaliacaoAntropometrica = AvaliacaoAntropometrica::where('atendimento_id', $atendimentoId)
|
||||
->orderByDesc('created_at')
|
||||
->first();
|
||||
|
||||
$massa = empty($avaliacaoAntropometrica->massa ?? null)
|
||||
? ''
|
||||
: "{$avaliacaoAntropometrica->massa} {$avaliacaoAntropometrica->massaUnidadeMedida->sigla}";
|
||||
|
||||
$altura = empty($avaliacaoAntropometrica->altura ?? null)
|
||||
? ''
|
||||
: "{$avaliacaoAntropometrica->altura} {$avaliacaoAntropometrica->alturaUnidadeMedida->sigla}";
|
||||
|
||||
$data['paciente'] = self::getPacienteData(Atendimento::findOrFail($atendimentoId));
|
||||
|
||||
$data['avaliacaoAntropometrica'] = [
|
||||
'massa' => $massa,
|
||||
'altura' => $altura,
|
||||
];
|
||||
|
||||
$data['prescricoesInternas'] = [];
|
||||
|
||||
foreach ($prescricoesInternas as $key => $prescricaoInterna) {
|
||||
$avaliacaoAntropometrica = $prescricaoInterna->atendimentoMedico->avaliacaoAntropometrica;
|
||||
|
||||
$massa = empty($avaliacaoAntropometrica->massa ?? null)
|
||||
? ''
|
||||
: "{$avaliacaoAntropometrica->massa} {$avaliacaoAntropometrica->massaUnidadeMedida->sigla}";
|
||||
|
||||
$data['prescricoesInternas'][$key] = [
|
||||
'massa' => $massa,
|
||||
'dataHora' => $prescricaoInterna->updated_at->format('d/m/Y H:i:s'),
|
||||
'profissional' => [
|
||||
'nome' => $prescricaoInterna->updatedLotacao->usuario->cidadao->nome,
|
||||
'cbo' => $prescricaoInterna->updatedLotacao->ocupacao->nome,
|
||||
],
|
||||
'doseUnica' => $prescricaoInterna->dose_unica,
|
||||
'frequencia' => $prescricaoInterna->frequencia,
|
||||
'observacoes' => $prescricaoInterna->observacoes ?? '',
|
||||
'medicamentos' => [],
|
||||
'id' => $prescricaoInterna->id,
|
||||
'atendimento_medico_id' => $prescricaoInterna->atendimento_medico_id,
|
||||
];
|
||||
|
||||
foreach ($prescricaoInterna->medicamentos as $medicamento) {
|
||||
|
||||
$data['prescricoesInternas'][$key]['medicamentos'][] = [
|
||||
'nome' => $medicamento->medicamento->nome,
|
||||
'quantidade' => $medicamento->quantidade,
|
||||
'formaFarmaceutica' => $medicamento->medicamento->formaFarmaceutica->nome,
|
||||
'administracao' => $medicamento->administracao,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$template = $onlyContent ? self::TEMPLATE . '-conteudo' : self::TEMPLATE;
|
||||
|
||||
return Template::make(self::TITLE, $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(),
|
||||
];
|
||||
}
|
||||
|
||||
public function __invoke(int $atendimentoId)
|
||||
{
|
||||
return (new Pdf)->stream(self::getTemplate($atendimentoId), 'prescricao-interna');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Impressao\ProntoAtendimento\AtendimentoMedico;
|
||||
|
||||
use App\Enums\Cadastro\Medicamento\TipoReceita;
|
||||
use App\Enums\Cadastro\Medicamento\ViaAdministracao;
|
||||
use App\Enums\Cadastro\SujeitoAtencao\PreferenciaNome;
|
||||
use App\Enums\Cadastro\SujeitoAtencao\TipoRegistroUsuario;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Lotacao;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Paciente;
|
||||
use App\Models\ProntoAtendimento\Atendimento\Medico\Receita;
|
||||
use App\Models\ProntoAtendimento\Atendimento\Medico\ReceitaMedicamento;
|
||||
use App\Utils\DataUtil;
|
||||
use App\Utils\Exports\Pdf;
|
||||
use App\Utils\Exports\Template;
|
||||
use App\Utils\MaskUtil;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class ReceitaController extends Controller
|
||||
{
|
||||
private const TITLE = 'Receita médica';
|
||||
private const TEMPLATE = 'pronto-atendimento.atendimento-medico.receita-medica';
|
||||
|
||||
public static function getTemplate($atendimentoId = null, $params = [])
|
||||
{
|
||||
$receitasIds = $params['receitas_ids'] ?? [];
|
||||
$params['para_assinatura_eletronica'] = $params['para_assinatura_eletronica'] ?? false;
|
||||
|
||||
$paraAssinaturaEletronica = $params['para_assinatura_eletronica'] === true
|
||||
|| (DataUtil::isStringBoolean($params['para_assinatura_eletronica'])
|
||||
&& DataUtil::isStringTrue($params['para_assinatura_eletronica']));
|
||||
|
||||
$receitas = $atendimentoId
|
||||
? Receita::orderByDesc('created_at')
|
||||
->whereHas('medicamentos')
|
||||
->whereHas('atendimentoMedico', function($query) use ($atendimentoId) {
|
||||
$query->where('atendimento_id', $atendimentoId);
|
||||
})
|
||||
->when(!empty($receitasIds), fn ($q) => $q->whereIn('id', $receitasIds))
|
||||
->get()
|
||||
: request()->receitas;
|
||||
|
||||
$data['receitas'] = [];
|
||||
$data['exibirAssinatura'] = !$paraAssinaturaEletronica;
|
||||
|
||||
foreach ($receitas as $key => $receita) {
|
||||
|
||||
if ((is_array($receita) && is_numeric($receita['id'] ?? null))
|
||||
|| $receita instanceof Receita
|
||||
) {
|
||||
|
||||
if (!($receita instanceof Receita)) {
|
||||
|
||||
$receita = Receita::findOrFail($receita['id']);
|
||||
}
|
||||
|
||||
$paciente = $receita->atendimentoMedico->atendimento->faa->paciente;
|
||||
|
||||
$enderecoPaciente = $paciente->cidadao->domicilio
|
||||
? "{$paciente->cidadao->domicilio->endereco->completo} - "
|
||||
. MaskUtil::getCepMasked($paciente->cidadao->domicilio->endereco->logradouro->cep)
|
||||
: '';
|
||||
|
||||
$data['receitas'][$key] = [
|
||||
'isEspecial' => false,
|
||||
'profissional' => [
|
||||
'nome' => $receita->updatedLotacao->usuario->cidadao->nome,
|
||||
'cbo' => $receita->updatedLotacao->ocupacao->nome,
|
||||
'documento' => $receita->updatedLotacao->usuario->registro_tipo_id
|
||||
? ($receita->updatedLotacao->usuario->registro_tipo_id === TipoRegistroUsuario::OUTRO
|
||||
? $receita->updatedLotacao->usuario->registro_tipo_outro
|
||||
: $receita->updatedLotacao->usuario->registroTipo->sigla
|
||||
) . ": {$receita->updatedLotacao->usuario->registro_numero}"
|
||||
: 'Conselho profissional: NÃO INFORMADO',
|
||||
],
|
||||
'unidade' => [
|
||||
'endereco' => $receita->updatedLotacao->infraestrutura->endereco->completo,
|
||||
'telefone' => MaskUtil::getPhoneMasked($receita->updatedLotacao->infraestrutura->telefone),
|
||||
],
|
||||
'paciente' => [
|
||||
'nome' => $paciente->cidadao->nome,
|
||||
'nomeSocial' => $paciente->cidadao->nome_social,
|
||||
'prefereNomeSocial' => $paciente->cidadao->preferencia_nome_id === PreferenciaNome::NOME_SOCIAL,
|
||||
'endereco' => $enderecoPaciente,
|
||||
'telefone' => MaskUtil::getPhoneMasked($paciente->cidadao->telefone_principal->numero ?? null),
|
||||
],
|
||||
'dataCadastro' => [
|
||||
'porExtenso' => $receita->created_at->translatedFormat('d \de F \de Y'),
|
||||
],
|
||||
'medicamentos' => [],
|
||||
];
|
||||
|
||||
$medicamentos = $receita->medicamentos->where('medicamento.receita_tipo_id', TipoReceita::COMUM);
|
||||
|
||||
foreach ($medicamentos as $medicamento) {
|
||||
$data['receitas'][$key]['medicamentos'][] = [
|
||||
'nome' => $medicamento->medicamento->nome,
|
||||
'usoContinuo' => $medicamento->uso_continuo,
|
||||
'doseUnica' => $medicamento->dose_unica,
|
||||
'livre' => $medicamento->livre,
|
||||
'viaAdministracao' => $medicamento->medicamento->via_administracao_id === ViaAdministracao::OUTRAS
|
||||
? $medicamento->via_administracao_outras
|
||||
: $medicamento->medicamento->viaAdministracao->nome,
|
||||
'posologia' => $medicamento->livre ? $medicamento->descricao : $medicamento->posologia,
|
||||
'recomendacoes' => $medicamento->recomendacoes ?? '',
|
||||
'descricao' => $medicamento->descricao ?? ''
|
||||
];
|
||||
}
|
||||
|
||||
$medicamentosManuais = $receita->medicamentos->whereNotNull('medicamento_manual');
|
||||
|
||||
foreach ($medicamentosManuais as $medicamentoManual) {
|
||||
$data['receitas'][$key]['medicamentos'][] = [
|
||||
'medicamento_manual' => $medicamentoManual->medicamento_manual,
|
||||
'usoContinuo' => $medicamentoManual->uso_continuo,
|
||||
'doseUnica' => $medicamentoManual->dose_unica,
|
||||
'livre' => $medicamentoManual->livre,
|
||||
'viaAdministracao' => null,
|
||||
'posologia' => $medicamentoManual->livre ? $medicamentoManual->descricao : $medicamentoManual->posologia,
|
||||
'recomendacoes' => $medicamentoManual->recomendacoes ?? '',
|
||||
'descricao' => $medicamentoManual->descricao ?? ''
|
||||
];
|
||||
}
|
||||
|
||||
$prescricoesManuais = $receita->medicamentos->whereNotNull('prescricao_manual');
|
||||
|
||||
foreach ($prescricoesManuais as $prescricaoManual) {
|
||||
$data['receitas'][$key]['medicamentos'][] = [
|
||||
'prescricao_manual' => $prescricaoManual->prescricao_manual,
|
||||
];
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
$paciente = Paciente::findOrFail(request()->paciente_id);
|
||||
$lotacao = Lotacao::findOrFail(auth()->payload()->get('lotacao_id'));
|
||||
|
||||
$enderecoPaciente = $paciente->cidadao->domicilio
|
||||
? "{$paciente->cidadao->domicilio->endereco->completo} - "
|
||||
. MaskUtil::getCepMasked($paciente->cidadao->domicilio->endereco->logradouro->cep)
|
||||
: '';
|
||||
|
||||
$data['receitas'][$key] = [
|
||||
'isEspecial' => false,
|
||||
'profissional' => [
|
||||
'nome' => $lotacao->usuario->cidadao->nome,
|
||||
'cbo' => $lotacao->ocupacao->nome,
|
||||
'documento' => $lotacao->usuario->registro_tipo_id
|
||||
? ($lotacao->usuario->registro_tipo_id === TipoRegistroUsuario::OUTRO
|
||||
? $lotacao->usuario->registro_tipo_outro
|
||||
: $lotacao->usuario->registroTipo->sigla
|
||||
) . ": {$lotacao->usuario->registro_numero}"
|
||||
: 'Conselho profissional: NÃO INFORMADO',
|
||||
],
|
||||
'unidade' => [
|
||||
'endereco' => $lotacao->infraestrutura->endereco->completo,
|
||||
'telefone' => MaskUtil::getPhoneMasked($lotacao->infraestrutura->telefone),
|
||||
],
|
||||
'paciente' => [
|
||||
'nome' => $paciente->cidadao->nome,
|
||||
'nomeSocial' => $paciente->cidadao->nome_social,
|
||||
'prefereNomeSocial' => $paciente->cidadao->preferencia_nome_id === PreferenciaNome::NOME_SOCIAL,
|
||||
'endereco' => $enderecoPaciente,
|
||||
'telefone' => MaskUtil::getPhoneMasked($paciente->cidadao->telefone_principal->numero ?? null),
|
||||
],
|
||||
'dataCadastro' => [
|
||||
'porExtenso' => Carbon::now()->translatedFormat('d \de F \de Y'),
|
||||
],
|
||||
'medicamentos' => [],
|
||||
];
|
||||
|
||||
foreach ($receita['medicamentos'] as $medicamento) {
|
||||
|
||||
$medicamento = new ReceitaMedicamento($medicamento);
|
||||
|
||||
if ($medicamento->medicamento && $medicamento->medicamento->receita_tipo_id === TipoReceita::COMUM) {
|
||||
|
||||
$data['receitas'][$key]['medicamentos'][] = [
|
||||
'nome' => $medicamento->medicamento->nome,
|
||||
'usoContinuo' => $medicamento->uso_continuo,
|
||||
'doseUnica' => $medicamento->dose_unica,
|
||||
'livre' => $medicamento->livre,
|
||||
'viaAdministracao' => $medicamento->medicamento->via_administracao_id === ViaAdministracao::OUTRAS
|
||||
? $medicamento->via_administracao_outras
|
||||
: $medicamento->medicamento->viaAdministracao->nome,
|
||||
'posologia' => $medicamento->livre ? $medicamento->descricao : $medicamento->posologia,
|
||||
'recomendacoes' => $medicamento->recomendacoes ?? '',
|
||||
'descricao' => $medicamento->descricao ?? ''
|
||||
];
|
||||
}
|
||||
|
||||
if ($medicamento->medicamento_manual) {
|
||||
|
||||
$data['receitas'][$key]['medicamentos'][] = [
|
||||
'medicamento_manual' => $medicamento->medicamento_manual,
|
||||
'usoContinuo' => $medicamento->uso_continuo,
|
||||
'doseUnica' => $medicamento->dose_unica,
|
||||
'livre' => $medicamento->livre,
|
||||
'viaAdministracao' => null,
|
||||
'posologia' => $medicamento->livre ? $medicamento->descricao : $medicamento->posologia,
|
||||
'recomendacoes' => $medicamento->recomendacoes ?? '',
|
||||
'descricao' => $medicamento->descricao ?? '',
|
||||
];
|
||||
}
|
||||
|
||||
if ($medicamento->prescricao_manual) {
|
||||
|
||||
$data['receitas'][$key]['medicamentos'][] = [
|
||||
'prescricao_manual' => $medicamento->prescricao_manual,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Template::make(self::TITLE, self::TEMPLATE, true)->withData($data)->getHtml();
|
||||
}
|
||||
|
||||
public function __invoke($atendimentoId = null)
|
||||
{
|
||||
$pdf = new Pdf();
|
||||
$pdf->setPaper('A4', 'landscape');
|
||||
|
||||
return $pdf->stream(self::getTemplate($atendimentoId, request()->all()), 'receita-medica');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Impressao\ProntoAtendimento\AtendimentoMedico;
|
||||
|
||||
use App\Enums\Cadastro\Medicamento\TipoReceita;
|
||||
use App\Enums\Cadastro\Medicamento\ViaAdministracao;
|
||||
use App\Enums\Cadastro\SujeitoAtencao\PreferenciaNome;
|
||||
use App\Enums\Cadastro\SujeitoAtencao\TipoRegistroUsuario;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Lotacao;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Paciente;
|
||||
use App\Models\ProntoAtendimento\Atendimento\Medico\Receita;
|
||||
use App\Models\ProntoAtendimento\Atendimento\Medico\ReceitaMedicamento;
|
||||
use App\Utils\DataUtil;
|
||||
use App\Utils\Exports\Pdf;
|
||||
use App\Utils\Exports\Template;
|
||||
use App\Utils\MaskUtil;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class ReceitaEspecialController extends Controller
|
||||
{
|
||||
private const TITLE = 'Receituário controle especial';
|
||||
private const TEMPLATE = 'pronto-atendimento.atendimento-medico.receita-medica';
|
||||
|
||||
public static function getTemplate($atendimentoId = null, $params = [])
|
||||
{
|
||||
$receitasIds = $params['receitas_ids'] ?? [];
|
||||
$params['para_assinatura_eletronica'] = $params['para_assinatura_eletronica'] ?? false;
|
||||
|
||||
$paraAssinaturaEletronica = $params['para_assinatura_eletronica'] === true
|
||||
|| (DataUtil::isStringBoolean($params['para_assinatura_eletronica'])
|
||||
&& DataUtil::isStringTrue($params['para_assinatura_eletronica']));
|
||||
|
||||
$receitas = $atendimentoId
|
||||
? Receita::orderByDesc('created_at')
|
||||
->whereHas('medicamentos')
|
||||
->whereHas('atendimentoMedico', function($query) use ($atendimentoId) {
|
||||
$query->where('atendimento_id', $atendimentoId);
|
||||
})
|
||||
->when(!empty($receitasIds), fn ($q) => $q->whereIn('id', $receitasIds))
|
||||
->get()
|
||||
: request()->receitas;
|
||||
|
||||
$data['receitas'] = [];
|
||||
$data['exibirAssinatura'] = !$paraAssinaturaEletronica;
|
||||
|
||||
$tiposEpeciais = collect([
|
||||
TipoReceita::ESPECIAL,
|
||||
TipoReceita::ESPECIAL_AMARELA,
|
||||
TipoReceita::ESPECIAL_AZUL
|
||||
]);
|
||||
|
||||
foreach ($receitas as $key => $receita) {
|
||||
|
||||
if ((is_array($receita) && is_numeric($receita['id'] ?? null))
|
||||
|| $receita instanceof Receita
|
||||
) {
|
||||
|
||||
if (!($receita instanceof Receita)) {
|
||||
|
||||
$receita = Receita::findOrFail($receita['id']);
|
||||
}
|
||||
|
||||
$paciente = $receita->atendimentoMedico->atendimento->faa->paciente;
|
||||
|
||||
$enderecoPaciente = $paciente->cidadao->domicilio
|
||||
? "{$paciente->cidadao->domicilio->endereco->completo} - "
|
||||
. MaskUtil::getCepMasked($paciente->cidadao->domicilio->endereco->logradouro->cep)
|
||||
: '';
|
||||
|
||||
$data['receitas'][$key] = [
|
||||
'isEspecial' => true,
|
||||
'profissional' => [
|
||||
'nome' => $receita->updatedLotacao->usuario->cidadao->nome,
|
||||
'cbo' => $receita->updatedLotacao->ocupacao->nome,
|
||||
'documento' => $receita->updatedLotacao->usuario->registro_tipo_id
|
||||
? ($receita->updatedLotacao->usuario->registro_tipo_id === TipoRegistroUsuario::OUTRO
|
||||
? $receita->updatedLotacao->usuario->registro_tipo_outro
|
||||
: $receita->updatedLotacao->usuario->registroTipo->sigla
|
||||
) . ": {$receita->updatedLotacao->usuario->registro_numero}"
|
||||
: 'Conselho profissional: NÃO INFORMADO',
|
||||
],
|
||||
'unidade' => [
|
||||
'endereco' => $receita->updatedLotacao->infraestrutura->endereco->completo,
|
||||
'telefone' => MaskUtil::getPhoneMasked($receita->updatedLotacao->infraestrutura->telefone),
|
||||
],
|
||||
'paciente' => [
|
||||
'nome' => $paciente->cidadao->nome,
|
||||
'nomeSocial' => $paciente->cidadao->nome_social,
|
||||
'prefereNomeSocial' => $paciente->cidadao->preferencia_nome_id === PreferenciaNome::NOME_SOCIAL,
|
||||
'endereco' => $enderecoPaciente,
|
||||
'rg' => $paciente->cidadao->carteiraIdentidade->numero ?? null,
|
||||
'telefone' => MaskUtil::getPhoneMasked($paciente->cidadao->telefone_principal->numero ?? null),
|
||||
],
|
||||
'dataCadastro' => [
|
||||
'porExtenso' => $receita->created_at->translatedFormat('d \de F \de Y'),
|
||||
],
|
||||
'medicamentos' => [],
|
||||
];
|
||||
|
||||
$medicamentos = $receita->medicamentos
|
||||
->whereIn('medicamento.receita_tipo_id', $tiposEpeciais->toArray());
|
||||
|
||||
foreach ($medicamentos as $medicamento) {
|
||||
|
||||
$data['receitas'][$key]['medicamentos'][] = [
|
||||
'nome' => $medicamento->medicamento->nome,
|
||||
'usoContinuo' => $medicamento->uso_continuo,
|
||||
'doseUnica' => $medicamento->dose_unica,
|
||||
'livre' => $medicamento->livre,
|
||||
'viaAdministracao' => $medicamento->medicamento->via_administracao_id === ViaAdministracao::OUTRAS
|
||||
? $medicamento->via_administracao_outras
|
||||
: $medicamento->medicamento->viaAdministracao->nome,
|
||||
'posologia' => $medicamento->livre ? $medicamento->descricao : $medicamento->posologia,
|
||||
'recomendacoes' => $medicamento->recomendacoes ?? '',
|
||||
'descricao' => $medicamento->descricao ?? ''
|
||||
];
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
$paciente = Paciente::findOrFail(request()->paciente_id);
|
||||
$lotacao = Lotacao::findOrFail(auth()->payload()->get('lotacao_id'));
|
||||
|
||||
$enderecoPaciente = $paciente->cidadao->domicilio
|
||||
? "{$paciente->cidadao->domicilio->endereco->completo} - "
|
||||
. MaskUtil::getCepMasked($paciente->cidadao->domicilio->endereco->logradouro->cep)
|
||||
: '';
|
||||
|
||||
$data['receitas'][$key] = [
|
||||
'isEspecial' => true,
|
||||
'profissional' => [
|
||||
'nome' => $lotacao->usuario->cidadao->nome,
|
||||
'cbo' => $lotacao->ocupacao->nome,
|
||||
'documento' => $lotacao->usuario->registro_tipo_id
|
||||
? ($lotacao->usuario->registro_tipo_id === TipoRegistroUsuario::OUTRO
|
||||
? $lotacao->usuario->registro_tipo_outro
|
||||
: $lotacao->usuario->registroTipo->sigla
|
||||
) . ": {$lotacao->usuario->registro_numero}"
|
||||
: 'Conselho profissional: NÃO INFORMADO',
|
||||
],
|
||||
'unidade' => [
|
||||
'endereco' => $lotacao->infraestrutura->endereco->completo,
|
||||
'telefone' => MaskUtil::getPhoneMasked($lotacao->infraestrutura->telefone),
|
||||
],
|
||||
'paciente' => [
|
||||
'nome' => $paciente->cidadao->nome,
|
||||
'nomeSocial' => $paciente->cidadao->nome_social,
|
||||
'prefereNomeSocial' => $paciente->cidadao->preferencia_nome_id === PreferenciaNome::NOME_SOCIAL,
|
||||
'endereco' => $enderecoPaciente,
|
||||
'rg' => $paciente->cidadao->carteiraIdentidade->numero ?? null,
|
||||
'telefone' => MaskUtil::getPhoneMasked($paciente->cidadao->telefone_principal->numero ?? null),
|
||||
],
|
||||
'dataCadastro' => [
|
||||
'porExtenso' => Carbon::now()->translatedFormat('d \de F \de Y'),
|
||||
],
|
||||
'medicamentos' => [],
|
||||
];
|
||||
|
||||
foreach ($receita['medicamentos'] as $medicamento) {
|
||||
|
||||
$medicamento = new ReceitaMedicamento($medicamento);
|
||||
|
||||
if (!$medicamento->medicamento || !$tiposEpeciais->contains($medicamento->medicamento->receita_tipo_id)) {
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$data['receitas'][$key]['medicamentos'][] = [
|
||||
'nome' => $medicamento->medicamento->nome,
|
||||
'usoContinuo' => $medicamento->uso_continuo,
|
||||
'doseUnica' => $medicamento->dose_unica,
|
||||
'livre' => $medicamento->livre,
|
||||
'viaAdministracao' => $medicamento->medicamento->via_administracao_id === ViaAdministracao::OUTRAS
|
||||
? $medicamento->via_administracao_outras
|
||||
: $medicamento->medicamento->viaAdministracao->nome,
|
||||
'posologia' => $medicamento->livre ? $medicamento->descricao : $medicamento->posologia,
|
||||
'recomendacoes' => $medicamento->recomendacoes ?? '',
|
||||
'descricao' => $medicamento->descricao ?? ''
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Template::make(self::TITLE, self::TEMPLATE, true)->withData($data)->getHtml();
|
||||
}
|
||||
|
||||
public function __invoke($atendimentoId = null)
|
||||
{
|
||||
$pdf = new Pdf();
|
||||
$pdf->setPaper('A4', 'landscape');
|
||||
|
||||
return $pdf->stream(self::getTemplate($atendimentoId, request()->all()), 'receita-medica-especial');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
<?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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Impressao\ProntoAtendimento\AtendimentoMedico;
|
||||
|
||||
use App\Enums\Parametrizacao\Exame\Tipo;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ProntoAtendimento\Atendimento\Atendimento;
|
||||
use App\Models\ProntoAtendimento\Atendimento\Medico\AtendimentoMedico;
|
||||
use App\Models\ProntoAtendimento\PedidoExame\PedidoExame;
|
||||
use App\Utils\Exports\Pdf;
|
||||
use App\Utils\Exports\Template;
|
||||
use App\Utils\MaskUtil;
|
||||
|
||||
class SolicitacaoExameImagemController extends Controller
|
||||
{
|
||||
private const TITLE = 'Solicitação de exames de imagem';
|
||||
private const TEMPLATE = 'pronto-atendimento.atendimento-medico.solicitacao-exames-imagem';
|
||||
|
||||
public function __invoke(int $atendimentoId)
|
||||
{
|
||||
return (new Pdf)->stream(self::getTemplate($atendimentoId), 'solicitacao-exames-imagem');
|
||||
}
|
||||
|
||||
public static function getTemplate(int $atendimentoId)
|
||||
{
|
||||
$pedidosExames = PedidoExame::orderByDesc('created_at')
|
||||
->where('atendimento_id', $atendimentoId)
|
||||
->get();
|
||||
|
||||
$data['paciente'] = self::getPacienteData(Atendimento::findOrFail($atendimentoId));
|
||||
$data['pedidosExames'] = [];
|
||||
|
||||
foreach ($pedidosExames as $pedidoExame) {
|
||||
|
||||
$data['pedidosExames'][] = [
|
||||
'urgente' => $pedidoExame->urgente,
|
||||
'data' => $pedidoExame->created_at->format('d/m/Y H:i:s'),
|
||||
'justificativa' => $pedidoExame->justificativa,
|
||||
'medico' => [
|
||||
'nome' => $pedidoExame->createdLotacao->usuario->cidadao->nome,
|
||||
'cbo' => $pedidoExame->createdLotacao->ocupacao->nome
|
||||
],
|
||||
'exames' => self::getExames($pedidoExame)
|
||||
];
|
||||
}
|
||||
|
||||
return Template::make(self::TITLE, self::TEMPLATE)->withData($data)->getHtml();
|
||||
}
|
||||
|
||||
private static function getExames($pedidoExme)
|
||||
{
|
||||
$result = [];
|
||||
|
||||
foreach ($pedidoExme['exames'] as $item) {
|
||||
if ($item->exame->tipo_id === Tipo::IMAGEM) {
|
||||
$result[] = [
|
||||
'id' => $item->exame->id,
|
||||
'nome' => $item->exame->nome,
|
||||
'codigo' => $item->exame->codigo,
|
||||
'observacao_medico' => $item->observacao_medico,
|
||||
'observacao_executante' => $item->observacao_executante,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Impressao\ProntoAtendimento\AtendimentoMedico;
|
||||
|
||||
use App\Enums\Parametrizacao\Exame\Tipo;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ProntoAtendimento\Atendimento\Atendimento;
|
||||
use App\Models\ProntoAtendimento\Atendimento\Medico\AtendimentoMedico;
|
||||
use App\Models\ProntoAtendimento\PedidoExame\PedidoExame;
|
||||
use App\Utils\Exports\Pdf;
|
||||
use App\Utils\Exports\Template;
|
||||
use App\Utils\MaskUtil;
|
||||
|
||||
class SolicitacaoExameLaboratorialController extends Controller
|
||||
{
|
||||
private const TITLE = 'Solicitação de exames laboratoriais';
|
||||
private const TEMPLATE = 'pronto-atendimento.atendimento-medico.solicitacao-exames-laboratoriais';
|
||||
|
||||
public static function getTemplate(int $atendimentoId)
|
||||
{
|
||||
$pedidosExames = PedidoExame::orderByDesc('created_at')
|
||||
->where('atendimento_id', $atendimentoId)
|
||||
->get();
|
||||
|
||||
$data['paciente'] = self::getPacienteData(Atendimento::findOrFail($atendimentoId));
|
||||
$data['pedidosExames'] = [];
|
||||
|
||||
foreach ($pedidosExames as $pedidoExame) {
|
||||
$data['pedidosExames'][] = [
|
||||
'urgente' => $pedidoExame->urgente,
|
||||
'data' => $pedidoExame->created_at->format('d/m/Y H:i:s'),
|
||||
'justificativa' => $pedidoExame->justificativa,
|
||||
'medico' => [
|
||||
'nome' => $pedidoExame->createdLotacao->usuario->cidadao->nome,
|
||||
'cbo' => $pedidoExame->createdLotacao->ocupacao->nome
|
||||
],
|
||||
'exames' => self::getExames($pedidoExame)
|
||||
];
|
||||
}
|
||||
|
||||
return Template::make(self::TITLE, self::TEMPLATE)->withData($data)->getHtml();
|
||||
}
|
||||
|
||||
private static function getExames($pedidoExme)
|
||||
{
|
||||
$result = [];
|
||||
|
||||
foreach ($pedidoExme['exames'] as $item) {
|
||||
if ($item->exame->tipo_id === Tipo::LABORATORIAL) {
|
||||
$result[] = [
|
||||
'id' => $item->exame->id,
|
||||
'nome' => $item->exame->nome,
|
||||
'codigo' => $item->exame->codigo,
|
||||
'observacao_medico' => $item->observacao_medico,
|
||||
'observacao_executante' => $item->observacao_executante,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
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(),
|
||||
];
|
||||
}
|
||||
|
||||
public function __invoke(int $pedidoExameId)
|
||||
{
|
||||
return (new Pdf)->stream(self::getTemplate($pedidoExameId), 'solicitacao-exames-laboratoriais');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user