This commit is contained in:
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\ProntoAtendimento\Atendimento;
|
||||
|
||||
use App\Enums\Cadastro\Estabelecimento\Servico;
|
||||
use App\Enums\Cadastro\SujeitoAtencao\Sexo;
|
||||
use App\Enums\PainelSenha\PrioridadeTipo;
|
||||
use App\Http\Requests\FormRequest;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Paciente;
|
||||
use App\Rules\CnsTermoValido;
|
||||
use App\Rules\NomeCompleto;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class RecepcaoRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
switch ($this->method()) {
|
||||
|
||||
case 'POST': {
|
||||
|
||||
return $this->getPostRules();
|
||||
}
|
||||
default: {
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getPostRules()
|
||||
{
|
||||
return [
|
||||
'plantao_id' => [
|
||||
'nullable',
|
||||
'integer'
|
||||
],
|
||||
|
||||
/*
|
||||
* Paciente.
|
||||
*/
|
||||
|
||||
'paciente' => ['required', 'array'],
|
||||
'paciente.id' => ['nullable', 'integer'],
|
||||
'paciente.sexo_id' => ['required_without:paciente.id', 'nullable', 'integer'],
|
||||
'paciente.caracteristicas_fisicas' => ['required_without:paciente.id', 'string', 'max:500'],
|
||||
|
||||
/*
|
||||
* Fila.
|
||||
*/
|
||||
|
||||
'fila' => ['required', 'array'],
|
||||
'fila.id' => ['nullable', 'integer'],
|
||||
'fila.prioridade_id' => [
|
||||
'nullable',
|
||||
'integer',
|
||||
function ($attribute, $value, $fail) {
|
||||
|
||||
$sexoId = null;
|
||||
|
||||
if (isset($this->paciente['id']) && !is_null($this->paciente['id'])) {
|
||||
|
||||
$paciente = Paciente::with('cidadao')->find($this->paciente['id']);
|
||||
|
||||
if (!is_null($paciente)) {
|
||||
|
||||
$sexoId = $paciente->cidadao->sexo->id;
|
||||
}
|
||||
}
|
||||
else if (isset($this->paciente['sexo_id']) && !is_null($this->paciente['sexo_id'])) {
|
||||
|
||||
$sexoId = $this->paciente['sexo_id'];
|
||||
}
|
||||
|
||||
if ($sexoId === Sexo::MASCULINO && $value === PrioridadeTipo::GESTANTE) {
|
||||
|
||||
$fail('O '.$attribute.' não pode ser gestante quando o paciente for do sexo masculino.');
|
||||
}
|
||||
}
|
||||
],
|
||||
'fila.opcao_entrada_id' => ['required_without:fila.id', 'nullable', 'integer'],
|
||||
'fila.centro_custo_id_para' => ['required', 'integer'],
|
||||
|
||||
/*
|
||||
* Atendimento
|
||||
*/
|
||||
|
||||
'atendido_em' => ['required', 'date'],
|
||||
'urgente' => [
|
||||
Rule::requiredIf(fn () => isset($this->paciente['id'])),
|
||||
'nullable',
|
||||
'boolean'
|
||||
],
|
||||
'urgente_motivo' => ['required_if:urgente,true', 'nullable', 'string', 'max:100'],
|
||||
'origem_entrada_id' => ['nullable', 'integer'],
|
||||
'medico_samu' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:150'
|
||||
],
|
||||
"motivo_atendimento" => ['required', 'nullable', 'string', 'max:3000'],
|
||||
"acompanhante" => [
|
||||
'nullable',
|
||||
'string',
|
||||
'between:6,150',
|
||||
new NomeCompleto,
|
||||
new CnsTermoValido(['attribute' => 'Acompanhante']),
|
||||
],
|
||||
"unidade_encaminhamento_id" => ['nullable', 'integer'],
|
||||
"unidade_externa_encaminhamento_id" => ['nullable', 'integer'],
|
||||
"medico_solicitante_encaminhamento" => [
|
||||
'nullable',
|
||||
'string',
|
||||
'between:6,150',
|
||||
new NomeCompleto,
|
||||
],
|
||||
"servico_id" => ['required', 'integer'],
|
||||
"ocupacao_id" => [
|
||||
Rule::requiredIf(fn () => !is_null($this->servico_id)
|
||||
&& $this->servico_id === Servico::CONSULTA_MEDICA),
|
||||
'nullable',
|
||||
'integer'
|
||||
],
|
||||
"observacao" => ['nullable', 'string', 'max:3000'],
|
||||
|
||||
/*
|
||||
* RAAT.
|
||||
*/
|
||||
|
||||
'raat' => ['nullable', 'array'],
|
||||
|
||||
'raat.empresa' => [
|
||||
Rule::requiredIf(fn () => !is_null($this->raat)),
|
||||
'array'
|
||||
],
|
||||
'raat.empresa.nome' => [
|
||||
Rule::requiredIf(fn () => !is_null($this->raat)),
|
||||
'string',
|
||||
'between:2,150'
|
||||
],
|
||||
'raat.empresa.ramo_atividade' => ['nullable', 'string', 'between:2,150'],
|
||||
'raat.empresa.endereco' => ['nullable', 'string', 'between:2,150'],
|
||||
'raat.empresa.telefone' => ['nullable', 'digits_between:10,11'],
|
||||
|
||||
'raat.acidente' => [
|
||||
Rule::requiredIf(fn () => !is_null($this->raat)),
|
||||
'array'
|
||||
],
|
||||
'raat.acidente.data' => [
|
||||
Rule::requiredIf(fn () => !is_null($this->raat)),
|
||||
'date_format:Y-m-d'
|
||||
],
|
||||
'raat.acidente.hora' => ['nullable', 'date_format:H:i'],
|
||||
'raat.acidente.tipo_id' => ['nullable', 'integer'],
|
||||
'raat.acidente.local' => ['nullable', 'string', 'between:3,150'],
|
||||
'raat.acidente.descricao' => [
|
||||
Rule::requiredIf(fn () => !is_null($this->raat)),
|
||||
'string',
|
||||
'between:3,250'
|
||||
],
|
||||
|
||||
'raat.regime_trabalho_id' => ['nullable', 'integer'],
|
||||
'raat.regime_trabalho_outro' => ['nullable', 'string', 'max:50'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user