This commit is contained in:
224
api/app/Services/ProntoAtendimento/Aih/AihValidator.php
Normal file
224
api/app/Services/ProntoAtendimento/Aih/AihValidator.php
Normal file
@@ -0,0 +1,224 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\ProntoAtendimento\Aih;
|
||||
|
||||
use App\Enums\Geral\DocumentoTipo;
|
||||
use App\Models\ProntoAtendimento\Atendimento\Faa;
|
||||
use App\Rules\Cnpj;
|
||||
use App\Rules\Cns;
|
||||
use App\Rules\CnsTermoValido;
|
||||
use App\Rules\Cpf;
|
||||
use App\Rules\NomeCompleto;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class AihValidator
|
||||
{
|
||||
public static function validateSave()
|
||||
{
|
||||
$rules = [
|
||||
'paciente_id' => [
|
||||
'nullable',
|
||||
'integer'
|
||||
],
|
||||
'unidade_solicitante_id' => [
|
||||
'required',
|
||||
'integer'
|
||||
],
|
||||
'cid_principal_id' => [
|
||||
'required',
|
||||
'integer'
|
||||
],
|
||||
'cid_secundario_id' => [
|
||||
'nullable',
|
||||
'integer'
|
||||
],
|
||||
'cid_causas_associadas_id' => [
|
||||
'nullable',
|
||||
'integer'
|
||||
],
|
||||
'faa_id' => [
|
||||
'bail',
|
||||
'nullable',
|
||||
'integer',
|
||||
function ($attribute, $value, $fail) {
|
||||
|
||||
$faa = Faa::find($value);
|
||||
|
||||
if ($faa && $faa->paciente_id != request()->paciente_id) {
|
||||
|
||||
$fail('FAA não vinculada ao paciente.');
|
||||
}
|
||||
}
|
||||
],
|
||||
'principais_sinais_sintomas_clinicos' => [
|
||||
'required',
|
||||
'string',
|
||||
'max:1000'
|
||||
],
|
||||
'condicoes_que_justificam_internacao' => [
|
||||
'required',
|
||||
'string',
|
||||
'max:1000'
|
||||
],
|
||||
'principais_resultados_de_provas_diagnosticas' => [
|
||||
'required',
|
||||
'string',
|
||||
'max:1000'
|
||||
],
|
||||
'finalizada' => [
|
||||
'required',
|
||||
'boolean'
|
||||
]
|
||||
];
|
||||
|
||||
return request()->validate(array_merge(
|
||||
$rules,
|
||||
self::getPacienteValidations(),
|
||||
self::getProcedimentoValidations(),
|
||||
self::getCausaExternaValidations(),
|
||||
self::getAutorizacaoValidations()
|
||||
));
|
||||
}
|
||||
|
||||
private static function getPacienteValidations()
|
||||
{
|
||||
return [
|
||||
'paciente.sexo_id' => [
|
||||
'nullable',
|
||||
'required_without:paciente_id',
|
||||
'integer'
|
||||
],
|
||||
'paciente.caracteristicas_fisicas' => [
|
||||
'nullable',
|
||||
'required_without:paciente_id',
|
||||
'string',
|
||||
'max:500'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
private static function getProcedimentoValidations()
|
||||
{
|
||||
return [
|
||||
'procedimento.procedimento_solicitado_id' => [
|
||||
'bail',
|
||||
'required',
|
||||
'integer',
|
||||
],
|
||||
'procedimento.data_solicitacao' => [
|
||||
'required',
|
||||
'date_format:d/m/Y',
|
||||
'before_or_equal:now'
|
||||
],
|
||||
'procedimento.clinica_id' => [
|
||||
'required',
|
||||
'integer'
|
||||
],
|
||||
'procedimento.carater_internacao_id' => [
|
||||
'required',
|
||||
'integer'
|
||||
],
|
||||
'procedimento.profissional_solicitante_assistente_id' => [
|
||||
'required',
|
||||
'integer'
|
||||
],
|
||||
'procedimento.documento_tipo_id' => [
|
||||
'required',
|
||||
'integer'
|
||||
],
|
||||
'procedimento.documento_numero' => [
|
||||
'required',
|
||||
self::getDocumentoNumeroValidation(request()->documento_tipo_id)
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
private static function getCausaExternaValidations()
|
||||
{
|
||||
return [
|
||||
'causa_externa.causa_externa_id' => [
|
||||
'nullable',
|
||||
'integer'
|
||||
],
|
||||
'causa_externa.cnpj_seguradora' => [
|
||||
'nullable',
|
||||
new Cnpj
|
||||
],
|
||||
'causa_externa.numero_bilhete' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:10'
|
||||
],
|
||||
'causa_externa.serie' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:6'
|
||||
],
|
||||
'causa_externa.cnpj_empresa' => [
|
||||
'nullable',
|
||||
new Cnpj
|
||||
],
|
||||
'causa_externa.cnae_empresa' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:10'
|
||||
],
|
||||
'causa_externa.cbor' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:3'
|
||||
],
|
||||
'causa_externa.vinculo_previdencia_id' => [
|
||||
'nullable',
|
||||
'integer'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
private static function getAutorizacaoValidations()
|
||||
{
|
||||
return [
|
||||
'autorizacao.profissional_autorizador_id' => [
|
||||
'nullable',
|
||||
'integer'
|
||||
],
|
||||
'autorizacao.documento_tipo_id' => [
|
||||
'nullable',
|
||||
'integer'
|
||||
],
|
||||
'autorizacao.documento_numero' => [
|
||||
'nullable',
|
||||
self::getDocumentoNumeroValidation(request()->documento_tipo_id)
|
||||
],
|
||||
'autorizacao.data_autorizacao' => [
|
||||
'nullable',
|
||||
'date_format:d/m/Y',
|
||||
'before_or_equal:now'
|
||||
],
|
||||
'autorizacao.codigo_orgao_emissor' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:6'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
private static function getDocumentoNumeroValidation($documentoTipoId)
|
||||
{
|
||||
switch ($documentoTipoId) {
|
||||
|
||||
case DocumentoTipo::CPF: {
|
||||
|
||||
return new Cpf;
|
||||
}
|
||||
case DocumentoTipo::CNS: {
|
||||
|
||||
return new Cns;
|
||||
}
|
||||
default: {
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user