102 lines
2.6 KiB
PHP
102 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\ProntoAtendimento\Parametrizacao;
|
|
|
|
use App\Enums\Sigtap\Ocupacao;
|
|
use App\Http\Requests\FormRequest;
|
|
use App\Models\Sigtap\Procedimento;
|
|
|
|
class ParametrizacaoRequest extends FormRequest
|
|
{
|
|
public function authorize()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function rules()
|
|
{
|
|
switch($this->method()) {
|
|
|
|
case 'POST': {
|
|
|
|
return $this->getPostRules();
|
|
}
|
|
default: {
|
|
|
|
return [];
|
|
}
|
|
}
|
|
}
|
|
|
|
private function getPostRules()
|
|
{
|
|
return [
|
|
'servicos_enfermagem' => [
|
|
'array',
|
|
],
|
|
'servicos_enfermagem.*.procedimento_codigo' => [
|
|
'bail',
|
|
'required',
|
|
'string',
|
|
'size:10',
|
|
'distinct',
|
|
function ($attribute, $value, $fail) {
|
|
|
|
$procedimento = Procedimento::where('codigo', $value)->orderByDesc('competencia_id')->first();
|
|
|
|
$allowedToEnfermagem = $procedimento->ocupacoes()->whereIn('codigo', [
|
|
Ocupacao::ENFERMEIRO,
|
|
Ocupacao::TECNICO_ENFERMAGEM,
|
|
Ocupacao::AUXILIAR_ENFERMAGEM,
|
|
])->exists();
|
|
|
|
if (!$allowedToEnfermagem) {
|
|
|
|
$fail("Procedimento {$value} não permitido.");
|
|
}
|
|
}
|
|
],
|
|
'atendimento_medico' => [
|
|
'required',
|
|
'array',
|
|
],
|
|
'atendimento_medico.procedimento_padrao_codigo' => [
|
|
'nullable',
|
|
'string',
|
|
'size:10',
|
|
],
|
|
'atendimento_medico.tipos' => [
|
|
'array',
|
|
],
|
|
'atendimento_medico.tipos.*.infraestrutura_id' => [
|
|
'required',
|
|
'integer',
|
|
'distinct'
|
|
],
|
|
'atendimento_medico.tipos.*.tipo_id' => [
|
|
'required',
|
|
'integer',
|
|
],
|
|
'faturamento_automatico_enfermagem' => [
|
|
'required',
|
|
'boolean',
|
|
],
|
|
'assinatura_eletronica' => [
|
|
'required',
|
|
'boolean',
|
|
],
|
|
'lotacoes_exame_laboratorial' => [
|
|
'present',
|
|
'array',
|
|
],
|
|
'lotacoes_exame_laboratorial.*' => [
|
|
'integer'
|
|
],
|
|
'tempo_aidicional_plantao' => [
|
|
'nullable',
|
|
'digits_between:0,300',
|
|
],
|
|
];
|
|
}
|
|
}
|