This commit is contained in:
40
api/app/Rules/Sigtap/ProcedimentoIsValidForIdade.php
Normal file
40
api/app/Rules/Sigtap/ProcedimentoIsValidForIdade.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules\Sigtap;
|
||||
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ProcedimentoIsValidForIdade implements Rule
|
||||
{
|
||||
private $idade;
|
||||
|
||||
public function __construct($idade)
|
||||
{
|
||||
$this->idade = $idade;
|
||||
}
|
||||
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
return self::isValid($this->idade, $value);
|
||||
}
|
||||
|
||||
public static function isValid($idade, $value)
|
||||
{
|
||||
$idade *= 12;
|
||||
|
||||
$procedimento = DB::table('sigtap.procedimento')
|
||||
->where('id', $value)
|
||||
->select('idade_minima', 'idade_maxima')
|
||||
->first();
|
||||
|
||||
return
|
||||
($idade >= $procedimento->idade_minima || $procedimento->idade_minima === 9999) &&
|
||||
($idade <= $procedimento->idade_maxima || $procedimento->idade_maxima === 9999);
|
||||
}
|
||||
|
||||
public function message()
|
||||
{
|
||||
return 'Procedimento inválido para a idade informada.';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user