This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Cadastro\Estabelecimento;
|
||||
|
||||
use App\Http\Requests\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class SalaRequest extends FormRequest
|
||||
{
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
switch ($this->method()) {
|
||||
|
||||
case 'POST':
|
||||
case 'PUT': {
|
||||
|
||||
return $this->getPostPutRules();
|
||||
}
|
||||
default: {
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getPostPutRules()
|
||||
{
|
||||
return [
|
||||
'nome' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:3,30',
|
||||
Rule::unique('\App\Models\Cadastro\Estabelecimento\Sala', 'nome')
|
||||
->where(function ($query) {
|
||||
|
||||
return $query
|
||||
->where('centro_custo_id', $this->centro_custo_id)
|
||||
->whereNull('deleted_at');
|
||||
})
|
||||
->ignore($this->sala)
|
||||
],
|
||||
'centro_custo_id' => [
|
||||
'required',
|
||||
'integer',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'nome.unique' => 'O nome da Sala já foi inserido anteriormente.'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Cadastro\Estabelecimento;
|
||||
|
||||
use App\Http\Requests\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class SetorRequest extends FormRequest
|
||||
{
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
switch($this->method()) {
|
||||
case 'POST':
|
||||
return $this->getPostRules();
|
||||
case 'PUT':
|
||||
return $this->getPutRules();
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
private function getPostRules()
|
||||
{
|
||||
return [
|
||||
'tipo_id' => ['required'],
|
||||
'servico_id' => ['required', 'integer'],
|
||||
'nome' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:3,180',
|
||||
Rule::unique('\App\Models\Cadastro\Estabelecimento\Setor')->where(function ($query) {
|
||||
return $query
|
||||
->where('servico_id', $this->servico_id)
|
||||
->whereNull('deleted_at');
|
||||
}),
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
private function getPutRules()
|
||||
{
|
||||
return [
|
||||
'tipo_id' => ['required'],
|
||||
'servico_id' => ['required', 'integer'],
|
||||
'nome' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:3,180',
|
||||
Rule::unique('\App\Models\Cadastro\Estabelecimento\Setor')->where(function ($query) {
|
||||
return $query
|
||||
->where('servico_id', $this->servico_id)
|
||||
->whereNull('deleted_at');
|
||||
})->ignore($this->setor),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'nome.unique' => 'Um Setor com o mesmo Serviço e Nome já foi inserido anteriormente.'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Cadastro\Estabelecimento;
|
||||
|
||||
use App\Http\Requests\FormRequest;
|
||||
use App\Rules\CnsTermoValido;
|
||||
|
||||
class UnidadeExternaRequest 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()
|
||||
{
|
||||
$regex = '/[^a-zA-Z0-9áéíóúâêîôûãõäëïöüÁÉÍÓÚÂÊÎÔÛÃÕÄËÏÖÜ\'()\/,\s-]/';
|
||||
|
||||
return [
|
||||
'nome_fantasia' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:3,255',
|
||||
'not_regex:' . $regex,
|
||||
new CnsTermoValido(['attribute' => 'Nome Fantasia'])
|
||||
],
|
||||
'municipio_id' => [
|
||||
'required',
|
||||
'integer',
|
||||
'exists:\App\Models\Intranet\Municipio,id'
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,348 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Cadastro\Estabelecimento;
|
||||
|
||||
use App\Rules\CnsTermoValido;
|
||||
use App\Rules\Cnpj;
|
||||
use App\Http\Requests\FormRequest;
|
||||
use App\Utils\ImportacaoCns;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class UnidadeRequest 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();
|
||||
}
|
||||
case 'PUT': {
|
||||
|
||||
return $this->getPutRules();
|
||||
}
|
||||
default: {
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getPostRules()
|
||||
{
|
||||
return [
|
||||
'nome_fantasia' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:3,255',
|
||||
'unique:\App\Models\Cadastro\Estabelecimento\Unidade,nome_fantasia,NULL,id,deleted_at,NULL'
|
||||
],
|
||||
'razao_social' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:3,255',
|
||||
],
|
||||
'cnpj' => [
|
||||
'nullable',
|
||||
'digits:14',
|
||||
new Cnpj(['attribute' => 'CNPJ']),
|
||||
],
|
||||
'tipo_id' => [
|
||||
'required',
|
||||
'integer'
|
||||
],
|
||||
'esfera_administrativa_id' => [
|
||||
'required',
|
||||
'integer'
|
||||
],
|
||||
'natureza_juridica_id' => [
|
||||
'required',
|
||||
'integer'
|
||||
],
|
||||
'pertence_sus' => [
|
||||
'required',
|
||||
'boolean'
|
||||
],
|
||||
'unidade_referencia' => [
|
||||
'required',
|
||||
'boolean'
|
||||
],
|
||||
'unidade_prestadora' => [
|
||||
'required',
|
||||
'boolean'
|
||||
],
|
||||
'gestor_id' => [
|
||||
'nullable',
|
||||
'integer'
|
||||
],
|
||||
'cnes' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'between:7,7',
|
||||
],
|
||||
'email' => [
|
||||
'nullable',
|
||||
'email:rfc,dns',
|
||||
'max:180'
|
||||
],
|
||||
'site' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:180'
|
||||
],
|
||||
'infraestruturas' => [
|
||||
'required',
|
||||
'array'
|
||||
],
|
||||
'infraestruturas.*.infraestrutura_id' => [
|
||||
'nullable',
|
||||
'integer'
|
||||
],
|
||||
'infraestruturas.*.principal' => [
|
||||
'required',
|
||||
'boolean'
|
||||
],
|
||||
'infraestruturas.*.nome' => [
|
||||
'nullable',
|
||||
'required_if:infraestruturas.*.principal,0',
|
||||
'string',
|
||||
'between:3,255',
|
||||
],
|
||||
'infraestruturas.*.telefone' => [
|
||||
'required',
|
||||
'digits_between:10,11'
|
||||
],
|
||||
'infraestruturas.*.endereco' => [
|
||||
'required',
|
||||
'array'
|
||||
],
|
||||
'infraestruturas.*.endereco.logradouro_id' => [
|
||||
'required',
|
||||
'integer'
|
||||
],
|
||||
'infraestruturas.*.endereco.numero' => [
|
||||
'nullable',
|
||||
'digits_between:1,6',
|
||||
],
|
||||
'infraestruturas.*.endereco.complemento' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'not_regex:' . ImportacaoCns::regexValidacao(),
|
||||
new CnsTermoValido(['attribute' => 'Complemento'])
|
||||
],
|
||||
'infraestruturas.*.endereco.zona_id' => [
|
||||
'required',
|
||||
'integer',
|
||||
],
|
||||
'infraestruturas.*.centros_custo' => [
|
||||
'array'
|
||||
],
|
||||
'infraestruturas.*.centros_custo.*.setor_id' => [
|
||||
'required',
|
||||
'integer'
|
||||
],
|
||||
'infraestruturas.*.centros_custo.*.salas' => [
|
||||
'array'
|
||||
],
|
||||
'infraestruturas.*.centros_custo.*.salas.*.nome' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:3,30',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
private function getPutRules()
|
||||
{
|
||||
$custom = [];
|
||||
|
||||
if (is_array($this->infraestruturas)) {
|
||||
|
||||
foreach ($this->infraestruturas as $i => $infraestrutura) {
|
||||
|
||||
if (isset($infraestrutura['centros_custo'])) {
|
||||
|
||||
foreach ($infraestrutura['centros_custo'] as $j => $centroCusto) {
|
||||
|
||||
$custom["infraestruturas.{$i}.centros_custo.{$j}.setor_id"] = [
|
||||
'required',
|
||||
'integer',
|
||||
Rule::unique('\App\Models\Cadastro\Estabelecimento\CentroCusto', 'setor_id')
|
||||
->where(function ($query) use ($infraestrutura) {
|
||||
|
||||
return $query
|
||||
->where('infraestrutura_id', $infraestrutura['id'] ?? null)
|
||||
->whereNull('deleted_at');
|
||||
})
|
||||
->ignore($centroCusto['id'] ?? null)
|
||||
];
|
||||
|
||||
if (isset($centroCusto['salas'])) {
|
||||
|
||||
foreach ($centroCusto['salas'] as $k => $sala) {
|
||||
|
||||
$custom["infraestruturas.{$i}.centros_custo.{$j}.salas.{$k}.nome"] = [
|
||||
'required',
|
||||
'string',
|
||||
'between:3,30',
|
||||
Rule::unique('\App\Models\Cadastro\Estabelecimento\Sala', 'nome')
|
||||
->where(function ($query) use ($centroCusto) {
|
||||
|
||||
return $query
|
||||
->where('centro_custo_id', $centroCusto['id'] ?? null)
|
||||
->whereNull('deleted_at');
|
||||
})
|
||||
->ignore($sala['id'] ?? null)
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array_merge([
|
||||
'nome_fantasia' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:3,255',
|
||||
"unique:\App\Models\Cadastro\Estabelecimento\Unidade,nome_fantasia,{$this->unidade},id,deleted_at,NULL"
|
||||
],
|
||||
'razao_social' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:3,255',
|
||||
],
|
||||
'cnpj' => [
|
||||
'nullable',
|
||||
'digits:14',
|
||||
new Cnpj(['attribute' => 'CNPJ']),
|
||||
],
|
||||
'tipo_id' => [
|
||||
'required',
|
||||
'integer'
|
||||
],
|
||||
'esfera_administrativa_id' => [
|
||||
'required',
|
||||
'integer'
|
||||
],
|
||||
'natureza_juridica_id' => [
|
||||
'required',
|
||||
'integer'
|
||||
],
|
||||
'pertence_sus' => [
|
||||
'required',
|
||||
'boolean'
|
||||
],
|
||||
'unidade_referencia' => [
|
||||
'required',
|
||||
'boolean'
|
||||
],
|
||||
'unidade_prestadora' => [
|
||||
'required',
|
||||
'boolean'
|
||||
],
|
||||
'gestor_id' => [
|
||||
'nullable',
|
||||
'integer'
|
||||
],
|
||||
'cnes' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'between:7,7',
|
||||
],
|
||||
'email' => [
|
||||
'nullable',
|
||||
'email:rfc,dns',
|
||||
'max:180'
|
||||
],
|
||||
'site' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:180'
|
||||
],
|
||||
'infraestruturas' => [
|
||||
'required',
|
||||
'array'
|
||||
],
|
||||
'infraestruturas.*.id' => [
|
||||
'nullable',
|
||||
'integer'
|
||||
],
|
||||
'infraestruturas.*.principal' => [
|
||||
'required',
|
||||
'boolean'
|
||||
],
|
||||
'infraestruturas.*.nome' => [
|
||||
'nullable',
|
||||
'required_if:infraestruturas.*.principal,0',
|
||||
'string',
|
||||
'between:3,255',
|
||||
],
|
||||
'infraestruturas.*.telefone' => [
|
||||
'required',
|
||||
'digits_between:10,11'
|
||||
],
|
||||
'infraestruturas.*.endereco' => [
|
||||
'required',
|
||||
'array'
|
||||
],
|
||||
'infraestruturas.*.endereco.logradouro_id' => [
|
||||
'required',
|
||||
'integer'
|
||||
],
|
||||
'infraestruturas.*.endereco.numero' => [
|
||||
'nullable',
|
||||
'integer',
|
||||
'max:999999',
|
||||
],
|
||||
'infraestruturas.*.endereco.complemento' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'not_regex:' . ImportacaoCns::regexValidacao(),
|
||||
new CnsTermoValido(['attribute' => 'Complemento'])
|
||||
],
|
||||
'infraestruturas.*.endereco.zona_id' => [
|
||||
'required',
|
||||
'integer',
|
||||
],
|
||||
'infraestruturas.*.centros_custo' => [
|
||||
'array'
|
||||
],
|
||||
'infraestruturas.*.centros_custo.*.id' => [
|
||||
'nullable',
|
||||
'integer'
|
||||
],
|
||||
'infraestruturas.*.centros_custo.*.salas' => [
|
||||
'array'
|
||||
],
|
||||
'infraestruturas.*.centros_custo.*.salas.*.id' => [
|
||||
'nullable',
|
||||
'integer'
|
||||
]
|
||||
], $custom);
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'nome_fantasia.unique' => 'Já existe uma unidade com o Nome fantasia informado.',
|
||||
];
|
||||
}
|
||||
}
|
||||
63
api/app/Http/Requests/Cadastro/Localizacao/BairroRequest.php
Normal file
63
api/app/Http/Requests/Cadastro/Localizacao/BairroRequest.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Cadastro\Localizacao;
|
||||
|
||||
use App\Http\Requests\FormRequest;
|
||||
|
||||
class BairroRequest extends FormRequest
|
||||
{
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
switch ($this->method()) {
|
||||
|
||||
case 'POST': {
|
||||
|
||||
return $this->getPostRules();
|
||||
}
|
||||
case 'PUT': {
|
||||
|
||||
return $this->getPutRules();
|
||||
}
|
||||
default: {
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getPostRules()
|
||||
{
|
||||
return [
|
||||
'nome' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:3,180',
|
||||
'unique:\App\Models\Cadastro\Localizacao\Bairro,nome,NULL,id,deleted_at,NULL',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
private function getPutRules()
|
||||
{
|
||||
return [
|
||||
'nome' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:3,180',
|
||||
"unique:\App\Models\Cadastro\Localizacao\Bairro,nome,{$this->bairro},id,deleted_at,NULL",
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'nome.unique' => 'O nome do Bairro já foi inserido anteriormente.'
|
||||
];
|
||||
}
|
||||
}
|
||||
148
api/app/Http/Requests/Cadastro/Localizacao/LogradouroRequest.php
Normal file
148
api/app/Http/Requests/Cadastro/Localizacao/LogradouroRequest.php
Normal file
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Cadastro\Localizacao;
|
||||
|
||||
use App\Http\Requests\FormRequest;
|
||||
use App\Rules\CnsTermoValido;
|
||||
use App\Utils\DataUtil;
|
||||
use App\Utils\ImportacaoCns;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class LogradouroRequest extends FormRequest
|
||||
{
|
||||
private $regexCep = '/[^0-9]/';
|
||||
private $tamanhoNome = '3,250';
|
||||
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
$this->merge([
|
||||
'logradouro_nome' => html_entity_decode($this->logradouro_nome, ENT_QUOTES, 'UTF-8'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
switch ($this->method()) {
|
||||
|
||||
case 'POST': {
|
||||
|
||||
return $this->getPostRules();
|
||||
}
|
||||
case 'PUT': {
|
||||
|
||||
return $this->getPutRules();
|
||||
}
|
||||
default: {
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getPostRules()
|
||||
{
|
||||
if (DataUtil::getBooleanValueFromStringBoolean($this->search_by_base_endereco_nacional) === true) {
|
||||
$rules = [
|
||||
'municipio_id' => ['required', 'integer'],
|
||||
'logradouro_nome' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:' . $this->tamanhoNome,
|
||||
'not_regex:' . ImportacaoCns::regexValidacao(),
|
||||
new CnsTermoValido(['attribute' => 'Nome']),
|
||||
],
|
||||
'logradouro_cep' => [
|
||||
'required',
|
||||
'not_regex:' . $this->regexCep,
|
||||
],
|
||||
];
|
||||
} else {
|
||||
$rules = [
|
||||
'municipio_id' => ['required', 'integer'],
|
||||
'bairro_id' => ['required', 'integer'],
|
||||
'tipo_id' => ['required', 'integer'],
|
||||
'nome' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:' . $this->tamanhoNome,
|
||||
'not_regex:' . ImportacaoCns::regexValidacao(),
|
||||
new CnsTermoValido(['attribute' => 'Nome']),
|
||||
Rule::unique('\App\Models\Cadastro\Localizacao\Logradouro')->where(function ($query) {
|
||||
|
||||
return $query
|
||||
->where('municipio_id', $this->municipio_id)
|
||||
->where('bairro_id', $this->bairro_id)
|
||||
->where('tipo_id', $this->tipo_id)
|
||||
->whereNull('deleted_at');
|
||||
}),
|
||||
],
|
||||
'cep' => [
|
||||
'required',
|
||||
'not_regex:' . $this->regexCep,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
private function getPutRules()
|
||||
{
|
||||
if (DataUtil::getBooleanValueFromStringBoolean($this->search_by_base_endereco_nacional) === true) {
|
||||
$rules = [
|
||||
'municipio_id' => ['required', 'integer'],
|
||||
'nome' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:' . $this->tamanhoNome,
|
||||
'not_regex:' . ImportacaoCns::regexValidacao(),
|
||||
new CnsTermoValido(['attribute' => 'Nome']),
|
||||
],
|
||||
'cep' => [
|
||||
'required',
|
||||
'not_regex:' . $this->regexCep,
|
||||
],
|
||||
];
|
||||
} else {
|
||||
|
||||
$rules = [
|
||||
'municipio_id' => ['required', 'integer'],
|
||||
'bairro_id' => ['required', 'integer'],
|
||||
'tipo_id' => ['required', 'integer'],
|
||||
'nome' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:' . $this->tamanhoNome,
|
||||
'not_regex:' . ImportacaoCns::regexValidacao(),
|
||||
new CnsTermoValido(['attribute' => 'Nome']),
|
||||
Rule::unique('\App\Models\Cadastro\Localizacao\Logradouro')->where(function ($query) {
|
||||
|
||||
return $query
|
||||
->where('municipio_id', $this->municipio_id)
|
||||
->where('bairro_id', $this->bairro_id)
|
||||
->where('tipo_id', $this->tipo_id)
|
||||
->whereNull('deleted_at');
|
||||
})->ignore($this->logradouro)
|
||||
],
|
||||
'cep' => [
|
||||
'required',
|
||||
'not_regex:' . $this->regexCep,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'nome.unique' => 'Um Logradouro com o mesmo Tipo, Bairro, Município e Nome já foi inserido anteriormente.'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Cadastro\Localizacao;
|
||||
|
||||
use App\Http\Requests\FormRequest;
|
||||
|
||||
class LoteamentoRequest extends FormRequest
|
||||
{
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
switch ($this->method()) {
|
||||
|
||||
case 'POST': {
|
||||
|
||||
return $this->getPostRules();
|
||||
}
|
||||
case 'PUT': {
|
||||
|
||||
return $this->getPutRules();
|
||||
}
|
||||
default: {
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getPostRules()
|
||||
{
|
||||
return [
|
||||
'nome' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:1,100',
|
||||
'unique:\App\Models\Cadastro\Localizacao\Loteamento,nome,NULL,id,deleted_at,NULL',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
private function getPutRules()
|
||||
{
|
||||
return [
|
||||
'nome' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:1,100',
|
||||
"unique:\App\Models\Cadastro\Localizacao\Loteamento,nome,{$this->loteamento},id,deleted_at,NULL",
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'nome.unique' => 'O nome do Loteamento já foi inserido anteriormente.'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Cadastro\Medicamento;
|
||||
|
||||
use App\Http\Requests\FormRequest;
|
||||
use App\Models\Cadastro\Medicamento\Medicamento;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class MedicamentoRequest extends FormRequest
|
||||
{
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
switch ($this->method()) {
|
||||
|
||||
case 'POST':
|
||||
case 'PUT': {
|
||||
|
||||
return $this->getPostPutRules();
|
||||
}
|
||||
default: {
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getPostPutRules()
|
||||
{
|
||||
|
||||
return [
|
||||
|
||||
'nome' => [
|
||||
'required',
|
||||
'string',
|
||||
'max:255',
|
||||
Rule::unique(Medicamento::class)->ignore($this->medicamento)
|
||||
],
|
||||
'receita_tipo_id' => ['required', 'integer'],
|
||||
'unidade_medida_id' => ['required', 'integer'],
|
||||
'forma_farmaceutica_id' => ['required', 'integer'],
|
||||
'via_administracao_id' => ['required', 'integer'],
|
||||
'exibir_receita' => ['boolean'],
|
||||
'exibir_prescricao_interna' => ['boolean'],
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'nome.unique' => 'Este medicamento já foi cadastrado!'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Cadastro\SujeitoAtencao;
|
||||
|
||||
use App\Http\Requests\FormRequest;
|
||||
|
||||
class AlergiaRequest extends FormRequest
|
||||
{
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
switch($this->method()) {
|
||||
case 'POST':
|
||||
return $this->getPostPutRules();
|
||||
case 'PUT':
|
||||
return $this->getPostPutRules();
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
private function getPostPutRules()
|
||||
{
|
||||
return [
|
||||
'tipo_id' => [
|
||||
'required',
|
||||
'integer'
|
||||
],
|
||||
'agente_substancia_especifica' => [
|
||||
'required',
|
||||
'string',
|
||||
'min:3',
|
||||
'max:100',
|
||||
'unique:\App\Models\Cadastro\SujeitoAtencao\Alergia,agente_substancia_especifica,'
|
||||
. ($this->alergia ?? 'NULL') . ',id,deleted_at,NULL',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'agente_substancia_especifica.unique' =>
|
||||
'O agente / substância específica da Alergia já foi inserido anteriormente.'
|
||||
];
|
||||
}
|
||||
}
|
||||
677
api/app/Http/Requests/Cadastro/SujeitoAtencao/CidadaoRequest.php
Normal file
677
api/app/Http/Requests/Cadastro/SujeitoAtencao/CidadaoRequest.php
Normal file
@@ -0,0 +1,677 @@
|
||||
<?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.',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Cadastro\SujeitoAtencao;
|
||||
|
||||
use App\Http\Requests\FormRequest;
|
||||
|
||||
class ConvenioMedicoRequest extends FormRequest
|
||||
{
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
switch ($this->method()) {
|
||||
|
||||
case 'POST': {
|
||||
|
||||
return $this->getPostRules();
|
||||
}
|
||||
case 'PUT': {
|
||||
|
||||
return $this->getPutRules();
|
||||
}
|
||||
default: {
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getPostRules()
|
||||
{
|
||||
return [
|
||||
'nome' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:1,50',
|
||||
'unique:\App\Models\Cadastro\SujeitoAtencao\ConvenioMedico,nome,NULL,id,deleted_at,NULL',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
private function getPutRules()
|
||||
{
|
||||
return [
|
||||
'nome' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:1,50',
|
||||
'unique:\App\Models\Cadastro\SujeitoAtencao\ConvenioMedico'
|
||||
. ",nome,{$this->convenio_medico},id,deleted_at,NULL",
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'nome.unique' => 'O nome do Convênio Médico já foi inserido anteriormente.'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Cadastro\SujeitoAtencao;
|
||||
|
||||
use App\Http\Requests\FormRequest;
|
||||
|
||||
class PacienteRequest 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->getPostPutRules();
|
||||
}
|
||||
case 'PUT': {
|
||||
|
||||
return $this->getPostPutRules();
|
||||
}
|
||||
default: {
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getPostPutRules()
|
||||
{
|
||||
$cidadaoRules = array_merge([
|
||||
'cidadao.id' => [
|
||||
'nullable',
|
||||
'integer',
|
||||
'unique:\App\Models\Cadastro\SujeitoAtencao\Paciente,cidadao_id,'
|
||||
. ($this->route('paciente') ?? 'NULL') . ',id,deleted_at,NULL',
|
||||
],
|
||||
], CidadaoRequest::getPostPutRules($this));
|
||||
|
||||
$rules = array_merge($cidadaoRules, [
|
||||
'cadastro_simplificado' => [
|
||||
'required',
|
||||
'boolean',
|
||||
],
|
||||
'sem_documentos_em' => [
|
||||
'nullable',
|
||||
'date'
|
||||
],
|
||||
'email' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'between:5,100',
|
||||
'regex:/(.+)@(.+)\.(.+)/i',
|
||||
],
|
||||
'classificacao_id' => [
|
||||
'required',
|
||||
'integer',
|
||||
],
|
||||
'subclassificacao_id' => [
|
||||
'nullable',
|
||||
'integer',
|
||||
],
|
||||
'validade_inicio' => [
|
||||
'nullable',
|
||||
'date_format:Y-m-d',
|
||||
'before_or_equal:validade_fim',
|
||||
],
|
||||
'validade_fim' => [
|
||||
'nullable',
|
||||
'date_format:Y-m-d',
|
||||
'after_or_equal:validade_inicio',
|
||||
],
|
||||
'prontuario_unidade' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:10',
|
||||
],
|
||||
'unidade_id' => [
|
||||
'required',
|
||||
'integer',
|
||||
],
|
||||
'alimentos_acabaram' => [
|
||||
'nullable',
|
||||
'boolean',
|
||||
'required_unless:comeu_alguns_alimentos,null',
|
||||
],
|
||||
'comeu_alguns_alimentos' => [
|
||||
'nullable',
|
||||
'boolean',
|
||||
'required_unless:alimentos_acabaram,null',
|
||||
],
|
||||
]);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return array_merge(CidadaoRequest::getMessages(), [
|
||||
'comeu_alguns_alimentos.required_unless' =>
|
||||
'O campo "Nos últimos três meses, você comeu apenas alguns alimentos que ainda tinha porque o dinheiro acabou?" é obrigatório.',
|
||||
'alimentos_acabaram.required_unless' =>
|
||||
'O campo "Nos últimos três meses, os alimentos acabaram antes que você tivesse dinheiro para comprar mais comida" é obrigatório.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Cadastro\SujeitoAtencao;
|
||||
|
||||
use App\Http\Requests\FormRequest;
|
||||
use App\Rules\SenhaAntiga;
|
||||
use App\Rules\SenhaAtual;
|
||||
|
||||
class UsuarioPerfilRequest extends FormRequest
|
||||
{
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
switch($this->method()) {
|
||||
case 'PUT':
|
||||
return $this->getPutRules();
|
||||
break;
|
||||
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
private function getPutRules()
|
||||
{
|
||||
return [
|
||||
'email' => ['required'],
|
||||
'senha' => [$this->nova_senha ? 'required' : 'nullable', 'min:8', 'max:100'],
|
||||
'nova_senha' => [
|
||||
$this->senha ? 'required' : 'nullable',
|
||||
'min:8',
|
||||
'max:100',
|
||||
'regex:/^(?=.*\d)(?=.*[a-zA-Z]).{8,}$/',
|
||||
new SenhaAtual($this->usuario_perfil),
|
||||
new SenhaAntiga($this->usuario_perfil),
|
||||
'confirmed',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
134
api/app/Http/Requests/Cadastro/SujeitoAtencao/UsuarioRequest.php
Normal file
134
api/app/Http/Requests/Cadastro/SujeitoAtencao/UsuarioRequest.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Cadastro\SujeitoAtencao;
|
||||
|
||||
use App\Http\Requests\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class UsuarioRequest extends FormRequest
|
||||
{
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
switch ($this->method()) {
|
||||
|
||||
case 'POST': {
|
||||
|
||||
return $this->getPostPutRules();
|
||||
}
|
||||
case 'PUT': {
|
||||
|
||||
return $this->getPostPutRules();
|
||||
}
|
||||
default: {
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getPostPutRules()
|
||||
{
|
||||
$cidadaoRules = array_merge([
|
||||
'cidadao.id' => [
|
||||
'nullable',
|
||||
'integer',
|
||||
'unique:\App\Models\Cadastro\SujeitoAtencao\Usuario,cidadao_id,'
|
||||
. ($this->route('usuario') ?? 'NULL') . ',id,deleted_at,NULL',
|
||||
],
|
||||
], CidadaoRequest::getPostPutRules($this));
|
||||
|
||||
$rules = array_merge($cidadaoRules, [
|
||||
'documentos' => [
|
||||
'nullable',
|
||||
'array',
|
||||
],
|
||||
'documentos.conselho_profissional' => [
|
||||
'nullable',
|
||||
'array',
|
||||
],
|
||||
'documentos.conselho_profissional.registro_tipo_id' => [
|
||||
'nullable',
|
||||
'integer',
|
||||
],
|
||||
'documentos.conselho_profissional.registro_tipo_outro' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:50',
|
||||
],
|
||||
'documentos.conselho_profissional.registro_numero' => [
|
||||
'nullable',
|
||||
'required_with:documentos.conselho_profissional.registro_tipo_id',
|
||||
'string',
|
||||
'max:25',
|
||||
Rule::unique('\App\Models\Cadastro\SujeitoAtencao\Usuario', 'registro_numero')
|
||||
->where(function ($query) {
|
||||
|
||||
return $query
|
||||
->where(
|
||||
'registro_tipo_id',
|
||||
$this->documentos['conselho_profissional']['registro_tipo_id'] ?? null
|
||||
)
|
||||
->whereNull('deleted_at');
|
||||
})
|
||||
->ignore($this->route('usuario') ?? null)
|
||||
],
|
||||
'documentos.conselho_profissional.registro_estado_id' => [
|
||||
'bail',
|
||||
'nullable',
|
||||
'integer',
|
||||
],
|
||||
'email' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'between:5,180',
|
||||
'regex:/(.+)@(.+)\.(.+)/i',
|
||||
'unique:\App\Models\Cadastro\SujeitoAtencao\Usuario,email,'
|
||||
. ($this->route('usuario') ?? 'NULL') . ',id,deleted_at,NULL',
|
||||
],
|
||||
'usuario' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'between:3,100',
|
||||
'unique:\App\Models\Cadastro\SujeitoAtencao\Usuario,usuario,'
|
||||
. ($this->route('usuario') ?? 'NULL') . ',id,deleted_at,NULL',
|
||||
],
|
||||
'lotacoes' => [
|
||||
'array'
|
||||
],
|
||||
'lotacoes.*.id' => [
|
||||
'nullable',
|
||||
'integer'
|
||||
],
|
||||
'lotacoes.*.ocupacao_id' => [
|
||||
'required',
|
||||
'integer'
|
||||
],
|
||||
'lotacoes.*.realiza_atendimento' => [
|
||||
'required',
|
||||
'boolean'
|
||||
],
|
||||
'lotacoes.*.principal' => [
|
||||
'required',
|
||||
'boolean'
|
||||
],
|
||||
]);
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return array_merge(CidadaoRequest::getMessages(), [
|
||||
'email.regex' => 'Informe um email válido.',
|
||||
'email.unique' => 'O Email já está vinculado a outro usuário.',
|
||||
'usuario.unique' => 'O Nome de usuário (Login) já está vinculado a outro usuário.',
|
||||
'documentos.conselho_profissional.registro_numero.unique' =>
|
||||
'O número do Conselho profissional já está vinculado a outro usuário.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Cadastro\SujeitoAtencao;
|
||||
|
||||
use App\Http\Requests\FormRequest;
|
||||
|
||||
class UsuarioTrocaSenhaRequest extends FormRequest
|
||||
{
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
switch($this->method()) {
|
||||
case 'PUT':
|
||||
return $this->getPutRules();
|
||||
break;
|
||||
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
private function getPutRules()
|
||||
{
|
||||
return [
|
||||
'senha' => ['required', 'min:8', 'max:100'],
|
||||
'nova_senha' => ['required', 'min:8', 'max:100'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user