678 lines
26 KiB
PHP
678 lines
26 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Cadastro\SujeitoAtencao;
|
|
|
|
use App\Enums\Cadastro\SujeitoAtencao\Deficiencia;
|
|
use App\Enums\Cadastro\SujeitoAtencao\EstadoCivil;
|
|
use App\Enums\Cadastro\SujeitoAtencao\FatorRisco;
|
|
use App\Enums\Cadastro\SujeitoAtencao\LocalNascimento;
|
|
use App\Enums\Cadastro\SujeitoAtencao\ModeloCertidao;
|
|
use App\Enums\Cadastro\SujeitoAtencao\MotivoDuplicidadeCpf;
|
|
use App\Enums\Cadastro\SujeitoAtencao\Nacionalidade;
|
|
use App\Enums\Cadastro\SujeitoAtencao\RacaCor;
|
|
use App\Http\Requests\FormRequest;
|
|
use App\Models\Cadastro\Parametrizacao\Parametrizacao;
|
|
use App\Models\Cadastro\Parametrizacao\ParametrizacaoPermissaoOcupacao;
|
|
use App\Models\Cadastro\SujeitoAtencao\Lotacao;
|
|
use App\Rules\Cns;
|
|
use App\Rules\CnsTermoValido;
|
|
use App\Rules\Cpf;
|
|
use App\Rules\CpfDuplication;
|
|
use App\Rules\NisPisPasep;
|
|
use App\Rules\NomeCompleto;
|
|
use App\Utils\ImportacaoCns;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class CidadaoRequest extends FormRequest
|
|
{
|
|
public function authorize()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function rules()
|
|
{
|
|
return [];
|
|
}
|
|
|
|
public static function getPostPutRules($instance)
|
|
{
|
|
$parametrizcao = Parametrizacao::first();
|
|
$exigeCnsPaciente = $parametrizcao->exige_cns_paciente ?? true;
|
|
$exigeCpfPaciente = $parametrizcao->exige_cpf_paciente ?? true;
|
|
|
|
$rules = [
|
|
'cidadao' => [
|
|
'array',
|
|
'required',
|
|
],
|
|
'cidadao.cadastro_simplificado' => [
|
|
'required',
|
|
'boolean',
|
|
],
|
|
'cidadao.sem_documentos' => [
|
|
'required_if:cidadao.cadastro_simplificado,true',
|
|
'boolean',
|
|
],
|
|
'cidadao.cns' => [
|
|
'nullable',
|
|
Rule::requiredIf(function () use ($exigeCnsPaciente, $instance) {
|
|
if (isset($instance->origem) && $instance->origem === 'cadastroPaciente' && isset($instance->cidadao['dnv'])) {
|
|
return false;
|
|
}
|
|
|
|
if (isset($instance->cidadao['cadastro_simplificado']) && $instance->cidadao['cadastro_simplificado'] === true) {
|
|
return false;
|
|
}
|
|
|
|
return $exigeCnsPaciente;
|
|
}),
|
|
'digits:15',
|
|
new Cns,
|
|
fn($attr, $value, $fail) => \DB::table('cadastro_cidadao as c')
|
|
->join('cadastro_paciente as p', 'p.cidadao_id', '=', 'c.id')
|
|
->where('c.cns', $value)
|
|
->whereNull('c.deleted_at')
|
|
->whereNull('p.deleted_at')
|
|
->when($instance->cidadao['id'] ?? null, fn($q) => $q->where('c.id', '!=', $instance->cidadao['id']))
|
|
->exists() && $fail('O CNS já está vinculado a outro cidadão.'),
|
|
],
|
|
'cidadao.cpf' => [
|
|
'nullable',
|
|
Rule::requiredIf(function () use ($exigeCpfPaciente, $instance) {
|
|
if (isset($instance->origem) && $instance->origem === 'cadastroPaciente' && isset($instance->cidadao['dnv'])) {
|
|
return false;
|
|
}
|
|
|
|
if ($exigeCpfPaciente) {
|
|
return !(isset($instance->cidadao['sem_documentos']) && $instance->cidadao['sem_documentos']);
|
|
}
|
|
|
|
return false;
|
|
}),
|
|
'digits:11',
|
|
new Cpf,
|
|
new CpfDuplication($instance->cidadao),
|
|
],
|
|
'cidadao.cpf_nao_pertence_ao_cidadao' => [
|
|
'nullable',
|
|
'required_if:cidadao.cadastro_simplificado,false',
|
|
'boolean',
|
|
],
|
|
'cidadao.motivo_duplicidade_cpf_id' => [
|
|
'nullable',
|
|
'integer',
|
|
'required_if:cidadao.cpf_nao_pertence_ao_cidadao,true',
|
|
],
|
|
'cidadao.motivo_duplicidade_cpf_outro' => [
|
|
'nullable',
|
|
'required_if:cidadao.motivo_duplicidade_cpf_id,' . MotivoDuplicidadeCpf::OUTRO,
|
|
'string',
|
|
'between:3,50',
|
|
],
|
|
'cidadao.dnv' => [
|
|
'nullable',
|
|
'digits:11',
|
|
fn($attr, $value, $fail) => \DB::table('cadastro_cidadao as c')
|
|
->join('cadastro_paciente as p', 'p.cidadao_id', '=', 'c.id')
|
|
->where('c.dnv', $value)
|
|
->whereNull('c.deleted_at')
|
|
->whereNull('p.deleted_at')
|
|
->when($instance->cidadao['id'] ?? null, fn($q) => $q->where('c.id', '!=', $instance->cidadao['id']))
|
|
->exists() && $fail('O DNV já está vinculado a outro cidadão.'),
|
|
],
|
|
'cidadao.nome' => [
|
|
'required',
|
|
'string',
|
|
'between:6,150',
|
|
new CnsTermoValido(['attribute' => 'Nome']),
|
|
($instance['cidadao']['cadastro_simplificado'] ?? null) === true
|
|
? null
|
|
: new NomeCompleto,
|
|
],
|
|
'cidadao.nome_social' => [
|
|
'nullable',
|
|
'string',
|
|
'between:3,150',
|
|
new CnsTermoValido(['attribute' => 'Nome social']),
|
|
],
|
|
'cidadao.preferencia_nome_id' => [
|
|
'nullable',
|
|
'integer',
|
|
],
|
|
'cidadao.data_nascimento' => [
|
|
'nullable',
|
|
'date_format:Y-m-d',
|
|
'before_or_equal:now',
|
|
],
|
|
'cidadao.sexo_id' => [
|
|
'required',
|
|
'integer',
|
|
],
|
|
'cidadao.estado_civil_id' => [
|
|
'nullable',
|
|
'integer',
|
|
],
|
|
'cidadao.conjuge' => [
|
|
'nullable',
|
|
'required_if:cidadao.estado_civil_id,' . EstadoCivil::CASADO,
|
|
'string',
|
|
'between:8,150',
|
|
new NomeCompleto,
|
|
],
|
|
'cidadao.situacao_familiar_conjugal_id' => [
|
|
'nullable',
|
|
'integer',
|
|
],
|
|
'cidadao.raca_cor_id' => [
|
|
'nullable',
|
|
'integer',
|
|
],
|
|
'cidadao.etnia_indigena_id' => [
|
|
'nullable',
|
|
Rule::requiredIf(function () use ($instance) {
|
|
|
|
return ($instance->cidadao['raca_cor_id'] ?? null) === RacaCor::INDIGENA
|
|
&& ($instance->cidadao['nacionalidade_id'] ?? null) === Nacionalidade::BRASILEIRO;
|
|
}),
|
|
'integer'
|
|
],
|
|
'cidadao.tipo_sanguineo_id' => [
|
|
'nullable',
|
|
'integer',
|
|
],
|
|
'cidadao.deficiencia_id' => [
|
|
'nullable',
|
|
'integer',
|
|
],
|
|
'cidadao.deficiencia_outro' => [
|
|
'nullable',
|
|
'required_if:cidadao.deficiencia_id,' . Deficiencia::OUTRA,
|
|
'string',
|
|
'between:3,50',
|
|
],
|
|
'cidadao.mobilidade_reduzida_id' => [
|
|
'nullable',
|
|
'integer',
|
|
],
|
|
'cidadao.desconhece_nome_mae' => [
|
|
'required',
|
|
'boolean',
|
|
],
|
|
'cidadao.desconhece_nome_pai' => [
|
|
'required',
|
|
'boolean',
|
|
],
|
|
'cidadao.nome_mae' => [
|
|
'nullable',
|
|
'required_if:cidadao.desconhece_nome_mae,false',
|
|
'string',
|
|
'between:8,150',
|
|
new CnsTermoValido(['attribute' => 'Nome da mãe']),
|
|
new NomeCompleto,
|
|
],
|
|
'cidadao.nome_pai' => [
|
|
'nullable',
|
|
'required_if:cidadao.desconhece_nome_pai,false',
|
|
'between:8,150',
|
|
new CnsTermoValido(['attribute' => 'Nome do pai']),
|
|
new NomeCompleto,
|
|
],
|
|
'cidadao.local_nascimento_id' => [
|
|
'nullable',
|
|
'required_if:cidadao.cadastro_simplificado,false',
|
|
'integer',
|
|
],
|
|
'cidadao.pais_nascimento_id' => [
|
|
'nullable',
|
|
'required_if:cidadao.cadastro_simplificado,false',
|
|
],
|
|
'cidadao.nacionalidade_id' => [
|
|
'nullable',
|
|
'integer',
|
|
],
|
|
'cidadao.data_naturalizacao' => [
|
|
'nullable',
|
|
'required_if:cidadao.nacionalidade_id,' . Nacionalidade::NATURALIZADO_BRASILEIRO,
|
|
'exclude_unless:cidadao.nacionalidade_id,' . Nacionalidade::NATURALIZADO_BRASILEIRO,
|
|
'date_format:Y-m-d',
|
|
'after_or_equal:cidadao.data_nascimento',
|
|
'before_or_equal:now',
|
|
],
|
|
'cidadao.portaria_naturalizacao' => [
|
|
'nullable',
|
|
'required_if:cidadao.nacionalidade_id,' . Nacionalidade::NATURALIZADO_BRASILEIRO,
|
|
'exclude_unless:cidadao.nacionalidade_id,' . Nacionalidade::NATURALIZADO_BRASILEIRO,
|
|
'string',
|
|
'size:16',
|
|
],
|
|
'cidadao.estado_nascimento_id' => [
|
|
'nullable',
|
|
Rule::requiredIf(function () use ($instance) {
|
|
|
|
return !($instance['cidadao']['cadastro_simplificado'] ?? null)
|
|
&& ($instance['cidadao']['local_nascimento_id'] ?? null) !== LocalNascimento::EM_OUTRO_PAIS;
|
|
})
|
|
],
|
|
'cidadao.municipio_nascimento_id' => [
|
|
'nullable',
|
|
Rule::requiredIf(function () use ($instance) {
|
|
|
|
return !($instance['cidadao']['cadastro_simplificado'] ?? null)
|
|
&& ($instance['cidadao']['local_nascimento_id'] ?? null) !== LocalNascimento::EM_OUTRO_PAIS;
|
|
})
|
|
],
|
|
'cidadao.frequenta_escola' => [
|
|
'nullable',
|
|
'required_if:cidadao.cadastro_simplificado,false',
|
|
'boolean',
|
|
],
|
|
'cidadao.escolaridade_id' => [
|
|
'nullable',
|
|
'integer',
|
|
],
|
|
'cidadao.telefones' => [
|
|
'array',
|
|
'nullable',
|
|
function ($attribute, $value, $fail) {
|
|
|
|
if (empty($value)) return;
|
|
|
|
$hasPrincipal = false;
|
|
|
|
foreach (($value ?? []) as $telefone) {
|
|
|
|
if (($telefone['principal'] ?? null) === true) {
|
|
|
|
if ($hasPrincipal) {
|
|
|
|
$fail('Somente um telefone pode ser marcado como principal');
|
|
|
|
break;
|
|
}
|
|
else {
|
|
|
|
$hasPrincipal = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!$hasPrincipal) {
|
|
|
|
$fail('Obrigatório marcar um telefone como principal.');
|
|
}
|
|
},
|
|
],
|
|
'cidadao.telefones.*.id' => [
|
|
'nullable',
|
|
'integer',
|
|
],
|
|
'cidadao.telefones.*.numero' => [
|
|
'required',
|
|
'digits_between:10,11',
|
|
],
|
|
'cidadao.telefones.*.observacao' => [
|
|
'nullable',
|
|
'string',
|
|
'max:50',
|
|
],
|
|
'cidadao.telefones.*.autoriza_sms' => [
|
|
'required',
|
|
'boolean',
|
|
],
|
|
'cidadao.telefones.*.principal' => [
|
|
'required',
|
|
'boolean',
|
|
],
|
|
'cidadao.convenios_medicos' => [
|
|
'nullable',
|
|
'array',
|
|
],
|
|
'cidadao.convenios_medicos.*' => [
|
|
'required',
|
|
'integer',
|
|
],
|
|
'cidadao.data_entrada_domicilio' => [
|
|
'nullable',
|
|
'date_format:Y-m-d',
|
|
'after_or_equal:cidadao.data_nascimento',
|
|
'before_or_equal:now',
|
|
],
|
|
'cidadao.domicilio' => [
|
|
'nullable',
|
|
'array',
|
|
],
|
|
'cidadao.documentos' => [
|
|
'nullable',
|
|
'array',
|
|
],
|
|
'cidadao.documentos.carteira_identidade' => [
|
|
'nullable',
|
|
'array',
|
|
],
|
|
'cidadao.documentos.carteira_identidade.id' => [
|
|
'nullable',
|
|
'integer',
|
|
],
|
|
'cidadao.documentos.carteira_identidade.numero' => [
|
|
'nullable',
|
|
'string',
|
|
'between:6,15',
|
|
Rule::unique('\App\Models\Cadastro\SujeitoAtencao\CarteiraIdentidade', 'numero')->where(function ($query) use ($instance) {
|
|
return $query->where('cidadao_id', '!=', $instance->cidadao['id'])
|
|
->whereNull('deleted_at');
|
|
})
|
|
],
|
|
'cidadao.documentos.carteira_identidade.estado_id' => [
|
|
'nullable',
|
|
'integer',
|
|
],
|
|
'cidadao.documentos.carteira_identidade.orgao_emissor' => [
|
|
'nullable',
|
|
'string',
|
|
'between:5,8',
|
|
],
|
|
'cidadao.documentos.carteira_identidade.data_emissao' => [
|
|
'nullable',
|
|
'date_format:Y-m-d',
|
|
'after_or_equal:cidadao.data_nascimento',
|
|
'before_or_equal:now',
|
|
],
|
|
'cidadao.documentos.carteira_nacional_habilitacao' => [
|
|
'nullable',
|
|
'array',
|
|
],
|
|
'cidadao.documentos.carteira_nacional_habilitacao.id' => [
|
|
'nullable',
|
|
'integer',
|
|
],
|
|
'cidadao.documentos.carteira_nacional_habilitacao.numero' => [
|
|
'nullable',
|
|
'digits:11',
|
|
'unique:\App\Models\Cadastro\SujeitoAtencao\CarteiraHabilitacao,numero,'
|
|
. (($instance->cidadao['documentos']['carteira_nacional_habilitacao']['id'] ?? null) ?? 'NULL')
|
|
. ',id,deleted_at,NULL',
|
|
],
|
|
'cidadao.documentos.carteira_nacional_habilitacao.data_emissao' => [
|
|
'nullable',
|
|
'required_with:cidadao.documentos.carteira_nacional_habilitacao.numero',
|
|
'date_format:Y-m-d',
|
|
'after_or_equal:cidadao.data_nascimento',
|
|
'before_or_equal:now',
|
|
],
|
|
'cidadao.documentos.carteira_nacional_habilitacao.data_validade' => [
|
|
'nullable',
|
|
'required_with:cidadao.documentos.carteira_nacional_habilitacao.numero',
|
|
'date_format:Y-m-d',
|
|
'after_or_equal:cidadao.documentos.carteira_nacional_habilitacao.data_emissao',
|
|
],
|
|
'cidadao.documentos.carteira_nacional_habilitacao.estado_id' => [
|
|
'nullable',
|
|
'required_with:cidadao.documentos.carteira_nacional_habilitacao.numero',
|
|
'integer',
|
|
],
|
|
'cidadao.documentos.carteira_nacional_habilitacao.categoria_id' => [
|
|
'nullable',
|
|
'required_with:cidadao.documentos.carteira_nacional_habilitacao.numero',
|
|
'integer',
|
|
],
|
|
'cidadao.documentos.carteira_trabalho' => [
|
|
'nullable',
|
|
'array',
|
|
],
|
|
'cidadao.documentos.carteira_trabalho.id' => [
|
|
'nullable',
|
|
'integer',
|
|
],
|
|
'cidadao.documentos.carteira_trabalho.numero' => [
|
|
'nullable',
|
|
'string',
|
|
'between:7,16',
|
|
'unique:\App\Models\Cadastro\SujeitoAtencao\CarteiraTrabalho,numero,'
|
|
. (($instance->cidadao['documentos']['carteira_trabalho']['id'] ?? null) ?? 'NULL')
|
|
. ',id,deleted_at,NULL',
|
|
],
|
|
'cidadao.documentos.carteira_trabalho.serie' => [
|
|
'nullable',
|
|
'required_with:cidadao.documentos.carteira_trabalho.numero',
|
|
'string',
|
|
'size:5'
|
|
],
|
|
'cidadao.documentos.carteira_trabalho.data_emissao' => [
|
|
'nullable',
|
|
'required_with:cidadao.documentos.carteira_trabalho.numero',
|
|
'date_format:Y-m-d',
|
|
'after_or_equal:cidadao.data_nascimento',
|
|
'before_or_equal:now',
|
|
],
|
|
'cidadao.documentos.carteira_trabalho.estado_id' => [
|
|
'nullable',
|
|
'required_with:cidadao.documentos.carteira_trabalho.numero',
|
|
'integer',
|
|
],
|
|
'cidadao.documentos.carteira_trabalho.nis_pis_pasep' => [
|
|
'nullable',
|
|
'required_with:cidadao.documentos.carteira_trabalho.numero',
|
|
'digits:11',
|
|
new NisPisPasep
|
|
],
|
|
'cidadao.documentos.estrangeiro_entrada_brasil' => [
|
|
'nullable',
|
|
'array',
|
|
],
|
|
'cidadao.documentos.estrangeiro_entrada_brasil.id' => [
|
|
'nullable',
|
|
'integer',
|
|
],
|
|
'cidadao.documentos.estrangeiro_entrada_brasil.rne' => [
|
|
'nullable',
|
|
'string',
|
|
'max:20',
|
|
'unique:\App\Models\Cadastro\SujeitoAtencao\EstrangeiroEntradaBrasil,rne,'
|
|
. (($instance->cidadao['documentos']['estrangeiro_entrada_brasil']['id'] ?? null) ?? 'NULL')
|
|
. ',id,deleted_at,NULL',
|
|
],
|
|
'cidadao.documentos.estrangeiro_entrada_brasil.data_entrada' => [
|
|
'nullable',
|
|
'required_with:cidadao.documentos.estrangeiro__brasil.rne',
|
|
'date_format:Y-m-d',
|
|
'after_or_equal:cidadao.data_nascimento',
|
|
'before_or_equal:now',
|
|
],
|
|
'cidadao.documentos.titulo_eleitor' => [
|
|
'nullable',
|
|
'array',
|
|
],
|
|
'cidadao.documentos.titulo_eleitor.id' => [
|
|
'nullable',
|
|
'integer',
|
|
],
|
|
'cidadao.documentos.titulo_eleitor.numero' => [
|
|
'nullable',
|
|
'string',
|
|
'between:9,13',
|
|
'unique:\App\Models\Cadastro\SujeitoAtencao\TituloEleitor,numero,'
|
|
. (($instance->cidadao['documentos']['titulo_eleitor']['id'] ?? null) ?? 'NULL')
|
|
. ',id,deleted_at,NULL',
|
|
],
|
|
'cidadao.documentos.titulo_eleitor.zona' => [
|
|
'nullable',
|
|
'string',
|
|
'required_with:cidadao.documentos.titulo_eleitor.numero',
|
|
'size:4'
|
|
],
|
|
'cidadao.documentos.titulo_eleitor.secao' => [
|
|
'nullable',
|
|
'string',
|
|
'required_with:cidadao.documentos.titulo_eleitor.numero',
|
|
'size:4'
|
|
],
|
|
'cidadao.documentos.certidao' => [
|
|
'nullable',
|
|
'array',
|
|
],
|
|
'cidadao.documentos.certidao.id' => [
|
|
'nullable',
|
|
'integer',
|
|
],
|
|
'cidadao.documentos.certidao.tipo_id' => [
|
|
'nullable',
|
|
'integer',
|
|
],
|
|
'cidadao.documentos.certidao.modelo_id' => [
|
|
'nullable',
|
|
'required_with:cidadao.documentos.certidao.tipo_id',
|
|
'integer',
|
|
],
|
|
'cidadao.documentos.certidao.numero' => [
|
|
'nullable',
|
|
'required_with:cidadao.documentos.certidao.tipo_id',
|
|
(($instance->cidadao['documentos']['certidao']['modelo_id'] ?? null) === ModeloCertidao::ANTIGO
|
|
? 'between:8,40' : 'digits:32'),
|
|
Rule::unique('\App\Models\Cadastro\SujeitoAtencao\Certidao', 'numero')
|
|
->where(function ($query) use ($instance) {
|
|
|
|
return $query
|
|
->where('tipo_id', $instance->cidadao['documentos']['certidao']['tipo_id'] ?? null)
|
|
->whereNull('deleted_at');
|
|
})
|
|
->ignore($instance->cidadao['documentos']['certidao']['id'] ?? null)
|
|
],
|
|
'cidadao.documentos.certidao.cartorio_nome' => [
|
|
'nullable',
|
|
'required_if:cidadao.documentos.certidao.modelo_id,' . ModeloCertidao::ANTIGO,
|
|
'string',
|
|
'max:70',
|
|
],
|
|
'cidadao.documentos.certidao.livro' => [
|
|
'nullable',
|
|
'required_if:cidadao.documentos.certidao.modelo_id,' . ModeloCertidao::ANTIGO,
|
|
'string',
|
|
'max:8'
|
|
],
|
|
'cidadao.documentos.certidao.folha' => [
|
|
'nullable',
|
|
'required_if:cidadao.documentos.certidao.modelo_id,' . ModeloCertidao::ANTIGO,
|
|
'string',
|
|
'between:4,10'
|
|
],
|
|
'cidadao.documentos.certidao.data_emissao' => [
|
|
'nullable',
|
|
'required_if:cidadao.documentos.certidao.modelo_id,' . ModeloCertidao::ANTIGO,
|
|
'date_format:Y-m-d',
|
|
'after_or_equal:cidadao.data_nascimento',
|
|
'before_or_equal:now',
|
|
],
|
|
'cidadao.documentos.certidao.municipio_id' => [
|
|
'nullable',
|
|
'required_if:cidadao.documentos.certidao.modelo_id,' . ModeloCertidao::ANTIGO,
|
|
'integer',
|
|
],
|
|
'cidadao.documentos.certidao.cartorio_codigo' => [
|
|
'nullable',
|
|
'required_if:cidadao.documentos.certidao.modelo_id,' . ModeloCertidao::ANTIGO,
|
|
'string',
|
|
'size:15',
|
|
],
|
|
'cidadao.fatores_risco' => [
|
|
'nullable',
|
|
'array',
|
|
],
|
|
'cidadao.fatores_risco.*' => [
|
|
'required',
|
|
'integer',
|
|
],
|
|
'cidadao.fator_risco_outro' => [
|
|
'nullable',
|
|
Rule::requiredIf(fn () => in_array(FatorRisco::OUTRO, $instance->cidadao['fatores_risco'] ?? [])),
|
|
'string',
|
|
'max:100',
|
|
],
|
|
'cidadao.documentos.outro.protocolo_cross' => [
|
|
'nullable',
|
|
'digits_between:1,10',
|
|
],
|
|
];
|
|
|
|
$rulesEndereco = [
|
|
'cidadao.domicilio.endereco' => [
|
|
'nullable',
|
|
'array',
|
|
],
|
|
'cidadao.domicilio.endereco.logradouro_id' => [
|
|
'nullable',
|
|
'integer',
|
|
],
|
|
'cidadao.domicilio.endereco.numero' => [
|
|
'nullable',
|
|
'digits_between:1,6',
|
|
],
|
|
'cidadao.domicilio.endereco.complemento' => [
|
|
'nullable',
|
|
'string',
|
|
'between:3,180',
|
|
'not_regex:' . ImportacaoCns::regexValidacao(),
|
|
new CnsTermoValido(['attribute' => 'Complemento']),
|
|
],
|
|
'cidadao.domicilio.endereco.referencia' => [
|
|
'nullable',
|
|
'string',
|
|
'max:150',
|
|
'not_regex:' . ImportacaoCns::regexValidacao(),
|
|
new CnsTermoValido(['attribute' => 'Referência']),
|
|
],
|
|
'cidadao.domicilio.endereco.loteamento_id' => [
|
|
'nullable',
|
|
'integer',
|
|
],
|
|
'cidadao.domicilio.endereco.zona_id' => [
|
|
'nullable',
|
|
'required_with:cidadao.domicilio.endereco.logradouro_id',
|
|
'integer',
|
|
],
|
|
'cidadao.domicilio.endereco.latitude' => [
|
|
'nullable',
|
|
'string',
|
|
'size:10',
|
|
],
|
|
'cidadao.domicilio.endereco.longitude' => [
|
|
'nullable',
|
|
'string',
|
|
'size:10',
|
|
],
|
|
];
|
|
|
|
if (empty($params['id']) || !empty($params['id']) && self::hasPermission()) {
|
|
$rules = array_merge($rules, $rulesEndereco);
|
|
}
|
|
|
|
return $rules;
|
|
}
|
|
|
|
public static function hasPermission() {
|
|
|
|
$lotacao = Lotacao::findOrFail(auth()->payload()->get('lotacao_id'));
|
|
$count = ParametrizacaoPermissaoOcupacao::count();
|
|
|
|
return ParametrizacaoPermissaoOcupacao::where('ocupacao_id', $lotacao->ocupacao_id)->exists() || $count === 0;
|
|
}
|
|
|
|
public static function getMessages()
|
|
{
|
|
return [
|
|
'cidadao.documentos.titulo_eleitor.numero.unique' =>
|
|
'O número do Titulo de eleitor já está vinculado a outro cidadão.',
|
|
'cidadao.documentos.carteira_identidade.numero.unique' =>
|
|
'O número da Carteira de identidade já está vinculado a outro cidadão.',
|
|
'cidadao.documentos.carteira_trabalho.numero.unique' =>
|
|
'O número da Carteira de trabalho (CTPS) já está vinculado a outro cidadão.',
|
|
'cidadao.documentos.carteira_nacional_habilitacao.numero.unique' =>
|
|
'O número da Carteira nacional de habilitação (CNH) já está vinculado a outro cidadão.',
|
|
'cidadao.documentos.estrangeiro_entrada_brasil.rne.unique' =>
|
|
'O número do RNE já está vinculado a outro cidadão.',
|
|
'cidadao.documentos.certidao.numero.unique' =>
|
|
'O número da Certidão já está vinculado a outro cidadão.',
|
|
];
|
|
}
|
|
}
|