3389 lines
133 KiB
PHP
3389 lines
133 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\ProntoAtendimento\Atendimento\Enfermagem;
|
|
|
|
use App\Enums\Cadastro\Estabelecimento\SetorTipo;
|
|
use App\Enums\Cadastro\SujeitoAtencao\Deficiencia;
|
|
use App\Enums\Cadastro\SujeitoAtencao\FatorRisco as FatorRiscoEnum;
|
|
use App\Enums\Cadastro\SujeitoAtencao\Sexo;
|
|
use App\Enums\Cadastro\UnidadeMedida as UnidadeMedidaEnum;
|
|
use App\Enums\Geral\TipoMedidaAltura as TipoMedidaAlturaEnum;
|
|
use App\Enums\Parametrizacao\Exame\Status as ExameStatusEnum;
|
|
use App\Enums\Parametrizacao\Exame\Tipo as ExameTipo;
|
|
use App\Enums\ProntoAtendimento\Atendimento\Desfecho as DesfechoEnum;
|
|
use App\Enums\ProntoAtendimento\Atendimento\DorToracica as DorToracicaEnum;
|
|
use App\Enums\ProntoAtendimento\Atendimento\Medico\DeclaracaoComparecimentoTipo;
|
|
use App\Enums\ProntoAtendimento\OrigemUnidadeEncaminhamento;
|
|
use App\Enums\Sigtap\Ocupacao as OcupacaoEnum;
|
|
use App\Enums\Sigtap\Procedimento as ProcedimentoEnum;
|
|
use App\Exceptions\ProntoAtendimento\Atendimento\Enfermagem\PedidoExameCannotChangeStatusException;
|
|
use App\Exceptions\ProntoAtendimento\Atendimento\Enfermagem\PedidoExameItemCannotChangeStatusException;
|
|
use App\Exceptions\ProntoAtendimento\Atendimento\Enfermagem\PrescricaoInternaAplicacaoCannotChangeStatusException;
|
|
use App\Exceptions\ProntoAtendimento\Atendimento\Enfermagem\ServicoEnfermagemCannotChangeStatusException;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Controllers\Impressao\ProntoAtendimento\FaaEletronicaController;
|
|
use App\Http\Requests\ProntoAtendimento\Atendimento\EnfermagemRequest;
|
|
use App\Models\Cadastro\Estabelecimento\CentroCusto;
|
|
use App\Models\Cadastro\Estabelecimento\Unidade;
|
|
use App\Models\Cadastro\SujeitoAtencao\AlergiaCriticidade;
|
|
use App\Models\Cadastro\SujeitoAtencao\AlergiaTipo;
|
|
use App\Models\Cadastro\SujeitoAtencao\Cidadao;
|
|
use App\Models\Cadastro\SujeitoAtencao\FatorRisco;
|
|
use App\Models\Cadastro\SujeitoAtencao\Lotacao;
|
|
use App\Models\Cadastro\UnidadeExterna;
|
|
use App\Models\Cadastro\UnidadeMedida;
|
|
use App\Models\ExameLaboratorial\Parametrizacao\LaboratorioFaturaUsuario;
|
|
use App\Models\ExameLaboratorial\Parametrizacao\UnidadeFaturamentoUsuario;
|
|
use App\Models\Geral\GlasgowAberturaOcular;
|
|
use App\Models\Geral\GlasgowInterpretacaoResultado;
|
|
use App\Models\Geral\GlasgowReatividadePupilar;
|
|
use App\Models\Geral\GlasgowRespostaMotora;
|
|
use App\Models\Geral\GlasgowRespostaVerbal;
|
|
use App\Models\Geral\MedidaTempo;
|
|
use App\Models\PainelSenha\Encaminhamento;
|
|
use App\Models\PainelSenha\Prioridade;
|
|
use App\Models\Parametrizacao\Exame\ExameStatus;
|
|
use App\Models\Parametrizacao\Procedimento as ParametrizacaoProcedimento;
|
|
use App\Models\ProntoAtendimento\Atendimento\Atendimento;
|
|
use App\Models\ProntoAtendimento\Atendimento\Desfecho;
|
|
use App\Models\ProntoAtendimento\Atendimento\Enfermagem\Anotacao;
|
|
use App\Models\ProntoAtendimento\Atendimento\Enfermagem\AtendimentoEnfermagem;
|
|
use App\Models\ProntoAtendimento\Atendimento\Enfermagem\Avaliacao;
|
|
use App\Models\ProntoAtendimento\Atendimento\Enfermagem\Diagnostico;
|
|
use App\Models\ProntoAtendimento\Atendimento\Enfermagem\Historico;
|
|
use App\Models\ProntoAtendimento\Atendimento\Enfermagem\Implementacao;
|
|
use App\Models\ProntoAtendimento\Atendimento\Enfermagem\Planejamento;
|
|
use App\Models\ProntoAtendimento\Atendimento\EscalaComaGlasgow;
|
|
use App\Models\ProntoAtendimento\Atendimento\PrescricaoInterna;
|
|
use App\Models\ProntoAtendimento\Atendimento\PrescricaoInternaMedicamento;
|
|
use App\Models\ProntoAtendimento\Atendimento\PrescricaoInternaMedicamentoAplicacao;
|
|
use App\Models\ProntoAtendimento\Atendimento\ServicoEnfermagem;
|
|
use App\Models\ProntoAtendimento\Atendimento\Triagem\FormularioDorToracica;
|
|
use App\Models\ProntoAtendimento\Atendimento\Triagem\OrigemDorToracica;
|
|
use App\Models\ProntoAtendimento\Atendimento\Triagem\RelacionadoFormularioDorToracica;
|
|
use App\Models\ProntoAtendimento\ClassificacaoRisco\ClassificacaoRisco;
|
|
use App\Models\ProntoAtendimento\Parametrizacao\FaturamentoExameLaboratorial;
|
|
use App\Models\ProntoAtendimento\Parametrizacao\Parametrizacao;
|
|
use App\Models\ProntoAtendimento\PedidoExame\Item;
|
|
use App\Models\ProntoAtendimento\PedidoExame\Observacao;
|
|
use App\Models\ProntoAtendimento\PedidoExame\PedidoExame;
|
|
use App\Models\ProntoAtendimento\PrescricaoInternaLocalAplicacao;
|
|
use App\Models\Sigtap\Procedimento;
|
|
use App\Services\Ambulatorio\AtendimentoService as AmbulatorioAtendimentoService;
|
|
use App\Services\Parametrizacao\ProntoAtendimento\AtendimentoMedicoService as ParametrizacaoAtendimentoMedicoService;
|
|
use App\Services\ProntoAtendimento\AcidenteTrabalhoService;
|
|
use App\Services\ProntoAtendimento\Atendimento\AtendimentoService;
|
|
use App\Services\ProntoAtendimento\Atendimento\RaatService;
|
|
use App\Services\ProntoAtendimento\Fila\FilaService;
|
|
use App\Services\ProntoAtendimento\Impressao\ImpressaoService;
|
|
use App\Services\ProntoAtendimento\PedidoExame\LaudoService;
|
|
use App\Services\ProntoAtendimento\PlantaoService;
|
|
use App\Services\Sigtap\ProcedimentoValidationService;
|
|
use Carbon\Carbon;
|
|
use Exception;
|
|
use Illuminate\Http\Response;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class AtendimentoEnfermagemController extends Controller
|
|
{
|
|
protected $modulo = 'pronto-atendimento';
|
|
protected $funcionalidade = 'atendimento-enfermagem';
|
|
|
|
public function index()
|
|
{
|
|
$plantao = PlantaoService::getCurrentPlantao();
|
|
|
|
return response()->json(
|
|
[
|
|
'additionals' => [
|
|
'plantao_id' => $plantao->id ?? null,
|
|
'plantao_faixa_etaria_id' => $plantao->faixa_etaria_id ?? null,
|
|
],
|
|
],
|
|
Response::HTTP_OK
|
|
);
|
|
}
|
|
|
|
public function storeFaaAssinada($id)
|
|
{
|
|
$path = 'assinatura-eletronica' . DIRECTORY_SEPARATOR . app('config')->get('database.default') . DIRECTORY_SEPARATOR . 'pronto-atendimento' . DIRECTORY_SEPARATOR . 'atendimento-enfermagem';
|
|
$file = "{$id}.PDF";
|
|
|
|
$atendimentoEnfermagem = AtendimentoEnfermagem::findOrFail($id);
|
|
|
|
if (!is_null($atendimentoEnfermagem)) {
|
|
$pdf = base64_decode(request()->faa_assinada['data']);
|
|
|
|
if (!Storage::disk('local')->put($path . DIRECTORY_SEPARATOR . $file, $pdf)) {
|
|
throw new Exception('Erro ao assinar o arquivo.');
|
|
} else {
|
|
$atendimentoEnfermagem->update(['is_faa_assinada' => true]);
|
|
}
|
|
}
|
|
|
|
return response($atendimentoEnfermagem->fresh(), Response::HTTP_OK);
|
|
}
|
|
|
|
public function create($id)
|
|
{
|
|
$this->auth(__FUNCTION__);
|
|
|
|
$centroCustoLogado = $this->getCentroCustoLogado();
|
|
|
|
$atendimento = Atendimento::where('fila_id', $id)
|
|
->orderBy('created_at', 'desc')
|
|
->firstOrFail();
|
|
|
|
$lotacaoLogada = Lotacao::find(auth()->payload()->get('lotacao_id'));
|
|
|
|
return response()->json(
|
|
[
|
|
'form' => $this->getFormData($atendimento, Carbon::now(), $centroCustoLogado),
|
|
'model' => $this->getModelData($atendimento, Carbon::now()),
|
|
'additionals' => [
|
|
'is_enfermeiro' => $lotacaoLogada->ocupacao->codigo === OcupacaoEnum::ENFERMEIRO,
|
|
'is_auxiliar_tecnico_enfermagem' => collect([
|
|
OcupacaoEnum::TECNICO_ENFERMAGEM,
|
|
OcupacaoEnum::TECNICO_ENFERMAGEM_TERAPIA_INTENSIVA,
|
|
OcupacaoEnum::TECNICO_ENFERMAGEM_TRABALHO,
|
|
OcupacaoEnum::TECNICO_ENFERMAGEM_PSIQUIATRICA,
|
|
OcupacaoEnum::TECNICO_ENFERMAGEM_ESTRATEGIA_SAUDE_FAMILIA,
|
|
OcupacaoEnum::AUXILIAR_ENFERMAGEM,
|
|
OcupacaoEnum::AUXILIAR_ENFERMAGEM_TRABALHO,
|
|
OcupacaoEnum::AUXILIAR_ENFERMAGEM_ESTRATEGIA_SAUDE_FAMILIA,
|
|
])->contains($lotacaoLogada->ocupacao->codigo),
|
|
'timeline' => AtendimentoService::getTimelineItems($id),
|
|
'is_encaminhado_da_recepcao' => $atendimento->atendimentosTriagem->count() === 0
|
|
&& $atendimento->atendimentosMedico->count() === 0
|
|
&& $atendimento->atendimentosExameImagem->count() === 0
|
|
&& $atendimento->pacienteObservacoes->count() === 0
|
|
]
|
|
],
|
|
Response::HTTP_OK
|
|
);
|
|
}
|
|
|
|
public function store(EnfermagemRequest $request)
|
|
{
|
|
$this->auth(__FUNCTION__);
|
|
|
|
$atendimentoEnfermagem = new AtendimentoEnfermagem();
|
|
|
|
DB::transaction(function() use ($atendimentoEnfermagem, $request) {
|
|
|
|
$atendimento = Atendimento::findOrFail($request->atendimento_id);
|
|
$params = $request->all();
|
|
|
|
PlantaoService::setStatusComAtendimento($request->plantao_id);
|
|
|
|
$atendimentoEnfermagem->fill(['plantao_id' => $request->plantao_id]);
|
|
$atendimento->atendimentosEnfermagem()->save($atendimentoEnfermagem);
|
|
|
|
if ($request->cancelamento_desfecho == true) {
|
|
|
|
$atendimentoEnfermagem->atendimento->faa->update([
|
|
'canceled_desfecho_lotacao_id' => auth()->payload()->get('lotacao_id'),
|
|
]);
|
|
}
|
|
|
|
$gestacaoData = $this->prepareGestacaoData($params, $atendimentoEnfermagem);
|
|
if (!is_null($gestacaoData)) {
|
|
|
|
$atendimento->gestacoes()->create($gestacaoData);
|
|
|
|
if ($params['gestacao'] && $params['gestacao']['dum']) {
|
|
|
|
$atendimento->faa->paciente->dum()->updateOrCreate(
|
|
['paciente_id' => $atendimento->faa->paciente->id],
|
|
['data_ultima_menstruacao' => $params['gestacao']['dum']]
|
|
);
|
|
}
|
|
}
|
|
|
|
if ($request->classificacao_risco_id) {
|
|
$classificacaoRiscoData = $this->prepareClassificacaoRiscoData($params, $atendimentoEnfermagem);
|
|
$atendimento->classificacoesRisco()->create($classificacaoRiscoData);
|
|
}
|
|
|
|
if ($request->alergias) {
|
|
|
|
$atendimento->faa->paciente->cidadao->alergias()->sync($this->prepareAlergiasData($request->alergias));
|
|
}
|
|
|
|
$atendimento->faa->paciente->cidadao->medicamentosUsoContinuo()->sync($this->prepareMedicamentosUsoContinuoData($params));
|
|
|
|
if ($request->fatores_risco) {
|
|
|
|
$atendimento->faa->paciente->cidadao->fatoresRisco()->sync($request->fatores_risco);
|
|
|
|
if ($params['gestacao'] && $params['gestacao']['gestante']) {
|
|
|
|
if (!$atendimento->faa->paciente->cidadao->fatoresRisco->contains(FatorRiscoEnum::GESTANTE)) {
|
|
|
|
$atendimento->faa->paciente->cidadao->fatoresRisco()->attach(FatorRiscoEnum::GESTANTE);
|
|
}
|
|
}
|
|
|
|
$this->handleFatorRiscoOutro($atendimento, $request);
|
|
}
|
|
|
|
$sinaisVitaisData = $this->prepareSinaisVitaisData($params, $atendimentoEnfermagem);
|
|
if (!empty($sinaisVitaisData)) {
|
|
|
|
$atendimento->sinaisVitais()->createMany($sinaisVitaisData);
|
|
}
|
|
|
|
$this->storeAvaliacoesAntropometricas($atendimentoEnfermagem, $params);
|
|
|
|
$observacaoData = $this->prepareObservacaoData($params, $atendimentoEnfermagem);
|
|
if (!is_null($observacaoData)) {
|
|
|
|
$atendimento->observacoes()->create($observacaoData);
|
|
}
|
|
|
|
if (isset($request->anotacoes) && !empty($request->anotacoes)) {
|
|
|
|
$atendimentoEnfermagem->anotacoes()->createMany($request->anotacoes);
|
|
}
|
|
|
|
if (isset($request->medicamentos_uso)) {
|
|
$atendimento->medicamentosUso()->create([
|
|
'atendimento_enfermagem_id' => $atendimentoEnfermagem->id,
|
|
'descricao' => $request->medicamentos_uso,
|
|
]);
|
|
}
|
|
|
|
$procedimentosData = $this->prepareProcedimentosData($params, $atendimentoEnfermagem);
|
|
if (!empty($procedimentosData)) {
|
|
|
|
$atendimento->procedimentos()->createMany($procedimentosData);
|
|
}
|
|
|
|
if (isset($request->servicos_enfermagem)) {
|
|
|
|
$servicosEnfermagem = $this->prepareServicosEnfermagem($atendimentoEnfermagem, $request->servicos_enfermagem);
|
|
$atendimentoEnfermagem->servicosEnfermagem()->saveMany($servicosEnfermagem);
|
|
}
|
|
|
|
if (isset($request->prescricao_interna_aplicacoes)) {
|
|
|
|
$prescricaoInternaAplicacoes = $this->preparePrescricaoInternaAplicacoesData(
|
|
$atendimentoEnfermagem,
|
|
$request->prescricao_interna_aplicacoes
|
|
);
|
|
|
|
$this->saveProcedimentosPrescricaoInterna($atendimentoEnfermagem, $prescricaoInternaAplicacoes);
|
|
|
|
$atendimentoEnfermagem->prescricaoInternaAplicacoes()->saveMany($prescricaoInternaAplicacoes);
|
|
}
|
|
|
|
if (isset($request->pedidos_exames)) {
|
|
|
|
$this->handlePedidosExames($atendimentoEnfermagem, $request->pedidos_exames);
|
|
}
|
|
|
|
$historicoData = $this->prepareHistoricoData($atendimentoEnfermagem, $params);
|
|
if (!empty($historicoData)) {
|
|
|
|
$atendimentoEnfermagem->historico()->create($historicoData);
|
|
}
|
|
|
|
$diagnosticoData = $this->prepareDiagnosticoData($atendimentoEnfermagem, $params);
|
|
if (!empty($diagnosticoData)) {
|
|
|
|
$atendimentoEnfermagem->diagnostico()->create($diagnosticoData);
|
|
}
|
|
|
|
$planejamentoData = $this->preparePlanejamentoData($atendimentoEnfermagem, $params);
|
|
if (!empty($planejamentoData)) {
|
|
|
|
$atendimentoEnfermagem->planejamento()->create($planejamentoData);
|
|
}
|
|
|
|
$implementacaoData = $this->prepareImplementacaoData($atendimentoEnfermagem, $params);
|
|
if (!empty($implementacaoData)) {
|
|
|
|
$atendimentoEnfermagem->implementacao()->create($implementacaoData);
|
|
}
|
|
|
|
$avaliacaoData = $this->prepareAvaliacaoData($atendimentoEnfermagem, $params);
|
|
if (!empty($avaliacaoData)) {
|
|
|
|
$atendimentoEnfermagem->avaliacao()->create($avaliacaoData);
|
|
}
|
|
|
|
if (isset($request['escala_coma_glasgow'])) {
|
|
$atendimentoEnfermagem->escalasComaGlasgow()->createMany($request['escala_coma_glasgow']);
|
|
}
|
|
|
|
if (isset($params['finalizacao'])) {
|
|
|
|
$this->storeFinalizacao($params['finalizacao'], $atendimentoEnfermagem);
|
|
|
|
} else if (isset($params['centro_custo_id_para'])) {
|
|
|
|
FilaService::forward([
|
|
'centro_custo_id_para' => $params['centro_custo_id_para']
|
|
], $atendimento->fila_id);
|
|
}
|
|
});
|
|
|
|
$atendimentoEnfermagem->refresh();
|
|
|
|
$atendimentoEnfermagem->faa_id = $atendimentoEnfermagem->atendimento->faa_id;
|
|
|
|
$atendimentoEnfermagem->impressoes = ImpressaoService::getImpressoes(
|
|
$atendimentoEnfermagem->atendimento_id,
|
|
);
|
|
|
|
$hasClassificacaoRisco = false;
|
|
|
|
if ($atendimentoEnfermagem->classificacaoRisco) {
|
|
|
|
$classificacaoRiscoAnterior = $atendimentoEnfermagem->atendimento->classificacoesRisco()
|
|
->where('id', $atendimentoEnfermagem->classificacaoRisco->id - 1)
|
|
->first();
|
|
|
|
$hasClassificacaoRisco = !is_null($classificacaoRiscoAnterior)
|
|
&& $classificacaoRiscoAnterior->classificacao_risco_id !=
|
|
$atendimentoEnfermagem->classificacaoRisco->classificacao_risco_id;
|
|
}
|
|
|
|
$assinar = (Parametrizacao::first()->assinatura_eletronica ?? false) && (
|
|
$hasClassificacaoRisco
|
|
|| !is_null($atendimentoEnfermagem->medicamentoUso)
|
|
|| !(FaaEletronicaController::getAtendimentosEnfermagemData(collect([$atendimentoEnfermagem]))[0]['nodata'])
|
|
);
|
|
|
|
$atendimentoEnfermagem->assinar = $assinar;
|
|
|
|
return response()->json($atendimentoEnfermagem, Response::HTTP_CREATED);
|
|
}
|
|
|
|
private function saveProcedimentosPrescricaoInterna($atendimentoEnfermagem, $prescricaoInternaAplicacoes)
|
|
{
|
|
$quantidades = [];
|
|
|
|
foreach ($prescricaoInternaAplicacoes as $aplicacao) {
|
|
|
|
if ($aplicacao->status_id == ExameStatusEnum::REALIZADO) {
|
|
|
|
$hasAplicacaoRealizada = $aplicacao->prescricaoInternaMedicamento->prescricaoInterna()
|
|
->whereHas('medicamentos.aplicacoes', function ($query) {
|
|
|
|
$query->where('status_id', ExameStatusEnum::REALIZADO);
|
|
})
|
|
->get()
|
|
->isNotEmpty();
|
|
|
|
if (!$hasAplicacaoRealizada) {
|
|
|
|
$quantidades[$aplicacao->prescricaoInternaMedicamento->prescricao_interna_id] = 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
$quantidadeTotal = 0;
|
|
|
|
foreach ($quantidades as $quantidade) {
|
|
|
|
$quantidadeTotal += $quantidade;
|
|
}
|
|
|
|
if ($quantidadeTotal > 0) {
|
|
|
|
$this->faturarProcedimentoPadraoPrescricaoInterna($atendimentoEnfermagem, $quantidadeTotal);
|
|
}
|
|
}
|
|
|
|
private function faturarProcedimentoPadraoPrescricaoInterna($atendimentoEnfermagem, $quantidade)
|
|
{
|
|
$procedimentos = collect();
|
|
$procedimento = $this->getProcedimentoPadraoPrescricaoInterna();
|
|
|
|
$validation = new ProcedimentoValidationService($procedimento);
|
|
|
|
if ($validation->isOcupacaoValid($this->getCurrentLotacao()->ocupacao)) {
|
|
|
|
$procedimentos->push($atendimentoEnfermagem->atendimento->procedimentos()->create([
|
|
'lotacao_id' => auth()->payload()->get('lotacao_id'),
|
|
'atendimento_enfermagem_id' => $atendimentoEnfermagem->id,
|
|
'procedimento_id' => $procedimento->id,
|
|
'quantidade' => $quantidade,
|
|
]));
|
|
}
|
|
|
|
return $procedimentos;
|
|
}
|
|
|
|
private function getProcedimentoPadraoPrescricaoInterna()
|
|
{
|
|
return Procedimento::where(
|
|
'codigo',
|
|
ProcedimentoEnum::ADMINISTRACAO_DE_MEDICAMENTOS_NA_ATENCAO_ESPECIALIZADA
|
|
)
|
|
->orderByDesc('competencia_id')
|
|
->firstOrFail();
|
|
}
|
|
|
|
private function storeAvaliacoesAntropometricas($atendimentoEnfermagem, $params)
|
|
{
|
|
$data = $this->prepareAvaliacaoAntropometricaData($params, $atendimentoEnfermagem);
|
|
|
|
if (is_null($data)) {
|
|
|
|
return;
|
|
}
|
|
|
|
$ultima = $atendimentoEnfermagem->atendimento->avaliacoesAntropometricas()
|
|
->orderByDesc('created_at')
|
|
->first();
|
|
|
|
if (!is_null($ultima)
|
|
&& $data['massa'] == $ultima->massa
|
|
&& $data['massa_unidade_medida_id'] == $ultima->massa_unidade_medida_id
|
|
&& $data['altura_tipo_medida_id'] == $ultima->altura_tipo_medida_id
|
|
&& $data['altura'] == $ultima->altura
|
|
&& $data['altura_unidade_medida_id'] == $ultima->altura_unidade_medida_id
|
|
) {
|
|
|
|
return;
|
|
}
|
|
|
|
$atendimentoEnfermagem->atendimento->avaliacoesAntropometricas()->create($data);
|
|
}
|
|
|
|
private function prepareAlergiasData($params)
|
|
{
|
|
$alergias = [];
|
|
|
|
foreach (($params ?? []) as $alergia) {
|
|
|
|
$alergias[$alergia['alergia_id']] = [
|
|
'criticidade_id' => $alergia['criticidade_id'],
|
|
'reacoes_observacoes' => $alergia['reacoes_observacoes'] ?? null,
|
|
];
|
|
}
|
|
|
|
return $alergias;
|
|
}
|
|
|
|
private function prepareMedicamentosUsoContinuoData(array $params) : array
|
|
{
|
|
$medicamentos = [];
|
|
|
|
foreach (($params['medicamentos_uso_continuo'] ?? []) as $medicamento) {
|
|
|
|
$medicamentos[] = $medicamento['medicamento_id'];
|
|
}
|
|
|
|
return $medicamentos;
|
|
}
|
|
|
|
private function prepareProcedimentosData(array $params, AtendimentoEnfermagem $atendimentoEnfermagem) : array
|
|
{
|
|
$procedimentos = [];
|
|
|
|
foreach (($params['procedimentos'] ?? []) as $procedimento) {
|
|
|
|
$procedimentos[] = [
|
|
'lotacao_id' => auth()->payload()->get('lotacao_id'),
|
|
'atendimento_enfermagem_id' => $atendimentoEnfermagem->id,
|
|
'procedimento_id' => $procedimento['procedimento_id'],
|
|
'cid_principal_id' => $procedimento['cid_principal_id'] ?? null,
|
|
'quantidade' => $procedimento['quantidade'],
|
|
];
|
|
}
|
|
|
|
if (!is_null($atendimentoEnfermagem->avaliacaoAntropometrica)) {
|
|
|
|
$this->addProcedimentoAvaliacaoAntropometricaData($procedimentos, $atendimentoEnfermagem);
|
|
}
|
|
|
|
$sinaisVitais = $atendimentoEnfermagem->sinaisVitais()->get();
|
|
|
|
if ($sinaisVitais->isNotEmpty()) {
|
|
|
|
$this->addProcedimentosSinaisVitaisData($sinaisVitais, $procedimentos, $atendimentoEnfermagem->id);
|
|
}
|
|
|
|
if (!is_null($params['servicos_enfermagem'] ?? null)) {
|
|
|
|
$this->handleProcedimentoRealizado($procedimentos, $atendimentoEnfermagem, $params['servicos_enfermagem']);
|
|
}
|
|
|
|
if (isset($params['finalizacao']) && $params['finalizacao']['desfecho_id'] === DesfechoEnum::EVASAO) {
|
|
|
|
$this->addProcedimentoPadraoData($procedimentos, $atendimentoEnfermagem->atendimento);
|
|
}
|
|
|
|
return $procedimentos;
|
|
}
|
|
|
|
private function addProcedimentoAvaliacaoAntropometricaData(&$procedimentos, $atendimentoEnfermagem)
|
|
{
|
|
$procedimento = Procedimento::where('codigo', ProcedimentoEnum::AVALIACAO_ANTROPOMETRICA)
|
|
->orderByDesc('competencia_id')
|
|
->firstOrFail();
|
|
|
|
$validation = new ProcedimentoValidationService($procedimento);
|
|
|
|
if ($validation->isOcupacaoValid($this->getCurrentLotacao()->ocupacao)) {
|
|
|
|
if (!$atendimentoEnfermagem->atendimento->procedimentos->contains('procedimento_id', $procedimento->id)) {
|
|
|
|
$procedimentos[] = [
|
|
'lotacao_id' => auth()->payload()->get('lotacao_id'),
|
|
'atendimento_enfermagem_id' => $atendimentoEnfermagem->id,
|
|
'procedimento_id' => $procedimento->id,
|
|
'quantidade' => 1,
|
|
];
|
|
}
|
|
}
|
|
}
|
|
|
|
private function addProcedimentosSinaisVitaisData($sinaisVitais, &$procedimentos, int $atendimentoEnfermagemId)
|
|
{
|
|
$quantidadeMedicoesPa = 0;
|
|
$quantidadeMedicoesGlicemia = 0;
|
|
|
|
foreach ($sinaisVitais as $sinaisVitaisItem) {
|
|
|
|
if (!is_null($sinaisVitaisItem->pa)) {
|
|
|
|
$quantidadeMedicoesPa++;
|
|
}
|
|
|
|
if (!is_null($sinaisVitaisItem->glicemia)) {
|
|
|
|
$quantidadeMedicoesGlicemia++;
|
|
}
|
|
}
|
|
|
|
if ($quantidadeMedicoesPa > 0) {
|
|
|
|
$this->addProcedimentoPaData($quantidadeMedicoesPa, $procedimentos, $atendimentoEnfermagemId);
|
|
}
|
|
|
|
if ($quantidadeMedicoesGlicemia > 0) {
|
|
|
|
$this->addProcedimentoGlicemiaData($quantidadeMedicoesGlicemia, $procedimentos, $atendimentoEnfermagemId);
|
|
}
|
|
}
|
|
|
|
private function addProcedimentoPaData($quantidade, &$procedimentos, int $atendimentoEnfermagemId)
|
|
{
|
|
$proc = Procedimento::where('codigo', ProcedimentoEnum::AFERICAO_PRESSAO_ARTERIAL)
|
|
->orderByDesc('competencia_id')
|
|
->firstOrFail();
|
|
|
|
$validation = new ProcedimentoValidationService($proc);
|
|
|
|
if ($validation->isOcupacaoValid($this->getCurrentLotacao()->ocupacao)) {
|
|
|
|
if (collect($procedimentos)->contains('procedimento_id', $proc->id)) {
|
|
|
|
foreach ($procedimentos as $i => $procedimento) {
|
|
|
|
if ($procedimento['procedimento_id'] === $proc->id) {
|
|
|
|
$procedimentos[$i]['quantidade'] += $quantidade;
|
|
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
|
|
$procedimentos[] = [
|
|
'lotacao_id' => auth()->payload()->get('lotacao_id'),
|
|
'atendimento_enfermagem_id' => $atendimentoEnfermagemId,
|
|
'procedimento_id' => $proc->id,
|
|
'quantidade' => $quantidade,
|
|
];
|
|
}
|
|
}
|
|
}
|
|
|
|
private function addProcedimentoGlicemiaData($quantidade, &$procedimentos, int $atendimentoEnfermagemId)
|
|
{
|
|
$proc = Procedimento::where('codigo', ProcedimentoEnum::GLICEMIA_CAPILAR)
|
|
->orderByDesc('competencia_id')
|
|
->firstOrFail();
|
|
|
|
$validation = new ProcedimentoValidationService($proc);
|
|
|
|
if ($validation->isOcupacaoValid($this->getCurrentLotacao()->ocupacao)) {
|
|
|
|
if (collect($procedimentos)->contains('procedimento_id', $proc->id)) {
|
|
|
|
foreach ($procedimentos as $i => $procedimento) {
|
|
|
|
if ($procedimento['procedimento_id'] === $proc->id) {
|
|
|
|
$procedimentos[$i]['quantidade'] += $quantidade;
|
|
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
|
|
$procedimentos[] = [
|
|
'lotacao_id' => auth()->payload()->get('lotacao_id'),
|
|
'atendimento_enfermagem_id' => $atendimentoEnfermagemId,
|
|
'procedimento_id' => $proc->id,
|
|
'quantidade' => $quantidade,
|
|
];
|
|
}
|
|
}
|
|
}
|
|
|
|
private function handleFatorRiscoOutro($atendimento, $params)
|
|
{
|
|
$atendimento->faa->paciente->cidadao->fator_risco_outro = null;
|
|
|
|
if (in_array(FatorRiscoEnum::OUTRO, $params['fatores_risco'] ?? [])) {
|
|
|
|
$atendimento->faa->paciente->cidadao->fator_risco_outro = $params['fator_risco_outro'] ?? null;
|
|
}
|
|
|
|
$atendimento->faa->paciente->cidadao->save();
|
|
}
|
|
|
|
private function handleProcedimentoRealizado(&$procedimentos, AtendimentoEnfermagem $atendimentoEnfermagem, array $servicosEnfermagem)
|
|
{
|
|
$procedimentoIds = $this->getServicosEnfermagem(
|
|
$atendimentoEnfermagem->atendimento,
|
|
$atendimentoEnfermagem->created_at,
|
|
[ExameStatusEnum::SOLICITADO]
|
|
)->pluck('procedimento.id');
|
|
|
|
foreach ($servicosEnfermagem as $servicoEnfermagem) {
|
|
|
|
if (!is_null($servicoEnfermagem['id'] ?? null)) {
|
|
|
|
if (!$procedimentoIds->contains($servicoEnfermagem['procedimento_id'])) {
|
|
|
|
throw new ServicoEnfermagemCannotChangeStatusException;
|
|
}
|
|
}
|
|
|
|
if (($servicoEnfermagem['status_id'] ?? null) == ExameStatusEnum::REALIZADO) {
|
|
|
|
$this->addProcedimentoServicoEnfermagemData(
|
|
$servicoEnfermagem['procedimento_id'],
|
|
$servicoEnfermagem['cid_id'] ?? null,
|
|
$procedimentos,
|
|
$atendimentoEnfermagem->id,
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
private function addProcedimentoServicoEnfermagemData(
|
|
$procedimentoId,
|
|
$cidId,
|
|
&$procedimentos,
|
|
int $atendimentoEnfermagemId
|
|
) {
|
|
|
|
$procedimentos[] = [
|
|
'lotacao_id' => auth()->payload()->get('lotacao_id'),
|
|
'atendimento_enfermagem_id' => $atendimentoEnfermagemId,
|
|
'procedimento_id' => $procedimentoId,
|
|
'cid_principal_id' => $cidId,
|
|
'quantidade' => 1,
|
|
];
|
|
}
|
|
|
|
private function addProcedimentoPadraoData(&$procedimentos, Atendimento $atendimento)
|
|
{
|
|
$procedimentoPadrao = $this->getProcedimentoPadrao();
|
|
|
|
if (is_null($procedimentoPadrao)) {
|
|
|
|
return null;
|
|
}
|
|
|
|
$quantidade = 1;
|
|
$primeiroAtendimentoEnfermagem = $atendimento->atendimentosEnfermagem->sortBy('created_at')->first();
|
|
|
|
if (collect($procedimentos)->contains('procedimento_id', $procedimentoPadrao['id'])) {
|
|
|
|
foreach ($procedimentos as $i => $procedimento) {
|
|
|
|
if ($procedimento['atendimento_enfermagem_id'] !== $primeiroAtendimentoEnfermagem->id) {
|
|
|
|
continue;
|
|
}
|
|
|
|
if ($procedimento['procedimento_id'] === $procedimentoPadrao['id']) {
|
|
|
|
$procedimentos[$i]['quantidade'] += $quantidade;
|
|
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
|
|
$procedimentos[] = [
|
|
'lotacao_id' => auth()->payload()->get('lotacao_id'),
|
|
'atendimento_enfermagem_id' => $primeiroAtendimentoEnfermagem->id,
|
|
'procedimento_id' => $procedimentoPadrao['id'],
|
|
'quantidade' => $quantidade,
|
|
];
|
|
}
|
|
}
|
|
|
|
private function getProcedimentoPadrao() : ?array
|
|
{
|
|
$parametrizacaoProcedimento = ParametrizacaoProcedimento::select('procedimento_codigo')
|
|
->where('pronto_atendimento_procedimento_padrao', true)
|
|
->get()
|
|
->first();
|
|
|
|
if (is_null($parametrizacaoProcedimento)) {
|
|
|
|
return null;
|
|
}
|
|
|
|
return [
|
|
'id' => $parametrizacaoProcedimento->procedimento->id,
|
|
'codigo' => $parametrizacaoProcedimento->procedimento->codigo,
|
|
];
|
|
}
|
|
|
|
private function prepareSinaisVitaisData(array $params, AtendimentoEnfermagem $atendimentoEnfermagem) : array
|
|
{
|
|
$sinaisVitaisData = [];
|
|
|
|
foreach (($params['sinais_vitais'] ?? []) as $sinaisVitais) {
|
|
|
|
$sinaisVitaisData[] = [
|
|
'atendimento_enfermagem_id' => $atendimentoEnfermagem->id,
|
|
'pa' => $sinaisVitais['pa'] ?? null,
|
|
'pa_unidade_medida_id' => isset($sinaisVitais['pa'])
|
|
? $sinaisVitais['pa_unidade_medida_id']
|
|
: null,
|
|
'glicemia' => $sinaisVitais['glicemia'] ?? null,
|
|
'temperatura' => $sinaisVitais['temperatura'] ?? null,
|
|
'pulso' => $sinaisVitais['pulso'] ?? null,
|
|
'respiracao' => $sinaisVitais['respiracao'] ?? null,
|
|
'saturacao' => $sinaisVitais['saturacao'] ?? null,
|
|
'intensidade_dor' => $sinaisVitais['intensidade_dor'] ?? null,
|
|
'cintura' => $sinaisVitais['cintura'] ?? null,
|
|
];
|
|
}
|
|
|
|
return $sinaisVitaisData;
|
|
}
|
|
|
|
private function prepareAvaliacaoAntropometricaData(array $params, AtendimentoEnfermagem $atendimentoEnfermagem) : ?array
|
|
{
|
|
if (!isset($params['avaliacao_antropometrica'])) {
|
|
|
|
return null;
|
|
}
|
|
|
|
$params = $params['avaliacao_antropometrica'];
|
|
|
|
return [
|
|
'atendimento_enfermagem_id' => $atendimentoEnfermagem->id,
|
|
'massa' => $params['massa'] ?? null,
|
|
'massa_unidade_medida_id' => isset($params['massa']) ? $params['massa_unidade_medida_id'] : null,
|
|
'altura' => $params['altura'] ?? null,
|
|
'altura_unidade_medida_id' => isset($params['altura']) ? $params['altura_unidade_medida_id'] : null,
|
|
'altura_tipo_medida_id' => isset($params['altura']) ? $params['altura_tipo_medida_id'] : null,
|
|
];
|
|
}
|
|
|
|
private function prepareGestacaoData(array $params, AtendimentoEnfermagem $atendimentoEnfermagem) : ?array
|
|
{
|
|
if (!isset($params['gestacao']) || $params['gestacao']['gestante'] == false) {
|
|
|
|
return null;
|
|
}
|
|
|
|
$cidadao = $atendimentoEnfermagem->atendimento->faa->paciente->cidadao;
|
|
$sexoPermitido = $cidadao->sexo_id === Sexo::FEMININO;
|
|
$idadePermitida = $cidadao->idade ? $cidadao->idade['anos'] >= 9 && $cidadao->idade['anos'] <= 60 : false;
|
|
|
|
if (!$sexoPermitido || !$idadePermitida) {
|
|
|
|
return null;
|
|
}
|
|
|
|
$params = $params['gestacao'];
|
|
|
|
return [
|
|
'atendimento_enfermagem_id' => $atendimentoEnfermagem->id,
|
|
'gestante' => $params['gestante'],
|
|
'dum' => $params['gestante'] ? ($params['dum'] ?? null) : null,
|
|
];
|
|
}
|
|
|
|
private function prepareClassificacaoRiscoData(array $params, AtendimentoEnfermagem $atendimentoEnfermagem) : array
|
|
{
|
|
return [
|
|
'atendimento_enfermagem_id' => $atendimentoEnfermagem->id,
|
|
'classificacao_risco_id' => $params['classificacao_risco_id'],
|
|
];
|
|
}
|
|
|
|
private function prepareObservacaoData(array $params, AtendimentoEnfermagem $atendimentoEnfermagem) : ?array
|
|
{
|
|
if (!isset($params['observacoes']) || (isset($params['observacoes']) && empty($params['observacoes']))) {
|
|
|
|
return null;
|
|
}
|
|
|
|
return [
|
|
'atendimento_enfermagem_id' => $atendimentoEnfermagem->id,
|
|
'descricao' => $params['observacoes'] ?? null,
|
|
];
|
|
}
|
|
|
|
private function prepareServicosEnfermagem(AtendimentoEnfermagem $atendimentoEnfermagem, array $params) : array
|
|
{
|
|
$servicosEnfermagem = [];
|
|
|
|
foreach ($params as $param) {
|
|
|
|
$servicoEnfermagem = new ServicoEnfermagem();
|
|
|
|
if (isset($param['id']) && is_numeric($param['id'])) {
|
|
|
|
$servicoEnfermagem = ServicoEnfermagem::findOrFail($param['id']);
|
|
}
|
|
|
|
$servicoEnfermagem->status_id = isset($param['status_id']) ? $param['status_id'] : ExameStatusEnum::SOLICITADO;
|
|
$servicoEnfermagem->atendimento_enfermagem_id = $atendimentoEnfermagem->id;
|
|
$servicoEnfermagem->procedimento_id = $param['procedimento_id'];
|
|
$servicoEnfermagem->cid_id = $param['cid_id'] ?? null;
|
|
$servicoEnfermagem->horario_realizacao = $param['horario_realizacao'] ?? null;
|
|
$servicoEnfermagem->observacoes = $param['observacoes'] ?? null;
|
|
|
|
$servicosEnfermagem[] = $servicoEnfermagem;
|
|
}
|
|
|
|
return $servicosEnfermagem;
|
|
}
|
|
|
|
private function preparePrescricaoInternaAplicacoesData(
|
|
AtendimentoEnfermagem $atendimentoEnfermagem,
|
|
array $prescricaoInternaAplicacoes
|
|
) : array
|
|
{
|
|
$result = [];
|
|
|
|
$prescricoesInterna = $this->getPrescricoesInterna(
|
|
$atendimentoEnfermagem->atendimento,
|
|
$atendimentoEnfermagem->created_at,
|
|
false
|
|
);
|
|
|
|
foreach ($prescricaoInternaAplicacoes as $prescricaoInternaMedicamentoAplicacao) {
|
|
|
|
$aplicacao = PrescricaoInternaMedicamentoAplicacao::findOrFail(
|
|
$prescricaoInternaMedicamentoAplicacao['id']
|
|
);
|
|
|
|
if (!$this->isAplicacaoAllowChangeStatus($aplicacao, $prescricoesInterna)) {
|
|
|
|
throw new PrescricaoInternaAplicacaoCannotChangeStatusException;
|
|
}
|
|
|
|
$aplicacao->atendimento_enfermagem_id = $atendimentoEnfermagem->id;
|
|
$aplicacao->status_id = $prescricaoInternaMedicamentoAplicacao['status_id'];
|
|
$aplicacao->horario_aplicacao = $prescricaoInternaMedicamentoAplicacao['horario_aplicacao'];
|
|
$aplicacao->local_aplicacao_id = $prescricaoInternaMedicamentoAplicacao['local_aplicacao_id'];
|
|
|
|
$result[] = $aplicacao;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
private function isAplicacaoAllowChangeStatus(
|
|
PrescricaoInternaMedicamentoAplicacao $aplicacao,
|
|
array $prescricoesInterna
|
|
) : bool
|
|
{
|
|
$prescricoesInterna = collect($prescricoesInterna);
|
|
|
|
$prescricao = $prescricoesInterna->firstWhere(
|
|
'id',
|
|
$aplicacao->prescricaoInternaMedicamento->prescricaoInterna->id
|
|
);
|
|
|
|
if (is_null($prescricao) || $aplicacao->status_id !== ExameStatusEnum::SOLICITADO) {
|
|
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
private function handlePedidosExames(AtendimentoEnfermagem $atendimentoEnfermagem, array $pedidosExamesRequested)
|
|
{
|
|
$pedidoExamesAllowedChange = collect(
|
|
$this->getPedidosExames($atendimentoEnfermagem->atendimento)
|
|
);
|
|
|
|
$quantidadesProcedimento = [];
|
|
|
|
foreach ($pedidosExamesRequested as $pedidoExamesRequested) {
|
|
|
|
$isForm = $pedidoExamesRequested['is_form'];
|
|
$pedidoExameRequestedId = $pedidoExamesRequested['id'] ?? null;
|
|
|
|
if (is_null($pedidoExameRequestedId)) {
|
|
|
|
$pedidoExamesData = $this->preparePedidoExamesData($atendimentoEnfermagem, $pedidoExamesRequested);
|
|
if (!empty($pedidoExamesData)) {
|
|
|
|
$pedidoExames = $atendimentoEnfermagem->pedidosExames()->create($pedidoExamesData);
|
|
|
|
$itensSaved = $this->storePedidoExamesItens($pedidoExames, $pedidoExamesData['exames']);
|
|
|
|
foreach ($itensSaved as $itemSaved) {
|
|
|
|
if ($itemSaved->exame->tipo_id === ExameTipo::LABORATORIAL
|
|
&& $itemSaved->status_id == ExameStatusEnum::REALIZADO
|
|
) {
|
|
|
|
$quantidadesProcedimento[$itemSaved->pedido_exame_id] = 1;
|
|
|
|
$lotacaoLaboratorio = Lotacao::where('usuario_id', $pedidoExamesRequested['laboratorio_usuario_id'])
|
|
->where('infraestrutura_id', $pedidoExamesRequested['laboratorio_infraestrutura_id'])
|
|
->where('ocupacao_id', $pedidoExamesRequested['laboratorio_ocupacao_id'])
|
|
->first();
|
|
|
|
$atendimentoEnfermagem->atendimento->procedimentos()->create([
|
|
'lotacao_id' => $lotacaoLaboratorio->id ?? null,
|
|
'atendimento_enfermagem_id' => $atendimentoEnfermagem->id,
|
|
'procedimento_id' => $itemSaved->exame->procedimento->id,
|
|
'quantidade' => 1,
|
|
]);
|
|
}
|
|
}
|
|
|
|
if(count($pedidoExamesData['files'] ?? []) > 0) {
|
|
|
|
$this->storeFiles($pedidoExames, $pedidoExamesData['files'], $atendimentoEnfermagem);
|
|
}
|
|
}
|
|
|
|
continue;
|
|
}
|
|
|
|
if (!is_numeric($pedidoExameRequestedId)) {
|
|
|
|
continue;
|
|
}
|
|
|
|
if (!$isForm && !$pedidoExamesAllowedChange->pluck('id')->contains($pedidoExameRequestedId)) {
|
|
|
|
throw new PedidoExameCannotChangeStatusException;
|
|
}
|
|
|
|
if (!$isForm) {
|
|
|
|
$this->requestedPedidoExamesAllowChangeStatus($pedidoExamesRequested, $pedidoExamesAllowedChange);
|
|
}
|
|
|
|
$pedidoExames = PedidoExame::findOrFail($pedidoExameRequestedId);
|
|
|
|
if (!$isForm) {
|
|
|
|
foreach ($pedidoExamesRequested['exames'] as $item) {
|
|
|
|
$pedidoItem = $pedidoExames->exames->firstWhere('id', $item['id']);
|
|
|
|
if ($item['status_id'] == ExameStatusEnum::REALIZADO && $pedidoItem->horario_realizacao == null) {
|
|
|
|
$pedidoItem->horario_realizacao = $item['horario_realizacao'] ?? null;
|
|
$pedidoItem->save();
|
|
}
|
|
|
|
if ($pedidoItem->status_id != ($item['status_id'] ?? ExameStatusEnum::SOLICITADO)) {
|
|
|
|
$faturar = is_null($pedidoItem->lotacao_executante_id);
|
|
|
|
$pedidoItem->atendimento_enfermagem_id = $atendimentoEnfermagem->id;
|
|
$pedidoItem->status_id = $item['status_id'] ?? ExameStatusEnum::SOLICITADO;
|
|
$pedidoItem->horario_realizacao = $item['horario_realizacao'] ?? null;
|
|
$pedidoItem->lotacao_executante_id = $item['lotacao_executante_id'] ?? null;
|
|
|
|
if ($pedidoItem->exame->tipo_id === ExameTipo::LABORATORIAL
|
|
&& $pedidoItem->status_id == ExameStatusEnum::REALIZADO
|
|
) {
|
|
|
|
$hasExameRealizado = $pedidoItem->pedidoExame()
|
|
->whereHas('exames', function ($query) {
|
|
|
|
$query->where('status_id', ExameStatusEnum::REALIZADO);
|
|
})
|
|
->get()
|
|
->isNotEmpty();
|
|
|
|
if (!$hasExameRealizado) {
|
|
|
|
$quantidadesProcedimento[$pedidoItem->pedido_exame_id] = 1;
|
|
}
|
|
|
|
if ($faturar) {
|
|
|
|
$lotacaoLaboratorio = Lotacao::where('usuario_id', $pedidoExamesRequested['laboratorio_usuario_id'])
|
|
->where('infraestrutura_id', $pedidoExamesRequested['laboratorio_infraestrutura_id'])
|
|
->where('ocupacao_id', $pedidoExamesRequested['laboratorio_ocupacao_id'])
|
|
->first();
|
|
|
|
$atendimentoEnfermagem->atendimento->procedimentos()->create([
|
|
'lotacao_id' => $lotacaoLaboratorio->id ?? null,
|
|
'atendimento_enfermagem_id' => $atendimentoEnfermagem->id,
|
|
'procedimento_id' => $pedidoItem->exame->procedimento->id,
|
|
'quantidade' => 1,
|
|
]);
|
|
}
|
|
}
|
|
|
|
$pedidoItem->save();
|
|
|
|
$this->storeItemObservacao($pedidoItem, $item['observacao'] ?? null);
|
|
}
|
|
}
|
|
}
|
|
|
|
if(count($pedidoExamesRequested['files'] ?? []) > 0) {
|
|
|
|
$this->storeFiles($pedidoExames, $pedidoExamesRequested['files'], $atendimentoEnfermagem);
|
|
}
|
|
|
|
$lotacao = Lotacao::where('usuario_id', $pedidoExamesRequested['usuario_id'])
|
|
->where('infraestrutura_id', $pedidoExamesRequested['usuario_infraestrutura_id'])
|
|
->where('ocupacao_id', $pedidoExamesRequested['ocupacao_id'])
|
|
->first();
|
|
|
|
$lotacaoLaboratorio = Lotacao::where('usuario_id', $pedidoExamesRequested['laboratorio_usuario_id'])
|
|
->where('infraestrutura_id', $pedidoExamesRequested['laboratorio_infraestrutura_id'])
|
|
->where('ocupacao_id', $pedidoExamesRequested['laboratorio_ocupacao_id'])
|
|
->first();
|
|
|
|
$pedidoExames->usuario_id = $pedidoExamesRequested['usuario_id'];
|
|
$pedidoExames->ocupacao_id = $pedidoExamesRequested['ocupacao_id'];
|
|
$pedidoExames->lotacao_id = $lotacao->id ?? null;
|
|
$pedidoExames->laboratorio_usuario_id = $pedidoExamesRequested['laboratorio_usuario_id'];
|
|
$pedidoExames->laboratorio_ocupacao_id = $pedidoExamesRequested['laboratorio_ocupacao_id'];
|
|
$pedidoExames->laboratorio_lotacao_id = $lotacaoLaboratorio->id ?? null;
|
|
|
|
$pedidoExames->save();
|
|
}
|
|
|
|
$lotacaoPedidos = [];
|
|
|
|
foreach ($quantidadesProcedimento as $index => $quantidade) {
|
|
|
|
$lotacaoExame = PedidoExame::findOrFail($index)->lotacao_id;
|
|
|
|
if (isset($lotacaoPedidos[$lotacaoExame])) {
|
|
$lotacaoPedidos[$lotacaoExame]['quantidade'] += $quantidade;
|
|
} else {
|
|
$lotacaoPedidos[$lotacaoExame] = [
|
|
'lotacao_id' => $lotacaoExame,
|
|
'quantidade' => $quantidade,
|
|
];
|
|
}
|
|
}
|
|
|
|
foreach ($lotacaoPedidos as $lotacaoPedido) {
|
|
|
|
$lotacao = Lotacao::where('id', $lotacaoPedido['lotacao_id'])->first();
|
|
|
|
if ($lotacao) {
|
|
|
|
$this->faturarProcedimentoPadraoExameLaboratorial($atendimentoEnfermagem, $lotacaoPedido['quantidade'], $lotacao);
|
|
}
|
|
}
|
|
}
|
|
|
|
private function faturarProcedimentoPadraoExameLaboratorial($atendimentoEnfermagem, $quantidade, $lotacao)
|
|
{
|
|
$procedimentos = collect();
|
|
$procedimento = $this->getProcedimentoPadraoExameLaboratorial();
|
|
|
|
$validation = new ProcedimentoValidationService($procedimento);
|
|
|
|
if ($validation->isOcupacaoValid($this->getCurrentLotacao()->ocupacao)) {
|
|
|
|
$procedimentos->push($atendimentoEnfermagem->atendimento->procedimentos()->create([
|
|
'lotacao_id' => is_object($lotacao) ? $lotacao->id : ($lotacao ?? null),
|
|
'atendimento_enfermagem_id' => $atendimentoEnfermagem->id,
|
|
'procedimento_id' => $procedimento->id,
|
|
'quantidade' => $quantidade,
|
|
]));
|
|
}
|
|
|
|
return $procedimentos;
|
|
}
|
|
|
|
private function getProcedimentoPadraoExameLaboratorial()
|
|
{
|
|
return Procedimento::where(
|
|
'codigo',
|
|
ProcedimentoEnum::COLETA_DE_MATERIAL_PARA_EXAME_LABORATORIAL
|
|
)
|
|
->orderByDesc('competencia_id')
|
|
->firstOrFail();
|
|
}
|
|
|
|
private function prepareHistoricoData($atendimentoEnfermagem, $params)
|
|
{
|
|
if (!isset($params['historico'])) {
|
|
|
|
return [];
|
|
}
|
|
|
|
return [
|
|
'atendimento_id' => $atendimentoEnfermagem->atendimento->id,
|
|
'atendimento_enfermagem_id' => $atendimentoEnfermagem->id,
|
|
'descricao' => $params['historico'],
|
|
];
|
|
}
|
|
|
|
private function prepareDiagnosticoData($atendimentoEnfermagem, $params)
|
|
{
|
|
if (!isset($params['diagnostico'])) {
|
|
|
|
return [];
|
|
}
|
|
|
|
return [
|
|
'atendimento_id' => $atendimentoEnfermagem->atendimento->id,
|
|
'atendimento_enfermagem_id' => $atendimentoEnfermagem->id,
|
|
'descricao' => $params['diagnostico'],
|
|
];
|
|
}
|
|
|
|
private function preparePlanejamentoData($atendimentoEnfermagem, $params)
|
|
{
|
|
if (!isset($params['planejamento'])) {
|
|
|
|
return [];
|
|
}
|
|
|
|
return [
|
|
'atendimento_id' => $atendimentoEnfermagem->atendimento->id,
|
|
'atendimento_enfermagem_id' => $atendimentoEnfermagem->id,
|
|
'descricao' => $params['planejamento'],
|
|
];
|
|
}
|
|
|
|
private function prepareImplementacaoData($atendimentoEnfermagem, $params)
|
|
{
|
|
if (!isset($params['implementacao'])) {
|
|
|
|
return [];
|
|
}
|
|
|
|
return [
|
|
'atendimento_id' => $atendimentoEnfermagem->atendimento->id,
|
|
'atendimento_enfermagem_id' => $atendimentoEnfermagem->id,
|
|
'descricao' => $params['implementacao'],
|
|
];
|
|
}
|
|
|
|
private function prepareAvaliacaoData($atendimentoEnfermagem, $params)
|
|
{
|
|
if (!isset($params['avaliacao'])) {
|
|
|
|
return [];
|
|
}
|
|
|
|
return [
|
|
'atendimento_id' => $atendimentoEnfermagem->atendimento->id,
|
|
'atendimento_enfermagem_id' => $atendimentoEnfermagem->id,
|
|
'descricao' => $params['avaliacao'],
|
|
];
|
|
}
|
|
|
|
private function preparePedidoExamesData(AtendimentoEnfermagem $atendimentoEnfermagem, array $pedidoExames) : ?array
|
|
{
|
|
|
|
$lotacao = Lotacao::where('usuario_id', $pedidoExames['usuario_id'])
|
|
->where('infraestrutura_id', $pedidoExames['usuario_infraestrutura_id'])
|
|
->where('ocupacao_id', $pedidoExames['ocupacao_id'])
|
|
->first();
|
|
|
|
$lotacaoLaboratorio = Lotacao::where('usuario_id', $pedidoExames['laboratorio_usuario_id'])
|
|
->where('infraestrutura_id', $pedidoExames['laboratorio_infraestrutura_id'])
|
|
->where('ocupacao_id', $pedidoExames['laboratorio_ocupacao_id'])
|
|
->first();
|
|
|
|
$result = [
|
|
'atendimento_id' => $atendimentoEnfermagem->atendimento->id,
|
|
'data_solicitacao' => isset($pedidoExames['data_solicitacao'])
|
|
? Carbon::createFromFormat('d/m/Y', $pedidoExames['data_solicitacao'])
|
|
: null,
|
|
'unidade_encaminhamento_id' => $pedidoExames['unidade_encaminhamento_id'] ?? null,
|
|
'unidade_externa_encaminhamento_id' => $pedidoExames['unidade_externa_encaminhamento_id'] ?? null,
|
|
'medico_solicitante_encaminhamento' => $pedidoExames['medico_solicitante_encaminhamento'] ?? null,
|
|
'urgente' => $pedidoExames['urgente'],
|
|
'justificativa' => $pedidoExames['justificativa'],
|
|
'usuario_id' => $pedidoExames['usuario_id'],
|
|
'ocupacao_id' => $pedidoExames['ocupacao_id'],
|
|
'lotacao_id' => $lotacao->id ?? null,
|
|
'laboratorio_usuario_id' => $pedidoExames['laboratorio_usuario_id'],
|
|
'laboratorio_ocupacao_id' => $pedidoExames['laboratorio_ocupacao_id'],
|
|
'laboratorio_lotacao_id' => $lotacaoLaboratorio->id ?? null,
|
|
'files' => $pedidoExames['files'] ?? [],
|
|
'exames' => [],
|
|
];
|
|
|
|
foreach ($pedidoExames['exames'] as $item) {
|
|
|
|
$result['exames'][] = [
|
|
'atendimento_enfermagem_id' => $atendimentoEnfermagem->id,
|
|
'exame_id' => $item['exame_id'],
|
|
'status_id' => $item['status_id'] ?? ExameStatusEnum::SOLICITADO,
|
|
'horario_realizacao' => $item['horario_realizacao'] ?? null,
|
|
'lotacao_executante_id' => $item['lotacao_executante_id'],
|
|
'observacao' => $item['observacao'] ?? null,
|
|
];
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
private function storePedidoExamesItens(PedidoExame $pedidoExames, array $itens)
|
|
{
|
|
$itensSaved = [];
|
|
|
|
foreach ($itens as $item) {
|
|
|
|
$pedidoItem = $pedidoExames->exames()->create($item);
|
|
|
|
$itensSaved[] = $pedidoItem;
|
|
|
|
$this->storeItemObservacao($pedidoItem, $item['observacao'] ?? null);
|
|
}
|
|
|
|
return $itensSaved;
|
|
}
|
|
|
|
private function storeFiles(PedidoExame $pedidoExame, array $files, $atendimentoEnfermagem)
|
|
{
|
|
$laudoService = new LaudoService();
|
|
$laudoService->storeFile($pedidoExame, $files, ['atendimento_enfermagem_id' => $atendimentoEnfermagem->id]);
|
|
}
|
|
|
|
private function storeItemObservacao(Item $item, ?string $observacao)
|
|
{
|
|
if (!is_null($observacao ?? null)) {
|
|
|
|
$item->observacoes()->create([
|
|
'observacao' => $observacao
|
|
]);
|
|
}
|
|
}
|
|
|
|
private function requestedPedidoExamesAllowChangeStatus($pedidoExamesRequested, $pedidoExamesAllowedChange)
|
|
{
|
|
$pedidoExamesAllowedIds = $pedidoExamesAllowedChange
|
|
->firstWhere('id', $pedidoExamesRequested['id'])['exames']->pluck('exame.id', 'id',);
|
|
|
|
foreach ($pedidoExamesRequested['exames'] as $item) {
|
|
|
|
$exameIdAllowed = $pedidoExamesAllowedIds[$item['id']];
|
|
|
|
if ($exameIdAllowed != $item['exame_id']) {
|
|
|
|
throw new PedidoExameItemCannotChangeStatusException;
|
|
}
|
|
}
|
|
}
|
|
|
|
private function storeFinalizacao(array $params, AtendimentoEnfermagem $atendimentoEnfermagem)
|
|
{
|
|
$faaParams = [
|
|
'desfecho_id' => $params['desfecho_id'],
|
|
'finalizado' => true,
|
|
];
|
|
|
|
switch ($params['desfecho_id']) {
|
|
|
|
case DesfechoEnum::ALTA_MEDICA: {
|
|
|
|
$atendimentoMedicoDesfecho = $atendimentoEnfermagem->atendimento->atendimentosMedico()
|
|
->whereNotNull('desfecho_id')
|
|
->orderByDesc('created_at')
|
|
->first();
|
|
|
|
$faaParams['usuario_id'] = Lotacao::findOrFail($params['alta_medica']['lotacao_id'])->usuario_id;
|
|
$faaParams['lotacao_id'] = $params['alta_medica']['lotacao_id'];
|
|
$faaParams['data_hora_desfecho'] = $atendimentoMedicoDesfecho->created_at;
|
|
|
|
break;
|
|
}
|
|
case DesfechoEnum::PACIENTE_ATENDIDO: {
|
|
|
|
$faaParams['usuario_id'] = $atendimentoEnfermagem->createdLotacao->usuario_id;
|
|
$faaParams['lotacao_id'] = $atendimentoEnfermagem->createdLotacao->id;
|
|
$faaParams['data_hora_desfecho'] = $atendimentoEnfermagem->created_at;
|
|
|
|
break;
|
|
}
|
|
case DesfechoEnum::EVASAO: {
|
|
|
|
$faaParams['usuario_id'] = $atendimentoEnfermagem->createdLotacao->usuario_id;
|
|
$faaParams['lotacao_id'] = $atendimentoEnfermagem->createdLotacao->id;
|
|
$faaParams['data_hora_desfecho'] = $atendimentoEnfermagem->created_at;
|
|
|
|
FilaService::evade([
|
|
'motivo_evasao' => $params['evasao']['motivo']
|
|
], $atendimentoEnfermagem->atendimento->fila_id);
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
$atendimentoEnfermagem->atendimento->faa->update($faaParams);
|
|
|
|
if ($params['desfecho_id'] != DesfechoEnum::EVASAO) {
|
|
|
|
FilaService::dispatch($atendimentoEnfermagem->atendimento->fila->centroCusto);
|
|
}
|
|
}
|
|
|
|
private function hasExamesLaboratorialSolicitadosOrAguardandoResultado($pedidoExames)
|
|
{
|
|
foreach($pedidoExames->exames as $item) {
|
|
|
|
if($item->exame->tipo_id === ExameTipo::LABORATORIAL) {
|
|
|
|
if($item->status_id === ExameStatusEnum::SOLICITADO) {
|
|
return true;
|
|
}
|
|
else if($item->status_id === ExameStatusEnum::AGUARDANDO_RESULTADO) {
|
|
return true;
|
|
} else if ($item->status_id === ExameStatusEnum::REALIZADO && $item->horario_realizacao == null) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
private function getCentroCustoLogado() : CentroCusto
|
|
{
|
|
return CentroCusto::findOrFail(auth()->payload()->get('centro_custo_id'));
|
|
}
|
|
|
|
private function getFormData(Atendimento $atendimento, Carbon $datetime, $centroCustoLogado)
|
|
{
|
|
$lotacao = $this->getLotacaoLogado();
|
|
|
|
$parametrizacao = ParametrizacaoAtendimentoMedicoService::get($centroCustoLogado->infraestrutura_id);
|
|
|
|
$declaracoesComparecimento = [];
|
|
|
|
foreach ($atendimento->atendimentosMedico as $atendimentoMedico) {
|
|
foreach ($atendimentoMedico->declaracoesComparecimento as $declaracaoComparecimento) {
|
|
$nome = $declaracaoComparecimento->tipo_id === DeclaracaoComparecimentoTipo::PACIENTE
|
|
? $declaracaoComparecimento->atendimentoMedico->atendimento->faa->paciente->cidadao->nome
|
|
: $declaracaoComparecimento->nome;
|
|
|
|
$declaracoesComparecimento[] = [
|
|
'id' => $declaracaoComparecimento->id,
|
|
'tipo_id' => $declaracaoComparecimento->tipo_id ?? null,
|
|
];
|
|
}
|
|
}
|
|
|
|
$ultimoAtendimentoMedicoId = $this->getUltimoAtendimentoMedicoId($atendimento);
|
|
|
|
$exibeHistoricoErpsaude = app('config')->get('database.default') == 'santarita' ? true : false;
|
|
|
|
return [
|
|
'data_atual' => Carbon::now()->format('d/m/Y'),
|
|
'tipo_atendimento_id' => $parametrizacao->tipo_id,
|
|
'origens_unidade' => [
|
|
[ 'id' => OrigemUnidadeEncaminhamento::INTERNA, 'nome' => 'INTERNA' ],
|
|
[ 'id' => OrigemUnidadeEncaminhamento::EXTERNA, 'nome' => 'EXTERNA' ],
|
|
],
|
|
'prescricao_interna_locais_aplicacao' => PrescricaoInternaLocalAplicacao::orderBy('descricao')->get(),
|
|
'alergia_tipos' => $this->getAlergiaTipos(),
|
|
'alergia_criticidades' => $this->getAlergiaCriticidades(),
|
|
'classificacoes_risco' => $this->getClassificacoesRisco(),
|
|
'encaminhamento_setores' => $this->getSetoresEncaminhamento(),
|
|
'paciente' => $this->getPaciente($atendimento),
|
|
'historico_atendimento' => $this->getHistoricoAtendimento($atendimento),
|
|
'unidades_medida' => $this->getUnidadesMedida(),
|
|
'unidades_medida_tempo' => MedidaTempo::all(),
|
|
'atendimento_medico' => [
|
|
'id' => $ultimoAtendimentoMedicoId,
|
|
'evolucoes' => $this->getAreaAtendimentoMedicoByKey($atendimento, 'evolucao', $datetime),
|
|
'atendimentos_gerais' => $this->getAreaAtendimentoMedicoByKey($atendimento, 'atendimento_geral', $datetime),
|
|
'queixas_principal_duracao' => $this->getAreaAtendimentoMedicoByKey($atendimento, 'queixa_principal_duracao', $datetime),
|
|
'historias' => $this->getAreaAtendimentoMedicoByKey($atendimento, 'historia', $datetime),
|
|
'exames_fisico' => $this->getAreaAtendimentoMedicoByKey($atendimento, 'exame_fisico', $datetime),
|
|
'diagnosticos' => $this->getAreaAtendimentoMedicoByKey($atendimento, 'diagnostico', $datetime),
|
|
'condutas' => $this->getAreaAtendimentoMedicoByKey($atendimento, 'conduta', $datetime),
|
|
'observacoes_enfermagem' => $this->getAreaAtendimentoMedicoByKey($atendimento, 'observacoes_enfermagem', $datetime),
|
|
'procedimentos' => $this->getProcedimentos($atendimento, $datetime, 'atendimento_medico'),
|
|
'solicitou_reavaliacao' => $this->getSolicitacaoReavaliacao($atendimento),
|
|
'declaracoes_comparecimento' => $declaracoesComparecimento,
|
|
],
|
|
'atendimento_exame_imagem' => [
|
|
'procedimentos' => $this->getProcedimentos($atendimento, $datetime, 'exame_imagem'),
|
|
],
|
|
'recepcao' => [
|
|
'motivo_atendimento' => $atendimento->recepcao->motivo_atendimento ?? null,
|
|
'is_encaminhamento' => $atendimento->recepcao->is_encaminhamento,
|
|
'origem_unidade_encaminhamento' => $atendimento->recepcao->origem_unidade_encaminhamento,
|
|
'unidade_encaminhamento' => Unidade::find($atendimento->recepcao->unidade_encaminhamento_id),
|
|
'unidade_externa_encaminhamento' => UnidadeExterna::find($atendimento->recepcao->unidade_externa_encaminhamento_id),
|
|
'medico_solicitante_encaminhamento' => $atendimento->recepcao->medico_solicitante_encaminhamento,
|
|
],
|
|
'atendimento_triagem' => [
|
|
'outras_avaliacoes_condicoes' => $this->getOutrasAvaliacoesCondicoes($atendimento),
|
|
'procedimentos' => $this->getProcedimentos($atendimento, $datetime, 'atendimento_triagem'),
|
|
],
|
|
'raat' => RaatService::getOptionsParecerMedico(),
|
|
'atendimento_enfermagem' => [
|
|
'planejamentos' => $this->getAreaAtendimentoEnfermagemByKey($atendimento, 'planejamento'),
|
|
'diagnosticos' => $this->getAreaAtendimentoEnfermagemByKey($atendimento, 'diagnostico'),
|
|
'avaliacoes' => $this->getAreaAtendimentoEnfermagemByKey($atendimento, 'avaliacao'),
|
|
'historicos' => $this->getAreaAtendimentoEnfermagemByKey($atendimento, 'historico'),
|
|
'implementacoes' => $this->getAreaAtendimentoEnfermagemByKey($atendimento, 'implementacao'),
|
|
'observacoes' => $this->getHistoricoObservacaoAtendimentoEnfermagem($atendimento, $datetime),
|
|
'anotacoes' => $this->getAnotacoes($atendimento, $datetime),
|
|
],
|
|
'observacoes' => $this->getHistoricoObservacao($atendimento, $datetime),
|
|
'lotacao' => [
|
|
'ocupacao' => [
|
|
'codigo' => $lotacao->ocupacao->codigo,
|
|
'nome' => $lotacao->ocupacao->nome,
|
|
],
|
|
'profissional' => [
|
|
'id' => $lotacao->usuario->id,
|
|
'nome' => $lotacao->usuario->cidadao->nome,
|
|
],
|
|
],
|
|
'fatores_risco' => $this->getFatoresRisco($atendimento),
|
|
'fatores_risco_gestante' => $this->getFatoresRiscoGestante($atendimento),
|
|
'medicamentos_uso' => $this->getMedicamentosUso($atendimento, $datetime),
|
|
'sinais_vitais' => $this->getSinaisVitais($atendimento, $datetime),
|
|
'exame_status' => $this->getExameStatus(),
|
|
'servicos_enfermagem' => $this->getServicosEnfermagem(
|
|
$atendimento,
|
|
$datetime,
|
|
[ExameStatusEnum::REALIZADO, ExameStatusEnum::NAO_REALIZADO]
|
|
),
|
|
'procedimentos' => $this->getProcedimentos($atendimento, $datetime, 'atendimento_enfermagem'),
|
|
'prescricoes_interna' => $this->getPrescricoesInterna($atendimento, $datetime, true),
|
|
'observacao_enfermagem' => [],
|
|
'pedidos_exames' => $this->getPedidosExames($atendimento, true),
|
|
'desfechos' => $this->getDesfechos($atendimento),
|
|
'profissionais_atendimento' => $this->getProfissionaisAtendimento($atendimento),
|
|
'statusExame' => ExameStatus::all(),
|
|
'dataHora' => Carbon::now()->format('d/m/Y'),
|
|
'escalas_coma_glasgow' => $this->getEscalasComaGlasgow($atendimento),
|
|
'glasgow' => [
|
|
'aberturas_ocular' => $this->getGlasgowAberturaOcular(),
|
|
'reatividades_Pupilar' => $this->getGlasgowReatividadePupilar(),
|
|
'respostas_motora' => $this->getGlasgowRespostaMotora(),
|
|
'respostas_verbal' => $this->getGlasgowRespostaVerbal(),
|
|
],
|
|
'formulario_dor_toracica' => [
|
|
'dor_toracica_data_sintoma' => null,
|
|
'dor_toracica_hora_ecg_admissao' => null,
|
|
'hora_sintoma' => null,
|
|
'hora_ecg_admissao' => null,
|
|
'dispneia' => null,
|
|
'caracteristica_dor' => $this->getCaracteristicaDor(),
|
|
'localizacao_dor' => $this->getLocalizacaoDor(),
|
|
'fator_desencadeante' => $this->getFatorDesencadeante(),
|
|
'fatores_risco_toracica' => $this->getFatoresRiscoToracica(),
|
|
'duracao_dor' => $this->getDuracaoDor(),
|
|
],
|
|
'prioridades' => Prioridade::orderBy('nome')
|
|
->get()
|
|
->map(fn ($prioridade) => [
|
|
'id' => $prioridade->id,
|
|
'nome' => $prioridade->nome,
|
|
]),
|
|
'prioridade_id' => $atendimento->fila->prioridade_id,
|
|
'historico' => AmbulatorioAtendimentoService::getHistorico($atendimento->faa->paciente->id),
|
|
'historico_erpsaude' => $exibeHistoricoErpsaude ? AmbulatorioAtendimentoService::getHistoricoErpsaude($atendimento->faa->paciente) : null,
|
|
'exibe_historico_erpsaude' => $exibeHistoricoErpsaude,
|
|
'unidades_faturamento' => self::getUnidadesFaturamento(),
|
|
'laboratorios_faturamento' => self::getLaboratoriosFaturamento(),
|
|
'lotacoes_executantes' => FaturamentoExameLaboratorial::whereHas('lotacao', function ($query) {
|
|
|
|
$query->where('infraestrutura_id', self::getCurrentLotacao()->infraestrutura_id);
|
|
})
|
|
->get()
|
|
->map(fn ($parametrizacao) => [
|
|
'id' => $parametrizacao->lotacao->id,
|
|
'descricao' => "{$parametrizacao->lotacao->usuario->nome} - "
|
|
. $parametrizacao->lotacao->ocupacao->codigo
|
|
])
|
|
->sortBy('descricao')
|
|
->values(),
|
|
];
|
|
}
|
|
|
|
private function getOutrasAvaliacoesCondicoes($atendimento)
|
|
{
|
|
return $atendimento->atendimentosTriagem()->whereNotNull('outras_avaliacoes_condicoes')
|
|
->get()
|
|
->map(function($query) {
|
|
return [
|
|
'centro_custo' => [
|
|
'setor' => [
|
|
'nome' => $query->createdCentroCusto->setor->nome ?? null,
|
|
],
|
|
],
|
|
'classificacao_risco' => [
|
|
'nome' => $query->classificacaoRisco->classificacaoRisco->nome ?? null,
|
|
],
|
|
'data_hora' => $query->created_at->format('d/m/Y H:i:s'),
|
|
'descricao' => $query->outras_avaliacoes_condicoes,
|
|
'lotacao' => [
|
|
'ocupacao' => [
|
|
'nome' => $query->createdLotacao->ocupacao->nome ?? null,
|
|
],
|
|
'profissional' => [
|
|
'nome' => $query->createdLotacao->usuario->cidadao->nome ?? null,
|
|
],
|
|
],
|
|
];
|
|
})
|
|
->values();
|
|
}
|
|
|
|
private function getLotacaoLogado()
|
|
{
|
|
return Lotacao::findOrFail(auth()->payload()->get('lotacao_id'));
|
|
}
|
|
|
|
private function getAlergiaTipos()
|
|
{
|
|
return AlergiaTipo::all()->map(function($query) {
|
|
return [
|
|
'id' => $query->id,
|
|
'descricao' => $query->descricao,
|
|
];
|
|
});
|
|
}
|
|
|
|
private static function getFatoresRisco()
|
|
{
|
|
$result = FatorRisco::orderBy('id')
|
|
->whereIn('id', [
|
|
FatorRiscoEnum::CANCERO,
|
|
FatorRiscoEnum::DIABETES,
|
|
FatorRiscoEnum::ETILISMO,
|
|
FatorRiscoEnum::HIPERTENSAO,
|
|
FatorRiscoEnum::OBESIDADE,
|
|
FatorRiscoEnum::PERFIL_SANGUINEO_ALTERADO,
|
|
FatorRiscoEnum::RADIOTERAPIA,
|
|
FatorRiscoEnum::TABAGISMO,
|
|
FatorRiscoEnum::USO_DE_MEDICAMENTOS_ANTINEOPLASICOS_OU_IMUNOSSUPRESSORES,
|
|
FatorRiscoEnum::OUTRO,
|
|
])
|
|
->get()
|
|
->map(fn ($fatorRisco) => [
|
|
'id' => $fatorRisco->id,
|
|
'nome' => $fatorRisco->nome,
|
|
]);
|
|
|
|
return $result;
|
|
}
|
|
|
|
private static function getFatoresRiscoGestante()
|
|
{
|
|
$result = FatorRisco::orderBy('nome')
|
|
->whereIn('id', [
|
|
FatorRiscoEnum::CANCERO,
|
|
FatorRiscoEnum::DIABETES,
|
|
FatorRiscoEnum::ETILISMO,
|
|
FatorRiscoEnum::HIPERTENSAO,
|
|
FatorRiscoEnum::OBESIDADE,
|
|
FatorRiscoEnum::PERFIL_SANGUINEO_ALTERADO,
|
|
FatorRiscoEnum::RADIOTERAPIA,
|
|
FatorRiscoEnum::TABAGISMO,
|
|
FatorRiscoEnum::USO_DE_MEDICAMENTOS_ANTINEOPLASICOS_OU_IMUNOSSUPRESSORES,
|
|
FatorRiscoEnum::OUTRO,
|
|
FatorRiscoEnum::GESTANTE,
|
|
])
|
|
->get()
|
|
->map(fn ($fatorRisco) => [
|
|
'id' => $fatorRisco->id,
|
|
'nome' => $fatorRisco->nome,
|
|
]);
|
|
|
|
return $result;
|
|
}
|
|
|
|
private function getCidadaoFatoresRisco($atendimento)
|
|
{
|
|
$cidadao = $atendimento->faa->paciente->cidadao;
|
|
$fatoresRisco = $cidadao->fatoresRisco;
|
|
$result = [];
|
|
|
|
foreach ($fatoresRisco as $fatorRisco) {
|
|
$result[] = $fatorRisco->cidadaoFatorRisco->fator_risco_id;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
private function getAlergiaCriticidades()
|
|
{
|
|
return AlergiaCriticidade::all()->map(function($query) {
|
|
return [
|
|
'id' => $query->id,
|
|
'nome' => $query->nome,
|
|
];
|
|
});
|
|
}
|
|
|
|
private function getClassificacoesRisco()
|
|
{
|
|
return ClassificacaoRisco::all()->map(function($query) {
|
|
return [
|
|
'id' => $query->id,
|
|
'nome' => $query->nome,
|
|
'cor' => $query->tipo->cor,
|
|
'cor_nome' => $query->tipo->cor_nome,
|
|
];
|
|
});
|
|
}
|
|
|
|
private function getSetoresEncaminhamento()
|
|
{
|
|
return Encaminhamento::where('centro_custo_id_de', $this->getCentroCustoLogado()->id)
|
|
->whereHas('centroCustoPara', function ($query) {
|
|
|
|
$query->whereHas('setor', function ($query) {
|
|
|
|
$query->whereNotIn('tipo_id', [SetorTipo::RECEPCAO, SetorTipo::TRIAGEM]);
|
|
});
|
|
})
|
|
->get()
|
|
->map(function($query) {
|
|
return [
|
|
'id' => $query->centroCustoPara->id,
|
|
'nome' => $query->centroCustoPara->setor->nome,
|
|
'tipo' => [
|
|
'id' => $query->centroCustoPara->setor->tipo_id ?? null
|
|
],
|
|
];
|
|
});
|
|
}
|
|
|
|
private function getPaciente($atendimento)
|
|
{
|
|
return [
|
|
'id' => $atendimento->faa->paciente->id,
|
|
'nome' => $atendimento->faa->paciente->cidadao->nome,
|
|
'nome_social' => $atendimento->faa->paciente->cidadao->nome_social,
|
|
'preferencia_nome_id' => $atendimento->faa->paciente->cidadao->preferencia_nome_id,
|
|
'prontuario' => $atendimento->faa->paciente->prontuario,
|
|
'is_desconhecido' => $atendimento->faa->paciente->is_desconhecido,
|
|
'data_nascimento' => $atendimento->faa->paciente->cidadao->data_nascimento,
|
|
'idade' => $atendimento->faa->paciente->cidadao->idade,
|
|
'sexo' => $atendimento->faa->paciente->cidadao->sexo,
|
|
'pcd' => $this->getPcd($atendimento->faa->paciente->cidadao)
|
|
];
|
|
}
|
|
|
|
private function getHistoricoAtendimento($atendimento)
|
|
{
|
|
$historicoAtendimento = Atendimento::whereHas('faa', function($query) use ($atendimento) {
|
|
$query->where('paciente_id', $atendimento->faa->paciente_id);
|
|
})
|
|
->where('id', '<>', $atendimento->id)
|
|
->orderBy('created_at', 'desc')
|
|
->take(10)
|
|
->get();
|
|
|
|
return $historicoAtendimento->map(function($value) {
|
|
$atendimento = $value->faa->atendimentos->sortByDesc('created_at')->first();
|
|
$atendimentoClassificacaoRisco = $atendimento->classificacoesRisco->sortByDesc('created_at')->first();
|
|
$atendimentoCid = $atendimento->cids->sortByDesc('created_at')->first();
|
|
|
|
$hasAtendimento = $atendimento->where(function ($query) {
|
|
|
|
$query->whereHas('atendimentosTriagem')
|
|
->orWhereHas('atendimentosMedico')
|
|
->orWhereHas('atendimentosEnfermagem')
|
|
->orWhereHas('pedidosExames')
|
|
->orWhereHas('pacienteObservacoes');
|
|
})
|
|
->where('id', $atendimento->id)
|
|
->exists();
|
|
|
|
if (!$hasAtendimento) {
|
|
|
|
$procedimentoPadrao = $atendimento->procedimentos->where('is_parametrizado', true)->last();
|
|
|
|
$lotacaoProfissionalResponsavel = !is_null($procedimentoPadrao)
|
|
? $procedimentoPadrao->lotacao
|
|
: $atendimento->createdLotacao ?? null;
|
|
|
|
} else {
|
|
|
|
$firstAtendimentoMedico = $atendimento->atendimentosMedico->first();
|
|
|
|
$lotacaoProfissionalResponsavel = !is_null($firstAtendimentoMedico)
|
|
? $firstAtendimentoMedico->createdLotacao
|
|
: $atendimento->createdLotacao ?? null;
|
|
}
|
|
|
|
$params = [
|
|
'atendido_em' => Carbon::create($value->recepcao->atendido_em)->format('d/m/Y H:i:s') ?? null,
|
|
'cid' => [
|
|
'codigo' => $atendimentoCid->cid->codigo ?? $procedimentoPadrao->cidPrincipal->codigo ?? null,
|
|
'nome' => $atendimentoCid->cid->nome ?? $procedimentoPadrao->cidPrincipal->nome ?? null,
|
|
],
|
|
'classificacao_risco' => [
|
|
'cor' => $atendimentoClassificacaoRisco->classificacaoRisco->tipo->cor ?? "#FFFFFF",
|
|
'nome' => $atendimentoClassificacaoRisco->classificacaoRisco->nome ?? null,
|
|
],
|
|
'id' => $atendimento->id ?? null,
|
|
'lotacao' => [
|
|
'ocupacao' => [
|
|
'nome' => $lotacaoProfissionalResponsavel->ocupacao->nome ?? null,
|
|
],
|
|
'profissional' => [
|
|
'nome' => $lotacaoProfissionalResponsavel->usuario->cidadao->nome ?? null,
|
|
],
|
|
],
|
|
'unidade' => [
|
|
'nome' => $atendimento->createdLotacao->infraestrutura->unidade->nome_fantasia ?? null,
|
|
],
|
|
'desfecho' => [
|
|
'nome' => $atendimento->faa->desfecho->nome ?? null,
|
|
],
|
|
];
|
|
|
|
return $params;
|
|
});
|
|
}
|
|
|
|
private function getPcd($cidadao)
|
|
{
|
|
if ($cidadao->deficiencia_id === null) {
|
|
|
|
return null;
|
|
}
|
|
|
|
$deficiencia = [
|
|
'id' => $cidadao->deficiencia->id,
|
|
'deficiencia_base_id' => $cidadao->deficiencia->deficiencia_base_id,
|
|
'descricao' => $cidadao->deficiencia->descricao,
|
|
];
|
|
|
|
if ($cidadao->deficiencia->deficiencia_base_id === Deficiencia::OUTRA) {
|
|
|
|
$deficiencia['deficiencia_outro'] = $cidadao->deficiencia_outro;
|
|
|
|
return $deficiencia;
|
|
}
|
|
|
|
return $deficiencia;
|
|
}
|
|
|
|
private function getUnidadesMedida()
|
|
{
|
|
return UnidadeMedida::all()->map(function($query) {
|
|
return [
|
|
'id' => $query->id,
|
|
'nome' => $query->nome,
|
|
'sigla' => $query->sigla,
|
|
];
|
|
});
|
|
}
|
|
|
|
private function getSolicitacaoReavaliacao(Atendimento $atendimento)
|
|
{
|
|
$atendimentoMedico = $atendimento->atendimentosMedico()
|
|
->orderBy('created_at', 'desc')
|
|
->first();
|
|
|
|
return $atendimentoMedico->solicitou_reavaliacao ?? null;
|
|
}
|
|
|
|
private function getUltimoAtendimentoMedicoId($atendimento)
|
|
{
|
|
$atendimentoMedico = $atendimento->atendimentosMedico()
|
|
->orderBy('created_at', 'desc')
|
|
->first();
|
|
|
|
return $atendimentoMedico->id ?? null;
|
|
|
|
}
|
|
|
|
private function getAreaAtendimentoMedicoByKey(Atendimento $atendimento, string $key, Carbon $datetime)
|
|
{
|
|
$atendimentosMedico = $atendimento->atendimentosMedico()
|
|
->where('created_at', '<=', $datetime)
|
|
->whereNotNull($key)
|
|
->orderBy('created_at')
|
|
->get();
|
|
|
|
$result = [];
|
|
|
|
$fieldsAtendimentoSimples = array('evolucao', 'atendimento_geral', 'observacoes_enfermagem');
|
|
$fieldsAtendimentoEstruturado = array(
|
|
'evolucao',
|
|
'queixa_principal_duracao',
|
|
'historia',
|
|
'exame_fisico',
|
|
'diagnostico',
|
|
'conduta',
|
|
'observacoes_enfermagem',
|
|
);
|
|
|
|
foreach ($atendimentosMedico as $atendimentoMedico) {
|
|
|
|
if ($atendimentoMedico->simples) {
|
|
|
|
if (in_array($key, $fieldsAtendimentoSimples)) {
|
|
|
|
$result[] = array_merge(
|
|
$this->getBaseHistoricoAreaAtendimento($atendimentoMedico, $atendimentoMedico->atendimento),
|
|
[
|
|
'descricao' => $atendimentoMedico->$key
|
|
]
|
|
);
|
|
}
|
|
|
|
continue;
|
|
}
|
|
|
|
if (in_array($key, $fieldsAtendimentoEstruturado)) {
|
|
|
|
$result[] = array_merge(
|
|
$this->getBaseHistoricoAreaAtendimento($atendimentoMedico, $atendimentoMedico->atendimento),
|
|
[
|
|
'descricao' => $atendimentoMedico->$key
|
|
]
|
|
);
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
private function getHistoricoObservacao(Atendimento $atendimento, Carbon $datetime)
|
|
{
|
|
$result = [];
|
|
|
|
$observacoes = $atendimento->observacoes()
|
|
->where('created_at', '<=', $datetime)
|
|
->orderBy('created_at')
|
|
->get();
|
|
|
|
|
|
foreach ($observacoes as $observacao) {
|
|
|
|
$result[] = array_merge(
|
|
$this->getBaseHistoricoAreaAtendimento($observacao, $observacao->atendimento),
|
|
[
|
|
'descricao' => $observacao->descricao
|
|
]
|
|
);
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
private function getAreaAtendimentoEnfermagemByKey($atendimento, $key)
|
|
{
|
|
switch($key) {
|
|
|
|
case 'historico': {
|
|
|
|
return Historico::where('atendimento_id', $atendimento->id)
|
|
->orderBy('created_at')
|
|
->get()
|
|
->map(function ($historico) use ($atendimento) {
|
|
|
|
return array_merge(
|
|
$this->getBaseHistoricoAreaAtendimento($historico, $atendimento),
|
|
[
|
|
'descricao' => $historico->descricao,
|
|
]
|
|
);
|
|
});
|
|
}
|
|
|
|
case 'diagnostico': {
|
|
|
|
return Diagnostico::where('atendimento_id', $atendimento->id)
|
|
->orderBy('created_at')
|
|
->get()
|
|
->map(function ($diagnostico) use ($atendimento) {
|
|
|
|
return array_merge(
|
|
$this->getBaseHistoricoAreaAtendimento($diagnostico, $atendimento),
|
|
[
|
|
'descricao' => $diagnostico->descricao,
|
|
''
|
|
]
|
|
);
|
|
});
|
|
}
|
|
|
|
case 'planejamento': {
|
|
|
|
return Planejamento::where('atendimento_id', $atendimento->id)
|
|
->orderBy('created_at')
|
|
->get()
|
|
->map(function ($planejamento) use ($atendimento) {
|
|
|
|
return array_merge(
|
|
$this->getBaseHistoricoAreaAtendimento($planejamento, $atendimento),
|
|
[
|
|
'descricao' => $planejamento->descricao,
|
|
]
|
|
);
|
|
});
|
|
}
|
|
|
|
case 'implementacao': {
|
|
|
|
return Implementacao::where('atendimento_id', $atendimento->id)
|
|
->orderBy('created_at')
|
|
->get()
|
|
->map(function ($implementacao) use ($atendimento) {
|
|
|
|
return array_merge(
|
|
$this->getBaseHistoricoAreaAtendimento($implementacao, $atendimento),
|
|
[
|
|
'descricao' => $implementacao->descricao,
|
|
]
|
|
);
|
|
});
|
|
}
|
|
|
|
case 'avaliacao': {
|
|
|
|
return Avaliacao::where('atendimento_id', $atendimento->id)
|
|
->orderBy('created_at')
|
|
->get()
|
|
->map(function ($avaliacao) use ($atendimento) {
|
|
|
|
return array_merge(
|
|
$this->getBaseHistoricoAreaAtendimento($avaliacao, $atendimento),
|
|
[
|
|
'descricao' => $avaliacao->descricao,
|
|
]
|
|
);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
private function getHistoricoObservacaoAtendimentoEnfermagem(Atendimento $atendimento, Carbon $datetime)
|
|
{
|
|
$observacoes = $atendimento->observacoes()
|
|
->whereNotNull('atendimento_enfermagem_id')
|
|
->get();
|
|
|
|
$result = [];
|
|
|
|
foreach ($observacoes as $observacao) {
|
|
|
|
$result[] = array_merge(
|
|
$this->getBaseHistoricoAreaAtendimento($observacao, $observacao->atendimento),
|
|
[
|
|
'descricao' => $observacao->descricao
|
|
]
|
|
);
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
private function getMedicamentosUso($atendimento, $datetime)
|
|
{
|
|
return $atendimento->medicamentosUso
|
|
->where('created_at', '<=', $datetime)
|
|
->map(function($query) use ($atendimento) {
|
|
return array_merge(
|
|
$this->getBaseHistoricoAreaAtendimento($query, $atendimento),
|
|
[
|
|
'descricao' => $query->descricao,
|
|
]);
|
|
});
|
|
}
|
|
|
|
private function getSinaisVitais($atendimento, $datetime)
|
|
{
|
|
$sinaisVitais = $atendimento->sinaisVitais()->where('created_at', '<=', $datetime)->get();
|
|
$result = [];
|
|
|
|
foreach ($sinaisVitais as $sinalVital) {
|
|
|
|
$result[] = [
|
|
'id' => $sinalVital->id,
|
|
'pa' => $sinalVital->pa,
|
|
'pa_unidade_medida_id' => $sinalVital->pa_unidade_medida_id,
|
|
'glicemia' => $sinalVital->glicemia,
|
|
'glicemia_unidade_medida_id' => UnidadeMedidaEnum::MILIGRAMAS_POR_DECILITRO,
|
|
'temperatura' => $sinalVital->temperatura,
|
|
'temperatura_unidade_medida_id' => UnidadeMedidaEnum::CELSIUS,
|
|
'pulso' => $sinalVital->pulso,
|
|
'pulso_unidade_medida_id' => UnidadeMedidaEnum::BATIMENTOS_POR_MINUTO,
|
|
'respiracao' => $sinalVital->respiracao,
|
|
'respiracao_unidade_medida_id' => UnidadeMedidaEnum::MOVIMENTOS_POR_MINUTO,
|
|
'saturacao' => $sinalVital->saturacao,
|
|
'saturacao_unidade_medida_id' => UnidadeMedidaEnum::PORCENTAGEM,
|
|
'intensidade_dor' => $sinalVital->intensidade_dor,
|
|
'intensidade_dor_unidade_medida_id' => UnidadeMedidaEnum::NIVEL_DE_DOR,
|
|
'cintura' => $sinalVital->cintura,
|
|
'cintura_unidade_medida_id' => UnidadeMedidaEnum::CENTIMETROS,
|
|
'lotacao' => [
|
|
'ocupacao' => [
|
|
'id' => $sinalVital->createdLotacao->ocupacao->id ?? null,
|
|
'codigo' => $sinalVital->createdLotacao->ocupacao->codigo ?? null,
|
|
'nome' => $sinalVital->createdLotacao->ocupacao->nome ?? null,
|
|
],
|
|
'profissional' => [
|
|
'nome' => $sinalVital->createdLotacao->usuario->cidadao->nome ?? null,
|
|
],
|
|
],
|
|
'centro_custo' => [
|
|
'setor' => [
|
|
'nome' => $sinalVital->createdCentroCusto->setor->nome ?? null,
|
|
],
|
|
],
|
|
'classificacao_risco' => [
|
|
'nome' => (
|
|
$sinalVital->atendimentoMedico
|
|
?? $sinalVital->atendimentoTriagem
|
|
?? $sinalVital->atendimentoEnfermagem
|
|
?? $sinalVital->pacienteObservacao
|
|
)->classificacaoRisco->classificacaoRisco->nome ?? null,
|
|
],
|
|
'data_hora' => $sinalVital->created_at->format('d/m/Y H:i:s'),
|
|
];
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
private function getAnotacoes($atendimento, $datetime)
|
|
{
|
|
return Anotacao::where('created_at', '<=', $datetime)
|
|
->whereHas('atendimentoEnfermagem', function ($query) use ($atendimento) {
|
|
|
|
$query->where('atendimento_id', $atendimento->id);
|
|
})
|
|
->get()
|
|
->map(function ($anotacao) {
|
|
return array_merge(
|
|
$this->getBaseHistoricoAreaAtendimento($anotacao->atendimentoEnfermagem, $anotacao->atendimentoEnfermagem->atendimento),
|
|
[
|
|
'id' => $anotacao->id,
|
|
'data_hora_anotacao' => $anotacao->anotado_em->format('d/m/Y H:i'),
|
|
'anotacao' => $anotacao->descricao,
|
|
]
|
|
);
|
|
})
|
|
->sortBy('created_at');
|
|
}
|
|
|
|
private function getExameStatus()
|
|
{
|
|
return ExameStatus::all();
|
|
}
|
|
|
|
private function getDesfechos(Atendimento $atendimento) : array
|
|
{
|
|
$allowed = [
|
|
DesfechoEnum::EVASAO
|
|
];
|
|
|
|
if ($atendimento->atendimentosMedico->count() > 0) {
|
|
|
|
$lastAtendimentoMedico = $atendimento->atendimentosMedico->last();
|
|
|
|
if (!$lastAtendimentoMedico->solicitou_reavaliacao) {
|
|
|
|
$allowed = array_merge(
|
|
$allowed,
|
|
[
|
|
DesfechoEnum::ALTA_MEDICA
|
|
]
|
|
);
|
|
}
|
|
|
|
} else {
|
|
|
|
$allowed = array_merge(
|
|
$allowed,
|
|
[
|
|
DesfechoEnum::PACIENTE_ATENDIDO
|
|
]
|
|
);
|
|
}
|
|
|
|
return Desfecho::whereIn('id', $allowed)
|
|
->get()
|
|
->map(function ($desfecho) {
|
|
|
|
return [
|
|
'id' => $desfecho->id,
|
|
'nome' => $desfecho->nome,
|
|
];
|
|
})
|
|
->toArray();
|
|
}
|
|
|
|
private function getProfissionaisAtendimento($atendimento)
|
|
{
|
|
return $atendimento->atendimentosMedico
|
|
->map(fn ($atendimentoMedico) => [
|
|
'id' => $atendimentoMedico->createdLotacao->usuario->id,
|
|
'lotacao_id' => $atendimentoMedico->createdLotacao->id,
|
|
'nome' => "{$atendimentoMedico->createdLotacao->usuario->nome} - "
|
|
. $atendimentoMedico->createdLotacao->ocupacao->nome,
|
|
])
|
|
->unique('lotacao_id')
|
|
->values();
|
|
}
|
|
|
|
private function getModelData($atendimento, $datetime)
|
|
{
|
|
$faa = $atendimento->faa;
|
|
$parecerMedico = $faa->raat && $faa->raat->pareceresMedico ? $faa->raat->pareceresMedico()->orderByDesc('created_at')->first() : [];
|
|
|
|
$cidadao = Cidadao::findOrFail($atendimento->faa->paciente->cidadao_id);
|
|
|
|
$cids = $atendimento->cids()
|
|
->with('cid')
|
|
->orderBy('created_at')
|
|
->get()
|
|
->makeHidden(['atendimento_id', 'atendimento_medico_id', 'cid_id']);
|
|
$cidPrincipal = $cids->last();
|
|
|
|
$atendimentoMedicoDesfecho = $atendimento->atendimentosMedico()
|
|
->whereNotNull('desfecho_id')
|
|
->orderByDesc('created_at')
|
|
->first();
|
|
|
|
if($atendimento->faa->paciente->cidadao->sexo_id === Sexo::FEMININO && $atendimento->faa->paciente->cidadao->idade
|
|
&& $atendimento->faa->paciente->cidadao->idade['anos'] >= 9
|
|
&& $atendimento->faa->paciente->cidadao->idade['anos'] <= 60){
|
|
|
|
$exibirFatorRiscoGestante = true;
|
|
|
|
} else {
|
|
|
|
$exibirFatorRiscoGestante = false;
|
|
}
|
|
|
|
if ($atendimento->dor_toracica == true) {
|
|
|
|
$formulario = FormularioDorToracica::where('atendimento_id', $atendimento->id)->get();
|
|
|
|
foreach ($formulario as $registro) {
|
|
|
|
$formulario_id = $registro->id;
|
|
$data_sintoma = $registro->data_sintoma;
|
|
$hora_sintoma = $registro->hora_sintoma;
|
|
$data_ecg_admissao = $registro->data_ecg_admissao;
|
|
$hora_ecg_admissao = $registro->hora_ecg_admissao;
|
|
$dispneia = $registro->dispneia;
|
|
}
|
|
|
|
$formularioRelacionadoDor = RelacionadoFormularioDorToracica::where('formulario_id', $formulario_id)->get();
|
|
|
|
$dorToracicaRelacionada = [];
|
|
|
|
foreach ($formularioRelacionadoDor as $registroRelacionado) {
|
|
|
|
$dorToracicaRelacionada[] = $registroRelacionado->dor_toracica_id;
|
|
}
|
|
}
|
|
|
|
return [
|
|
'atendimento_id' => $atendimento->id,
|
|
'dor_toracica' => $atendimento->dor_toracica,
|
|
'classificacao_risco_id' => $this->getClassificacaoRisco($atendimento, $datetime)['classificacao_risco_id'] ?? null,
|
|
'alergias' => $this->getAlergiasCidadao($atendimento, $datetime),
|
|
'medicamentos_uso_continuo' => $this->getMedicamentosUsoContinuo($atendimento, $datetime),
|
|
'medicamentos_ativos' => [],
|
|
'sinais_vitais' => [],
|
|
'anotacoes' => [],
|
|
'avaliacao_antropometrica' => $this->getAvaliacaoAntropometrica($atendimento, $datetime),
|
|
'gestacao' => $this->getGestacao($atendimento),
|
|
'servicos_enfermagem' => $this->getServicosEnfermagem($atendimento, $datetime, [ExameStatusEnum::SOLICITADO]),
|
|
'cid' => [
|
|
'id' => $cidPrincipal->cid->id ?? null,
|
|
'codigo' => $cidPrincipal->cid->codigo ?? null,
|
|
'nome' => $cidPrincipal->cid->nome ?? null,
|
|
],
|
|
'finalizacao' => [
|
|
'desfecho_id' => null,
|
|
'alta_medica' => [
|
|
'lotacao_id' => $atendimentoMedicoDesfecho->createdLotacao->id ?? null,
|
|
],
|
|
'evasao' => [
|
|
'motivo' => null,
|
|
],
|
|
'encaminhamento_hospitalar' => [
|
|
'unidade_id' => null,
|
|
'unidade_outra' => false,
|
|
'unidade_nome' => null,
|
|
'quarto' => null,
|
|
'leito' => null,
|
|
'cid' => null,
|
|
'medico_hospitalar' => null,
|
|
'observacoes' => null,
|
|
],
|
|
'obito' => [
|
|
'data_obito' => null,
|
|
'hora_obito' => null,
|
|
'obito_em' => null,
|
|
'declaracao' => null,
|
|
'causa' => null,
|
|
'cid' => null,
|
|
]
|
|
],
|
|
'acidente_trabalho' => AcidenteTrabalhoService::getAcidenteTrabalho($atendimento->faa),
|
|
'fatores_risco' => $this->getCidadaoFatoresRisco($atendimento),
|
|
'fator_risco_outro' => $cidadao->fator_risco_outro ?? null,
|
|
'planejamento' => null,
|
|
'implementacao' => null,
|
|
'diagnostico' => null,
|
|
'avaliacao' => null,
|
|
'historico' => null,
|
|
'observacao' => null,
|
|
'medicamentos_uso' => null,
|
|
'procedimentos' => [],
|
|
'encaminhamento_setor' => null,
|
|
'prescricoes_interna' => $this->getPrescricoesInterna($atendimento, $datetime, false),
|
|
'pedidos_exames' => $this->getPedidosExames($atendimento),
|
|
'exibirFatorRiscoGestante' => $exibirFatorRiscoGestante,
|
|
'escalas_coma_glasgow' => [],
|
|
'centro_custo_id_para' => null,
|
|
'dor_toracica_data_sintoma' => $data_sintoma ?? null,
|
|
'dor_toracica_hora_sintoma' => $hora_sintoma ?? null,
|
|
'dor_toracica_data_ecg_admissao' => $data_ecg_admissao ?? null,
|
|
'dor_toracica_hora_ecg_admissao' => $hora_ecg_admissao ?? null,
|
|
'dor_toracica_caracteristica_dor' => $dorToracicaRelacionada ?? null,
|
|
'dor_toracica_localizacao_dor' => $dorToracicaRelacionada ?? null,
|
|
'dor_toracica_fator_descadeante' => $dorToracicaRelacionada ?? null,
|
|
'dor_toracica_duracao_dor' => $dorToracicaRelacionada ?? null,
|
|
'dor_toracica_fatores_riscos' => $dorToracicaRelacionada ?? null,
|
|
'dor_toracica_dispneia' => $dispneia ?? null,
|
|
'cancelamento_desfecho' => false,
|
|
];
|
|
}
|
|
|
|
private function getAlergiasCidadao($atendimento, $datetime)
|
|
{
|
|
return $atendimento->faa->paciente->cidadao->alergias()
|
|
->wherePivot('created_at', '<=', $datetime)
|
|
->get()
|
|
->map(function($query, $i) {
|
|
return [
|
|
'index' => $i,
|
|
'alergia' => [
|
|
'id' => $query->cidadaoAlergia->alergia_id,
|
|
'agente_substancia_especifica' => $query->agente_substancia_especifica,
|
|
'criticidade' => [
|
|
'id' => $query->cidadaoAlergia->criticidade->id,
|
|
'nome' => $query->cidadaoAlergia->criticidade->nome,
|
|
],
|
|
'reacoes_observacoes' => $query->cidadaoAlergia->reacoes_observacoes,
|
|
'tipo' => [
|
|
'id' => $query->tipo->id,
|
|
'descricao' => $query->tipo->descricao,
|
|
]
|
|
],
|
|
'lotacao' => [
|
|
'ocupacao' => [
|
|
'id' => $query->cidadaoAlergia->createdLotacao->ocupacao->id ?? null,
|
|
'codigo' => $query->cidadaoAlergia->createdLotacao->ocupacao->codigo ?? null,
|
|
'nome' => $query->cidadaoAlergia->createdLotacao->ocupacao->nome ?? null,
|
|
],
|
|
'profissional' => [
|
|
'nome' => $query->cidadaoAlergia->createdLotacao->usuario->cidadao->nome ?? null,
|
|
],
|
|
],
|
|
'centro_custo' => [
|
|
'setor' => [
|
|
'nome' => $query->cidadaoAlergia->createdCentroCusto->setor->nome ?? null,
|
|
],
|
|
],
|
|
'data_hora' => $query->cidadaoAlergia->created_at->format('d/m/Y H:i:s') ?? null,
|
|
];
|
|
});
|
|
}
|
|
|
|
private function getMedicamentosUsoContinuo($atendimento, $datetime)
|
|
{
|
|
$medicamentos = $atendimento->faa->paciente->cidadao->medicamentosUsoContinuo()->wherePivot('created_at', '<=', $datetime)->get();
|
|
$result = [];
|
|
|
|
foreach ($medicamentos as $medicamento) {
|
|
$result[] = [
|
|
'medicamento' => [
|
|
'nome' => $medicamento->nome,
|
|
'id' => $medicamento->CidadaoMedicamentoUsoContinuo->medicamento_id,
|
|
],
|
|
'lotacao' => [
|
|
'ocupacao' => [
|
|
'id' => $medicamento->CidadaoMedicamentoUsoContinuo->createdLotacao->ocupacao->id ?? null,
|
|
'codigo' => $medicamento->CidadaoMedicamentoUsoContinuo->createdLotacao->ocupacao->codigo ?? null,
|
|
'nome' => $medicamento->CidadaoMedicamentoUsoContinuo->createdLotacao->ocupacao->nome ?? null,
|
|
],
|
|
'profissional' => [
|
|
'nome' => $medicamento->CidadaoMedicamentoUsoContinuo->createdLotacao->usuario->cidadao->nome ?? null,
|
|
],
|
|
],
|
|
'centro_custo' => [
|
|
'setor' => [
|
|
'nome' => $medicamento->CidadaoMedicamentoUsoContinuo->createdCentroCusto->setor->nome ?? null,
|
|
],
|
|
],
|
|
'data_hora' => $medicamento->CidadaoMedicamentoUsoContinuo->created_at->format('d/m/Y H:i:s') ?? null,
|
|
];
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
private function getAvaliacaoAntropometrica(Atendimento $atendimento, $datetime) : ?array
|
|
{
|
|
$avaliacaoAntropometrica = $atendimento->avaliacoesAntropometricas()
|
|
->where('created_at', '<=', $datetime)->orderByDesc('created_at')->first();
|
|
|
|
return [
|
|
'massa' => $avaliacaoAntropometrica->massa ?? null,
|
|
'massa_unidade_medida_id' => $avaliacaoAntropometrica->massa_unidade_medida_id ?? UnidadeMedidaEnum::QUILOGRAMAS,
|
|
'altura_tipo_medida_id' => $avaliacaoAntropometrica->altura_tipo_medida_id ?? TipoMedidaAlturaEnum::ESTATURA,
|
|
'altura' => $avaliacaoAntropometrica->altura ?? null,
|
|
'altura_unidade_medida_id' => $avaliacaoAntropometrica->altura_unidade_medida_id ?? UnidadeMedidaEnum::METROS,
|
|
'imc' => $avaliacaoAntropometrica->imc ?? ['imc' => '', 'classificacao' => ''],
|
|
'setor' => $avaliacaoAntropometrica->createdCentroCusto->setor->nome ?? null,
|
|
'profissional' => $avaliacaoAntropometrica->createdLotacao->usuario->cidadao->nome ?? null,
|
|
'ocupacao' => $avaliacaoAntropometrica->createdLotacao->ocupacao ?? null,
|
|
'classificacao_risco_id' => $avaliacaoAntropometrica
|
|
? $this->getClassificacaoRisco($atendimento, $avaliacaoAntropometrica->created_at) : null,
|
|
'data_hora' => $avaliacaoAntropometrica ? $avaliacaoAntropometrica->created_at->format('Y-m-d H:i:s') : null,
|
|
];
|
|
}
|
|
|
|
private function getClassificacaoRisco($atendimento, $datetime)
|
|
{
|
|
$classificacaoRisco = $atendimento->classificacoesRisco()
|
|
->where('created_at', '<=', $datetime)
|
|
->get()
|
|
->sortByDesc('created_at')
|
|
->first();
|
|
|
|
if ($classificacaoRisco == null)
|
|
return null;
|
|
|
|
return [
|
|
'id' => $classificacaoRisco->id,
|
|
'classificacao_risco_id' => $classificacaoRisco->classificacao_risco_id,
|
|
'nome' => $classificacaoRisco->classificacaoRisco->nome,
|
|
];
|
|
}
|
|
|
|
private function getServicosEnfermagem(Atendimento $atendimento, Carbon $datetime, array $status)
|
|
{
|
|
return ServicoEnfermagem::where('created_at', '<=', $datetime)
|
|
->where(function ($query) use ($atendimento) {
|
|
|
|
$query->whereHas('atendimentoEnfermagem', function ($query) use ($atendimento) {
|
|
|
|
$query->where('atendimento_id', $atendimento->id);
|
|
})
|
|
->orWhereHas('atendimentoMedico', function ($query) use ($atendimento) {
|
|
|
|
$query->where('atendimento_id', $atendimento->id);
|
|
});
|
|
})
|
|
->whereIn('status_id', $status)
|
|
->get()
|
|
->map(function ($servico) use ($atendimento, $datetime) {
|
|
return [
|
|
'cbo' => $servico->createdLotacao->ocupacao->codigo,
|
|
'centro_custo' => [
|
|
'setor' => [
|
|
'nome' => $servico->createdCentroCusto->setor->nome ?? null,
|
|
],
|
|
],
|
|
'lotacao' => [
|
|
'ocupacao' => [
|
|
'codigo' => $servico->createdLotacao->ocupacao->codigo,
|
|
'nome' => $servico->createdLotacao->ocupacao->nome,
|
|
],
|
|
'profissional' => [
|
|
'nome' => $servico->createdLotacao->usuario->cidadao->nome,
|
|
],
|
|
],
|
|
'ocupacao' => $servico->createdLotacao->ocupacao,
|
|
'data_hora' => $servico->created_at->format('d/m/Y H:i:s'),
|
|
'classificacao_risco' => $this->getClassificacaoRisco($atendimento, $datetime),
|
|
'id' => $servico->id,
|
|
'procedimento' => [
|
|
'id' => $servico->procedimento->id,
|
|
'codigo' => $servico->procedimento->codigo,
|
|
'nome' => $servico->procedimento->nome,
|
|
'has_cid_principal' => $servico->procedimento->has_cid_principal
|
|
],
|
|
'status' => [
|
|
'id' => $servico->status_id,
|
|
],
|
|
'cid' => $servico->cid,
|
|
'horario_realizacao' => $servico->horario_realizacao,
|
|
'profissional' => [
|
|
'nome' => $servico->updatedLotacao->usuario->cidadao->nome,
|
|
],
|
|
'disabled' => $this->isDisabled($servico->status->id)
|
|
];
|
|
});
|
|
}
|
|
|
|
private function getGestacao($atendimento)
|
|
{
|
|
$gestacao = $atendimento->gestacoes()->orderByDesc('created_at')->first();
|
|
$gestacaoPaciente = $atendimento->faa->paciente->dum;
|
|
|
|
return [
|
|
'dpp' => $gestacaoPaciente && $gestacaoPaciente->data_possivel_parto
|
|
? Carbon::create($gestacaoPaciente->data_possivel_parto)->format('d/m/Y')
|
|
: $gestacao->dpp ?? null,
|
|
'dum_min_date' => $atendimento->created_at->subDays(308)->format('d/m/Y'),
|
|
'dum_max_date' => $atendimento->created_at->format('d/m/Y'),
|
|
'dum' => $gestacaoPaciente && $gestacaoPaciente->data_ultima_menstruacao
|
|
? $gestacaoPaciente->data_ultima_menstruacao
|
|
: $gestacao->dum ?? null,
|
|
'gestante' => $atendimento->faa->paciente->cidadao->fatoresRisco->contains(FatorRiscoEnum::GESTANTE)
|
|
?? $gestacao->gestante ?? false,
|
|
'idade_gestacional' => [
|
|
'dias' => $gestacaoPaciente && $gestacaoPaciente->idade_gestacional_dias
|
|
? $gestacaoPaciente->idade_gestacional_dias
|
|
: $gestacao->idade_gestacional['dias'] ?? null,
|
|
'semanas' => $gestacaoPaciente && $gestacaoPaciente->idade_gestacional_semanas
|
|
? $gestacaoPaciente->idade_gestacional_semanas
|
|
: $gestacao->idade_gestacional['semanas'] ?? null,
|
|
],
|
|
];
|
|
}
|
|
|
|
private function getProcedimentos(Atendimento $atendimento, Carbon $datetime, String $tipoAtendimento) : array
|
|
{
|
|
$procedimentos = $atendimento->procedimentos()
|
|
->with('procedimento', 'cidPrincipal')
|
|
->whereNotNull($tipoAtendimento . '_id')
|
|
->orderBy('created_at')
|
|
->get();
|
|
|
|
$result = [];
|
|
|
|
foreach ($procedimentos as $procedimento) {
|
|
|
|
$result[] = [
|
|
'id' => $procedimento->id,
|
|
'cbo' => $procedimento->createdLotacao->ocupacao->codigo,
|
|
'procedimento' => [
|
|
'nome' => $procedimento->procedimento->nome ?? null,
|
|
'codigo' => $procedimento->procedimento->codigo ?? null,
|
|
],
|
|
'codigo' => $procedimento->procedimento->codigo ?? null,
|
|
'cid_principal' => [
|
|
'id' => $procedimento->cidPrincipal->id ?? null,
|
|
'codigo' => $procedimento->cidPrincipal->codigo ?? null,
|
|
'nome' => $procedimento->cidPrincipal->nome ?? null,
|
|
],
|
|
'quantidade' => $procedimento->quantidade ?? null,
|
|
'centro_custo' => [
|
|
'setor' => [
|
|
'nome' => $procedimento->createdCentroCusto->setor->nome ?? null,
|
|
],
|
|
],
|
|
'lotacao' => [
|
|
'ocupacao' => [
|
|
'codigo' => $procedimento->createdLotacao->ocupacao->codigo,
|
|
'nome' => $procedimento->createdLotacao->ocupacao->nome,
|
|
],
|
|
'profissional' => [
|
|
'nome' => $procedimento->createdLotacao->usuario->cidadao->nome,
|
|
],
|
|
],
|
|
'ocupacao' => $procedimento->createdLotacao->ocupacao,
|
|
'classificacao_risco' => $this->getClassificacaoRisco($atendimento, $datetime),
|
|
'data_hora' => $procedimento->created_at->format('d/m/Y H:i:s'),
|
|
];
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
public static function getUnidadesFaturamento()
|
|
{
|
|
|
|
$lotacaoLogada = Lotacao::findOrFail(auth()->payload()->get('lotacao_id'));
|
|
|
|
return UnidadeFaturamentoUsuario::where(function ($query) use ($lotacaoLogada){
|
|
|
|
$query->whereHas('unidadeFaturamentoAutomatico', function ($query) use ($lotacaoLogada){
|
|
|
|
$query
|
|
->where('infraestrutura_id', $lotacaoLogada->infraestrutura_id)
|
|
->orWhere(function ($query) use ($lotacaoLogada){
|
|
|
|
$query->whereHas('unidadeFaturamentoUnidade', function ($query) use ($lotacaoLogada){
|
|
|
|
$query->where('infraestrutura_id', $lotacaoLogada->infraestrutura_id);
|
|
});
|
|
});
|
|
});
|
|
})
|
|
->groupBy('usuario_id')
|
|
->get()
|
|
->map(fn ($query) => [
|
|
'id' => $query->usuario_id,
|
|
'usuario_ocupacao' => $query->usuario->nome . ' - ' . $query->ocupacao->codigo,
|
|
'ocupacao_id' => $query->ocupacao_id,
|
|
'infraestrutura_id' => $query->unidadeFaturamentoAutomatico->infraestrutura_id,
|
|
]);
|
|
}
|
|
|
|
public static function getLaboratoriosFaturamento()
|
|
{
|
|
|
|
$lotacaoLogada = Lotacao::findOrFail(auth()->payload()->get('lotacao_id'));
|
|
|
|
return LaboratorioFaturaUsuario::where(function ($query) use ($lotacaoLogada){
|
|
|
|
$query->whereHas('laboratorioFaturaAutomatico', function ($query) use ($lotacaoLogada){
|
|
|
|
$query
|
|
->where('infraestrutura_id', $lotacaoLogada->infraestrutura_id)
|
|
->orWhere(function ($query) use ($lotacaoLogada){
|
|
|
|
$query->whereHas('laboratorioFaturaUnidade', function ($query) use ($lotacaoLogada){
|
|
|
|
$query->where('infraestrutura_id', $lotacaoLogada->infraestrutura_id);
|
|
});
|
|
});
|
|
});
|
|
})
|
|
->groupBy('usuario_id')
|
|
->get()
|
|
->map(fn ($query) => [
|
|
'id' => $query->usuario_id,
|
|
'usuario_ocupacao' => $query->usuario->nome . ' - ' . $query->ocupacao->codigo,
|
|
'ocupacao_id' => $query->ocupacao_id,
|
|
'infraestrutura_id' => $query->laboratorioFaturaAutomatico->infraestrutura_id,
|
|
]);
|
|
}
|
|
|
|
private function handleUsuarioLaboratorio($pedidoExames)
|
|
{
|
|
$usuarios = self::getLaboratoriosFaturamento();
|
|
|
|
if ($usuarios->count() === 1) {
|
|
return [
|
|
'id' => $usuarios->first()['id'],
|
|
'ocupacao_id' => $usuarios->first()['ocupacao_id'] ?? null,
|
|
'infraestrutura_id' => $usuarios->first()['infraestrutura_id'] ?? null,
|
|
];
|
|
}
|
|
|
|
if ($pedidoExames->laboratorio_usuario_id) {
|
|
$usuarioEncontrado = $usuarios->firstWhere('id', $pedidoExames->laboratorio_usuario_id);
|
|
|
|
if ($usuarioEncontrado) {
|
|
return [
|
|
'id' => $usuarioEncontrado['id'],
|
|
'ocupacao_id' => $usuarioEncontrado['ocupacao_id'] ?? null,
|
|
'infraestrutura_id' => $usuarioEncontrado['infraestrutura_id'] ?? null,
|
|
];
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
private function handleUsuarioUnidade($pedidoExames)
|
|
{
|
|
$usuarios = self::getUnidadesFaturamento();
|
|
|
|
if ($usuarios->count() === 1) {
|
|
return [
|
|
'id' => $usuarios->first()['id'],
|
|
'ocupacao_id' => $usuarios->first()['ocupacao_id'] ?? null,
|
|
'infraestrutura_id' => $usuarios->first()['infraestrutura_id'] ?? null,
|
|
];
|
|
}
|
|
|
|
if ($pedidoExames->usuario_id) {
|
|
$usuarioEncontrado = $usuarios->firstWhere('id', $pedidoExames->usuario_id);
|
|
|
|
if ($usuarioEncontrado) {
|
|
return [
|
|
'id' => $usuarioEncontrado['id'],
|
|
'ocupacao_id' => $usuarioEncontrado['ocupacao_id'] ?? null,
|
|
'infraestrutura_id' => $usuarioEncontrado['infraestrutura_id'] ?? null,
|
|
];
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
private function getPrescricoesInterna(Atendimento $atendimento, Carbon $datetime, bool $isForm) : array
|
|
{
|
|
$result = [];
|
|
|
|
$prescricoes = PrescricaoInterna::where('created_at', '<=', $datetime)
|
|
->whereHas('atendimentoMedico', function ($query) use ($atendimento) {
|
|
|
|
$query->where('atendimento_id', $atendimento->id);
|
|
})
|
|
->get();
|
|
|
|
foreach ($prescricoes as $prescricaoInterna) {
|
|
|
|
$data = [
|
|
'id' => $prescricaoInterna->id,
|
|
'frequencia' => $prescricaoInterna->frequencia,
|
|
'observacoes' => $prescricaoInterna->observacoes,
|
|
'medicamentos' => $this->getMedicamentosPrescricaoInterna($prescricaoInterna),
|
|
'lotacao' => [
|
|
'ocupacao' => [
|
|
'id' => $prescricaoInterna->createdLotacao->ocupacao->id ?? null,
|
|
'codigo' => $prescricaoInterna->createdLotacao->ocupacao->codigo ?? null,
|
|
'nome' => $prescricaoInterna->createdLotacao->ocupacao->nome ?? null,
|
|
],
|
|
'profissional' => [
|
|
'nome' => $prescricaoInterna->createdLotacao->usuario->cidadao->nome ?? null,
|
|
],
|
|
],
|
|
'centro_custo' => [
|
|
'setor' => [
|
|
'nome' => $prescricaoInterna->createdCentroCusto->setor->nome ?? null,
|
|
],
|
|
],
|
|
'classificacao_risco' => [
|
|
'nome' => $prescricaoInterna->atendimentoMedico->classificacaoRisco->classificacaoRisco->nome ?? null,
|
|
],
|
|
'data_hora' => $prescricaoInterna->created_at->format('d/m/Y H:i:s'),
|
|
];
|
|
|
|
if ($isForm && !$this->hasAplicacoesSolicitado($prescricaoInterna)) {
|
|
|
|
$result[] = array_merge(
|
|
$this->getBaseHistoricoAreaAtendimento($prescricaoInterna, $prescricaoInterna->atendimentoMedico->atendimento),
|
|
$data
|
|
);
|
|
|
|
continue;
|
|
}
|
|
|
|
if (!$isForm && $this->hasAplicacoesSolicitado($prescricaoInterna)) {
|
|
|
|
$result[] = array_merge(
|
|
$this->getBaseHistoricoAreaAtendimento($prescricaoInterna, $prescricaoInterna->atendimentoMedico->atendimento),
|
|
$data
|
|
);
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
private function getMedicamentosPrescricaoInterna(PrescricaoInterna $prescricaoInterna) : array
|
|
{
|
|
$result = [];
|
|
foreach ($prescricaoInterna->medicamentos as $item) {
|
|
|
|
$result[] = [
|
|
'id' => $item->id,
|
|
'medicamento' => [
|
|
'nome' => $item->medicamento->nome,
|
|
'forma_farmaceutica' => [
|
|
'nome' => $item->medicamento->formaFarmaceutica->nome
|
|
]
|
|
],
|
|
'unidade_medida' => [
|
|
'sigla' => $item->unidadeMedida->sigla ?? null,
|
|
],
|
|
'quantidade' => $item->quantidade,
|
|
'administracao' => $item->administracao,
|
|
'aplicacoes' => $this->getAplicacoesMedicamentoPrescricaoInterna($item),
|
|
];
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
private function getAplicacoesMedicamentoPrescricaoInterna(PrescricaoInternaMedicamento $medicamento)
|
|
{
|
|
return $medicamento->aplicacoes->map(function ($aplicacao) {
|
|
|
|
return [
|
|
'id' => $aplicacao->id,
|
|
'status' => [
|
|
'id' => $aplicacao->status->id,
|
|
'nome' => $aplicacao->status->nome,
|
|
],
|
|
'profissional' => [
|
|
'nome' => $aplicacao->updatedLotacao->usuario->cidadao->nome,
|
|
],
|
|
'disabled' => $this->isDisabled($aplicacao->status->id),
|
|
'horario_aplicacao' => $aplicacao->horario_aplicacao,
|
|
'local_aplicacao_id' => $aplicacao->local_aplicacao_id,
|
|
];
|
|
});
|
|
}
|
|
|
|
private function isDisabled(int $statusId)
|
|
{
|
|
return $statusId === ExameStatusEnum::REALIZADO
|
|
|| $statusId === ExameStatusEnum::NAO_REALIZADO;
|
|
}
|
|
|
|
private function hasAplicacoesSolicitado(PrescricaoInterna $prescricaoInterna) : bool
|
|
{
|
|
foreach ($prescricaoInterna->medicamentos as $medicamento) {
|
|
|
|
$aplicacoesSolicitadas = $medicamento->aplicacoes->where('status_id', ExameStatusEnum::SOLICITADO);
|
|
|
|
if ($aplicacoesSolicitadas->count() > 0) {
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
private function getPedidosExames(Atendimento $atendimento, bool $isForm = false)
|
|
{
|
|
$result = [];
|
|
|
|
foreach ($atendimento->pedidosExames as $pedidoExames) {
|
|
|
|
$exames = $this->getExamesPedidoExames($pedidoExames);
|
|
|
|
$usuarioUnidade = $this->handleUsuarioUnidade($pedidoExames);
|
|
$usuarioLaboratorio = $this->handleUsuarioLaboratorio($pedidoExames);
|
|
|
|
$dataPedido = [
|
|
'id' => $pedidoExames->id,
|
|
'urgente' => $pedidoExames->urgente,
|
|
"dataSolicitacao" => $pedidoExames->created_at->format('d/m/Y H:i'),
|
|
"centro_custo" => [
|
|
"infraestrutura" => $pedidoExames->createdLotacao->infraestrutura->unidade->nome_fantasia,
|
|
"setor" => $pedidoExames->createdCentroCusto->setor->nome
|
|
],
|
|
'lotacao' => [
|
|
'ocupacao' => [
|
|
'codigo' => $pedidoExames->createdLotacao->ocupacao->codigo,
|
|
'nome' => $pedidoExames->createdLotacao->ocupacao->nome
|
|
],
|
|
'profissional' => [
|
|
'nome' => $pedidoExames->createdLotacao->usuario->cidadao->nome,
|
|
]
|
|
],
|
|
'justificativa' => $pedidoExames->justificativa,
|
|
'usuario_id' => $usuarioUnidade ? $usuarioUnidade['id'] : null,
|
|
'ocupacao_id' => $usuarioUnidade ? $usuarioUnidade['ocupacao_id'] : null,
|
|
'usuario_infraestrutura_id' => $usuarioUnidade ? $usuarioUnidade['infraestrutura_id'] : null,
|
|
'laboratorio_usuario_id' => $usuarioLaboratorio ? $usuarioLaboratorio['id'] : null,
|
|
'laboratorio_ocupacao_id' => $usuarioLaboratorio ? $usuarioLaboratorio['ocupacao_id'] : null,
|
|
'laboratorio_infraestrutura_id' => $usuarioLaboratorio ? $usuarioLaboratorio['infraestrutura_id'] : null,
|
|
'exames' => $exames,
|
|
'files' => $pedidoExames->laudos
|
|
->where('created_at', '>=', $pedidoExames->created_at)
|
|
->map(fn($laudo) => [
|
|
'id' => $laudo->id,
|
|
'name' => $laudo->nome,
|
|
'hash' => $laudo->hash
|
|
])
|
|
];
|
|
|
|
if($isForm && !$this->hasExamesLaboratorialSolicitadosOrAguardandoResultado($pedidoExames)) {
|
|
$result[] = $dataPedido;
|
|
}
|
|
|
|
if(!$isForm && $this->hasExamesLaboratorialSolicitadosOrAguardandoResultado($pedidoExames)) {
|
|
$result[] = $dataPedido;
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
private function getExamesPedidoExames(PedidoExame $pedidoExames)
|
|
{
|
|
$itens = $pedidoExames->exames();
|
|
|
|
return $itens->get()
|
|
->map(function ($item) {
|
|
|
|
$disabled =
|
|
$item->status_id === ExameStatusEnum::REALIZADO
|
|
|| $item->status_id === ExameStatusEnum::NAO_REALIZADO
|
|
|| $item->exame->tipo_id === ExameTipo::IMAGEM;
|
|
|
|
$disabled_horario =
|
|
$item->status_id === ExameStatusEnum::REALIZADO && $item->horario_realizacao != null
|
|
|| $item->status_id === ExameStatusEnum::NAO_REALIZADO
|
|
|| $item->exame->tipo_id === ExameTipo::IMAGEM;
|
|
|
|
return [
|
|
'id' => $item->id,
|
|
'data_solicitacao' => $item->data_solicitacao ?? $item->created_at->format('d/m/Y H:i'),
|
|
'unidade_solicitante' =>
|
|
$item->unidade_solicitante ??
|
|
$item->createdLotacao->infraestrutura->unidade->nome_fantasia,
|
|
'medico_solicitante' => $item->medico_solicitante ?? $item->createdLotacao->usuario->cidadao->nome,
|
|
'observacoes' => $this->getObservacoes($item),
|
|
'disabled' => $disabled,
|
|
'disabled_horario' => $disabled_horario,
|
|
'exame' => [
|
|
'id' => $item->exame->id,
|
|
'nome' => $item->exame->nome,
|
|
'tipo' => [
|
|
'id' => $item->exame->tipo->id,
|
|
'nome' => $item->exame->tipo->nome,
|
|
],
|
|
'procedimento' => [
|
|
'codigo' => $item->exame->procedimento->codigo ?? null,
|
|
'nome' => $item->exame->procedimento->nome ?? null,
|
|
],
|
|
'observacao' => $item->exame->observacao
|
|
],
|
|
'status' => [
|
|
'id' => $item->status->id,
|
|
'nome' => $item->status->nome,
|
|
],
|
|
'horario_realizacao' => $item->horario_realizacao,
|
|
'lotacao_executante_id' => $item->lotacao_executante_id,
|
|
];
|
|
});
|
|
}
|
|
|
|
private function getObservacoes(Item $item)
|
|
{
|
|
return Observacao::where('item_id', $item->id)->get()
|
|
->map(function ($observacao) use ($item) {
|
|
return array_merge (
|
|
$this->getBaseHistoricoAreaAtendimento($observacao, $item->pedidoExame->atendimento),
|
|
[
|
|
'observacao' => $observacao->observacao
|
|
]
|
|
);
|
|
});
|
|
}
|
|
|
|
private function getBaseHistoricoAreaAtendimento($model, $atendimento)
|
|
{
|
|
$result = [
|
|
'centro_custo' => [
|
|
'setor' => [
|
|
'nome' => $model->createdCentroCusto->setor->nome,
|
|
],
|
|
],
|
|
'lotacao' => [
|
|
'ocupacao' => [
|
|
'codigo' => $model->createdLotacao->ocupacao->codigo,
|
|
'nome' => $model->createdLotacao->ocupacao->nome,
|
|
],
|
|
'profissional' => [
|
|
'nome' => $model->createdLotacao->usuario->cidadao->nome,
|
|
],
|
|
],
|
|
'classificacao_risco' => [
|
|
'nome' => $this->getClassificacaoRisco($atendimento, $model->created_at)['nome'] ?? null
|
|
],
|
|
'data_hora' => $model->created_at->format('d/m/Y H:i:s'),
|
|
];
|
|
|
|
return $result;
|
|
}
|
|
|
|
public function faturarProcedimentosAutomaticamente($request)
|
|
{
|
|
$procedimentos = (object) [
|
|
'prescricao_interna' => collect(),
|
|
'exame_laboratorial' => collect(),
|
|
'exame_imagem' => collect(),
|
|
];
|
|
|
|
DB::transaction(function() use ($request, $procedimentos) {
|
|
|
|
$atendimento = Atendimento::findOrFail($request->atendimento_id);
|
|
$atendimentoEnfermagem = null;
|
|
|
|
$prescricoesInternas = $this->getPrescricoesInternasParaFaturamentoAutomatico($atendimento);
|
|
$pedidosExamesLaboratoriais = $this->getPedidoExamesLaboratoriaisParaFaturamentoAutomatico($atendimento);
|
|
$pedidosExamesImagem = $this->getPedidoExamesImagemParaFaturamentoAutomatico($atendimento);
|
|
|
|
if ($prescricoesInternas->isNotEmpty()
|
|
|| $pedidosExamesLaboratoriais->isNotEmpty()
|
|
|| $pedidosExamesImagem->isNotEmpty()
|
|
) {
|
|
|
|
PlantaoService::setStatusComAtendimento($request->plantao_id);
|
|
|
|
$atendimentoEnfermagem = new AtendimentoEnfermagem([
|
|
'plantao_id' => $request->plantao_id,
|
|
'automatico' => true,
|
|
]);
|
|
|
|
$atendimento->atendimentosEnfermagem()->save($atendimentoEnfermagem);
|
|
}
|
|
|
|
if ($prescricoesInternas->isNotEmpty()) {
|
|
|
|
$procedimentos->prescricao_interna = $this->faturarPrescricoesInternasAutomaticamente(
|
|
$prescricoesInternas,
|
|
$atendimentoEnfermagem
|
|
);
|
|
}
|
|
|
|
if ($pedidosExamesLaboratoriais->isNotEmpty()) {
|
|
|
|
$procedimentos->exame_laboratorial = $this->faturarExamesLaboratoriaisAutomaticamente(
|
|
$pedidosExamesLaboratoriais,
|
|
$atendimentoEnfermagem,
|
|
$request->lotacao_id
|
|
);
|
|
}
|
|
|
|
if ($pedidosExamesImagem->isNotEmpty()) {
|
|
|
|
$procedimentos->exame_imagem = $this->faturarExamesImagemAutomaticamente(
|
|
$pedidosExamesImagem,
|
|
$atendimentoEnfermagem
|
|
);
|
|
}
|
|
});
|
|
|
|
return $procedimentos;
|
|
}
|
|
|
|
private function getPrescricoesInternasParaFaturamentoAutomatico($atendimento)
|
|
{
|
|
return PrescricaoInterna::where('created_at', '<=', Carbon::now())
|
|
->whereHas('atendimentoMedico', function ($query) use ($atendimento) {
|
|
|
|
$query->where('atendimento_id', $atendimento->id);
|
|
})
|
|
->get();
|
|
}
|
|
|
|
private function faturarPrescricoesInternasAutomaticamente($prescricoesInternas, $atendimentoEnfermagem)
|
|
{
|
|
$procedimentos = collect();
|
|
$quantidadeAdministracoes = 0;
|
|
|
|
$prescricoesInternas
|
|
->each(function ($prescricao) use ($atendimentoEnfermagem, &$quantidadeAdministracoes) {
|
|
|
|
$prescricao->medicamentos
|
|
->each(function ($medicamento) use ($atendimentoEnfermagem, &$quantidadeAdministracoes) {
|
|
|
|
$medicamento->aplicacoes()
|
|
->where('status_id', ExameStatusEnum::SOLICITADO)
|
|
->get()
|
|
->each(function ($aplicacao) use ($atendimentoEnfermagem, &$quantidadeAdministracoes) {
|
|
|
|
$aplicacao->atendimento_enfermagem_id = $atendimentoEnfermagem->id;
|
|
$aplicacao->status_id = ExameStatusEnum::REALIZADO;
|
|
|
|
$hasAplicacaoRealizada = $aplicacao->prescricaoInternaMedicamento->prescricaoInterna()
|
|
->whereHas('medicamentos.aplicacoes', function ($query) {
|
|
|
|
$query->where('status_id', ExameStatusEnum::REALIZADO);
|
|
})
|
|
->get()
|
|
->isNotEmpty();
|
|
|
|
if (!$hasAplicacaoRealizada) {
|
|
|
|
$quantidadeAdministracoes++;
|
|
}
|
|
|
|
$aplicacao->save();
|
|
});
|
|
});
|
|
});
|
|
|
|
if ($quantidadeAdministracoes > 0) {
|
|
|
|
$atendimentoProcedimento = $this->faturarProcedimentoPadraoPrescricaoInterna(
|
|
$atendimentoEnfermagem,
|
|
$quantidadeAdministracoes
|
|
)->first();
|
|
|
|
if (!is_null($atendimentoProcedimento)) {
|
|
|
|
$procedimentos->push($this->getProcedimentoFaturadoAutomaticamenteData($atendimentoProcedimento));
|
|
}
|
|
}
|
|
|
|
return $procedimentos;
|
|
}
|
|
|
|
public function getPedidoExamesLaboratoriaisParaFaturamentoAutomatico($atendimento)
|
|
{
|
|
return $atendimento->pedidosExames()
|
|
->whereHas('exames', function ($query) {
|
|
|
|
$query->whereHas('exame', fn ($q) => $q->where('tipo_id', ExameTipo::LABORATORIAL))
|
|
->whereIn('status_id', [ExameStatusEnum::SOLICITADO, ExameStatusEnum::AGUARDANDO_RESULTADO]);
|
|
})
|
|
->get();
|
|
}
|
|
|
|
private function faturarExamesLaboratoriaisAutomaticamente($pedidosExames, $atendimentoEnfermagem, $lotacaoId)
|
|
{
|
|
$procedimentos = collect();
|
|
$quantidadeColetas = 0;
|
|
|
|
$pedidosExames
|
|
->each(function ($pedido) use ($atendimentoEnfermagem, $lotacaoId, $procedimentos, &$quantidadeColetas) {
|
|
|
|
$pedido->exames()
|
|
->whereHas('exame', fn ($q) => $q->where('tipo_id', ExameTipo::LABORATORIAL))
|
|
->whereIn('status_id', [ExameStatusEnum::SOLICITADO, ExameStatusEnum::AGUARDANDO_RESULTADO])
|
|
->get()
|
|
->each(function ($exame) use ($atendimentoEnfermagem, $lotacaoId, $procedimentos, &$quantidadeColetas) {
|
|
|
|
$exame->atendimento_enfermagem_id = $atendimentoEnfermagem->id;
|
|
$exame->status_id = ExameStatusEnum::REALIZADO;
|
|
$exame->lotacao_executante_id = $lotacaoId;
|
|
|
|
$hasExameRealizado = $exame->pedidoExame()
|
|
->whereHas('exames', function ($query) {
|
|
|
|
$query->whereHas('exame', fn ($q) => $q->where('tipo_id', ExameTipo::LABORATORIAL))
|
|
->where('status_id', ExameStatusEnum::REALIZADO);
|
|
})
|
|
->get()
|
|
->isNotEmpty();
|
|
|
|
if (!$hasExameRealizado) {
|
|
|
|
$quantidadeColetas++;
|
|
}
|
|
|
|
$exame->save();
|
|
|
|
$procedimento = $atendimentoEnfermagem->atendimento->procedimentos()->create([
|
|
'lotacao_id' => $exame->lotacao_executante_id,
|
|
'atendimento_enfermagem_id' => $atendimentoEnfermagem->id,
|
|
'procedimento_id' => $exame->exame->procedimento->id,
|
|
'quantidade' => 1,
|
|
]);
|
|
|
|
$procedimentos->push($this->getProcedimentoFaturadoAutomaticamenteData($procedimento));
|
|
});
|
|
});
|
|
|
|
if ($quantidadeColetas > 0) {
|
|
|
|
$atendimentoProcedimento = $this->faturarProcedimentoPadraoExameLaboratorial(
|
|
$atendimentoEnfermagem,
|
|
$quantidadeColetas,
|
|
$lotacaoId
|
|
)->first();
|
|
|
|
if (!is_null($atendimentoProcedimento)) {
|
|
|
|
$procedimentos->push($this->getProcedimentoFaturadoAutomaticamenteData($atendimentoProcedimento));
|
|
}
|
|
}
|
|
|
|
return $procedimentos;
|
|
}
|
|
|
|
private function getPedidoExamesImagemParaFaturamentoAutomatico($atendimento)
|
|
{
|
|
return $atendimento->pedidosExames()
|
|
->whereHas('exames', function ($query) {
|
|
|
|
$query->whereHas('exame', fn ($q) => $q->where('tipo_id', ExameTipo::IMAGEM))
|
|
->whereIn('status_id', [ExameStatusEnum::SOLICITADO, ExameStatusEnum::AGUARDANDO_RESULTADO]);
|
|
})
|
|
->get();
|
|
}
|
|
|
|
private function faturarExamesImagemAutomaticamente($pedidosExames, $atendimentoEnfermagem)
|
|
{
|
|
$procedimentos = collect();
|
|
|
|
$pedidosExames->each(fn ($p) => $p->exames()
|
|
->whereHas('exame', fn ($q) => $q->where('tipo_id', ExameTipo::IMAGEM))
|
|
->whereIn('status_id', [ExameStatusEnum::SOLICITADO, ExameStatusEnum::AGUARDANDO_RESULTADO])
|
|
->get()
|
|
->each(function ($exame) use ($atendimentoEnfermagem, $procedimentos) {
|
|
|
|
$exame->atendimento_enfermagem_id = $atendimentoEnfermagem->id;
|
|
$exame->status_id = ExameStatusEnum::REALIZADO;
|
|
|
|
$exame->save();
|
|
|
|
$procedimento = $atendimentoEnfermagem->atendimento->procedimentos()->create([
|
|
'lotacao_id' => $exame->pedidoExame->atendimentoMedico->created_lotacao_id,
|
|
'atendimento_enfermagem_id' => $atendimentoEnfermagem->id,
|
|
'procedimento_id' => $exame->exame->procedimento->id,
|
|
'quantidade' => 1,
|
|
]);
|
|
|
|
$procedimentos->push($this->getProcedimentoFaturadoAutomaticamenteData($procedimento));
|
|
}));
|
|
|
|
return $procedimentos;
|
|
}
|
|
|
|
private function getProcedimentoFaturadoAutomaticamenteData($atendimentoProcedimento)
|
|
{
|
|
$procedimento = $atendimentoProcedimento->procedimento;
|
|
$lotacao = $atendimentoProcedimento->lotacao;
|
|
|
|
return (object) [
|
|
'procedimento' => "{$procedimento->codigo} - {$procedimento->nome}",
|
|
'profissional' => isset($lotacao->usuario, $lotacao->usuario->cidadao, $lotacao->ocupacao)
|
|
? "{$lotacao->usuario->cidadao->nome} - {$lotacao->ocupacao->nome}"
|
|
: 'Informação não disponível',
|
|
];
|
|
}
|
|
|
|
private function getEscalasComaGlasgow($atendimento)
|
|
{
|
|
return EscalaComaGlasgow::whereHas('pacienteObservacao', function($query) use ($atendimento) {
|
|
|
|
$query->where('atendimento_id', $atendimento->id);
|
|
})->orWhereHas('atendimentoTriagem', function($query) use ($atendimento) {
|
|
|
|
$query->where('atendimento_id', $atendimento->id);
|
|
})
|
|
->get()
|
|
->map(function ($escalaComaGlasgow) use ($atendimento) {
|
|
return array_merge(
|
|
$this->getBaseHistoricoAreaAtendimento($escalaComaGlasgow, $atendimento),
|
|
[
|
|
'id' => $escalaComaGlasgow->id,
|
|
'pontuacao' => $this->getEscalaComaGlasgowPontuacao($escalaComaGlasgow),
|
|
'abertura_ocular' => $escalaComaGlasgow->aberturaOcular,
|
|
'resposta_verbal' => $escalaComaGlasgow->respostaVerbal,
|
|
'resposta_motora' => $escalaComaGlasgow->respostaMotora,
|
|
'reatividade_pupilar' => $escalaComaGlasgow->reatividadePupilar,
|
|
'observacoes' => $escalaComaGlasgow->observacao,
|
|
'resultado' => $this->getEscalaComaGlasgowResultado($escalaComaGlasgow),
|
|
]
|
|
);
|
|
});
|
|
}
|
|
|
|
private function getEscalaComaGlasgowResultado($escalaComaGlasgow)
|
|
{
|
|
$pontuacao = $this->getEscalaComaGlasgowPontuacao($escalaComaGlasgow);
|
|
|
|
if ($escalaComaGlasgow->aberturaOcular->pontos === 0
|
|
|| $escalaComaGlasgow->respostaVerbal->pontos === 0
|
|
|| $escalaComaGlasgow->respostaMotora->pontos === 0) {
|
|
|
|
return 'A pontuação não pode ser calculada. Um ou mais itens não foram testados';
|
|
}
|
|
|
|
$glasgowInterpretacaoResultado = GlasgowInterpretacaoResultado::all();
|
|
|
|
$result = $glasgowInterpretacaoResultado->filter(function ($glasgowInterpretacaoResultado, $key) use ($pontuacao) {
|
|
|
|
return $pontuacao >= $glasgowInterpretacaoResultado->min
|
|
&& $pontuacao <= ($glasgowInterpretacaoResultado->max ?? PHP_INT_MAX);
|
|
})->first();
|
|
|
|
return $result->descricao;
|
|
}
|
|
|
|
private function getEscalaComaGlasgowPontuacao($escalaComaGlasgow)
|
|
{
|
|
$result = $escalaComaGlasgow->aberturaOcular->pontos
|
|
+ $escalaComaGlasgow->respostaVerbal->pontos
|
|
+ $escalaComaGlasgow->respostaMotora->pontos
|
|
- $escalaComaGlasgow->reatividadePupilar->pontos;
|
|
|
|
return $result;
|
|
}
|
|
|
|
private function getGlasgowAberturaOcular()
|
|
{
|
|
return GlasgowAberturaOcular::all()
|
|
->map(function ($aberturaOcular) {
|
|
|
|
return [
|
|
'id' => $aberturaOcular->id,
|
|
'descricao' => $aberturaOcular->descricao,
|
|
'pontos' => $aberturaOcular->pontos,
|
|
];
|
|
});
|
|
}
|
|
|
|
private function getGlasgowReatividadePupilar()
|
|
{
|
|
return GlasgowReatividadePupilar::all()
|
|
->map(function ($reatividadePupilar) {
|
|
|
|
return [
|
|
'id' => $reatividadePupilar->id,
|
|
'descricao' => $reatividadePupilar->descricao,
|
|
'pontos' => $reatividadePupilar->pontos,
|
|
];
|
|
});
|
|
}
|
|
|
|
private function getGlasgowRespostaMotora()
|
|
{
|
|
return GlasgowRespostaMotora::all()
|
|
->map(function ($respostaMotora) {
|
|
|
|
return [
|
|
'id' => $respostaMotora->id,
|
|
'descricao' => $respostaMotora->descricao,
|
|
'pontos' => $respostaMotora->pontos,
|
|
];
|
|
});
|
|
}
|
|
|
|
private function getGlasgowRespostaVerbal()
|
|
{
|
|
return GlasgowRespostaVerbal::all()
|
|
->map(function ($respostaVerbal) {
|
|
|
|
return [
|
|
'id' => $respostaVerbal->id,
|
|
'descricao' => $respostaVerbal->descricao,
|
|
'pontos' => $respostaVerbal->pontos,
|
|
];
|
|
});
|
|
}
|
|
|
|
private static function getCaracteristicaDor()
|
|
{
|
|
$caracteristicasEnum = [
|
|
DorToracicaEnum::CONTRICAO,
|
|
DorToracicaEnum::QUEIMACAO,
|
|
DorToracicaEnum::COMPRESSAO,
|
|
DorToracicaEnum::PESO,
|
|
DorToracicaEnum::DOR_SURDA
|
|
];
|
|
|
|
$result = OrigemDorToracica::whereIn('id', $caracteristicasEnum)
|
|
->orderBy('nome')
|
|
->get()
|
|
->map(fn ($dorToracica) => [
|
|
'id' => $dorToracica->id,
|
|
'nome' => $dorToracica->nome,
|
|
]);
|
|
|
|
return $result;
|
|
}
|
|
|
|
private static function getLocalizacaoDor()
|
|
{
|
|
$caracteristicasEnum = [
|
|
DorToracicaEnum::RETROESTERNAL,
|
|
DorToracicaEnum::MSE,
|
|
DorToracicaEnum::FACE,
|
|
DorToracicaEnum::PESCOCO,
|
|
DorToracicaEnum::DENTES,
|
|
DorToracicaEnum::INTER_ESCAPULAR,
|
|
DorToracicaEnum::EPIGASTRICA,
|
|
];
|
|
|
|
$result = OrigemDorToracica::whereIn('id', $caracteristicasEnum)
|
|
->orderBy('nome')
|
|
->get()
|
|
->map(fn ($dorToracica) => [
|
|
'id' => $dorToracica->id,
|
|
'nome' => $dorToracica->nome,
|
|
]);
|
|
|
|
return $result;
|
|
}
|
|
|
|
private static function getFatorDesencadeante()
|
|
{
|
|
$caracteristicasEnum = [
|
|
DorToracicaEnum::EXERCICIO,
|
|
DorToracicaEnum::EXCITACAO,
|
|
DorToracicaEnum::ESTRESSE,
|
|
DorToracicaEnum::FRIO,
|
|
DorToracicaEnum::REFEICOES_COPIOSAS,
|
|
];
|
|
|
|
$result = OrigemDorToracica::whereIn('id', $caracteristicasEnum)
|
|
->orderBy('nome')
|
|
->get()
|
|
->map(fn ($dorToracica) => [
|
|
'id' => $dorToracica->id,
|
|
'nome' => $dorToracica->nome,
|
|
]);
|
|
|
|
return $result;
|
|
}
|
|
|
|
private static function getFatoresRiscoToracica()
|
|
{
|
|
$caracteristicasEnum = [
|
|
DorToracicaEnum::HAS,
|
|
DorToracicaEnum::DM,
|
|
DorToracicaEnum::DISLIPIDEMIA,
|
|
DorToracicaEnum::HISTORIA_FAMILIAR,
|
|
DorToracicaEnum::IDADE_MAIOR_SESSENTA,
|
|
DorToracicaEnum::OBESIDADE,
|
|
DorToracicaEnum::TABAGISMO,
|
|
DorToracicaEnum::REVASCULARIZADO_PREVIO,
|
|
];
|
|
|
|
$result = OrigemDorToracica::whereIn('id', $caracteristicasEnum)
|
|
->orderBy('nome')
|
|
->get()
|
|
->map(fn ($dorToracica) => [
|
|
'id' => $dorToracica->id,
|
|
'nome' => $dorToracica->nome,
|
|
]);
|
|
|
|
return $result;
|
|
}
|
|
|
|
private static function getDuracaoDor()
|
|
{
|
|
$result = OrigemDorToracica::orderBy('id')
|
|
->where('id', '=', DorToracicaEnum::DURACAO_DA_DOR)
|
|
->get()
|
|
->map(fn ($duracao) => [
|
|
'id' => $duracao->id,
|
|
'nome' => $duracao->nome,
|
|
]);
|
|
|
|
return $result;
|
|
}
|
|
}
|