588 lines
26 KiB
PHP
588 lines
26 KiB
PHP
<?php
|
|
|
|
namespace App\Services\ExameImagem;
|
|
|
|
use App\Enums\Cadastro\SujeitoAtencao\PreferenciaNome;
|
|
use App\Enums\ExameImagem\Fechamento\Status;
|
|
use App\Models\ExameImagem\Agendamento\Agendamento;
|
|
use App\Models\ExameImagem\Agendamento\AgendamentoExame;
|
|
use App\Services\Service;
|
|
use App\Utils\MaskUtil;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class ExameAgendadoRealizadoService extends Service
|
|
{
|
|
|
|
public static function index($idPaciente)
|
|
{
|
|
$agendamentosBuilder = self::getAgendamentosBuilder($idPaciente);
|
|
|
|
$agendamentosBuilder = $agendamentosBuilder
|
|
->select(
|
|
'exame_imagem_agendamento.id AS atendimento_id',
|
|
'exame_imagem_agendamento.agendamento_numero AS agendamento_numero',
|
|
'exame_imagem_agendamento.medico_id',
|
|
'exame_imagem_agendamento.unidade_id',
|
|
'exame_imagem_agendamento.exame_id AS grupo_id',
|
|
'exame_imagem_agendamento.urgente',
|
|
'exame_imagem_agendamento.profissional_id',
|
|
'exame_imagem_agendamento.nome_responsavel',
|
|
'exame_imagem_agendamento.urgente',
|
|
'exame_imagem_agendamento.observacao',
|
|
'exame_imagem_agendamento.hora_exame',
|
|
'cadastro_unidade.nome_fantasia',
|
|
'cadastro_infraestrutura.telefone AS telefone',
|
|
'cadastro_endereco.id AS endereco_id',
|
|
'cadastro_endereco.numero AS endereco_numero',
|
|
'cadastro_logradouro.id AS logradouro_id',
|
|
'cadastro_logradouro.nome AS logradouro_nome',
|
|
'cadastro_bairro.id AS bairro_id',
|
|
'cadastro_bairro.nome AS bairro_nome',
|
|
'medico_cidadao.nome AS medico_solicitante',
|
|
'cadastro_paciente.id AS paciente_id',
|
|
'cidadao.nome AS paciente_nome',
|
|
'cidadao.nome_social AS nome_social',
|
|
'cidadao.preferencia_nome_id AS preferencia_nome_id',
|
|
'cadastro_grupo.nome AS grupo',
|
|
'cadastro_unidade_solicitante.nome_fantasia AS unidade_solicitante_nome',
|
|
'profissional.nome AS profissional_nome',
|
|
'parametrizacao_exame.id AS exame_id',
|
|
'parametrizacao_exame.nome AS exame_nome',
|
|
|
|
DB::raw("DATE_FORMAT(exame_imagem_agendamento.data, '%d/%m/%Y') AS data"),
|
|
DB::raw('DATE_FORMAT(exame_imagem_agendamento.hora_exame, "%H:%i") AS hora_exame'),
|
|
DB::raw("DATE_FORMAT(exame_imagem_agendamento.created_at, '%d/%m/%Y') AS data_pedido"),
|
|
DB::raw('LPAD(cadastro_paciente.prontuario,7,0) AS prontuario'),
|
|
DB::raw('IF (cidadao.data_nascimento IS NULL, "Não informada", DATE_FORMAT(cidadao.data_nascimento, "%d/%m/%Y")) as data_nascimento'),
|
|
DB::raw(
|
|
'(
|
|
CASE WHEN cidadao.nome_mae IS NULL THEN
|
|
"Não informado"
|
|
ELSE
|
|
cidadao.nome_mae
|
|
END
|
|
) as nome_mae'
|
|
),
|
|
);
|
|
|
|
return $agendamentosBuilder
|
|
->get()
|
|
->map(function ($plantao) {
|
|
|
|
return [
|
|
'data' => $plantao->data,
|
|
'paciente_nome' => $plantao->paciente_nome,
|
|
'hora_exame' => $plantao->hora_exame,
|
|
'nome_fantasia' => $plantao->nome_fantasia,
|
|
'profissional_nome' => $plantao->profissional_nome,
|
|
'exames_incluidos' => AgendamentoExame::where('agendamento_id', $plantao->atendimento_id)
|
|
->get()
|
|
->map(function ($query) {
|
|
return [
|
|
'id' => $query->id,
|
|
'exame_id' => $query->exame_id,
|
|
'nome' => $query->exame->nome,
|
|
'codigo' => $query->exame->codigo ?? null,
|
|
'observacao' => $query->exame->observacao,
|
|
'status_id' => $query->status_id,
|
|
'valor' => $query->exame->procedimento->valor_servico_ambilatorial ?? null,
|
|
];
|
|
}),
|
|
];
|
|
});
|
|
}
|
|
|
|
private static function getAgendamentosBuilder($idPaciente)
|
|
{
|
|
$agendamentos = DB::table('exame_imagem_agendamento')
|
|
->join(
|
|
'cadastro_infraestrutura',
|
|
'cadastro_infraestrutura.id',
|
|
'exame_imagem_agendamento.infraestrutura_id'
|
|
)
|
|
->join(
|
|
'cadastro_unidade',
|
|
'cadastro_unidade.id',
|
|
'cadastro_infraestrutura.unidade_id'
|
|
)
|
|
->join(
|
|
'cadastro_infraestrutura AS cadastro_infraestrutura_solicitante',
|
|
'cadastro_infraestrutura_solicitante.id',
|
|
'exame_imagem_agendamento.infraestrutura_solicitante_id'
|
|
)
|
|
->join(
|
|
'cadastro_unidade AS cadastro_unidade_solicitante',
|
|
'cadastro_unidade_solicitante.id',
|
|
'cadastro_infraestrutura_solicitante.unidade_id'
|
|
)
|
|
->join(
|
|
'cadastro_endereco',
|
|
'cadastro_endereco.id',
|
|
'cadastro_infraestrutura.endereco_id'
|
|
)
|
|
->join(
|
|
'cadastro_logradouro',
|
|
'cadastro_logradouro.id',
|
|
'cadastro_endereco.logradouro_id'
|
|
)
|
|
->join(
|
|
'cadastro_bairro',
|
|
'cadastro_bairro.id',
|
|
'cadastro_logradouro.bairro_id'
|
|
)
|
|
->join(
|
|
'cadastro_usuario',
|
|
'cadastro_usuario.id',
|
|
'exame_imagem_agendamento.medico_id'
|
|
)
|
|
->join(
|
|
'cadastro_cidadao AS medico_cidadao',
|
|
'medico_cidadao.id',
|
|
'cadastro_usuario.cidadao_id'
|
|
)
|
|
->join(
|
|
'parametrizacao_exame',
|
|
'parametrizacao_exame.id',
|
|
'exame_imagem_agendamento.exame_id'
|
|
)
|
|
->join(
|
|
'cadastro_grupo',
|
|
'cadastro_grupo.id',
|
|
'parametrizacao_exame.grupo_tipo_id'
|
|
)
|
|
->join(
|
|
'cadastro_usuario AS profissional_cidadao',
|
|
'profissional_cidadao.id',
|
|
'exame_imagem_agendamento.profissional_id'
|
|
)
|
|
->join(
|
|
'cadastro_cidadao AS profissional',
|
|
'profissional.id',
|
|
'profissional_cidadao.cidadao_id'
|
|
)
|
|
->leftJoin(
|
|
'cadastro_paciente',
|
|
'cadastro_paciente.id',
|
|
'exame_imagem_agendamento.paciente_id'
|
|
)
|
|
->leftJoin(
|
|
'cadastro_cidadao AS cidadao',
|
|
'cidadao.id',
|
|
'cadastro_paciente.cidadao_id'
|
|
)
|
|
->where('exame_imagem_agendamento.paciente_id', $idPaciente)
|
|
->orderBy('data');
|
|
|
|
return $agendamentos;
|
|
}
|
|
|
|
public static function getDados($idPaciente)
|
|
{
|
|
$paciente = DB::table('exame_imagem_agendamento')
|
|
->select(
|
|
'cadastro_paciente.id AS id_paciente',
|
|
'cidadao.nome AS paciente_nome',
|
|
'cidadao.nome_social AS nome_social',
|
|
'cadastro_sexo_paciente.descricao AS sexo',
|
|
'cadastro_unidade.nome_fantasia AS unidade_referencia',
|
|
DB::raw('LPAD(cadastro_paciente.prontuario,7,0) AS prontuario'),
|
|
DB::raw('IF (cidadao.data_nascimento IS NULL, "Não informada", DATE_FORMAT(cidadao.data_nascimento, "%d/%m/%Y")) as data_nascimento'),
|
|
DB::raw(
|
|
'(
|
|
CASE WHEN cidadao.nome_mae IS NULL THEN
|
|
"Não informado"
|
|
ELSE
|
|
cidadao.nome_mae
|
|
END
|
|
) as nome_mae'
|
|
),
|
|
)
|
|
->join(
|
|
'cadastro_paciente',
|
|
'cadastro_paciente.id',
|
|
'exame_imagem_agendamento.paciente_id'
|
|
)
|
|
->leftJoin(
|
|
'cadastro_cidadao AS cidadao',
|
|
'cidadao.id',
|
|
'cadastro_paciente.cidadao_id'
|
|
)
|
|
->leftJoin(
|
|
'cadastro_sexo AS cadastro_sexo_paciente',
|
|
'cadastro_sexo_paciente.id',
|
|
'cidadao.sexo_id'
|
|
)
|
|
->leftJoin(
|
|
'cadastro_cidadao_telefone AS telefone',
|
|
'telefone.cidadao_id',
|
|
'cidadao.id'
|
|
)
|
|
->leftJoin(
|
|
'cadastro_unidade',
|
|
'cadastro_unidade.id',
|
|
'cadastro_paciente.unidade_id'
|
|
)
|
|
->where('exame_imagem_agendamento.paciente_id', $idPaciente)
|
|
->orderBy('data')
|
|
->first();
|
|
|
|
return $paciente;
|
|
}
|
|
|
|
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,
|
|
],
|
|
'model' => [
|
|
'periodo' => [
|
|
'start' => $currentDate,
|
|
'end' => $currentDate,
|
|
],
|
|
'atendimento' => null,
|
|
'prontuario' => null,
|
|
'data_nascimento' => null,
|
|
'paciente' => 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 $request)
|
|
{
|
|
$agendamentos = DB::table('exame_imagem_agendamento_exame')
|
|
->select(
|
|
'exame_imagem_agendamento_exame.id AS id_paciente',
|
|
'exame_imagem_agendamento_exame.agendamento_id AS agendamento_id',
|
|
'exame_imagem_agendamento.medico_id',
|
|
'exame_imagem_agendamento.retroativo',
|
|
'exame_imagem_agendamento.unidade_id',
|
|
'exame_imagem_agendamento.profissional_id',
|
|
'exame_imagem_agendamento.jornada_id AS jornada_agendamento',
|
|
'exame_imagem_agendamento.agendamento_numero AS agendamento_numero',
|
|
'cadastro_unidade.nome_fantasia',
|
|
'medico_cidadao.nome AS medico_solicitante',
|
|
'profissional.nome AS profissional',
|
|
'exame_imagem_jornada.id AS jornada_id',
|
|
'exame_imagem_jornada.status_id AS jornada_status_id',
|
|
'cadastro_unidade_solicitante.nome_fantasia AS unidade_solicitante_nome',
|
|
'cadastro_paciente.id AS paciente_id',
|
|
'cadastro_grupo.nome AS grupo',
|
|
'cadastro_grupo.id AS grupo_exame_id',
|
|
'cidadao.nome AS paciente_nome',
|
|
'cidadao.nome_social AS nome_social',
|
|
'parametrizacao_exame.id AS exame_id',
|
|
'parametrizacao_exame.nome AS exame',
|
|
|
|
DB::raw('DATE_FORMAT(exame_imagem_agendamento.hora_exame, "%H:%i") AS hora_exame'),
|
|
DB::raw("DATE_FORMAT(exame_imagem_agendamento.data, '%Y/%m/%d') AS data"),
|
|
DB::raw("DATE_FORMAT(exame_imagem_agendamento.created_at, '%d/%m/%Y') AS data_pedido"),
|
|
DB::raw('LPAD(cadastro_paciente.prontuario,7,0) AS prontuario'),
|
|
DB::raw('IF (cidadao.data_nascimento IS NULL, "Não informada", DATE_FORMAT(cidadao.data_nascimento, "%d/%m/%Y")) as data_nascimento'),
|
|
DB::raw("
|
|
(
|
|
SELECT GROUP_CONCAT(cadastro_cidadao_telefone.numero SEPARATOR ', ')
|
|
FROM cadastro_cidadao_telefone
|
|
WHERE cadastro_cidadao_telefone.principal = TRUE
|
|
AND cadastro_cidadao_telefone.cidadao_id = cadastro_paciente.cidadao_id
|
|
AND cadastro_cidadao_telefone.deleted_at IS NULL
|
|
) AS paciente_telefone
|
|
"),
|
|
DB::raw(
|
|
'(
|
|
CASE WHEN cidadao.nome_mae IS NULL THEN
|
|
"Não informado"
|
|
ELSE
|
|
cidadao.nome_mae
|
|
END
|
|
) as nome_mae'
|
|
),
|
|
)
|
|
->leftJoin(
|
|
'exame_imagem_agendamento',
|
|
'exame_imagem_agendamento.id',
|
|
'exame_imagem_agendamento_exame.agendamento_id'
|
|
)
|
|
->leftJoin(
|
|
'cadastro_infraestrutura',
|
|
'cadastro_infraestrutura.id',
|
|
'exame_imagem_agendamento.infraestrutura_id'
|
|
)
|
|
->leftJoin(
|
|
'cadastro_unidade',
|
|
'cadastro_unidade.id',
|
|
'cadastro_infraestrutura.unidade_id'
|
|
)
|
|
->leftJoin(
|
|
'cadastro_infraestrutura AS cadastro_infraestrutura_solicitante',
|
|
'cadastro_infraestrutura_solicitante.id',
|
|
'exame_imagem_agendamento.infraestrutura_solicitante_id'
|
|
)
|
|
->leftJoin(
|
|
'cadastro_unidade AS cadastro_unidade_solicitante',
|
|
'cadastro_unidade_solicitante.id',
|
|
'cadastro_infraestrutura_solicitante.unidade_id'
|
|
)
|
|
->leftJoin(
|
|
'cadastro_usuario',
|
|
'cadastro_usuario.id',
|
|
'exame_imagem_agendamento.medico_id'
|
|
)
|
|
->leftJoin(
|
|
'cadastro_cidadao AS medico_cidadao',
|
|
'medico_cidadao.id',
|
|
'cadastro_usuario.cidadao_id'
|
|
)
|
|
->leftJoin(
|
|
'cadastro_usuario AS profissional_cidadao',
|
|
'profissional_cidadao.id',
|
|
'exame_imagem_agendamento.profissional_id'
|
|
)
|
|
->leftJoin(
|
|
'cadastro_cidadao AS profissional',
|
|
'profissional.id',
|
|
'profissional_cidadao.cidadao_id'
|
|
)
|
|
->leftJoin(
|
|
'cadastro_cidadao AS cadastro_cidadao_usuario',
|
|
'cadastro_cidadao_usuario.id',
|
|
'cadastro_usuario.cidadao_id'
|
|
)
|
|
->leftJoin(
|
|
'parametrizacao_exame',
|
|
'parametrizacao_exame.id',
|
|
'exame_imagem_agendamento_exame.exame_id'
|
|
)
|
|
->leftJoin(
|
|
'cadastro_grupo',
|
|
'cadastro_grupo.id',
|
|
'exame_imagem_agendamento.exame_id'
|
|
)
|
|
->leftJoin(
|
|
'exame_imagem_jornada',
|
|
'exame_imagem_jornada.id',
|
|
'exame_imagem_agendamento.jornada_id'
|
|
)
|
|
->leftJoin(
|
|
'cadastro_usuario_registro_tipo',
|
|
'cadastro_usuario_registro_tipo.id',
|
|
'profissional_cidadao.registro_tipo_id'
|
|
)
|
|
->leftJoin(
|
|
'cadastro_paciente',
|
|
'cadastro_paciente.id',
|
|
'exame_imagem_agendamento_exame.paciente_id'
|
|
)
|
|
->leftJoin(
|
|
'cadastro_cidadao AS cidadao',
|
|
'cidadao.id',
|
|
'cadastro_paciente.cidadao_id'
|
|
)
|
|
->groupBy('paciente_id')
|
|
->orderBy('cidadao.nome')
|
|
->where(function ($query) {
|
|
|
|
$query->where('exame_imagem_agendamento_exame.status_id', Status::AGENDADO)
|
|
->orWhere('exame_imagem_agendamento_exame.status_id', Status::REALIZADO)
|
|
->orWhere('exame_imagem_agendamento_exame.status_id', NULL);
|
|
});
|
|
|
|
if ($request->paciente_id) {
|
|
|
|
$agendamentos->where('exame_imagem_agendamento.paciente_id', $request->paciente_id);
|
|
}
|
|
|
|
if ($request->prontuario) {
|
|
|
|
$agendamentos->where('cadastro_paciente.prontuario', $request->prontuario);
|
|
}
|
|
|
|
if ($request->data_nascimento) {
|
|
$agendamentos->where('cidadao.data_nascimento', $request->data_nascimento);
|
|
}
|
|
|
|
|
|
$agendamentos = $agendamentos->get();
|
|
|
|
return $agendamentos;
|
|
}
|
|
|
|
public static function show($id)
|
|
{
|
|
|
|
$agendamento = Agendamento::where('paciente_id', $id)->firstOrFail();
|
|
|
|
return [
|
|
'form' => [
|
|
'data_atual' => Carbon::now()->format('d/m/Y'),
|
|
'paciente' => [
|
|
'nome' => $agendamento->paciente->cidadao->nome ?? null,
|
|
'nomeSocial' => $agendamento->paciente->cidadao->nome_social,
|
|
'prefereNomeSocial' => $agendamento->paciente->cidadao
|
|
->preferencia_nome_id === PreferenciaNome::NOME_SOCIAL,
|
|
'data_nascimento' => $agendamento->paciente->cidadao->data_nascimento
|
|
? $agendamento->paciente->cidadao->data_nascimento->format('d/m/Y')
|
|
: '',
|
|
'cpf' => $agendamento->paciente->cidadao->cpf
|
|
? MaskUtil::getCpfMasked($agendamento->paciente->cidadao->cpf) : null,
|
|
'rg' => $agendamento->paciente->cidadao->carteiraIdentidade->numero ?? null,
|
|
'convenio_medico_nome' => $agendamento->paciente->cidadao->conveniosMedico->first()->nome ?? null,
|
|
'situacao_familiar' => $agendamento->paciente->cidadao->situacaoFamiliarConjugal->descricao ?? null,
|
|
'prontuario' => $agendamento->paciente->prontuario,
|
|
'unidade' => $agendamento->paciente->unidade->nome_fantasia ?? null,
|
|
'sexo' => $agendamento->paciente->cidadao->sexo ?? '-',
|
|
'classificacao_id' => $agendamento->paciente->classificacao_id ?? '-',
|
|
'classificacao_nome' => $agendamento->paciente->classificacao->descricao ?? '-',
|
|
'cns' => $agendamento->paciente->cidadao->cns ? MaskUtil::getCnsMasked($agendamento->paciente->cidadao->cns) : '',
|
|
'telefone' => MaskUtil::getPhoneMasked($agendamento->paciente->cidadao->telefone_principal->numero ?? ''),
|
|
],
|
|
'endereco' => [
|
|
'estado_id' => isset($agendamento->paciente->cidadao->domicilio->endereco->logradouro->municipio->estado->id)
|
|
? $agendamento->paciente->cidadao->domicilio->endereco->logradouro->municipio->estado->id
|
|
: '',
|
|
'municipio' => isset($agendamento->paciente->cidadao->domicilio->endereco->logradouro->municipio)
|
|
? $agendamento->paciente->cidadao->domicilio->endereco->logradouro->municipio
|
|
: '',
|
|
'logradouro' => isset($agendamento->paciente->cidadao->domicilio->endereco->logradouro)
|
|
? $agendamento->paciente->cidadao->domicilio->endereco->logradouro
|
|
: '',
|
|
'cep' => isset($agendamento->paciente->cidadao->domicilio->endereco->logradouro->cep)
|
|
? MaskUtil::getCepMasked($agendamento->paciente->cidadao->domicilio->endereco->logradouro->cep)
|
|
: '',
|
|
'numero' => isset($agendamento->paciente->cidadao->domicilio->endereco->numero)
|
|
? $agendamento->paciente->cidadao->domicilio->endereco->numero
|
|
: '',
|
|
'sem_numero' => isset($agendamento->paciente->cidadao->domicilio->endereco->sem_numero)
|
|
? $agendamento->paciente->cidadao->domicilio->endereco->sem_numero
|
|
: '',
|
|
'complemento' => isset($agendamento->paciente->cidadao->domicilio->endereco->complemento)
|
|
? $agendamento->paciente->cidadao->domicilio->endereco->complemento
|
|
: '',
|
|
'zona_id' => isset($agendamento->paciente->cidadao->domicilio->endereco->zona_id)
|
|
? $agendamento->paciente->cidadao->domicilio->endereco->zona_id
|
|
: '',
|
|
],
|
|
],
|
|
'model' => [
|
|
'data_atual' => Carbon::now()->format('d/m/Y'),
|
|
'agendados' => Agendamento::where('paciente_id', $id)
|
|
->whereHas('agendamentoExame', function ($query) {
|
|
|
|
$query->where('exame_imagem_agendamento_exame.status_id', Status::AGENDADO)
|
|
->orWhere('exame_imagem_agendamento_exame.status_id', NULL);
|
|
})
|
|
->get()
|
|
->map(fn ($agendamento) => [
|
|
'agendamento_id' => $agendamento->id,
|
|
'agendamento_numero' => $agendamento->agendamento_numero,
|
|
'data' => (new Carbon($agendamento->data))->format('d/m/Y') ?? null,
|
|
'incluido' => AgendamentoExame::where('agendamento_id', $agendamento->id)
|
|
->get()
|
|
->map(function ($query) {
|
|
return [
|
|
'id' => $query->id,
|
|
'exame_id' => $query->exame_id,
|
|
'nome' => $query->exame->nome,
|
|
'codigo' => $query->exame->codigo ?? null,
|
|
'valor' => $query->valor,
|
|
'status' => $query->status->nome ?? 'AGENDADO',
|
|
'status_id' => $query->status_id,
|
|
'prazo_entrega' => $query->exame->prazo_entrega ?? null,
|
|
'observacao' => $query->exame->observacao ?? null
|
|
];
|
|
})
|
|
->values(),
|
|
'grupo_exame_id' => $agendamento->exame_id,
|
|
'grupo_exame_nome' => $agendamento->grupo->nome,
|
|
'profissional_id' => $agendamento->profissional_id,
|
|
'profissional_nome' => $agendamento->jornada->usuario->nome,
|
|
'paciente_id' => $agendamento->paciente_id,
|
|
'unidade_nome' => $agendamento->unidade->nome_fantasia,
|
|
'local_atendimento' => $agendamento->infraestrutura->nome,
|
|
'medico_id' => $agendamento->medico_id,
|
|
'medico_nome' => $agendamento->medico->nome,
|
|
])
|
|
->sortBy('data')
|
|
->values(),
|
|
'realizados' => Agendamento::where('paciente_id', $id)
|
|
->whereHas('agendamentoExame', function ($query) {
|
|
$query->where('exame_imagem_agendamento_exame.status_id', Status::REALIZADO);
|
|
})
|
|
->whereNotExists(function($query) {
|
|
|
|
$query->select(DB::raw(1))
|
|
->from('exame_imagem_agendamento_exame')
|
|
->whereColumn('exame_imagem_agendamento_exame.agendamento_id', 'exame_imagem_agendamento.id')
|
|
->where('exame_imagem_agendamento_exame.status_id', Status::AGENDADO);
|
|
})
|
|
->get()
|
|
->map(fn ($agendamento) => [
|
|
'agendamento_id' => $agendamento->id,
|
|
'agendamento_numero' => $agendamento->agendamento_numero,
|
|
'data' => (new Carbon($agendamento->data))->format('d/m/Y') ?? null,
|
|
'incluido' => AgendamentoExame::where('agendamento_id', $agendamento->id)
|
|
->get()
|
|
->map(function ($query) {
|
|
return [
|
|
'id' => $query->id,
|
|
'exame_id' => $query->exame_id,
|
|
'nome' => $query->exame->nome,
|
|
'codigo' => $query->exame->codigo ?? null,
|
|
'valor' => $query->valor,
|
|
'status_id' => $query->status_id,
|
|
'status' => self::getStatus($query),
|
|
'prazo_entrega' => $query->exame->prazo_entrega ?? null,
|
|
'observacao' => $query->exame->observacao ?? null
|
|
];
|
|
})
|
|
->values(),
|
|
'medico_id' => $agendamento->medico_id,
|
|
'medico_nome' => $agendamento->medico->nome,
|
|
'paciente_id' => $agendamento->paciente_id,
|
|
'unidade_nome' => $agendamento->unidade->nome_fantasia,
|
|
'local_atendimento' => $agendamento->infraestrutura->nome,
|
|
'grupo_exame_id' => $agendamento->exame_id,
|
|
'grupo_exame_nome' => $agendamento->grupo->nome,
|
|
'profissional_id' => $agendamento->profissional_id,
|
|
'profissional_nome' => $agendamento->jornada->usuario->nome,
|
|
])
|
|
->sortBy('data')
|
|
->values(),
|
|
],
|
|
];
|
|
}
|
|
|
|
public static function getStatus($query)
|
|
{
|
|
|
|
if ($query->status_id == Status::REALIZADO) {
|
|
|
|
return 'REALIZADO';
|
|
|
|
} else if ($query->status_id == Status::FALTOU) {
|
|
|
|
return 'FALTOU';
|
|
|
|
} else if ($query->status_id == Status::RESULTADO) {
|
|
return 'RESULTADO';
|
|
|
|
} else if ($query->status_id == Status::AGENDADO) {
|
|
|
|
return 'AGENDADO';
|
|
}
|
|
|
|
return $query->status->nome;
|
|
}
|
|
}
|