This commit is contained in:
34
api/app/Rules/Sigtap/CidIsRelatedToProcedimento.php
Normal file
34
api/app/Rules/Sigtap/CidIsRelatedToProcedimento.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules\Sigtap;
|
||||
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CidIsRelatedToProcedimento implements Rule
|
||||
{
|
||||
private $procedimentoId;
|
||||
|
||||
public function __construct($procedimentoId)
|
||||
{
|
||||
$this->procedimentoId = $procedimentoId;
|
||||
}
|
||||
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
return self::isValid($this->procedimentoId, $value);
|
||||
}
|
||||
|
||||
public static function isValid($procedimentoId, $cidId)
|
||||
{
|
||||
return DB::table('sigtap.procedimento_cid as procedimento_cid')
|
||||
->where('procedimento_cid.procedimento_id', $procedimentoId)
|
||||
->where('procedimento_cid.cid_id', $cidId)
|
||||
->exists();
|
||||
}
|
||||
|
||||
public function message()
|
||||
{
|
||||
return 'CID inválido para o procedimento informado.';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user