This commit is contained in:
@@ -0,0 +1,326 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\ProntoAtendimento\Impressao;
|
||||
|
||||
use App\Enums\Cadastro\SujeitoAtencao\PreferenciaNome;
|
||||
use App\Enums\Parametrizacao\Exame\Tipo;
|
||||
use App\Enums\ProntoAtendimento\Atendimento\Medico\DeclaracaoComparecimentoTipo;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Sexo;
|
||||
use App\Models\ProntoAtendimento\AssistenciaSocial\AssistenciaSocial;
|
||||
use App\Models\ProntoAtendimento\Atendimento\Atendimento;
|
||||
use App\Models\ProntoAtendimento\Atendimento\Medico\AtendimentoMedico;
|
||||
use App\Models\ProntoAtendimento\Atendimento\ServicoEnfermagem;
|
||||
use App\Services\Service;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ImpressaoFaaEletronicaService extends Service
|
||||
{
|
||||
public static function list()
|
||||
{
|
||||
$now = Carbon::now();
|
||||
$currentDate = $now->format('d/m/Y');
|
||||
$currentLotacao = self::getCurrentLotacao();
|
||||
|
||||
return [
|
||||
'form' => [
|
||||
'unidade' => $currentLotacao->infraestrutura->unidade->nome_fantasia,
|
||||
'infraestrutura' => $currentLotacao->infraestrutura->nome,
|
||||
'sexos' => Sexo::orderBy('descricao')->get(['id', 'descricao'])->makeHidden('identificador')
|
||||
],
|
||||
'model' => [
|
||||
'periodo' => [
|
||||
'start' => $currentDate,
|
||||
'end' => $currentDate,
|
||||
],
|
||||
'sexo_id' => null,
|
||||
'paciente' => null,
|
||||
'data_nascimento' => null,
|
||||
'faa' => null,
|
||||
],
|
||||
'additionals' => [
|
||||
'periodo_min_date' => $now->copy()->subYears(130)->format('d/m/Y'),
|
||||
'current_date' => $now->format('d/m/Y')
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public static function datatable($request)
|
||||
{
|
||||
self::validateDatatableRequest($request);
|
||||
|
||||
$atendimentos = DB::table('pronto_atendimento_atendimento AS atendimento')
|
||||
->leftJoin('painel_senha_fila AS fila', 'fila.id', 'atendimento.fila_id')
|
||||
->leftJoin('painel_senha_opcao_entrada AS opcao_entrada', 'opcao_entrada.id', 'fila.opcao_entrada_id')
|
||||
->leftJoin('pronto_atendimento_assistencia_social AS assistencia', 'assistencia.atendimento_id', 'atendimento.id')
|
||||
->join('pronto_atendimento_faa AS faa', 'faa.id', 'atendimento.faa_id')
|
||||
->join('cadastro_paciente AS paciente', 'paciente.id', 'faa.paciente_id')
|
||||
->join('cadastro_cidadao AS cidadao', 'cidadao.id', 'paciente.cidadao_id')
|
||||
->leftJoin('cadastro_sexo AS sexo', 'sexo.id', 'cidadao.sexo_id')
|
||||
->join('pronto_atendimento_atendimento_recepcao AS recepcao', 'recepcao.atendimento_id', 'atendimento.id')
|
||||
->join('cadastro_centro_custo AS centro_custo', 'centro_custo.id', 'atendimento.created_centro_custo_id')
|
||||
->join('cadastro_infraestrutura AS infraestrutura', 'infraestrutura.id', 'centro_custo.infraestrutura_id')
|
||||
->select([
|
||||
'atendimento.id AS atendimento_id',
|
||||
'recepcao.atendido_em AS data',
|
||||
'recepcao.acompanhante AS acompanhante',
|
||||
'infraestrutura.nome as infraestrutura',
|
||||
'faa.id AS faa',
|
||||
'faa.numero AS faa_numero',
|
||||
'assistencia.id AS assistencia_id',
|
||||
'assistencia.anotacao AS anotacao',
|
||||
DB::raw("CONCAT(opcao_entrada.sigla, fila.senha) AS senha"),
|
||||
'fila.created_at AS senha_data_hora_emissao',
|
||||
'sexo.descricao AS sexo',
|
||||
'paciente.prontuario AS paciente_prontuario',
|
||||
'cidadao.data_nascimento AS paciente_data_nascimento',
|
||||
'cidadao.nome_mae AS paciente_nome_mae',
|
||||
'cidadao.nome AS paciente_nome',
|
||||
'cidadao.nome_social AS paciente_nome_social',
|
||||
'cidadao.preferencia_nome_id as paciente_preferencia_nome_id',
|
||||
'cidadao.caracteristicas_fisicas AS paciente_caracteristicas_fisicas',
|
||||
'paciente.sequencial_desconhecido_em AS paciente_sequencial_desconhecido_em',
|
||||
])
|
||||
->where('centro_custo.infraestrutura_id', self::getCurrentCentroCusto()->infraestrutura_id)
|
||||
->whereBetween('recepcao.atendido_em', [
|
||||
Carbon::createFromFormat('d/m/Y', $request->periodo['start'])->setTime(0, 0, 0),
|
||||
Carbon::createFromFormat('d/m/Y', $request->periodo['end'])->setTime(23, 59, 59)
|
||||
])
|
||||
->when($request->sexo_id, function ($query, $value) {
|
||||
|
||||
$query->where('cidadao.sexo_id', $value);
|
||||
})
|
||||
->when($request->paciente, function ($query, $value) {
|
||||
|
||||
$query->where('cidadao.nome', 'like', "{$value}%");
|
||||
})
|
||||
->when($request->data_nascimento, function ($query, $value) {
|
||||
|
||||
$query->whereDate('cidadao.data_nascimento', Carbon::createFromFormat('d/m/Y', $value));
|
||||
})
|
||||
->when($request->faa, function ($query, $value) {
|
||||
|
||||
$query->where('faa.numero', $value);
|
||||
})
|
||||
->get()
|
||||
->map(function ($atendimento) {
|
||||
|
||||
$atendimento->impressoes = self::getImpressoes($atendimento);
|
||||
|
||||
if (is_null($atendimento->paciente_nome_mae)) {
|
||||
|
||||
$atendimento->paciente_nome_mae = 'Não informado';
|
||||
}
|
||||
|
||||
if (is_null($atendimento->paciente_caracteristicas_fisicas)) {
|
||||
|
||||
$atendimento->paciente_caracteristicas_fisicas = 'Não informado';
|
||||
}
|
||||
|
||||
$atendimento->paciente_is_desconhecido = !is_null($atendimento->paciente_sequencial_desconhecido_em);
|
||||
$atendimento->data = (new Carbon($atendimento->data))->format('d/m/Y');
|
||||
|
||||
$atendimento->paciente_prefere_nome_social = $atendimento
|
||||
->paciente_preferencia_nome_id === PreferenciaNome::NOME_SOCIAL;
|
||||
|
||||
$atendimento->paciente_data_nascimento = is_null($atendimento->paciente_data_nascimento)
|
||||
? 'Não informada'
|
||||
: (new Carbon($atendimento->paciente_data_nascimento))->format('d/m/Y');
|
||||
|
||||
unset(
|
||||
$atendimento->acompanhante,
|
||||
$atendimento->infraestrutura,
|
||||
$atendimento->senha,
|
||||
$atendimento->senha_data_hora_emissao,
|
||||
$atendimento->paciente_preferencia_nome_id,
|
||||
$atendimento->paciente_sequencial_desconhecido_em
|
||||
);
|
||||
|
||||
return $atendimento;
|
||||
});
|
||||
|
||||
return $atendimentos;
|
||||
}
|
||||
|
||||
private static function getImpressoes($atendimento)
|
||||
{
|
||||
$atendimentoId = $atendimento->atendimento_id;
|
||||
|
||||
return [
|
||||
'recepcao' => [
|
||||
[
|
||||
'value' => 'etiqueta',
|
||||
'text' => 'Etiqueta',
|
||||
'disabled' => false,
|
||||
'data' => [
|
||||
'atendido_em' => (new Carbon($atendimento->data))->format('d/m/Y H:i'),
|
||||
'infraestrutura' => $atendimento->infraestrutura,
|
||||
'acompanhante' => $atendimento->acompanhante ?? '',
|
||||
'paciente' => $atendimento->paciente_nome,
|
||||
'data_nascimento' => is_null($atendimento->paciente_data_nascimento)
|
||||
? '' : (new Carbon($atendimento->paciente_data_nascimento))->format('d/m/Y'),
|
||||
'senha' => $atendimento->senha
|
||||
]
|
||||
],
|
||||
[
|
||||
'value' => 'raat',
|
||||
'text' => 'RAAT',
|
||||
'disabled' => Atendimento::where('id', $atendimentoId)
|
||||
->whereHas('faa.raat')->get()->isEmpty()
|
||||
],
|
||||
[
|
||||
'value' => 'senha',
|
||||
'text' => 'Senha',
|
||||
'disabled' => Atendimento::where('id', $atendimentoId)
|
||||
->whereHas('fila')->get()->isEmpty(),
|
||||
'data' => [
|
||||
'data' => is_null($atendimento->senha_data_hora_emissao)
|
||||
? '' : (new Carbon($atendimento->senha_data_hora_emissao))->format('d/m/Y'),
|
||||
'hora' => is_null($atendimento->senha_data_hora_emissao)
|
||||
? '' : (new Carbon($atendimento->senha_data_hora_emissao))->format('H:i:s'),
|
||||
'senha' => $atendimento->senha,
|
||||
]
|
||||
],
|
||||
],
|
||||
'medicoEnfermagem' => [
|
||||
[
|
||||
'value' => 'atestado',
|
||||
'text' => 'Atestado',
|
||||
'disabled' => AtendimentoMedico::where('atendimento_id', $atendimentoId)
|
||||
->whereHas('atestado')->get()->isEmpty()
|
||||
],
|
||||
[
|
||||
'value' => 'declaracaoAcompanhante',
|
||||
'text' => 'Declaração de Comparecimento - Acompanhante',
|
||||
'disabled' => AtendimentoMedico::where('atendimento_id', $atendimentoId)
|
||||
->whereHas('declaracoesComparecimento', function ($query) {
|
||||
|
||||
$query->where('tipo_id', DeclaracaoComparecimentoTipo::ACOMPANHANTE);
|
||||
})->get()->isEmpty()
|
||||
],
|
||||
[
|
||||
'value' => 'declaracaoPaciente',
|
||||
'text' => 'Declaração de Comparecimento - Paciente',
|
||||
'disabled' => AtendimentoMedico::where('atendimento_id', $atendimentoId)
|
||||
->whereHas('declaracoesComparecimento', function ($query) {
|
||||
|
||||
$query->where('tipo_id', DeclaracaoComparecimentoTipo::PACIENTE);
|
||||
})->get()->isEmpty()
|
||||
],
|
||||
[
|
||||
'value' => 'encaminhamentoHospitalar',
|
||||
'text' => 'Encaminhamento Hospitalar',
|
||||
'disabled' => AtendimentoMedico::where('atendimento_id', $atendimentoId)
|
||||
->whereHas('encaminhamentoHospitalar')->get()->isEmpty()
|
||||
],
|
||||
[
|
||||
'value' => 'examesImagem',
|
||||
'text' => 'Exames - Imagem',
|
||||
'disabled' => Atendimento::where('id', $atendimentoId)
|
||||
->whereHas('pedidosExames.exames.exame', function ($query) {
|
||||
|
||||
$query->where('tipo_id', Tipo::IMAGEM);
|
||||
})->get()->isEmpty()
|
||||
],
|
||||
[
|
||||
'value' => 'examesLaboratorial',
|
||||
'text' => 'Exames - Laboratorial',
|
||||
'disabled' => Atendimento::where('id', $atendimentoId)
|
||||
->whereHas('pedidosExames.exames.exame', function ($query) {
|
||||
|
||||
$query->where('tipo_id', Tipo::LABORATORIAL);
|
||||
})->get()->isEmpty()
|
||||
],
|
||||
[
|
||||
'value' => 'guiaEncaminhamento',
|
||||
'text' => 'Guia de Encaminhamento',
|
||||
'disabled' => AtendimentoMedico::where('atendimento_id', $atendimentoId)
|
||||
->whereHas('encaminhamentos')->get()->isEmpty()
|
||||
],
|
||||
[
|
||||
'value' => 'orientacoesPaciente',
|
||||
'text' => 'Orientação ao paciente',
|
||||
'disabled' => AtendimentoMedico::where('atendimento_id', $atendimentoId)
|
||||
->whereNotNull('orientacoes')->get()->isEmpty()
|
||||
],
|
||||
[
|
||||
'value' => 'prescricaoInterna',
|
||||
'text' => 'Prescrição Interna',
|
||||
'disabled' => AtendimentoMedico::where('atendimento_id', $atendimentoId)
|
||||
->whereHas('prescricoesInternas')->get()->isEmpty()
|
||||
],
|
||||
[
|
||||
'value' => 'receitaMedica',
|
||||
'text' => 'Receita Médica',
|
||||
'disabled' => AtendimentoMedico::where('atendimento_id', $atendimentoId)
|
||||
->whereHas('receita')->get()->isEmpty()
|
||||
],
|
||||
[
|
||||
'value' => 'servicoEnfermagem',
|
||||
'text' => 'Serviços Enfermagem',
|
||||
'disabled' => ServicoEnfermagem::whereHas('atendimentoMedico', function ($query) use ($atendimentoId) {
|
||||
|
||||
$query->where('atendimento_id', $atendimentoId);
|
||||
})
|
||||
->orWhereHas('atendimentoEnfermagem', function ($query) use ($atendimentoId) {
|
||||
|
||||
$query->where('atendimento_id', $atendimentoId);
|
||||
})
|
||||
->orWhereHas('pacienteObservacao', function ($query) use ($atendimentoId) {
|
||||
|
||||
$query->where('atendimento_id', $atendimentoId);
|
||||
})
|
||||
->get()
|
||||
->isEmpty()
|
||||
],
|
||||
],
|
||||
'assistenciaSocial' => [
|
||||
[
|
||||
'value' => 'assistencia',
|
||||
'text' => 'Assistencia',
|
||||
'disabled' => false,
|
||||
'data' => [
|
||||
'paciente' => $atendimento->paciente_nome,
|
||||
'anotacao' => $atendimento->anotacao
|
||||
]
|
||||
],
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
private static function validateDatatableRequest($request)
|
||||
{
|
||||
$minDate = Carbon::now()->subYears(130)->format('Y-m-d');
|
||||
|
||||
$request->validate([
|
||||
'periodo.start' => [
|
||||
'required',
|
||||
'date_format:d/m/Y',
|
||||
"after_or_equal:{$minDate}",
|
||||
'before_or_equal:periodo.end',
|
||||
],
|
||||
'periodo.end' => [
|
||||
'required',
|
||||
'date_format:d/m/Y',
|
||||
'after_or_equal:periodo.start',
|
||||
'before_or_equal:now',
|
||||
],
|
||||
'sexo_id' => [
|
||||
'nullable',
|
||||
'integer',
|
||||
],
|
||||
'paciente' => [
|
||||
'nullable',
|
||||
'string',
|
||||
],
|
||||
'data_nascimento' => [
|
||||
'nullable',
|
||||
'date_format:d/m/Y',
|
||||
],
|
||||
'faa' => [
|
||||
'nullable',
|
||||
'integer',
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,921 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\ProntoAtendimento\Impressao;
|
||||
|
||||
use App\Enums\Cadastro\Medicamento\TipoReceita;
|
||||
use App\Enums\Cadastro\SujeitoAtencao\PreferenciaNome;
|
||||
use App\Enums\Parametrizacao\Exame\Tipo;
|
||||
use App\Enums\ProntoAtendimento\Atendimento\Medico\DeclaracaoComparecimentoTipo;
|
||||
use App\Enums\ProntoAtendimento\TipoFormularioAcidenteTrabalho;
|
||||
use App\Http\Controllers\ProntoAtendimento\Atendimento\Enfermagem\AtendimentoEnfermagemController;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Sexo;
|
||||
use App\Models\Cns\TermoInvalido;
|
||||
use App\Models\ProntoAtendimento\Atendimento\Atendimento;
|
||||
use App\Models\ProntoAtendimento\Atendimento\Enfermagem\AtendimentoEnfermagem;
|
||||
use App\Models\ProntoAtendimento\Atendimento\ExameImagem\AtendimentoExameImagem;
|
||||
use App\Models\ProntoAtendimento\Atendimento\Medico\AtendimentoMedico;
|
||||
use App\Models\ProntoAtendimento\Atendimento\Medico\Atestado;
|
||||
use App\Models\ProntoAtendimento\Atendimento\Medico\Receita;
|
||||
use App\Models\ProntoAtendimento\Atendimento\Observacao\PacienteObservacao;
|
||||
use App\Models\ProntoAtendimento\Atendimento\PrescricaoInterna;
|
||||
use App\Models\ProntoAtendimento\Atendimento\Recepcao;
|
||||
use App\Models\ProntoAtendimento\Atendimento\ServicoEnfermagem;
|
||||
use App\Models\ProntoAtendimento\Atendimento\Triagem\AtendimentoTriagem;
|
||||
use App\Models\ProntoAtendimento\Parametrizacao\FaturamentoExameLaboratorial;
|
||||
use App\Services\Service;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class ImpressaoService extends Service
|
||||
{
|
||||
public static function list()
|
||||
{
|
||||
$now = Carbon::now();
|
||||
$currentDate = $now->format('d/m/Y');
|
||||
$currentLotacao = self::getCurrentLotacao();
|
||||
|
||||
return [
|
||||
'form' => [
|
||||
'unidade' => $currentLotacao->infraestrutura->unidade->nome_fantasia,
|
||||
'infraestrutura' => $currentLotacao->infraestrutura->nome,
|
||||
'sexos' => Sexo::orderBy('descricao')->get(['id', 'descricao'])->makeHidden('identificador')
|
||||
],
|
||||
'model' => [
|
||||
'periodo' => [
|
||||
'start' => $currentDate,
|
||||
'end' => $currentDate,
|
||||
],
|
||||
'sexo_id' => null,
|
||||
'paciente' => null,
|
||||
'data_nascimento' => null,
|
||||
'faa' => null,
|
||||
],
|
||||
'additionals' => [
|
||||
'periodo_min_date' => $now->copy()->subYears(130)->format('d/m/Y'),
|
||||
'current_date' => $now->format('d/m/Y'),
|
||||
'termos_invalidos' => TermoInvalido::all()->map(fn ($termo) => $termo->descricao),
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public static function datatable($request)
|
||||
{
|
||||
self::validateDatatableRequest($request);
|
||||
|
||||
$atendimentos = DB::table('pronto_atendimento_atendimento AS atendimento')
|
||||
->leftJoin('painel_senha_fila AS fila', 'fila.id', 'atendimento.fila_id')
|
||||
->leftJoin('painel_senha_opcao_entrada AS opcao_entrada', 'opcao_entrada.id', 'fila.opcao_entrada_id')
|
||||
->join('pronto_atendimento_faa AS faa', 'faa.id', 'atendimento.faa_id')
|
||||
->join('cadastro_paciente AS paciente', 'paciente.id', 'faa.paciente_id')
|
||||
->join('cadastro_cidadao AS cidadao', 'cidadao.id', 'paciente.cidadao_id')
|
||||
->leftJoin('cadastro_sexo AS sexo', 'sexo.id', 'cidadao.sexo_id')
|
||||
->leftJoin('cadastro_carteira_identidade AS carteira_identidade', 'carteira_identidade.cidadao_id', 'cidadao.id')
|
||||
->leftJoin('cadastro_carteira_habilitacao AS carteira_habilitacao', 'carteira_habilitacao.cidadao_id', 'cidadao.id')
|
||||
->join('pronto_atendimento_atendimento_recepcao AS recepcao', 'recepcao.atendimento_id', 'atendimento.id')
|
||||
->join('cadastro_centro_custo AS centro_custo', 'centro_custo.id', 'atendimento.created_centro_custo_id')
|
||||
->join('cadastro_infraestrutura AS infraestrutura', 'infraestrutura.id', 'centro_custo.infraestrutura_id')
|
||||
->join('cadastro_unidade AS unidade', 'unidade.id', 'infraestrutura.unidade_id')
|
||||
->select([
|
||||
'atendimento.id AS atendimento_id',
|
||||
'recepcao.atendido_em AS data',
|
||||
DB::raw("TIME_FORMAT(recepcao.atendido_em, '%H:%i') AS hora"),
|
||||
'recepcao.acompanhante AS acompanhante',
|
||||
'infraestrutura.nome as infraestrutura',
|
||||
'unidade.nome_fantasia as unidade',
|
||||
'faa.id AS faa',
|
||||
'faa.numero AS faa_numero',
|
||||
DB::raw("CONCAT(opcao_entrada.sigla, fila.senha) AS senha"),
|
||||
'fila.created_at AS senha_data_hora_emissao',
|
||||
'sexo.descricao AS sexo',
|
||||
'paciente.prontuario AS paciente_prontuario',
|
||||
'cidadao.data_nascimento AS paciente_data_nascimento',
|
||||
'cidadao.nome_mae AS paciente_nome_mae',
|
||||
'cidadao.nome AS paciente_nome',
|
||||
'cidadao.nome_social AS paciente_nome_social',
|
||||
'cidadao.preferencia_nome_id as paciente_preferencia_nome_id',
|
||||
'cidadao.caracteristicas_fisicas AS paciente_caracteristicas_fisicas',
|
||||
'cidadao.cpf AS paciente_cpf',
|
||||
'cidadao.cns AS paciente_cns',
|
||||
'carteira_identidade.numero AS paciente_rg',
|
||||
'carteira_habilitacao.numero AS paciente_cnh',
|
||||
'paciente.sequencial_desconhecido_em AS paciente_sequencial_desconhecido_em',
|
||||
DB::raw("DATE_FORMAT(IF(faa.data_hora_desfecho, faa.data_hora_desfecho, faa.updated_at), '%d/%m/%Y') AS data_desfecho"),
|
||||
DB::raw("TIME_FORMAT(IF(faa.data_hora_desfecho, faa.data_hora_desfecho, faa.updated_at), '%H:%i') AS hora_desfecho"),
|
||||
'faa.finalizado',
|
||||
])
|
||||
->where('centro_custo.infraestrutura_id', self::getCurrentCentroCusto()->infraestrutura_id)
|
||||
->whereBetween('recepcao.atendido_em', [
|
||||
Carbon::createFromFormat('d/m/Y', $request->periodo['start'])->setTime(0, 0, 0),
|
||||
Carbon::createFromFormat('d/m/Y', $request->periodo['end'])->setTime(23, 59, 59)
|
||||
])
|
||||
->when($request->sexo_id, function ($query, $value) {
|
||||
|
||||
$query->where('cidadao.sexo_id', $value);
|
||||
})
|
||||
->when($request->paciente, function ($query, $value) {
|
||||
|
||||
$query->where('cidadao.nome', 'like', "{$value}%");
|
||||
})
|
||||
->when($request->data_nascimento, function ($query, $value) {
|
||||
|
||||
$query->whereDate('cidadao.data_nascimento', Carbon::createFromFormat('d/m/Y', $value));
|
||||
})
|
||||
->when($request->faa, function ($query, $value) {
|
||||
|
||||
$query->where('faa.numero', $value);
|
||||
})
|
||||
->whereNull('faa.deleted_at')
|
||||
->get()
|
||||
->map(function ($atendimento) {
|
||||
|
||||
$atendimento->impressoes = self::getImpressoes(
|
||||
$atendimento->atendimento_id,
|
||||
[
|
||||
'recepcao' => [
|
||||
'etiqueta' => [
|
||||
'atendido_em' => (new Carbon($atendimento->data))->format('d/m/Y H:i'),
|
||||
'infraestrutura' => $atendimento->infraestrutura ?? $atendimento->unidade,
|
||||
'acompanhante' => $atendimento->acompanhante ?? '',
|
||||
'paciente' => $atendimento->paciente_nome,
|
||||
'data_nascimento' => is_null($atendimento->paciente_data_nascimento)
|
||||
? '' : (new Carbon($atendimento->paciente_data_nascimento))->format('d/m/Y'),
|
||||
'senha' => $atendimento->senha
|
||||
],
|
||||
'senha' => [
|
||||
'data' => is_null($atendimento->senha_data_hora_emissao)
|
||||
? '' : (new Carbon($atendimento->senha_data_hora_emissao))->format('d/m/Y'),
|
||||
'hora' => is_null($atendimento->senha_data_hora_emissao)
|
||||
? '' : (new Carbon($atendimento->senha_data_hora_emissao))->format('H:i:s'),
|
||||
'senha' => $atendimento->senha,
|
||||
]
|
||||
]
|
||||
]
|
||||
);
|
||||
|
||||
if (is_null($atendimento->paciente_nome_mae)) {
|
||||
|
||||
$atendimento->paciente_nome_mae = 'Não informado';
|
||||
}
|
||||
|
||||
if (is_null($atendimento->paciente_caracteristicas_fisicas)) {
|
||||
|
||||
$atendimento->paciente_caracteristicas_fisicas = 'Não informado';
|
||||
}
|
||||
|
||||
$atendimento->paciente_is_desconhecido = !is_null($atendimento->paciente_sequencial_desconhecido_em);
|
||||
$atendimento->data = (new Carbon($atendimento->data))->format('d/m/Y');
|
||||
|
||||
$atendimento->paciente_prefere_nome_social = $atendimento
|
||||
->paciente_preferencia_nome_id === PreferenciaNome::NOME_SOCIAL;
|
||||
|
||||
$atendimento->paciente_data_nascimento = is_null($atendimento->paciente_data_nascimento)
|
||||
? 'Não informada'
|
||||
: (new Carbon($atendimento->paciente_data_nascimento))->format('d/m/Y');
|
||||
|
||||
unset(
|
||||
$atendimento->infraestrutura,
|
||||
$atendimento->senha,
|
||||
$atendimento->senha_data_hora_emissao,
|
||||
$atendimento->paciente_preferencia_nome_id,
|
||||
$atendimento->paciente_sequencial_desconhecido_em
|
||||
);
|
||||
|
||||
return $atendimento;
|
||||
});
|
||||
|
||||
return $atendimentos;
|
||||
}
|
||||
|
||||
public static function getAtendimentosAssinados($atendimentoId)
|
||||
{
|
||||
$path = 'assinatura-eletronica' . DIRECTORY_SEPARATOR . app('config')->get('database.default') . DIRECTORY_SEPARATOR . 'pronto-atendimento';
|
||||
|
||||
$atendimentos = DB::table('pronto_atendimento_atendimento_triagem as triagem')
|
||||
->join('cadastro_lotacao as triagem_lotacao', 'triagem_lotacao.id', 'triagem.created_lotacao_id')
|
||||
->join('cadastro_usuario as triagem_usuario', 'triagem_usuario.id', 'triagem_lotacao.usuario_id')
|
||||
->join('cadastro_cidadao as triagem_cidadao', 'triagem_cidadao.id', 'triagem_usuario.cidadao_id')
|
||||
->join('sigtap.ocupacao as triagem_ocupacao', 'triagem_ocupacao.id', 'triagem_lotacao.ocupacao_id')
|
||||
->where('triagem.is_faa_assinada', true)
|
||||
->where('triagem.atendimento_id', $atendimentoId)
|
||||
->select(DB::raw("
|
||||
triagem.id,
|
||||
'triagem' as tipo_identificador,
|
||||
'TRIAGEM' as tipo,
|
||||
triagem.created_at as data_hora,
|
||||
triagem_cidadao.nome as profissional,
|
||||
CONCAT(triagem_ocupacao.codigo, ' - ', triagem_ocupacao.nome) as ocupacao
|
||||
"))
|
||||
->unionAll(
|
||||
DB::table('pronto_atendimento_atendimento_medico as medico')
|
||||
->join('cadastro_lotacao as medico_lotacao', 'medico_lotacao.id', 'medico.created_lotacao_id')
|
||||
->join('cadastro_usuario as medico_usuario', 'medico_usuario.id', 'medico_lotacao.usuario_id')
|
||||
->join('cadastro_cidadao as medico_cidadao', 'medico_cidadao.id', 'medico_usuario.cidadao_id')
|
||||
->join('sigtap.ocupacao as medico_ocupacao', 'medico_ocupacao.id', 'medico_lotacao.ocupacao_id')
|
||||
->where('medico.is_faa_assinada', true)
|
||||
->where('medico.atendimento_id', $atendimentoId)
|
||||
->select(DB::raw("
|
||||
medico.id,
|
||||
'medico' as tipo_identificador,
|
||||
CONCAT('MÉDICO', IF(medico.is_observacao = 1,' (OBSERVAÇÃO)', '')) as tipo,
|
||||
medico.created_at as data_hora,
|
||||
medico_cidadao.nome as profissional,
|
||||
CONCAT(medico_ocupacao.codigo, ' - ', medico_ocupacao.nome) as ocupacao
|
||||
"))
|
||||
)
|
||||
->unionAll(
|
||||
DB::table('pronto_atendimento_atendimento_enfermagem as enfermagem')
|
||||
->join('cadastro_lotacao as enfermagem_lotacao', 'enfermagem_lotacao.id', 'enfermagem.created_lotacao_id')
|
||||
->join('cadastro_usuario as enfermagem_usuario', 'enfermagem_usuario.id', 'enfermagem_lotacao.usuario_id')
|
||||
->join('cadastro_cidadao as enfermagem_cidadao', 'enfermagem_cidadao.id', 'enfermagem_usuario.cidadao_id')
|
||||
->join('sigtap.ocupacao as enfermagem_ocupacao', 'enfermagem_ocupacao.id', 'enfermagem_lotacao.ocupacao_id')
|
||||
->where('enfermagem.is_faa_assinada', true)
|
||||
->where('enfermagem.atendimento_id', $atendimentoId)
|
||||
->select(DB::raw("
|
||||
enfermagem.id,
|
||||
'enfermagem' as tipo_identificador,
|
||||
'ENFERMAGEM' as tipo,
|
||||
enfermagem.created_at as data_hora,
|
||||
enfermagem_cidadao.nome as profissional,
|
||||
CONCAT(enfermagem_ocupacao.codigo, ' - ', enfermagem_ocupacao.nome) as ocupacao
|
||||
"))
|
||||
)
|
||||
->unionAll(
|
||||
DB::table('pronto_atendimento_paciente_observacao as observacao')
|
||||
->join('cadastro_lotacao as observacao_lotacao', 'observacao_lotacao.id', 'observacao.created_lotacao_id')
|
||||
->join('cadastro_usuario as observacao_usuario', 'observacao_usuario.id', 'observacao_lotacao.usuario_id')
|
||||
->join('cadastro_cidadao as observacao_cidadao', 'observacao_cidadao.id', 'observacao_usuario.cidadao_id')
|
||||
->join('sigtap.ocupacao as observacao_ocupacao', 'observacao_ocupacao.id', 'observacao_lotacao.ocupacao_id')
|
||||
->where('observacao.is_faa_assinada', true)
|
||||
->where('observacao.atendimento_id', $atendimentoId)
|
||||
->select(DB::raw("
|
||||
observacao.id,
|
||||
'observacao' as tipo_identificador,
|
||||
'ENFERMAGEM (OBSERVAÇÃO)' as tipo,
|
||||
observacao.created_at as data_hora,
|
||||
observacao_cidadao.nome as profissional,
|
||||
CONCAT(observacao_ocupacao.codigo, ' - ', observacao_ocupacao.nome) as ocupacao
|
||||
"))
|
||||
)
|
||||
->get();
|
||||
|
||||
$atendimentos->each(function ($atendimento) use ($path) {
|
||||
|
||||
$atendimento->receitas_medicas_assinadas = collect();
|
||||
$atendimento->faa_assinada = null;
|
||||
|
||||
if ($atendimento->tipo_identificador == 'triagem') {
|
||||
$file = $path . DIRECTORY_SEPARATOR . "atendimento-triagem" . DIRECTORY_SEPARATOR . "{$atendimento->id}.PDF";
|
||||
|
||||
if (Storage::disk('local')->exists($file)) {
|
||||
$atendimento->faa_assinada = base64_encode(Storage::disk('local')->get($file));
|
||||
}
|
||||
}
|
||||
|
||||
else if ($atendimento->tipo_identificador == 'medico') {
|
||||
$file = $path . DIRECTORY_SEPARATOR . "atendimento-medico" . DIRECTORY_SEPARATOR . "{$atendimento->id}.PDF";
|
||||
|
||||
$receita = Receita::firstWhere('atendimento_medico_id', $atendimento->id);
|
||||
|
||||
if (!is_null($receita) && $receita->is_assinada) {
|
||||
|
||||
$receita->receitasAssinadas()
|
||||
->where('ordem', $receita->receitasAssinadas()->max('ordem'))
|
||||
->get('id')
|
||||
->each(function($receitaAssinada) use ($path, $atendimento) {
|
||||
$file = $path . DIRECTORY_SEPARATOR . "atendimento-medico-receita-medica" . DIRECTORY_SEPARATOR . "{$receitaAssinada->id}.PDF";
|
||||
|
||||
if (Storage::disk('local')->exists($file)) {
|
||||
$atendimento->receitas_medicas_assinadas->push(base64_encode(Storage::disk('local')->get($file)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (Storage::disk('local')->exists($file)) {
|
||||
$atendimento->faa_assinada = base64_encode(Storage::disk('local')->get($file));
|
||||
}
|
||||
}
|
||||
|
||||
else if ($atendimento->tipo_identificador == 'enfermagem') {
|
||||
$file = $path . DIRECTORY_SEPARATOR . "atendimento-enfermagem" . DIRECTORY_SEPARATOR . "{$atendimento->id}.PDF";
|
||||
|
||||
if (Storage::disk('local')->exists($file)) {
|
||||
$atendimento->faa_assinada = base64_encode(Storage::disk('local')->get($file));
|
||||
}
|
||||
}
|
||||
|
||||
else if ($atendimento->tipo_identificador == 'observacao') {
|
||||
$file = $path . DIRECTORY_SEPARATOR . "paciente-observacao" . DIRECTORY_SEPARATOR . "{$atendimento->id}.PDF";
|
||||
|
||||
if (Storage::disk('local')->exists($file)) {
|
||||
$atendimento->faa_assinada = base64_encode(Storage::disk('local')->get($file));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return $atendimentos;
|
||||
}
|
||||
|
||||
public static function getImpressoes($atendimentoId, $data = [])
|
||||
{
|
||||
$excluded = $data['excluded'] ?? [];
|
||||
$recepcaoData = $data['recepcao'] ?? [];
|
||||
$triagemData = $data['triagem'] ?? [];
|
||||
$faturarEnfermagem = $data['faturar_enfermagem'] ?? false;
|
||||
|
||||
$impressoes = [
|
||||
'additionals' => [
|
||||
'faturar_enfermagem' => $faturarEnfermagem,
|
||||
'usuarios_faturamento_exame_laboratorial' => $faturarEnfermagem
|
||||
? self::getUsuariosFaturamentoExameLaboratorial()
|
||||
: [],
|
||||
'has_exames_laboratoriais_pendente' => $faturarEnfermagem
|
||||
? (new AtendimentoEnfermagemController())->getPedidoExamesLaboratoriaisParaFaturamentoAutomatico(
|
||||
Atendimento::findOrFail($atendimentoId)
|
||||
)->isNotEmpty() : false,
|
||||
],
|
||||
'recepcao' => self::getImpressoesRecepcao($atendimentoId, $recepcaoData),
|
||||
'triagem' => self::getImpressoesTriagem($atendimentoId, $triagemData),
|
||||
'medicoEnfermagem' => self::getImpressoesMedicoEnfermagem($atendimentoId),
|
||||
'faa' => self::getImpressoesFaa($atendimentoId),
|
||||
];
|
||||
|
||||
foreach ($excluded as $key => $value) {
|
||||
|
||||
if (is_array($value)) {
|
||||
|
||||
foreach ($value as $col => $vl) {
|
||||
|
||||
$indice = array_search($vl, array_column($impressoes[$key], $col));
|
||||
if ($indice >= 0) {
|
||||
|
||||
unset($impressoes[$key][$indice]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
if (array_key_exists($value, $impressoes)) {
|
||||
|
||||
unset($impressoes[$value]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $impressoes;
|
||||
}
|
||||
|
||||
private static function getUsuariosFaturamentoExameLaboratorial()
|
||||
{
|
||||
$usuariosFaturamentoExameLaboratorial = collect();
|
||||
|
||||
FaturamentoExameLaboratorial::whereHas('lotacao', function ($query) {
|
||||
|
||||
$query->where('infraestrutura_id', self::getCurrentLotacao()->infraestrutura_id);
|
||||
})->each(function ($parametrizacao) use ($usuariosFaturamentoExameLaboratorial) {
|
||||
|
||||
$lotacao = $parametrizacao->lotacao;
|
||||
|
||||
$usuario = $usuariosFaturamentoExameLaboratorial
|
||||
->where('id', $lotacao->usuario_id)
|
||||
->first();
|
||||
|
||||
if (is_null($usuario)) {
|
||||
|
||||
$usuario = (object) [
|
||||
'id' => $lotacao->usuario->id,
|
||||
'nome' => $lotacao->usuario->cidadao->nome,
|
||||
'lotacoes' => collect(),
|
||||
];
|
||||
|
||||
$usuariosFaturamentoExameLaboratorial->push($usuario);
|
||||
}
|
||||
|
||||
$usuario->lotacoes->push((object) [
|
||||
'id' => $lotacao->id,
|
||||
'ocupacao_descricao' => "{$lotacao->ocupacao->codigo} - {$lotacao->ocupacao->nome}",
|
||||
]);
|
||||
});
|
||||
|
||||
$usuariosFaturamentoExameLaboratorial
|
||||
->sortBy('nome')
|
||||
->values()
|
||||
->each(fn ($u) => $u->lotacoes->sortBy('ocupacao_descricao')->values());
|
||||
|
||||
return $usuariosFaturamentoExameLaboratorial;
|
||||
}
|
||||
|
||||
public static function getImpressoesRecepcao($atendimentoId, $data = [])
|
||||
{
|
||||
$impressoesRecepcao = [];
|
||||
|
||||
if (isset($data['etiqueta'])) {
|
||||
|
||||
$impressoesRecepcao[] = [
|
||||
'value' => 'etiqueta',
|
||||
'text' => 'Etiqueta',
|
||||
'disabled' => false,
|
||||
'data' => $data['etiqueta']
|
||||
];
|
||||
}
|
||||
|
||||
// $impressoesRecepcao[] = [
|
||||
// 'value' => 'raat',
|
||||
// 'text' => 'RAAT',
|
||||
// 'disabled' => Atendimento::where('id', $atendimentoId)
|
||||
// ->whereHas('faa.raat')->get()->isEmpty()
|
||||
// ];
|
||||
|
||||
if (isset($data['senha'])) {
|
||||
|
||||
$impressoesRecepcao[] = [
|
||||
'value' => 'senha',
|
||||
'text' => 'Senha',
|
||||
'disabled' => Atendimento::where('id', $atendimentoId)
|
||||
->whereHas('fila')->get()->isEmpty(),
|
||||
'data' => $data['senha']
|
||||
];
|
||||
}
|
||||
|
||||
$impressoesRecepcao[] = [
|
||||
'value' => 'termoCiencia',
|
||||
'text' => 'Termo de ciência',
|
||||
'disabled' => false,
|
||||
];
|
||||
|
||||
return $impressoesRecepcao;
|
||||
}
|
||||
|
||||
public static function getImpressoesTriagem($atendimentoId, $data = [])
|
||||
{
|
||||
$impressoesTriagem = [];
|
||||
|
||||
if (isset($data['etiqueta'])) {
|
||||
|
||||
$impressoesTriagem[] = [
|
||||
'value' => 'etiqueta',
|
||||
'text' => 'Etiqueta',
|
||||
'disabled' => false,
|
||||
'data' => $data['etiqueta']
|
||||
];
|
||||
}
|
||||
|
||||
$atendimento = Atendimento::where('id', $atendimentoId)
|
||||
->whereHas('faa.raat')
|
||||
->with(['faa.raat' => function ($query) {
|
||||
$query->latest('created_at')->limit(1);
|
||||
}])
|
||||
->first();
|
||||
|
||||
$tipoFormularioAcidenteTrabalho = TipoFormularioAcidenteTrabalho::AMBOS;
|
||||
|
||||
if ($atendimento) {
|
||||
$raat = $atendimento->faa->raat;
|
||||
$tipoFormularioAcidenteTrabalho = $raat->tipo_formulario_acidente_trabalho;
|
||||
}
|
||||
|
||||
$impressoesTriagem[] = [
|
||||
'value' => 'raat',
|
||||
'text' => 'RAAT',
|
||||
'disabled' => !$atendimento || ($tipoFormularioAcidenteTrabalho == TipoFormularioAcidenteTrabalho::CAT)
|
||||
];
|
||||
|
||||
$impressoesTriagem[] = [
|
||||
'value' => 'cat',
|
||||
'text' => 'CAT',
|
||||
'disabled' => !$atendimento || ($tipoFormularioAcidenteTrabalho == TipoFormularioAcidenteTrabalho::RAAT)
|
||||
];
|
||||
|
||||
$impressoesTriagem[] = [
|
||||
'value' => 'guiaEncaminhamento',
|
||||
'text' => 'Guia de Encaminhamento',
|
||||
'disabled' => AtendimentoTriagem::where('atendimento_id', $atendimentoId)->whereHas('encaminhamentos')->get()->isEmpty(),
|
||||
];
|
||||
|
||||
return $impressoesTriagem;
|
||||
}
|
||||
|
||||
public static function getImpressoesMedicoEnfermagem($atendimentoId)
|
||||
{
|
||||
|
||||
$atendimentosPrescricaoInterna = self::getAtendimentosPrescricaoInterna($atendimentoId);
|
||||
|
||||
return [
|
||||
[
|
||||
'value' => 'atestadoAcompanhante',
|
||||
'text' => 'Atestado - Acompanhante',
|
||||
'disabled' => self::getAtestadoAcompanhanteDisabled($atendimentoId)
|
||||
],
|
||||
[
|
||||
'value' => 'atestado',
|
||||
'text' => 'Atestado - Paciente',
|
||||
'disabled' => self::getAtestadoPacienteDisabled($atendimentoId)
|
||||
],
|
||||
[
|
||||
'value' => 'declaracaoAcompanhante',
|
||||
'text' => 'Declaração de Comparecimento - Acompanhante',
|
||||
'disabled' => self::getDeclaracaoAcompanhanteDisabled($atendimentoId)
|
||||
],
|
||||
[
|
||||
'value' => 'declaracaoPaciente',
|
||||
'text' => 'Declaração de Comparecimento - Paciente',
|
||||
'disabled' => self::getDeclaracaoPacienteDisabled($atendimentoId)
|
||||
],
|
||||
[
|
||||
'value' => 'encaminhamentoHospitalar',
|
||||
'text' => 'Encaminhamento Hospitalar',
|
||||
'disabled' => AtendimentoMedico::where('atendimento_id', $atendimentoId)
|
||||
->whereHas('encaminhamentoHospitalar')->get()->isEmpty()
|
||||
],
|
||||
[
|
||||
'value' => 'examesImagem',
|
||||
'text' => 'Exames - Imagem',
|
||||
'disabled' => Atendimento::where('id', $atendimentoId)
|
||||
->whereHas('pedidosExames.exames.exame', function ($query) {
|
||||
|
||||
$query->where('tipo_id', Tipo::IMAGEM);
|
||||
})->get()->isEmpty()
|
||||
],
|
||||
[
|
||||
'value' => 'examesLaboratorial',
|
||||
'text' => 'Exames - Laboratorial',
|
||||
'data' => [
|
||||
'atendimentos' => $atendimentosPrescricaoInterna,
|
||||
],
|
||||
'disabled' => Atendimento::where('id', $atendimentoId)
|
||||
->whereHas('pedidosExames.exames.exame', function ($query) {
|
||||
|
||||
$query->where('tipo_id', Tipo::LABORATORIAL);
|
||||
})->get()->isEmpty()
|
||||
],
|
||||
[
|
||||
'value' => 'guiaEncaminhamento',
|
||||
'text' => 'Guia de Encaminhamento',
|
||||
'disabled' => AtendimentoMedico::where('atendimento_id', $atendimentoId)
|
||||
->whereHas('encaminhamentos')->get()->isEmpty()
|
||||
],
|
||||
[
|
||||
'value' => 'orientacoesPaciente',
|
||||
'text' => 'Orientação ao paciente',
|
||||
'disabled' => AtendimentoMedico::where('atendimento_id', $atendimentoId)
|
||||
->whereNotNull('orientacoes')->get()->isEmpty()
|
||||
],
|
||||
[
|
||||
'value' => 'prescricaoInterna',
|
||||
'text' => 'Prescrição Interna',
|
||||
'data' => [
|
||||
'atendimentos' => $atendimentosPrescricaoInterna,
|
||||
],
|
||||
'disabled' => AtendimentoMedico::where('atendimento_id', $atendimentoId)
|
||||
->whereHas('prescricoesInternas')->get()->isEmpty()
|
||||
],
|
||||
[
|
||||
'value' => 'receitaMedicaComum',
|
||||
'text' => 'Receita Médica - Comum',
|
||||
'disabled' => AtendimentoMedico::where('atendimento_id', $atendimentoId)
|
||||
->where(function($query) {
|
||||
$query->whereHas('receita.medicamentos.medicamento', function ($query) {
|
||||
|
||||
$query->where('receita_tipo_id', TipoReceita::COMUM);
|
||||
})
|
||||
->orWhereHas('receita.medicamentos', function ($query) {
|
||||
|
||||
$query->whereNotNull('prescricao_manual');
|
||||
});
|
||||
})
|
||||
->get()->isEmpty()
|
||||
],
|
||||
[
|
||||
'value' => 'receitaMedicaEspecial',
|
||||
'text' => 'Receita Médica - Especial',
|
||||
'disabled' => AtendimentoMedico::where('atendimento_id', $atendimentoId)
|
||||
->whereHas('receita.medicamentos.medicamento', function ($query) {
|
||||
|
||||
$query->whereIn('receita_tipo_id', [
|
||||
TipoReceita::ESPECIAL,
|
||||
TipoReceita::ESPECIAL_AMARELA,
|
||||
TipoReceita::ESPECIAL_AZUL
|
||||
]);
|
||||
})->get()->isEmpty()
|
||||
],
|
||||
[
|
||||
'value' => 'servicoEnfermagem',
|
||||
'text' => 'Serviços Enfermagem',
|
||||
'disabled' => ServicoEnfermagem::whereHas('atendimentoMedico', function ($query) use ($atendimentoId) {
|
||||
|
||||
$query->where('atendimento_id', $atendimentoId);
|
||||
})
|
||||
->orWhereHas('atendimentoEnfermagem', function ($query) use ($atendimentoId) {
|
||||
|
||||
$query->where('atendimento_id', $atendimentoId);
|
||||
})
|
||||
->orWhereHas('pacienteObservacao', function ($query) use ($atendimentoId) {
|
||||
|
||||
$query->where('atendimento_id', $atendimentoId);
|
||||
})
|
||||
->get()
|
||||
->isEmpty()
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public static function getAtendimentosPrescricaoInterna($atendimentoId)
|
||||
{
|
||||
|
||||
$atendimento = AtendimentoMedico::where('atendimento_id', $atendimentoId)
|
||||
->whereHas('prescricoesInternas')->get();
|
||||
|
||||
$resultados = $atendimento->map(function ($item) {
|
||||
$prescricoes = PrescricaoInterna::whereHas('atendimentoMedico', function ($query) use ($item) {
|
||||
$query->where('atendimento_medico_id', $item->id);
|
||||
})->get();
|
||||
|
||||
$dadosPrescricoes = $prescricoes->map(function ($prescricao) {
|
||||
|
||||
return [
|
||||
'id' => $prescricao->id,
|
||||
];
|
||||
});
|
||||
|
||||
return [
|
||||
'tipo' => 'prescricao',
|
||||
'value' => 'prescricao_' . $item->id,
|
||||
'id' => $item->id,
|
||||
'nome' => $item->plantao->lotacao->usuario->nome ?? null,
|
||||
'data_hora' => $item->created_at,
|
||||
'data' => $item->created_at->format('d/m/Y'),
|
||||
'hora' => $item->created_at->format('H:i'),
|
||||
'nova_prescricao' => $dadosPrescricoes,
|
||||
];
|
||||
})
|
||||
->sortBy('data_hora')
|
||||
->values()
|
||||
->map(function ($atendimento, $i) {
|
||||
|
||||
$atendimento['text'] = ++$i . 'º Atendimento - ' . $atendimento['nome'] . ' - ' . $atendimento['data'] . ' ás ' . $atendimento['hora'];
|
||||
|
||||
unset($atendimento['data_hora']);
|
||||
|
||||
return $atendimento;
|
||||
})
|
||||
->all();
|
||||
|
||||
return $resultados;
|
||||
}
|
||||
|
||||
public static function getDeclaracaoPacienteDisabled($atendimentoId) {
|
||||
|
||||
return
|
||||
AtendimentoMedico::where('atendimento_id', $atendimentoId)
|
||||
->whereHas('declaracoesComparecimento', function ($query) {
|
||||
|
||||
$query->where('tipo_id', DeclaracaoComparecimentoTipo::PACIENTE);
|
||||
})->get()->isEmpty()
|
||||
|
||||
&& AtendimentoEnfermagem::where('atendimento_id', $atendimentoId)
|
||||
->whereHas('declaracoesComparecimento', function ($query) {
|
||||
|
||||
$query->where('tipo_id', DeclaracaoComparecimentoTipo::PACIENTE);
|
||||
})->get()->isEmpty()
|
||||
|
||||
&& AtendimentoTriagem::where('atendimento_id', $atendimentoId)
|
||||
->whereHas('declaracoesComparecimento', function ($query) {
|
||||
|
||||
$query->where('tipo_id', DeclaracaoComparecimentoTipo::PACIENTE);
|
||||
})->get()->isEmpty()
|
||||
|
||||
&& PacienteObservacao::where('atendimento_id', $atendimentoId)
|
||||
->whereHas('declaracoesComparecimento', function ($query) {
|
||||
|
||||
$query->where('tipo_id', DeclaracaoComparecimentoTipo::PACIENTE);
|
||||
})->get()->isEmpty()
|
||||
|
||||
&& AtendimentoExameImagem::where('atendimento_id', $atendimentoId)
|
||||
->whereHas('declaracoesComparecimento', function ($query) {
|
||||
|
||||
$query->where('tipo_id', DeclaracaoComparecimentoTipo::PACIENTE);
|
||||
})->get()->isEmpty()
|
||||
|
||||
&& Recepcao::where('atendimento_id', $atendimentoId)
|
||||
->whereHas('declaracoesComparecimento', function ($query) {
|
||||
|
||||
$query->where('tipo_id', DeclaracaoComparecimentoTipo::PACIENTE);
|
||||
})->get()->isEmpty() ? true : false;
|
||||
}
|
||||
|
||||
public static function getAtestadoAcompanhanteDisabled($atendimentoId)
|
||||
{
|
||||
return
|
||||
!Atestado::whereHas('atendimentoMedico', fn ($q) => $q->where('atendimento_id', $atendimentoId))
|
||||
->where('paciente', false)
|
||||
->exists();
|
||||
}
|
||||
|
||||
public static function getAtestadoPacienteDisabled($atendimentoId)
|
||||
{
|
||||
return
|
||||
!Atestado::whereHas('atendimentoMedico', fn ($q) => $q->where('atendimento_id', $atendimentoId))
|
||||
->where('paciente', true)
|
||||
->exists();
|
||||
}
|
||||
|
||||
public static function getDeclaracaoAcompanhanteDisabled($atendimentoId)
|
||||
{
|
||||
|
||||
return
|
||||
AtendimentoMedico::where('atendimento_id', $atendimentoId)
|
||||
->whereHas('declaracoesComparecimento', function ($query) {
|
||||
|
||||
$query->where('tipo_id', DeclaracaoComparecimentoTipo::ACOMPANHANTE);
|
||||
})->get()->isEmpty()
|
||||
|
||||
&& AtendimentoEnfermagem::where('atendimento_id', $atendimentoId)
|
||||
->whereHas('declaracoesComparecimento', function ($query) {
|
||||
|
||||
$query->where('tipo_id', DeclaracaoComparecimentoTipo::ACOMPANHANTE);
|
||||
})->get()->isEmpty()
|
||||
|
||||
&& AtendimentoTriagem::where('atendimento_id', $atendimentoId)
|
||||
->whereHas('declaracoesComparecimento', function ($query) {
|
||||
|
||||
$query->where('tipo_id', DeclaracaoComparecimentoTipo::ACOMPANHANTE);
|
||||
})->get()->isEmpty()
|
||||
|
||||
&& PacienteObservacao::where('atendimento_id', $atendimentoId)
|
||||
->whereHas('declaracoesComparecimento', function ($query) {
|
||||
|
||||
$query->where('tipo_id', DeclaracaoComparecimentoTipo::ACOMPANHANTE);
|
||||
})->get()->isEmpty()
|
||||
|
||||
&& AtendimentoExameImagem::where('atendimento_id', $atendimentoId)
|
||||
->whereHas('declaracoesComparecimento', function ($query) {
|
||||
|
||||
$query->where('tipo_id', DeclaracaoComparecimentoTipo::ACOMPANHANTE);
|
||||
})->get()->isEmpty()
|
||||
|
||||
&& Recepcao::where('atendimento_id', $atendimentoId)
|
||||
->whereHas('declaracoesComparecimento', function ($query) {
|
||||
|
||||
$query->where('tipo_id', DeclaracaoComparecimentoTipo::ACOMPANHANTE);
|
||||
})->get()->isEmpty() ? true : false;
|
||||
}
|
||||
|
||||
public static function getImpressoesFaa($atendimentoId)
|
||||
{
|
||||
$atendimentosObservacao = self::getAtendimentosObservacao($atendimentoId);
|
||||
|
||||
return [
|
||||
[
|
||||
'value' => 'simplificada',
|
||||
'text' => 'Simplificada',
|
||||
'disabled' => false
|
||||
],
|
||||
[
|
||||
'value' => 'completa',
|
||||
'text' => 'Completa',
|
||||
'disabled' => false
|
||||
],
|
||||
[
|
||||
'value' => 'eletronica',
|
||||
'text' => 'Eletrônica',
|
||||
'disabled' => false
|
||||
],
|
||||
[
|
||||
'value' => 'eletronicaObservacao',
|
||||
'text' => 'Eletrônica (Paciente em observação)',
|
||||
'disabled' => empty($atendimentosObservacao),
|
||||
'data' => [
|
||||
'atendimentos' => $atendimentosObservacao,
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public static function getAtendimentosObservacao($atendimentoId)
|
||||
{
|
||||
$atendimento = Atendimento::findOrFail($atendimentoId);
|
||||
|
||||
return collect(array_merge(
|
||||
$atendimento->atendimentosMedico()
|
||||
->where('is_observacao', true)
|
||||
->get()
|
||||
->map(fn ($atendimento) => [
|
||||
'tipo' => 'medico',
|
||||
'value' => 'medico_' . $atendimento->id,
|
||||
'id' => $atendimento->id,
|
||||
'data_hora' => $atendimento->created_at,
|
||||
])->all(),
|
||||
$atendimento->atendimentosExameImagem()
|
||||
->where('is_observacao', true)
|
||||
->get()
|
||||
->map(fn ($atendimento) => [
|
||||
'tipo' => 'exame_imagem',
|
||||
'value' => 'exame_imagem_' . $atendimento->id,
|
||||
'id' => $atendimento->id,
|
||||
'data_hora' => $atendimento->created_at,
|
||||
])->all(),
|
||||
$atendimento->pacienteObservacoes
|
||||
->map(fn ($atendimento) => [
|
||||
'tipo' => 'observacao',
|
||||
'value' => 'observacao_' . $atendimento->id,
|
||||
'id' => $atendimento->id,
|
||||
'data_hora' => $atendimento->created_at,
|
||||
])->all(),
|
||||
))
|
||||
->sortBy('data_hora')
|
||||
->values()
|
||||
->map(function ($atendimento, $i) {
|
||||
|
||||
$atendimento['text'] = ++$i . 'º Atendimento';
|
||||
|
||||
unset($atendimento['data_hora']);
|
||||
|
||||
return $atendimento;
|
||||
})
|
||||
->all();
|
||||
}
|
||||
|
||||
private static function validateDatatableRequest($request)
|
||||
{
|
||||
$minDate = Carbon::now()->subYears(130)->format('Y-m-d');
|
||||
|
||||
$request->validate([
|
||||
'periodo.start' => [
|
||||
'required',
|
||||
'date_format:d/m/Y',
|
||||
"after_or_equal:{$minDate}",
|
||||
'before_or_equal:periodo.end',
|
||||
],
|
||||
'periodo.end' => [
|
||||
'required',
|
||||
'date_format:d/m/Y',
|
||||
'after_or_equal:periodo.start',
|
||||
'before_or_equal:now',
|
||||
],
|
||||
'sexo_id' => [
|
||||
'nullable',
|
||||
'integer',
|
||||
],
|
||||
'paciente' => [
|
||||
'nullable',
|
||||
'string',
|
||||
],
|
||||
'data_nascimento' => [
|
||||
'nullable',
|
||||
'date_format:d/m/Y',
|
||||
],
|
||||
'faa' => [
|
||||
'nullable',
|
||||
'integer',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public static function faturarEnfermagem($request)
|
||||
{
|
||||
return (new AtendimentoEnfermagemController())->faturarProcedimentosAutomaticamente($request);
|
||||
}
|
||||
|
||||
public static function getAtendimentosExameLaboratorial($atendimentoId)
|
||||
{
|
||||
|
||||
$atendimento = AtendimentoMedico::where('atendimento_id', $atendimentoId)
|
||||
->whereHas('prescricoesInternas')->get();
|
||||
|
||||
$resultados = $atendimento->map(function ($item) {
|
||||
$prescricoes = PrescricaoInterna::whereHas('atendimentoMedico', function ($query) use ($item) {
|
||||
$query->where('atendimento_medico_id', $item->id);
|
||||
})->get();
|
||||
|
||||
$dadosPrescricoes = $prescricoes->map(function ($prescricao) {
|
||||
|
||||
return [
|
||||
'id' => $prescricao->id,
|
||||
];
|
||||
});
|
||||
|
||||
return [
|
||||
'tipo' => 'prescricao',
|
||||
'value' => 'prescricao_' . $item->id,
|
||||
'id' => $item->id,
|
||||
'nome' => $item->plantao->lotacao->usuario->nome,
|
||||
'data_hora' => $item->created_at,
|
||||
'data' => $item->created_at->format('d/m/Y'),
|
||||
'hora' => $item->created_at->format('H:i'),
|
||||
'nova_prescricao' => $dadosPrescricoes,
|
||||
];
|
||||
})
|
||||
->sortBy('data_hora')
|
||||
->values()
|
||||
->map(function ($atendimento, $i) {
|
||||
|
||||
$atendimento['text'] = ++$i . 'º Atendimento - ' . $atendimento['nome'] . ' - ' . $atendimento['data'] . ' ás ' . $atendimento['hora'];
|
||||
|
||||
unset($atendimento['data_hora']);
|
||||
|
||||
return $atendimento;
|
||||
})
|
||||
->all();
|
||||
|
||||
return $resultados;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user